Skip to content

Commit d415ae6

Browse files
committed
slightly cleaner
1 parent b0ba10a commit d415ae6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

docs/ex/d3/zoomable-pack.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!doctype html>
2-
<notebook>
2+
<notebook theme="air">
33
<title>Zoomable circle packing</title>
44
<script id="1" type="text/markdown">
55
# Zoomable circle packing
@@ -16,20 +16,23 @@
1616
.range(["hsl(152,80%,80%)", "hsl(228,30%,40%)"])
1717
.interpolate(d3.interpolateHcl);
1818

19-
// Compute the layout.
20-
const pack = (data) => d3.pack()
19+
// Create the pack layout.
20+
const pack = d3.pack()
2121
.size([width, height])
22-
.padding(3)
23-
(d3.hierarchy(data)
22+
.padding(3);
23+
24+
// Compute the hierarchy from the JSON data; recursively sum the
25+
// values for each node; sort the tree by descending value; lastly
26+
// apply the pack layout.
27+
const root = pack(d3.hierarchy(data)
2428
.sum((d) => d.value)
2529
.sort((a, b) => b.value - a.value));
26-
const root = pack(data);
2730

2831
// Create the SVG container.
2932
const svg = d3.create("svg")
30-
.attr("viewBox", `-${width / 2} -${height / 2} ${width} ${height}`)
3133
.attr("width", width)
3234
.attr("height", height)
35+
.attr("viewBox", [-width / 2, -height / 2, width, height])
3336
.attr("style", `height: auto; background: ${color(0)}; cursor: pointer;`);
3437

3538
// Append the nodes.

0 commit comments

Comments
 (0)