Skip to content

Commit

Permalink
updated and fix svg export
Browse files Browse the repository at this point in the history
  • Loading branch information
CopyDemon committed Apr 1, 2024
1 parent ee82789 commit 8458624
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class Toolbar {
//call & register click event to export flowsheet to png function
//this is a header element its always there
this.registerEventExportFlowsheetToPng();
this.registerEventExportFlowsheetToSvg();

//call & register click event to refresh model
this.registerEventRefresh(this.getFSUrl, this.putFSUrl);
Expand Down Expand Up @@ -174,6 +175,8 @@ export class Toolbar {
registerEventExportFlowsheetToPng(){
//this element is static and 100% there.
const headerExportImageBtn = document.querySelector("#headerExportImageBtn") as HTMLElement;
const headerExportSvgBtn = document.querySelector("#headerExportSvgBtn") as HTMLElement;

headerExportImageBtn.addEventListener("click", () => {
let p = this._paper.paper;
const model_id = this.flowsheetId
Expand All @@ -197,6 +200,40 @@ export class Toolbar {
});
});
}

/**
* Button event handler register
* Export flowsheet to to SVG
*/
registerEventExportFlowsheetToSvg(){
const headerExportSvgBtn = document.querySelector("#headerExportSvgBtn") as HTMLElement;
headerExportSvgBtn.addEventListener("click", () => {
let p = this._paper.paper;
const model_id = this.flowsheetId

// Make sure to hide all of the vertices and bars on the links
// so they don't show up in the PNG
p.hideTools();
p.toSVG((svg:string) =>{
// convert svg to blob
const blob = new Blob([svg], {type: 'image/svg+xml;charset=utf-8'});
// create url for svg blob use for jjs lightbox to download
const svgUrl = URL.createObjectURL(blob);
new joint.ui.Lightbox({
image: svgUrl,
downloadable: true,
fileName: model_id.concat(".svg")
}).open();
}, {
scale:2,
pixelRatio:2,
preserveDimensions: true,
convertImagesToDataUris: true,
useComputedStyles: true,
stylesheet: '.scalable * { vector-effect: non-scaling-stroke }'
});
});
}

/**
* Toggle label show and hide
Expand Down
2 changes: 1 addition & 1 deletion IDAES-UI/src/components/mosaic/mosic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ function conditionallyRenderPanelHeaderBtn(
<Icon icon={IconNames.BRING_DATA} size={20} />
<ul className="mosaic_dropdown_download">
<li id="headerExportImageBtn">Export PNG</li>
<li>Export SVG</li>
<li id="headerExportSvgBtn">Export SVG</li>
</ul>
</Button>
</div>
Expand Down

0 comments on commit 8458624

Please sign in to comment.