1 Commits

Author SHA1 Message Date
9bc9f86ff1 [Fix] Pathway SVG Export has Edges again, Fix In/Out Edge coloring (#422)
Co-authored-by: Tim Lorsbach <tim@lorsba.ch>
Reviewed-on: enviPath/enviPy#422
2026-07-03 07:24:02 +12:00

View File

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