交叉滤镜减少功能 [英] Crossfilter reduce functions
问题描述
我想了解Crossfilter中如何使用reduce函数。即
I want to understand how the reduce functions are used in Crossfilter. Namely, the
reduceAdd(p,v){...}
reduceRemove(p,v){...}
和
reduceInitial(p,v){...}
in
group.reduce(reduceAdd, reduceRemove, reduceInitial);
来自交叉过滤器的API参考,我知道 p
和 v
参数分别表示组和维值。
From Crossfilter's API reference, I understand that the p
and v
arguments represent the group and dimension value respectively.
据我了解,reduce函数的返回值确定在元素之后应将groupValue更改为什么从组中添加或删除。
From what I understand, the return value of the reduce functions determine what the groupValue should be changed to after the element is added or removed from the group. Is this correct?
另外,reduceInitial函数的作用是什么?
Also, what is the reduceInitial function for?
推荐答案
如果您在编写的内容中将 bin value替换为 groupValue,那是正确的。
That is correct, if you substitute "bin value" for "groupValue" in what you wrote.
一组由一组垃圾箱组成;每个bin是一个键值对。对于每个组,提供给交叉过滤器的所有数据行将落入一个或另一个容器中。 reduce函数确定当某行落入bin或由于过滤器发生更改而将其从中删除时会发生什么。
A group is made of an array of bins; each bin is a key-value pair. For every group, all rows of the data supplied to crossfilter will "fall into" one bin or another. The reduce functions determine what happens when a row falls into a bin, or is removed from it because the filters changed.
Crossfilter通过使用来确定任何行落入哪个bin 维度值访问器和组值函数。
Crossfilter determines which bin any row falls into by using using the dimension value accessor and the group value function.
当交叉过滤器初始化新组时,它会将所有当前匹配的数据行添加到所有组中。该组使用维度值访问器和组值函数为每一行确定一个 key 。然后,它将使用该键查找bin,并将 reduceAdd
函数应用于先前的bin值和行数据以产生新的bin值。
When a crossfilter initializes a new group, it adds all the currently matching rows of the data to all the groups. The group determines a key for each row by using the dimension value accessor and the group value function. Then it looks up the bin using that key, and applies the reduceAdd
function to the previous bin value and the row data to produce the new bin value.
当交叉过滤器的任何维度上的任何过滤器更改值时,某些行将停止匹配,而某些行将开始匹配新的过滤器集。使用 reduceRemove
函数从匹配库中删除行,并添加开始匹配的行。 >使用 reduceAdd
函数。
When any filter on any dimension of the crossfilter changes value, some rows will stop matching and some rows will start matching the new set of filters. The rows that stop matching are removed from the matching bin using the reduceRemove
function, and the rows that start matching are added using the reduceAdd
function.
添加一行后,某些组可能没有与之匹配的bin该行的键。那时必须初始化一个新的容器,然后该组调用 reduceInitial
以获取用户指定的该容器的空白值
When a row is added, some groups may not already have a bin which matches the key for that row. At that point a new bin must be initialized and at that point the group calls reduceInitial
to get the user-specified blank value for the bins of that group.
reduceAdd
和 reduceRemove
函数类似于您将传递给Javascript Array.reduce函数。第一个参数 p
获取bin的先前值,第二个参数 v
获取当前要考虑的行数据。
The reduceAdd
and reduceRemove
functions are similar to the functions you would pass to Javascript's Array.reduce function. The first parameter p
takes the previous value of the bin, and the second paramter v
takes the current row data being considered.
与 Array.reduce
相比,在 group.reduce $ c中$ c>
- 可以删除和添加值
- 初始值由
reduceInitial
函数而不是传递给reduce
- 立即执行聚合;相反,您提供的功能是在过滤器发生更改或添加或删除数据时将被调用
- values can be removed as well as added
- the initial value is produced by the
reduceInitial
function instead of being passed toreduce
- it doesn't perform the aggregation immediately; instead you are supplying functions that will get called whenever filters change or data is added or removed
这篇关于交叉滤镜减少功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!