d3.js - Treemap where parent's value is greater than sum of its children

只谈情不闲聊 提交于 2019-12-23 02:43:11

问题


I am trying to use d3.js to display a treemap where a parent's value may be greater than the sum of its children. For example, say I am visualizing lines of code in a namespace hierarchy. Namespace B and C are children of A and are 1 line each. Namespace A is 3 lines - 1 line for B and C and 1 line for itself. Thus B and C alone do not dictate the size of A.

I want to display this property on the treemap. In particular, the parent should be a rectangle on top of the children rectangles whose size is correctly proportional. If the parent does not add any additional size, the parent should still be displayed but at minimal size (maybe a tiny rectangle spanning the top of the children, just to indicate the parent name).

Currently the children value nodes are just propagated up the hierarchy disregarding the actual size of non-leaf nodes.

I would like a solution in d3.js, because that is the library I am using in the rest of the code, but I am open to another framework if it solves the problem.

Thank you.


回答1:


You may want to try pull request #574 which allows internal hierarchy nodes to have value.

Otherwise, you could add invisible dummy nodes to your data that contain the extra value associated with internal nodes but not accounted for by their children. When you render the treemap, you can filter those nodes to prevent them from being displayed (even though they're part of the layout). Or you could set their style to display: none.



来源:https://stackoverflow.com/questions/11253740/d3-js-treemap-where-parents-value-is-greater-than-sum-of-its-children

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!