Sum By Level Node
Hierarchies become much more powerful when you can associate them with numbers. An org chart can not only show the names of each department or region, but can also show annual sales, current headcount, all sorts of values.
Typically, you will have data only for the leaves of the hierarchy (e.g. counts for each department) and must calculate the various totals and subtotals yourself. And you may want a high-level view of just the totals by major division.
The sum_by_level node makes this easy. All you need is the hierarchy and a simple value table with the base values.
Sum_by_level takes 6 parameters:
- Hierarchy. A data table of the hierarchical structure supplied by my hierarchy node. The hierarchy item column must contain labels (strings) identifying each node in the hierarchy.
- Value Table. A two-column table. The column names don't matter, but the first column must contain labels used in the hierarchy and the second column must contain numbers. Labels should be unique. Only labels of leaves are needed; parent totals will be calculated using those values.
- Precision. The desired precision of the totals. 0 will produce integer totals.
- Indent. If checked, labels in the output table will be indented based on their level in the hierarchy.
- Italicize Totals. If checked, parent totals will be shown in bold and italics to differentiate them from the supplied base values.
- Levels to Hide. If set to 0, all rows in the table will be shown. If set to 1, the lowest level values will be hidden, and so forth. If set to more than the number of levels in the hierarchy, the table will be empty.
The node will output a two-column table with the same column headings as the value table, with totals for each parent added in, listed in standard depth-first order.
For the demo, I first create a hierarchy representing an org chart and display that on top using my hier_chart node. I then create a simple value table showing location and sales for all the base items (using random numbers for the sales values). By "base items" I mean the nodes at the end of each subtree, like Singapore and Texas, not the parent items like USA or Asia Pacific.
I then feed the hierarchy and the value table into four copies of the sum_by_level node. Each copy takes in the same data but has different settings. The one on the left hides the lower 3 levels and does not do any formatting. Subsequent copies show progressively more of the table, increase the precision, and show different combinations of indenting and italicizing.
I then feed all four sum_by_level nodes into identical draw_table nodes and combine everything.
Sum_by_levels functions like a tree table. It is collapsible in the sense that you can opt to hide lower levels, handy when dealing with long, detailed tables. If you update your hierarchy, the table will update with it automatically.
I trust people who use Nodebox for data analysis and visualization will see the value in this. Artists may find it dreary, but I can see ways of harnessing this power for purely artistic ends. Consider that a challenge!
In the days ahead I hope to publish more nodes which use the new hierarchy data structure. Stay tuned!
-
sum_by_level_screenshot.png 779 KB
- sum_by_level_node.ndbx.zip 608 KB
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac