From ce7521f5ee0fbaf4776fa10a83469f387d138ab6 Mon Sep 17 00:00:00 2001 From: Mateusz Szalowski Date: Sat, 13 Aug 2022 15:36:42 +0200 Subject: [PATCH 1/3] Add a method to the circuit class, to export circuit SVG as url. --- src/circuit.mjs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/circuit.mjs b/src/circuit.mjs index 61ae8b9..5b92ba8 100644 --- a/src/circuit.mjs +++ b/src/circuit.mjs @@ -310,6 +310,19 @@ export class HeadlessCircuit { ret.subcircuits = subcircuits; return ret; } + getSvgExportUrl(circuitSvgDOMElement) { + // Remove useless in export jointJS tooltips + circuitSvgDOMElement + .querySelectorAll('foreignObject.tooltip') + .forEach(obj => obj.remove()); + + // Serialize SVG to string & encode it as URL + let data = (new XMLSerializer()).serializeToString(circuitSvgDOMElement); + data = '\r\n' + data; + const url = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(data); + + return url; + } waitForWire(wire, trigger) { if (trigger instanceof Vector3vl) trigger = [trigger]; From a4b72092cd838ad5d2d5393353d5c2c5f02ff1f7 Mon Sep 17 00:00:00 2001 From: Mateusz Szalowski Date: Sat, 13 Aug 2022 15:49:50 +0200 Subject: [PATCH 2/3] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index c583846..6d0b3f0 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,6 @@ Some ideas for further developing the simulator. * Saving and loading circuits, including layout and state. * Generic handling of negation for unary/binary gates (negation on inputs/outputs) for better clarity. * Zooming in/out on schematics. - * SVG export. * Verilog export. * Smartphone and tablet compatible UI. From 97239962a4aa89d7cdf39d49a22e0b012d1d6acb Mon Sep 17 00:00:00 2001 From: Mateusz Szalowski Date: Fri, 19 Aug 2022 21:57:21 +0200 Subject: [PATCH 3/3] Move getSvgExport to Circuit class. Simplify the method as advised in code review. --- src/circuit.mjs | 13 ------------- src/index.mjs | 6 ++++++ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/circuit.mjs b/src/circuit.mjs index 5b92ba8..61ae8b9 100644 --- a/src/circuit.mjs +++ b/src/circuit.mjs @@ -310,19 +310,6 @@ export class HeadlessCircuit { ret.subcircuits = subcircuits; return ret; } - getSvgExportUrl(circuitSvgDOMElement) { - // Remove useless in export jointJS tooltips - circuitSvgDOMElement - .querySelectorAll('foreignObject.tooltip') - .forEach(obj => obj.remove()); - - // Serialize SVG to string & encode it as URL - let data = (new XMLSerializer()).serializeToString(circuitSvgDOMElement); - data = '\r\n' + data; - const url = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(data); - - return url; - } waitForWire(wire, trigger) { if (trigger instanceof Vector3vl) trigger = [trigger]; diff --git a/src/index.mjs b/src/index.mjs index 3d0f92f..55feee0 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -84,6 +84,12 @@ export class Circuit extends HeadlessCircuit { this.trigger('changeRunning'); }); } + getSvgExport(jointjsPaper) { + let svgString = (new XMLSerializer()).serializeToString(jointjsPaper.svg); + svgString = '\r\n' + svgString; + + return svgString; + } _defaultWindowCallback(type, div, closingCallback) { const maxWidth = () => $(window).width() * 0.9; const maxHeight = () => $(window).height() * 0.9;