Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Crossfilter, is it possible to track max/min when grouping?

When using Crossfilter (https://github.com/square/crossfilter), I specify functions to use when adding and removing data from a group. It's fairly trivial to keep track of a running average (using CoffeeScript):

reduceAdd = (p, v) ->
  ++p.count;
  p.sum += v.digit;
  p

reduceRemove = (p, v) ->
  --p.count;
  p.sum -= v.digit;
  p

reduceInitial = ->
  {
    count: 0
    sum: 0
    average: ->
      return 0 if this.count == 0
      return this.sum / this.count
  }

Is it possible to keep track of the max and min of each group? I can't figure out a way short of keeping all elements in a huge array and doing a d3.min / d3.max. It seems that adding/removing data would be extremely inefficient.

I also looked for a way to tell Crossfilter to completely rebuild the group from scratch, rather than removing items from an existing group. If a filter is applied, the group is reset and rebuilt. Nothing obvious.

like image 596
Norman Elton Avatar asked May 09 '12 03:05

Norman Elton


1 Answers

You can use dimension.top(1) and dimension.bottom(1) to retrieve the current min and max. These methods respect any filters that may be active on the crossfilter.

like image 104
2 revs Avatar answered Oct 25 '22 12:10

2 revs