diff --git a/static/js/pw.js b/static/js/pw.js index da214d97..59abe8cc 100644 --- a/static/js/pw.js +++ b/static/js/pw.js @@ -1,13 +1,19 @@ console.log("loaded pw.js") -function findPaths(source_idx, target_idx, links) { +function findPaths(source_idx, links) { const resultLinks = new Set(); const visited = new Set(); // Helper function for depth-first search function dfs(current) { - if (current === target_idx) { + + if (visited.has(current)) { return; } + + if (links.filter(link => link.target.id === current).length === 0) { + return; + } + visited.add(current); links.forEach(link => { if ( @@ -23,7 +29,7 @@ function findPaths(source_idx, target_idx, links) { } // Start DFS dfs(source_idx); - return Array.from(resultLinks); // Convert Set to Array for result + return Array.from(resultLinks); } function predictFromNode(url) { @@ -707,7 +713,7 @@ function draw(pathway, elem) { if (!wasHighlighted) { d3.select(this).select("circle").classed("highlighted", !d3.select(this).select("circle").classed("highlighted")); - const inEdges = findPaths(d.id, 3, links); + const inEdges = findPaths(d.id, links); const outEdges = [] // Colorize out edges green for (const l of links) { @@ -805,14 +811,14 @@ function draw(pathway, elem) { function serializeSVG(svgElement) { - svgElement.querySelectorAll("line.link").forEach(line => { + svgElement.querySelectorAll("path.link").forEach(line => { const style = getComputedStyle(line); line.setAttribute("stroke", style.stroke); line.setAttribute("stroke-width", style.strokeWidth); line.setAttribute("fill", style.fill); }); - svgElement.querySelectorAll("line.link_no_arrow").forEach(line => { + svgElement.querySelectorAll("path.link_no_arrow").forEach(line => { const style = getComputedStyle(line); line.setAttribute("stroke", style.stroke); line.setAttribute("stroke-width", style.strokeWidth);