D3 Treemap多参数叠加 [英] D3 Treemap multiple parameter summing up the stack
问题描述
这其实是一个奇怪的问题。我正在处理此 https://secure.polisci.ohio-state。 edu / faq / d3 / zoomabletreemap_code.php ,目前尝试在树形图中传递多个参数,并尝试将它们合并到堆栈中,这些操作大多数是在可缩放树形图中完成的。
This is actually a strange question. I am working on this https://secure.polisci.ohio-state.edu/faq/d3/zoomabletreemap_code.php and currently trying to pass more than one parameter in the treemap and trying to sum them up the stack, as whats mostly done in zoomable treemap.
为此更改记录的代码如下:
The code documented for this change is given as:
// Aggregate the values for internal nodes. This is normally done by the
// treemap layout, but not here because of our custom implementation.
function accumulate(d) {
return d.children
? d.value = d.children.reduce(function(p, v) { return p + accumulate(v); }, 0)
: d.value;
}
但是在我的方法中,我总结了使用多个参数,说值和计数。
我试图改变相同的代码添加两个参数,但是did not似乎做的伎俩,有人可以指导我:
But in my approach I have to sum up using more than one parameter, say value and count. I tried to change the same code to add two parameters, but that didnt seem to do the trick, could someone guide me please:
function accumulate(d) {
return d.children
? d.value = d.children.reduce(function(p, v) { return p + accumulate(v); }, 0)
: d.value;
}
function accumulate1(d) {
return d.children
? d.count = d.children.reduce(function(p, v) { return p + accumulate(v); }, 0)
: d.count;
}
作为两个单独的函数,然后单独调用它们以计数和值从叶节点开始。
但是这不工作。
As two separate function, and then calling them separately to sum both count and value up the stack, starting from leaf nodes. But this is not working. Could you please guide me?
推荐答案
您应该能够将 accumulate
function:
You should be able to sum both values in the accumulate
function:
function accumulate(d) {
return d.children
? d.value = d.children.reduce(function(p, v) { return p + accumulate(v); }, 0)
: d.value + d.count;
}
这篇关于D3 Treemap多参数叠加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!