Managing data filtering, and grouping, simply.
A full interactive example can be found here
TODO: convert Makefile to gulpfile
Quick Example
var DM = dataManager()
.schema({
quantity: {
type: 'integer'
, filter: null
}
, 'date' : {
type: 'date'
, filter: 'reporting_dt'
, group: {
day: {
reduce : 'sum'
, sum: 'quantity'
}
, week: {
reduce : 'sum'
, map: 'week'
, sum: 'item_quantity'
}
}
}
, 'object-class': {
type: 'string'
, filter: 'class_id'
, group: {
objects: {
reduce:'sum'
, sum: 'quantity'
}
}
}
})
.setData(myData)
.filter('object-class','Fruit')
.filter('date',[new Date('2022-12-15'),new Date('2022-12-24')])
var dailyTotals = DM.group('date','day')
.all()
API Summary
- dataManager
-
schema(schema definition:Object) : dataManager
Set the schema definition for this data manager instance.
-
setData(data:Object) : dataManager
Set the data to be managed.
-
filter(field:String, filter:Array|String ) : dataManager
Filter a field by some data. Single and multiple values, and ranges are supported.
Single value : "abc"
Multiple values : ["abc","def"]
Value range : [[100,200]]
-
group(field:String, group:String ) : group
Get the fields grouped set.
-
getDimension(field:String) : dimension
Get the dimension configuration and access to the crossfilter dimension.
-
all() : groupSummary
Get the reduced summary of the entire data set.
** Events supported by dataManager:
Supported events: 'dataChanged','schemaChanged','filterChanged','dimensionCreated','groupCreated'
Example of using events:
DM = new dataManager()
DM.on('schemaChanged',function(oldSchema,newSchema){console.log('The schema changed %s',JSON.stringify(newSchema))})
DM.on('dataChanged',function(field){console.log('Data changed')})
DM.on('dimensionCreated',function(field){console.log('New dimension created for "%s"',field)})
DM.schema({'a':{}})
DM.setData([{a:'one'},{a:'two'},{a:'three'},{a:'ten'},{a:'four'},{a:'three'},{a:'six'},{a:'two'}])
DM.filter('a','two')
var filtered = DM.getDimension('a').top(Infinity)
-
group
-
all()
Get all data for the grouped set
-
order(value: Function)
change the sort order function of the grouping
-
orderNatural()
set the ordering using the natural return of the reduced value
-
reduce(add: Function, remove: Function, initial: Object)
set the reduce functions (this is done automatically from the schema definition)
-
reduceCount() : void
set the reduce function to count the number of rows in group.
-
reduceSum(value: String|Function)
set the reduce function to sum a row, or call a function to return a value to add to the total.
-
size() : int
Get the number of group keys.
-
top(num: int) : Array
Get the top NUM records from the group based on the sort order.
-
dimension
-
column: String
Name of the column in data set that this filter represents.
-
dimension: Object
Direct access to the crossfilter dimension object.
-
filter(data:Array|String) : dimension
Filter this dimension by the provided data.
Single value : "abc"
Multiple values : ["abc","def"]
Value range : [[100,200]]
-
group: function (group:String) : group
get grouping for this dimension by this object.