Created
April 9, 2017 06:56
-
-
Save nashibao/6d7ed6de680dc5f333bf9bc13bfe1f76 to your computer and use it in GitHub Desktop.
crossfilter sample code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = [{fld1: 'type1', fld2: 10},...] | |
cf = crossfilter(data) | |
# create dimension | |
dim1 = cf.dimension (d) -> return d.fld1 | |
dim2 = cf.dimension (d) -> return d.fld2 | |
# create group | |
group = dim2.group (fld2) -> return fld2 % 5 | |
# creaate reducer | |
sumAdd = (p, v) -> return p + v | |
sumReduce = (p, v) -> return p - v | |
reducer = group.reduce sumAdd, sumRemove, 0 | |
# filtering | |
dim1.filter('type1') | |
# get result | |
console.log reducer.top(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment