I am trying to allow the user a more visual representation of where they are in the tree by highlighting the "selected" node in the tree, as well as displaying an icon, similar to plus/minus, based on whether or not the children are shown.
I can't seem to find anywhere on how to do this, since it seems that once the tree is redrawn after the expand, the selected node information is gone, and cannot be acted upon. Currently my tree nodes highlight based on children being hidden/displayed or not having any, but I would like to track which node has been clicked with a fill color. my tree is based off of mbostock’s block #1093025. Any help would be greatly appreciated for the plus/minus icon toggle, as well as highlighting the selected node.
Current code to display expand/collapse icons:
nodeEnter.append("svg:image")
.attr("xlink:href", function(d) {
if (d._children) return "images/arrow_right.png";
else if (d.children) return "images/arrow_left.png";
})
.attr("x", "-12px")
.attr("y", "-10px")
.attr("width", 15)
.attr("width", 20);
Function to enlarge selected node with functions for resizing... can't get these to work at all or for it to recognize the selected node on redraw. Only the fill seems to recognize the selected node.
nodeEnter.append("rect")
.attr("y", newy)
.attr("height", newheight)
.attr("width", barWidth)
.style("fill", color)
.on("click", click);
function newy(d) {
if (d._isSelected)
return -barHeight / 1.25;
else
return -barheight/2;
}
function newheight(d) {
if (d._isSelected)
return barHeight * 1.75;
else
return barheight;
}