Skip to content

Instantly share code, notes, and snippets.

@nashibao
Created April 9, 2017 06:56
Show Gist options
  • Save nashibao/6d7ed6de680dc5f333bf9bc13bfe1f76 to your computer and use it in GitHub Desktop.
Save nashibao/6d7ed6de680dc5f333bf9bc13bfe1f76 to your computer and use it in GitHub Desktop.
crossfilter sample code
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