使用Crossfilter,是否可以在分组时跟踪最大/最小值? [英] Using Crossfilter, is it possible to track max/min when grouping?
问题描述
使用Crossfilter(https://github.com/square/crossfilter)时,我指定在添加和删除组中的数据时要使用的函数。跟踪运行平均值(使用CoffeeScript)非常简单:
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
}
是否可以跟踪每组的最大值和最小值?我无法弄清楚如何将所有元素保存在一个巨大的数组中并执行d3.min / d3.max。似乎添加/删除数据的效率非常低。
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.
我还想找一种方法告诉Crossfilter从头开始完全重建组,而不是从中删除项目现有的团体。如果应用过滤器,则重置并重建该组。没什么大不了的。
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.
推荐答案
在玩了一下之后,你可以通过再次调用group方法来重建组。
After playing around with this for a bit, you can rebuild the group by just calling the group method again.
这篇关于使用Crossfilter,是否可以在分组时跟踪最大/最小值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!