Commit 2e085486 authored by Adrian Wuillemet's avatar Adrian Wuillemet
Browse files

#65 Save svg only when graph not empty

parent a8fd8ed2
......@@ -37,52 +37,56 @@ function graphCSSRules() {
}
function saveSVG() {
let svg : any = document.querySelector("svg").cloneNode(true);
let styles = graphCSSRules();
let svgcode = `<?xml version="1.0" encoding="UTF-8"?>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:svg="http://www.w3.org/2000/svg"
height="210mm"
width="297mm"
viewBox="0 0 297 210"
version="1.1"
id="svg57"
>
<defs id="defs51" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="2560"
inkscape:window-height="1330"
inkscape:window-maximized="1" />
<style type="text/css">${styles}</style>
<metadata id="metadata54">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g transform="scale(0.25)" inkscape:label="Ebene 1" inkscape:groupmode="layer" id="layer1">${svg.innerHTML}</g>
</svg>
`;
if(graph.nodes.length !== 0) {
let svg : any = document.querySelector("svg").cloneNode(true);
let styles = graphCSSRules();
let svgcode = `<?xml version="1.0" encoding="UTF-8"?>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:svg="http://www.w3.org/2000/svg"
height="210mm"
width="297mm"
viewBox="0 0 297 210"
version="1.1"
id="svg57"
>
<defs id="defs51" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="2560"
inkscape:window-height="1330"
inkscape:window-maximized="1" />
<style type="text/css">${styles}</style>
<metadata id="metadata54">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g transform="scale(0.25)" inkscape:label="Ebene 1" inkscape:groupmode="layer" id="layer1">${svg.innerHTML}</g>
</svg>
`;
download(svgcode, `${filename()}.svg`, "image/svg+xml");
download(svgcode, `${filename()}.svg`, "image/svg+xml");
} else {
window.alert('Draw a graph first to save it as SVG!');
}
}
function saveCode() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment