Universe
The easiest and fastest way to explore your data
Before Universe, exploring and filtering large datasets in javascript meant constant data looping, complicated indxing, and countless lines of code to dissect your data.
With Universe, you can be there in just a few lines of code. You've got better things to do than write intense map-reduce functions or learn the intricate inner-workings of Crossfilter ;)
Features
- Simple, yet powerful query syntax
- Built on, and tightly integrated with Crossfilter, and Reductio - the fastest multi-dimensional JS data frameworks available
- Real-time updates to query results as you filter
- Flexible filtering system
- Automatic and invisible management of data indexing and memory
Demos
Getting Started
Installation
NPM
npm install crossfilter-universe --save
# the "universe" npm module name is still under negotiation. Stay tuned.
Download from the releases page. Serve the universe.js or universe.min.js file in the top-level directory as part of your application.
Create a new Universe
Pass universe
an array of objects or a Crossfilter instance:
var universe = require('universe')
var myUniverse = universe([
{date: "2011-11-14T16:17:54Z", quantity: 2, total: 190, tip: 100, type: "tab", productIDs: ["001"]},
{date: "2011-11-14T16:20:19Z", quantity: 2, total: 190, tip: 100, type: "tab", productIDs: ["001", "005"]},
{date: "2011-11-14T16:28:54Z", quantity: 1, total: 300, tip: 200, type: "visa", productIDs: ["004", "005"]},
...
])
.then(function(myUniverse){
return myUniverse
})
Query your data
.then(function(myUniverse){
myUniverse.query({
groupBy: 'type'
columns: {
$count: true,
quantity: {
$sum: 'quantity'
},
},
filter: {
quantity: {
$gt: 50
}
},
})
})
Use your data
.then(function(res) {
res.data === [
{"key": "cash","value": {"count": 2,"quantity": {"sum": 3}}},
{"key": "tab","value": {"count": 8,"quantity": {"sum": 16}}},
{"key": "visa","value": {"count": 2,"quantity": {"sum": 2}}}
]
dc.pieChart('#chart')
.dimension(res.dimension)
.group(res.group)
return res.universe
})
Explore your data
As you filter your data on the universe level, every query's result is updated in real-time to reflect changes in aggregation
.then(function(myUniverse) {
return myUniverse.filter('type', 'visa')
})
.then(function(myUniverse) {
return myUniverse.filter('type', ['visa', 'tab'])
})
.then(function(myUniverse) {
return myUniverse.filter('total', [50, 10], true)
})
.then(function(myUniverse) {
return myUniverse.filter('total', {
$lt: {
'$get(total)': {
'$nthLast(3)': {
$column: 'date'
}
}
}
})
})
.then(function(myUniverse){
return myUniverse.filter({
total: function(row){
return (row.quantity * row.sum) > 50
}
})
})
.then(function(myUniverse){
return myUniverse.filter('type')
})
.then(function(myUniverse){
return myUniverse.filterAll()
})
Clean Up
.then(function(myUniverse){
return myUniverse.clear('total')
})
.then(function(myUniverse){
return myUniverse.clear()
})
Pre-compile Columns
Pro-Tip: You can also pre-compile column indices before querying. Otherwise, ad-hoc indices are created and managed automagically for you anyway.
.then(function(myUniverse){
return myUniverse.column('a')
return myUniverse.column(['a', 'b', 'c'])
return myUniverse.column({
key: 'd',
type: 'string'
})
})
API #
universe( [data] , {config} ) #
.query( {queryObject} ) #
.filter( columnKey, filterObject, isArray, replace ) #
.column( columnKey/columnObject ) #
.clear( columnKey/columnObject/[columnKeys/columnObjects] ) #
-
Description
- Clears individual or all column defenitions and indexes
-
Parameters
columnKey
- the column property or array of columns you would like to clear eg.
.clear('total')
.clear({key: ['complex', 'key']})
.clear(['total', 'quantity'])
.clear([{key: ['complex', 'key']}, {key: ['another', 'one']}])
-
Returns
-
[Example](#Clean Up)
.add( [data] ) #
- Description
- Adds additional data to a universe instance. This data will be indexed, aggregated and queries/filters immediately updated when added.
- Parameters
[data]
- An new array of objects similar to the original dataset
- Returns