Skip to content

Commit a5081bf

Browse files
author
Jaroslaw Odzga
committed
Gracefully handle case when node does not have a parent in waterfall's
hierarchy visualization.
1 parent 9b57b5b commit a5081bf

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

tools/tracevis/js/waterfall.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,32 +134,30 @@ var WATERFALL = (function() {
134134

135135
var verticalEnter = traceEnter.filter( function(d) { return d.children || d._children; } )
136136

137-
verticalEnter.append("line")
137+
verticalEnter.append("path")
138138
.classed("vertical", true)
139-
.attr("x1", -3)
140-
.attr("y1", 4)
141-
.attr("x2", -3)
142-
.attr("y2", function (d) {
143-
if (d.lowestChild)
144-
return (d.lowestChild - d.level) * (barHeight + barSpacing);
145-
else
146-
4;
147-
} )
139+
.attr("d", function (d) {
140+
if (d.lowestChild)
141+
return "M-3 4 L-3 " + (d.lowestChild - d.level) * (barHeight + barSpacing);
142+
else
143+
return "M-3 4 L-3 4";
144+
})
148145
.style("stroke", "black")
149146
.style("stroke-width", 1)
150147
.style("stroke-linecap", "round")
151148
.style("stroke-dasharray", 3);
152149

153-
var vertical = trace.select("line.vertical");
154-
155-
vertical.attr("y2", function (d) {
156-
if (d.lowestChild)
157-
return (d.lowestChild - d.level) * (barHeight + barSpacing)
158-
else
159-
this.y2;
160-
} );
161-
162-
var noRootEnter = traceEnter.filter( function (d, i) { return i != 0 })
150+
trace.select("path.vertical")
151+
.transition()
152+
.duration(duration)
153+
.attr("d", function (d) {
154+
if (d.lowestChild)
155+
return "M-3 4 L-3 " + (d.lowestChild - d.level) * (barHeight + barSpacing);
156+
else
157+
return "M-3 4 L-3 4";
158+
})
159+
160+
var noRootEnter = traceEnter.filter( function (d, i) { return (i != 0) && (d.parent)})
163161
noRootEnter.append("line")
164162
.attr("x1", -4)
165163
.attr("y1", 0)
@@ -170,7 +168,8 @@ var WATERFALL = (function() {
170168
.style("stroke-linecap", "round")
171169
.style("stroke-dasharray", 3);
172170

173-
traceEnter.append("circle")
171+
traceEnter.filter( function (d, i) { return d.parent || d.children || d._children})
172+
.append("circle")
174173
.attr("r", 4)
175174
.attr("cx", -3)
176175
.style("stroke", "black")

0 commit comments

Comments
 (0)