What it is and how it works
Load order: netflow-scene.js, then netflow-hierarchy.js (this module draws through netflow-scene).
The nested views of Netflow Map as an add-on for netflow-engine: Treemap, Sunburst, Icicle, Circle pack and Tree.
layout(view, G, options)finds one parent for each item (from the links, or a box for each group) and lays the tree out.scene(L, options, NetflowScene)turns that layout into netflow-scene drawing lists, so the map's themes, names, key and SVG export apply.- It also holds the tree and drawing helpers that netflow-circular builds on.
- No page, no DOM; netflow-scene is passed in, not loaded.
Why it exists
Netflow Map draws these views from any map: a tree of links, or items grouped by a column. Kept here, the app and any other page use one tested copy. Netflow Map keeps the views built in.
Where it helps
- Seeing what holds how much (Treemap, Icicle, Sunburst, Circle pack).
- Drawing a map's start-out tree as a tidy tree.
- Pages that need these shapes without a chart library.
Not for: editing a tree by hand; it draws the tree it is given or finds.
How it compares
Real trees (2026.11.22; SEC filings and retail orders, 1,000 to 100,000 rows; ungoogled Chromium 156, Firefox 158, WebKitGTK 2.52.6, against d3-hierarchy 3.1.3): ahead in 106 of 108 cells at 21% to 125% of d3's time, 21% to 80% at 100,000 rows; the two cells that are not ahead are 1,000-row cells within the clock step. Earlier, on generated trees, against d3-hierarchy 3.1.2, measured by Netflow Map on its own copy of this code (the same layouts to the last digit) in the cloud test browsers, one at a time, early-stop A/B: ahead on 35 of 36 cases (treemap, icicle, pack and tree at 1,000, 10,000 and 100,000 items), at 0.29 to 0.98 of d3's time; one tie (WebKitGTK icicle at 1,000 items, 1.03, range 0.86 to 1.20). At 100,000 items: 0.29 to 0.78 of d3's time.
How to use it
Use
// netflow-scene.js, then netflow-hierarchy.js
var L = NetflowHierarchy.layout('treemap', { nodes: nodes, edges: edges }, { nest: 'auto', sized: true });
var S = NetflowHierarchy.scene(L, { theme: 'light' }, NetflowScene);
svgElement.outerHTML = NetflowScene.toSvg(S, 'Treemap');
G:{ nodes: [{ id, label, group, sizeV }], edges: [{ from, to, weight, count, widthV }] }(edges from parent to child;sizeVis a box's own size, 1 when missing; a link's amount iswidthVwhen given, else its flow, elseweight, elsecount, the number of times it was taken;nest: 'auto'follows the links when they already form a tree, else boxes bygroupwhen there are 2 or more groups, else the links from the start), plus optionaleAandeB(Int32Array item numbers of each link's ends; with them no id lookup is built).parentKey(option, since 1.9.0): when each item already carries its parent's id in a field, name that field and leaveedgesout:layout('icicle', { nodes: [{ id: 'b', up: 'a' }, ...] }, { nest: 'links', parentKey: 'up' }). An item whose field is missing,null, empty, its own id or an id that is not in the list is a top item. The picture is the same as with the matching list of links, and no list is built unless something readsedgeson the result (the drawing does). It saves building and reading the links: on the icicle layout with no sorting, 5 to 8% less time in ungoogled-chromium 156 and up to half in Firefox 158 at 100,000 items.- Rows as they are (options
sizeKeyandwrite, since 1.10.0): the fastest way to lay out rows that already exist, with no copy of them and nothing written onto them.sizeKey: 'value'reads each item's size from that field instead ofsizeV.write: falseleaves the items untouched: the places stay in the lists ofL.chart(chart.at[i]is the box of itemi;chart.Rholds four numbers per box for treemap, icicle and sunburst,chart.X,chart.Yandchart.Rrhold the centers and radii for tree and circle pack), andchart.placedisfalse.NetflowHierarchy.place(L)writesx,y,w,h,cx,cyandhvonto the items when you want them, andscene()calls it itself, so drawing needs no extra step. Example:layout('icicle', { nodes: rows }, { nest: 'links', parentKey: 'parent', sizeKey: 'value', write: false }). Same picture as the usual way. Measured against d3-hierarchy 3.1.3 fed the same rows, on 100 items in ungoogled-chromium 156: 0.44 to 0.62 of its time across the five views. - Small trees (since 1.10.0): layouts of up to about 300 items cut their lists from shared blocks of memory (each block is about 130 KB or less and is let go when the layouts that use it are), and trees of up to 32 boxes get
kids,labelandgroupat once instead of on first read. A 3-item layout takes about a fifth of the time it took in 1.9.0 in ungoogled-chromium 156. Results are the same. - Tiny trees (icicle and sunburst since 1.11.0, treemap, circle pack and tree since 1.12.0): trees of up to 24 items that name their own parent (
parentKey) are laid out by their own small piece of code, which shares nothing with the general path (plain lists in it made the code that lays out big trees slower for seconds afterwards, so it is kept apart). The result is the same as the general path gives. Against d3-hierarchy 3.1.3 fed the same rows in ungoogled-chromium 156, Firefox 158 and WebKitGTK 2.52.6, trees of 10 to 24 items take about 0.5 to 1.0 of d3's time in every view; at 3 items WebKitGTK's one-millisecond clock cannot tell the two apart. A loop, an item marked as the start, nesting by group,nest: 'auto'with no link at all, or a size that is not a plain number (treemap) use the general path. - Speed tip: a layout writes seven fields onto each item (
x,y,w,h,cx,cy,hv). Chromium is slow at adding fields to an object after it is made, so make each item with them already present:{ id, label, sizeV, x: 0, y: 0, w: 0, h: 0, cx: 0, cy: 0, hv: 0 }. Measured on the icicle layout in ungoogled-chromium 156: 12% less time at 1,000 items and 23% less at 100,000. Firefox 158 and WebKitGTK 2.52.6 do not change. The picture is the same either way. - Views:
treemap,sunburst,icicle,pack,tree(NetflowHierarchy.VIEWS). - Options:
nest(auto,linksorgroups),sized(box sizes fromsizeV),treeShape(tidy, the default,cluster,radial,radialClusterorindented). - Title block (optional, off unless given):
title(bold, top left),subtitle(under it) andsource(small, under the picture), set in thescene()options. The block sits outside the picture, so nothing in the picture moves, and the SVG export draws it. - Helpers:
hierarchy,sums,place,packSiblings,enclose,linkValue,itemValue,sector,pushSector. typedRects: true(option ofscene, since 1.7.0): treemap and icicle tiles are written toS.rectsTas typed arrays (x,y,w,has Float64Array,nodeas Int32Array with -1 for none,fillandstrokeas indexes intofillsandstrokes,sw,a; every tile has layer 1 and radius 0) instead of one object each inS.rects, which is then empty.toSvgandstyle(netflow-scene 1.14.0 or newer) handle both forms and give the same picture text;NetflowScene.rectTAt(S.rectsT, i)returns tileias the usual object. The object form stays the default. With an older netflow-scene the option is ignored.NetflowHierarchy.warm()(optional, since 1.6.0): call it from an idle callback, afternetflow-scene.jshas loaded. It draws a small made-up treemap and sunburst once and throws them away, so the engine has already optimized the drawing code when your first real picture comes. 6 to 11 ms of work; the first treemap and sunburst of 250 items then took 0.50 (ungoogled Chromium 156), 0.82 (Firefox 158) and 0.60 (WebKitGTK 2.52.6) of the time without it. Returnstrue, orfalsewhenNetflowSceneis missing. Pictures are the same with or without it.
Use with netflow-engine: load the files as page scripts (or keep the folders side by side in Node) and the views join NetflowEngine.VIEWS; or hand them over with NetflowEngine.use('hierarchy', NetflowHierarchy). Then NetflowEngine.build(graph, { view: 'treemap' }) lays the map out and NetflowHierarchy.scene(L, options, NetflowScene) draws it.
Use
// netflow-scene.js, then netflow-hierarchy.js
var L = NetflowHierarchy.layout('treemap', { nodes: nodes, edges: edges }, { nest: 'auto', sized: true });
var S = NetflowHierarchy.scene(L, { theme: 'light' }, NetflowScene);
svgElement.outerHTML = NetflowScene.toSvg(S, 'Treemap');
G:{ nodes: [{ id, label, group, sizeV }], edges: [{ from, to, weight, count, widthV }] }(edges from parent to child;sizeVis a box's own size, 1 when missing; a link's amount iswidthVwhen given, else its flow, elseweight, elsecount, the number of times it was taken;nest: 'auto'follows the links when they already form a tree, else boxes bygroupwhen there are 2 or more groups, else the links from the start), plus optionaleAandeB(Int32Array item numbers of each link's ends; with them no id lookup is built).parentKey(option, since 1.9.0): when each item already carries its parent's id in a field, name that field and leaveedgesout:layout('icicle', { nodes: [{ id: 'b', up: 'a' }, ...] }, { nest: 'links', parentKey: 'up' }). An item whose field is missing,null, empty, its own id or an id that is not in the list is a top item. The picture is the same as with the matching list of links, and no list is built unless something readsedgeson the result (the drawing does). It saves building and reading the links: on the icicle layout with no sorting, 5 to 8% less time in ungoogled-chromium 156 and up to half in Firefox 158 at 100,000 items.- Rows as they are (options
sizeKeyandwrite, since 1.10.0): the fastest way to lay out rows that already exist, with no copy of them and nothing written onto them.sizeKey: 'value'reads each item's size from that field instead ofsizeV.write: falseleaves the items untouched: the places stay in the lists ofL.chart(chart.at[i]is the box of itemi;chart.Rholds four numbers per box for treemap, icicle and sunburst,chart.X,chart.Yandchart.Rrhold the centers and radii for tree and circle pack), andchart.placedisfalse.NetflowHierarchy.place(L)writesx,y,w,h,cx,cyandhvonto the items when you want them, andscene()calls it itself, so drawing needs no extra step. Example:layout('icicle', { nodes: rows }, { nest: 'links', parentKey: 'parent', sizeKey: 'value', write: false }). Same picture as the usual way. Measured against d3-hierarchy 3.1.3 fed the same rows, on 100 items in ungoogled-chromium 156: 0.44 to 0.62 of its time across the five views. - Small trees (since 1.10.0): layouts of up to about 300 items cut their lists from shared blocks of memory (each block is about 130 KB or less and is let go when the layouts that use it are), and trees of up to 32 boxes get
kids,labelandgroupat once instead of on first read. A 3-item layout takes about a fifth of the time it took in 1.9.0 in ungoogled-chromium 156. Results are the same. - Tiny trees (icicle and sunburst since 1.11.0, treemap, circle pack and tree since 1.12.0): trees of up to 24 items that name their own parent (
parentKey) are laid out by their own small piece of code, which shares nothing with the general path (plain lists in it made the code that lays out big trees slower for seconds afterwards, so it is kept apart). The result is the same as the general path gives. Against d3-hierarchy 3.1.3 fed the same rows in ungoogled-chromium 156, Firefox 158 and WebKitGTK 2.52.6, trees of 10 to 24 items take about 0.5 to 1.0 of d3's time in every view; at 3 items WebKitGTK's one-millisecond clock cannot tell the two apart. A loop, an item marked as the start, nesting by group,nest: 'auto'with no link at all, or a size that is not a plain number (treemap) use the general path. - Speed tip: a layout writes seven fields onto each item (
x,y,w,h,cx,cy,hv). Chromium is slow at adding fields to an object after it is made, so make each item with them already present:{ id, label, sizeV, x: 0, y: 0, w: 0, h: 0, cx: 0, cy: 0, hv: 0 }. Measured on the icicle layout in ungoogled-chromium 156: 12% less time at 1,000 items and 23% less at 100,000. Firefox 158 and WebKitGTK 2.52.6 do not change. The picture is the same either way. - Views:
treemap,sunburst,icicle,pack,tree(NetflowHierarchy.VIEWS). - Options:
nest(auto,linksorgroups),sized(box sizes fromsizeV),treeShape(tidy, the default,cluster,radial,radialClusterorindented). - Title block (optional, off unless given):
title(bold, top left),subtitle(under it) andsource(small, under the picture), set in thescene()options. The block sits outside the picture, so nothing in the picture moves, and the SVG export draws it. - Helpers:
hierarchy,sums,place,packSiblings,enclose,linkValue,itemValue,sector,pushSector. typedRects: true(option ofscene, since 1.7.0): treemap and icicle tiles are written toS.rectsTas typed arrays (x,y,w,has Float64Array,nodeas Int32Array with -1 for none,fillandstrokeas indexes intofillsandstrokes,sw,a; every tile has layer 1 and radius 0) instead of one object each inS.rects, which is then empty.toSvgandstyle(netflow-scene 1.14.0 or newer) handle both forms and give the same picture text;NetflowScene.rectTAt(S.rectsT, i)returns tileias the usual object. The object form stays the default. With an older netflow-scene the option is ignored.NetflowHierarchy.warm()(optional, since 1.6.0): call it from an idle callback, afternetflow-scene.jshas loaded. It draws a small made-up treemap and sunburst once and throws them away, so the engine has already optimized the drawing code when your first real picture comes. 6 to 11 ms of work; the first treemap and sunburst of 250 items then took 0.50 (ungoogled Chromium 156), 0.82 (Firefox 158) and 0.60 (WebKitGTK 2.52.6) of the time without it. Returnstrue, orfalsewhenNetflowSceneis missing. Pictures are the same with or without it.
Use with netflow-engine: load the files as page scripts (or keep the folders side by side in Node) and the views join NetflowEngine.VIEWS; or hand them over with NetflowEngine.use('hierarchy', NetflowHierarchy). Then NetflowEngine.build(graph, { view: 'treemap' }) lays the map out and NetflowHierarchy.scene(L, options, NetflowScene) draws it.
Speed and efficiency numbers
Measured on real trees: cloud Chromium 156.0.8078.79, Firefox 158.0 and WebKitGTK 2.52.6 against d3-hierarchy 3.1.3, one browser at a time, 2026.11.22
The trees are real: the SEC 2026 Q1 numbers file (filing, then statement tag, then each value row) and the retail e-commerce file (country, then item, then each order line), cut to the first 1,000, 10,000 and 100,000 rows, sizes from the real value and quantity columns. Same job both ways: build the tree from rows, sum, sort, lay out (the method of testers/hierarchy-icicle-vs-d3-tester.html, 7 alternating rounds, 3 at 100,000 items). Whole milliseconds are all Firefox and WebKitGTK report, so small cells carry a rounding of up to 1 ms. This replaces the earlier generated trees.
Compared: netflow-hierarchy against d3-hierarchy on real trees (layout of 100,000 rows, percent of d3-hierarchy's time, lower is faster; Chromium / Firefox / WebKitGTK).
Across all 108 cells (2 real trees x 3 sizes x 6 layouts x 3 browsers) netflow-hierarchy is faster in 106, at 21% to 125% of d3's time; the two cells that are not faster are small (WebKitGTK tree at 1,000 SEC rows 1.25, Firefox unsorted icicle at 1,000 retail rows 1.13, within the clock steps). Harness and raw results: tools/real-corpus.
Source: Measured on real trees: cloud Chromium 156.0.8078.79, Firefox 158.0 and WebKitGTK 2.52.6 against d3-hierarchy 3.1.3, one browser at a time, 2026.11.22.
Against d3-hierarchy 3.1.3 on generated trees (earlier measurement, not re-run on real trees here)
The same job from the same rows: build the tree, sum, sort the children and lay out 100,000 items into positioned boxes, all five views. A fresh page for every library, one browser at a time, shared 4-core cloud machine. Time is shown as a percent of d3-hierarchy's time, so d3-hierarchy is always 100 and lower is faster.
Compared: netflow-hierarchy against d3-hierarchy 3.1.3 (layout of 100,000 items, percent of d3-hierarchy's time, lower is faster).
The lead is smaller on smaller charts. At 10,000 items netflow-hierarchy takes 43 to 94% of d3-hierarchy's time, and at 1,000 items 53 to 86%; in no view and no browser is it behind. Circle pack was measured again at version 1.8.2 on a mixed tree. On a tree with two children per item, a shape where earlier versions were slower than d3-hierarchy, circle pack now takes 0.60 to 0.70, 0.55 and 0.55 of d3-hierarchy's time at 1,000, 10,000 and 100,000 items in Chromium, 0.95, 0.67 and 0.66 in Firefox, and 0.71, 0.56 and 0.53 in WebKitGTK. Cloud test browsers only; laptop numbers are still to come.
Compared: netflow-hierarchy against d3-hierarchy 3.1.3 on an Android phone (Chrome 157), run by the owner on 2026-11-21 (layout of 100,000 items, percent of d3-hierarchy's time, middle tree shape, lower is faster).
The phone run covers five views, icicle without sorting, five tree shapes and 1,000, 10,000 and 100,000 items: 90 races, all won by netflow-hierarchy. The best result was 0.32 of d3-hierarchy's time and the closest 0.93. At 10,000 items the middle tree shape takes 43 to 71% and at 1,000 items 47 to 78%. In this test netflow-hierarchy's items are made with their seven output fields already present, as the netflow-hierarchy README advises. This is one phone, so it shows direction rather than a guarantee.
A second phone run, on version 1.10.0 (the owner's Quick run of 31 races on the same phone, 2026-11-21, 4:59 PM Detroit, rows fed untouched to both libraries), was faster than d3-hierarchy 3.1.3 in all 31 races: the best result was 0.34 of d3-hierarchy's time and the closest 0.87. The chart above is the earlier run on 1.8.2.
Size is the one place d3-hierarchy is smaller, and the two are not the same job. d3-hierarchy 3.1.3 minified is 14.8 KB (5.8 KB gzipped) and does layout only. netflow-hierarchy ships a minified copy of 32.5 KB (14.6 KB gzipped) that does layout and drawing in one file (the readable file is 22.6 KB gzipped), and its layout part alone is about 16.3 KB (7.4 KB gzipped). So d3-hierarchy is smaller and no size win is claimed.
Source: Against d3-hierarchy 3.1.3 on generated trees (earlier measurement, not re-run on real trees here).
Credits
The code is Netflow Map's own (LFC Foundry), cut out for this module; no code from other projects.
Original sources (links checked 2026-11-14; ideas only):
- Treemap: Bruls, Huizing and van Wijk, "Squarified Treemaps", 2000
- Tree: Reingold and Tilford, "Tidier Drawings of Trees", IEEE TSE, 1981, in the linear-time form of Buchheim, Junger and Leipert, "Improving Walker's Algorithm to Run in Linear Time", Graph Drawing 2002
- Circle pack: Wang, Wang, Dai and Wang, "Visualization of large hierarchical data by circle packing", CHI 2006, with the smallest enclosing circle by Emo Welzl, "Smallest enclosing disks (balls and ellipsoids)", 1991