diff --git a/static/js/pw.js b/static/js/pw.js index 59abe8cc..2bfc2c79 100644 --- a/static/js/pw.js +++ b/static/js/pw.js @@ -154,6 +154,10 @@ function draw(pathway, elem) { }); node.attr("transform", d => `translate(${d.x},${d.y})`); + + linkText + .attr("x", d => (d.source.x + d.target.x) / 2) + .attr("y", d => (d.source.y + d.target.y) / 2); } function dragstarted(event, d) { @@ -647,21 +651,32 @@ function draw(pathway, elem) { .on("tick", ticked); // Kanten zeichnen - const link = zoomable.append("g") - .selectAll("path") - .data(links) - .enter().append("path") - // Check if target is pseudo and draw marker only if not pseudo - .attr("class", d => d.target.pseudo ? "link_no_arrow" : "link") - .attr("marker-end", d => { - if (d.target.pseudo) return ''; - if (d.source.id === d.target.id) return 'url(#curve-arrow)'; // Use curve arrow for self-loops - return d.multi_step ? 'url(#doublearrow)' : 'url(#arrow)'; - }) - .attr("fill", "none") - .on("click", function(event, d) { + const linkGroup = zoomable.append("g") + .selectAll("g") + .data(links) + .enter() + .append("g") + .attr("class", "link-group"); + + + const link = linkGroup + .append("path") + .attr("class", d => d.target.pseudo ? "link_no_arrow" : "link") + .attr("marker-end", d => d.target.pseudo ? "" : "url(#arrow)") + .attr("fill", "none") + + // Check if target is pseudo and draw marker only if not pseudo + .attr("class", d => d.target.pseudo ? "link_no_arrow" : "link") + .attr("marker-end", d => { + if (d.target.pseudo) return ''; + if (d.source.id === d.target.id) return 'url(#curve-arrow)'; // Use curve arrow for self-loops + return d.multi_step ? 'url(#doublearrow)' : 'url(#arrow)'; + } + ) + .attr("fill", "none") + .on("click", function(event, d) { const wasHighlighted = d3.select(this).classed("highlighted"); - d3.selectAll("path").classed("highlighted", false); + d3.selectAll("path").classed("highlighted", false); if (!wasHighlighted) { const toHighlight = []; toHighlight.push(d.el); @@ -688,6 +703,18 @@ function draw(pathway, elem) { } }); + const linkText = linkGroup + .append("text") + .attr("class", "link-label") + .attr("text-anchor", "middle") + .attr("dy", -6) + .style("font-size", "4px") + .style("pointer-events", "none") + .style("display", "none") + .text(d => d.name) + .attr("x", d => (d.source.x + d.target.x) / 2) + .attr("y", d => (d.source.y + d.target.y) / 2); + // add element to links array link.each(function (d) { d.el = this; // attach the DOM element to the data object diff --git a/templates/objects/pathway.html b/templates/objects/pathway.html index 1ebfab4c..7474c380 100644 --- a/templates/objects/pathway.html +++ b/templates/objects/pathway.html @@ -177,6 +177,52 @@ tabindex="0" class="dropdown-content menu bg-base-100 rounded-box z-50 w-60 p-2" > +