D3.js nesting and rollup at the same time in v4

丶灬走出姿态 提交于 2019-12-01 08:51:41

The v4 changelog tells us that

When used in conjunction with nest.rollup, nest.entries now returns {key, value} objects for the leaf entries, instead of {key, values}.

It is this little renaming from values to value within the leaf nodes which eventually breaks the code. Changing the helper function accordingly should get you back on track:

// Recursively sum up children's values
function sumChildren(node) {
  if (node.value) {
    node.values = node.value;   // Ensure, leaf nodes will also have a values array
    delete node.value;          // ...instead of a single value
  }
  node.Population = node.values.reduce(function(r, v) {
    return r + (v.value? sumChildren(v) : v.Population);
  },0);
  return node.Population;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!