diff --git a/static/js/pw.js b/static/js/pw.js index a335f951..907f28e0 100644 --- a/static/js/pw.js +++ b/static/js/pw.js @@ -444,6 +444,13 @@ function serializeSVG(svgElement) { line.setAttribute("fill", style.fill); }); + svgElement.querySelectorAll("line.link_no_arrow").forEach(line => { + const style = getComputedStyle(line); + line.setAttribute("stroke", style.stroke); + line.setAttribute("stroke-width", style.strokeWidth); + line.setAttribute("fill", style.fill); + }); + const serializer = new XMLSerializer(); let svgString = serializer.serializeToString(svgElement); @@ -455,7 +462,26 @@ function serializeSVG(svgElement) { return svgString; } +function shrinkSVG(svgSelector) { + + const svg = d3.select(svgSelector); + const node = svg.node(); + + // Compute bounding box of everything inside the SVG + const bbox = node.getBBox(); + + const padding = 10; + svg.attr("viewBox", + `${bbox.x - padding} ${bbox.y - padding} ${bbox.width + 2 * padding} ${bbox.height + 2 * padding}` + ) + .attr("width", bbox.width + 2 * padding) + .attr("height", bbox.height + 2 * padding); + + return bbox; +} + function downloadSVG(svgElement, filename = 'chart.svg') { + shrinkSVG("#" + svgElement.id); const svgString = serializeSVG(svgElement); const blob = new Blob([svgString], {type: 'image/svg+xml;charset=utf-8'}); const url = URL.createObjectURL(blob); diff --git a/templates/objects/pathway.html b/templates/objects/pathway.html index 40f2d807..4e4cc27d 100644 --- a/templates/objects/pathway.html +++ b/templates/objects/pathway.html @@ -177,9 +177,6 @@
- {% if debug %} - - {% endif %}