diff --git a/content.js b/content.js index 2a92518..52f6239 100644 --- a/content.js +++ b/content.js @@ -31,5 +31,8 @@ if (isIE()) { // manage page content addLegend(); + addExpandAndCollapseTreeButtons(); + addInfoBoxResizeBar(); addSideNavLinks(); - addAutoComplete(document.getElementById("search_input")); \ No newline at end of file + addAutoComplete(document.getElementById("search_input")); + addTreesLinks() \ No newline at end of file diff --git a/dag.js b/dag.js index 0836142..d52f9f4 100644 --- a/dag.js +++ b/dag.js @@ -1,4 +1,4 @@ -let scale; +let treeData; let svgSelection; let defs; let layout; @@ -6,16 +6,27 @@ let dag; let nodes; let graph; let width = 600, height = 400; +let viewboxWidth = 11000, viewboxHeight = 10000; let maxTextLength = 200; let nodeWidth = maxTextLength + 20; let nodeHeight = 140; +let shownNodesMap = {}; +let nodeChildrenStateMap = {}; +let nodeParentsStateMap = {}; +let leavesNodesIds = []; +let rootsNodesIds = []; +let rootsNodesCoord = {}; +let currentTree = []; +let zoomTransform; +let currentHighlightedNodeId; // Define the zoom function for the zoomable tree var zoom = d3.zoom() - .scaleExtent([1, 10]) + .scaleExtent([1, 20]) .on('zoom', function(event) { graph .attr('transform', event.transform); + zoomTransform = event.transform; }); // How to draw edges @@ -25,103 +36,56 @@ const line = d3 .x((d) => d.x + nodeWidth/2) .y((d) => d.y + nodeHeight/2); - +/** + * Initialize tree with the two top layers nodes + */ function initGraph() { // fetch data and render - data = JSON.parse(getDataFromSessionStorage(repoName + "Tree")); - dag = d3.dagStratify()(data); - layout = d3 - .sugiyama() // base layout - .decross(d3.decrossTwoLayer().order(d3.twolayerAgg())) // minimize number of crossings - .nodeSize((node) => [(node ? 3.6 : 0.25) * nodeWidth, 2 * nodeWidth]); // set node size instead of constraining to fit - const { width, height } = layout(dag); - let sizeFactor = width/window.innerWidth - // -------------------------------- - // This code only handles rendering - // -------------------------------- - svgSelection = d3.select("svg"); - svgSelection.attr("viewBox", [0, 0, width, (window.innerHeight)*sizeFactor].join(" ")); - svgSelection.call(zoom); - graph = svgSelection.append("g"); - - defs = graph.append("defs"); // For gradients - - // Plot edges - graph - .append("g") - .selectAll("path") - .data(dag.links()) - .enter() - .append("path") - .attr("d", ({ points }) => line(points)) - .attr("fill", "none") - .attr("stroke-width", 3) - .style("stroke", "#222222"); - - // Select nodes - nodes = graph - .append("g") - .selectAll("g") - .data(dag.descendants()) - .enter() - .append("g") - .attr("class", "node") - .attr("transform", ({ x, y }) => `translate(${x}, ${y})`); - - // Plot nodes - nodes - .append("rect") - .attr("width", nodeWidth) - .attr("height", nodeHeight) - .attr("rx", function (d) { - switch (d.data.nodeType) { - case "designParameter": - return 40; - case "systemIndependent": - return 40; - default: - return 2; - } - }) - .attr("stroke-width", 1.5) - .style("fill", function (d) { - switch (d.data.nodeType) { - case "designParameter": - return "#b4acd2"; - case "systemIndependent": - return "#ace3b5"; - default: - return "#f4f4f9"; - } - }) - .on("click", onNodeClicked); - - // Add text to nodes - nodes - .append("text") - .attr("y", nodeHeight / 2) - .attr("x", 13) - .attr("dy", ".35em") - .text((d) => d.data.title) - .call(wrapNodeText, maxTextLength) - .on("click", onNodeClicked); - - // Add information icon - nodes.append("circle") - .attr("class", "iButton") - .attr("cx", nodeWidth-20) - .attr("cy", 20) - .attr("r", 15) - .on("mouseover", function () { d3.select(this).attr("r", 20); }) - .on("mouseout", function () { d3.select(this).attr("r", 15); }) - .on("click", onNodeInfoClicked); - - nodes.append("text") - .attr("class", "iText") - .attr("y", 26.5) - .attr("x", nodeWidth - 20 - (5 / 2)) - .html("i"); - }; + treeData = JSON.parse(getDataFromSessionStorage(repoName + "Tree")); + let data = structuredClone(treeData); // A clone is made to avoid any modifications in the original data + for(let i=0;i