Skip to content

Commit 2773cd9

Browse files
committed
Adopt inline(true) for all hierarchy examples.
The ones with transitions were a bit trickier, because they depended on the layout creating new copy of the nodes when the layout runs.
1 parent 7f5fa42 commit 2773cd9

15 files changed

Lines changed: 86 additions & 62 deletions

examples/bubble/bubble.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var r = 960,
33
fill = d3.scale.category20c();
44

55
var bubble = d3.layout.pack()
6+
.inline(true)
67
.sort(null)
78
.size([r, r]);
89

@@ -20,16 +21,16 @@ d3.json("flare.json", function(json) {
2021
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
2122

2223
node.append("svg:title")
23-
.text(function(d) { return d.data.className + ": " + format(d.value); });
24+
.text(function(d) { return d.className + ": " + format(d.value); });
2425

2526
node.append("svg:circle")
2627
.attr("r", function(d) { return d.r; })
27-
.style("fill", function(d) { return fill(d.data.packageName); });
28+
.style("fill", function(d) { return fill(d.packageName); });
2829

2930
node.append("svg:text")
3031
.attr("text-anchor", "middle")
3132
.attr("dy", ".3em")
32-
.text(function(d) { return d.data.className.substring(0, d.r / 3); });
33+
.text(function(d) { return d.className.substring(0, d.r / 3); });
3334
});
3435

3536
// Returns a flattened hierarchy containing all leaf nodes under the root.

examples/bundle/bundle-radial.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var r = 960 / 2,
22
splines = [];
33

44
var cluster = d3.layout.cluster()
5+
.inline(true)
56
.size([360, r - 120])
67
.sort(null)
78
.value(function(d) { return d.size; });
@@ -40,7 +41,7 @@ d3.json("flare-imports.json", function(classes) {
4041
.attr("dy", ".31em")
4142
.attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
4243
.attr("transform", function(d) { return d.x < 180 ? null : "rotate(180)"; })
43-
.text(function(d) { return d.data.key; });
44+
.text(function(d) { return d.key; });
4445
});
4546

