From 166f71b27cd42a70e75ce5c3e274d5b2d4051b37 Mon Sep 17 00:00:00 2001 From: Ehab Wahba Date: Fri, 3 Nov 2023 17:29:21 +0100 Subject: [PATCH] Added +/- icon for expand/collapse button --- dag.js | 27 +++++++++++++++++++++++++++ style.css | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/dag.js b/dag.js index b2c7ad7..32c8ed7 100644 --- a/dag.js +++ b/dag.js @@ -367,6 +367,32 @@ function drawTree(drawData,state) .on("mouseout", function () { d3.select(this).attr("r", 12); }) .on("click", onNodeToggleChildrenClicked); + nodesHaveChildren.append("text") + .attr("class", "iText") + .attr("x",function (d) { + switch (shownNodeChildrenMap[d.data.id]) { + case 1: + return nodeWidth/2 - 4.25; + default: + return nodeWidth/2 - 7; + } + }) + .attr("y",function (d) { + switch (shownNodeChildrenMap[d.data.id]) { + case 1: + return nodeHeight + 6; + default: + return nodeHeight + 8.5; + } + }) + .html(function (d) { + switch (shownNodeChildrenMap[d.data.id]) { + case 1: + return "-"; + default: + return "+"; + } + }) } /** * Search for nodes children and add them to the currentTree @@ -402,6 +428,7 @@ function NodeExpand(currentNodeId,data) nodeChildren.push(data[i]["id"]); } } + ///Link new nodes (clicked node children) to their existing children for(let i = 0;i