Draw rectangular layout of rooted tree
Closed this issue · 3 comments
ArtPoon commented
ArtPoon commented
Initial draw:
// draw points
svg2.selectAll(".dot")
.data(nodes)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 5)
.attr("cx", x2Map)
.attr("cy", y2Map)
.attr("stroke", "black")
.attr("stroke-width", 2)
.attr("fill", "white");
// draw lines
svg2.selectAll("lines")
.data(rootedEdges)
.enter().append("line")
.attr("x1", x2Map1)
.attr("y1", y2Map1)
.attr("x2", x2Map2)
.attr("y2", y2Map2)
.attr("stroke-width", 3)
.attr("stroke", "#777");
Refresh:
svg2.selectAll(".dot")
.data(nodes)
.transition().duration(100)
.attr("cx", x2Map)
.attr("cy", y2Map);
svg2.selectAll("lines")
.data(rootedEdges)
.transition().duration(100)
.attr("x1", x2Map1)
.attr("y1", y2Map1)
.attr("x2", x2Map2)
.attr("y2", y2Map2);
ArtPoon commented
rootedEdges
is definitely getting updated as the user relocates the root.
ArtPoon commented
The problem was that lines
wasn't selecting the line segments -- it has to be svg2.selectAll(".lines")
.