4647
d3.select(window).on("mousemove", function() {

examples/bundle/bundle-treemap.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var w = 960,
44
stroke = d3.scale.linear().domain([0, 1e4]).range(["brown", "steelblue"]);
55

66
var treemap = d3.layout.treemap()
7+
.inline(true)
78
.size([w, h])
89
.value(function(d) { return d.size; });
910

@@ -28,9 +29,9 @@ d3.json("flare-imports.json", function(classes) {
2829
.data(nodes)
2930
.enter().append("div")
3031
.attr("class", "cell")
31-
.style("background", function(d) { return d.children ? fill(d.data.key) : null; })
32+
.style("background", function(d) { return d.children ? fill(d.key) : null; })
3233
.call(cell)
33-
.text(function(d) { return d.children ? null : d.data.key; });
34+
.text(function(d) { return d.children ? null : d.key; });
3435

3536
div.append("svg:svg")
3637
.attr("width", w)

examples/bundle/packages.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232

3333
// Compute a map from name to node.
3434
nodes.forEach(function(d) {
35-
map[d.data.name] = d;
35+
map[d.name] = d;
3636
});
3737

3838
// For each import, construct a link from the source to target node.
3939
nodes.forEach(function(d) {
40-
if (d.data.imports) d.data.imports.forEach(function(i) {
41-
imports.push({source: map[d.data.name], target: map[i]});
40+
if (d.imports) d.imports.forEach(function(i) {
41+
imports.push({source: map[d.name], target: map[i]});
4242
});
4343
});
4444

examples/cluster/cluster-radial.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var r = 960 / 2;
22

33
var cluster = d3.layout.cluster()
4+
.inline(true)
45
.size([360, r - 120])
56
.sort(null)
67
.children(function(d) { return isNaN(d.value) ? d3.entries(d.value) : null; });
@@ -37,5 +38,5 @@ d3.json("flare.json", function(json) {
3738
.attr("dy", ".31em")
3839
.attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
3940
.attr("transform", function(d) { return d.x < 180 ? null : "rotate(180)"; })
40-
.text(function(d) { return d.data.key; });
41+
.text(function(d) { return d.key; });
4142
});

examples/cluster/cluster.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var w = 960,
22
h = 2200;
33

44
var cluster = d3.layout.cluster()
5+
.inline(true)
56
.size([h, w - 160])
67
.sort(null)
78
.children(function(d) { return isNaN(d.value) ? d3.entries(d.value) : null; });
@@ -37,5 +38,5 @@ d3.json("flare.json", function(json) {
3738
.attr("dx", function(d) { return d.children ? -8 : 8; })
3839
.attr("dy", 3)
3940
.attr("text-anchor", function(d) { return d.children ? "end" : "start"; })
40-
.text(function(d) { return d.data.key; });
41+
.text(function(d) { return d.key; });
4142
});

examples/pack/pack.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var w = 960,
33
format = d3.format(",d");
44

55
var pack = d3.layout.pack()
6+
.inline(true)
67
.size([w - 4, h - 4])
78
.children(function(d) { return isNaN(d.value) ? d3.entries(d.value) : null; });
89

@@ -21,13 +22,13 @@ d3.json("flare.json", function(json) {
2122
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
2223

2324
node.append("svg:title")
24-
.text(function(d) { return d.data.key + (d.children ? "" : ": " + format(d.value)); });
25+
.text(function(d) { return d.key + (d.children ? "" : ": " + format(d.value)); });
2526

2627
node.append("svg:circle")
2728
.attr("r", function(d) { return d.r; });
2829

2930
node.filter(function(d) { return !d.children; }).append("svg:text")
3031
.attr("text-anchor", "middle")
3132
.attr("dy", ".3em")
32-
.text(function(d) { return d.data.key.substring(0, d.r / 3); });
33+
.text(function(d) { return d.key.substring(0, d.r / 3); });
3334
});

examples/partition/partition-icicle-zoom.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
.attr("height", h);
2929

3030
var partition = d3.layout.partition()
31+
.inline(true)
3132
.children(function(d) { return isNaN(d.value) ? d3.entries(d.value) : null; })
3233
.value(function(d) { return d.value; });
3334

@@ -39,7 +40,7 @@
3940
.attr("y", function(d) { return y(d.y); })
4041
.attr("width", function(d) { return x(d.dx); })
4142
.attr("height", function(d) { return y(d.dy); })
42-
.attr("fill", function(d) { return color((d.children ? d : d.parent).data.key); })
43+
.attr("fill", function(d) { return color((d.children ? d : d.parent).key); })
4344
.on("click", click);
4445

4546
function click(d) {

examples/partition/partition-icicle.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
.attr("height", h);
2727

2828
var partition = d3.layout.partition()
29+
.inline(true)
2930
.size([w, h])
3031
.children(function(d) { return isNaN(d.value) ? d3.entries(d.value) : null; })
3132
.value(function(d) { return d.value; });
@@ -38,7 +39,7 @@
3839
.attr("y", function(d) { return d.y; })
3940
.attr("width", function(d) { return d.dx; })
4041
.attr("height", function(d) { return d.dy; })
41-
.style("fill", function(d) { return color((d.children ? d : d.parent).data.key); });
42+
.style("fill", function(d) { return color((d.children ? d : d.parent).key); });
4243
});
4344

4445
</script>

examples/partition/partition-sunburst-zoom.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
.attr("transform", "translate(" + w / 2 + "," + h / 2 + ")");
3333

3434
var partition = d3.layout.partition()
35+
.inline(true)
3536
.children(function(d) { return isNaN(d.value) ? d3.entries(d.value) : null; })
3637
.value(function(d) { return d.value; });
3738

@@ -46,7 +47,7 @@
4647
.data(partition(d3.entries(json)[0]))
4748
.enter().append("svg:path")
4849
.attr("d", arc)
49-
.style("fill", function(d) { return color((d.children ? d : d.parent).data.key); })
50+
.style("fill", function(d) { return color((d.children ? d : d.parent).key); })
5051
.on("click", click);
5152

5253
function click(d) {

0 commit comments

Comments
 (0)