tangled
alpha
login
or
join now
nonbinary.computer
/
or1-design
0
fork
atom
OR-1 dataflow CPU sketch
0
fork
atom
overview
issues
pulls
pipelines
feat: add SVG and PNG export functions
Orual
2 weeks ago
dc2a12a5
f9c806b5
+46
2 changed files
expand all
collapse all
unified
split
dfgraph
frontend
src
cytoscape-svg.d.ts
export.ts
+5
dfgraph/frontend/src/cytoscape-svg.d.ts
···
1
1
+
declare module "cytoscape-svg" {
2
2
+
import cytoscape from "cytoscape";
3
3
+
const ext: cytoscape.Ext;
4
4
+
export default ext;
5
5
+
}
+41
dfgraph/frontend/src/export.ts
···
1
1
+
import cytoscape from "cytoscape";
2
2
+
3
3
+
function downloadBlob(blob: Blob, filename: string): void {
4
4
+
const url = URL.createObjectURL(blob);
5
5
+
const a = document.createElement("a");
6
6
+
a.href = url;
7
7
+
a.download = filename;
8
8
+
document.body.appendChild(a);
9
9
+
a.click();
10
10
+
document.body.removeChild(a);
11
11
+
URL.revokeObjectURL(url);
12
12
+
}
13
13
+
14
14
+
export function exportSvg(cy: cytoscape.Core): void {
15
15
+
const svgContent: string = (cy as any).svg({ full: true });
16
16
+
const blob = new Blob([svgContent], { type: "image/svg+xml" });
17
17
+
downloadBlob(blob, "dfgraph.svg");
18
18
+
}
19
19
+
20
20
+
export function exportPng(cy: cytoscape.Core): void {
21
21
+
const pngPromise: Promise<Blob> = (cy as any).png({
22
22
+
full: true,
23
23
+
output: "blob-promise",
24
24
+
scale: 2,
25
25
+
});
26
26
+
pngPromise.then((blob: Blob) => {
27
27
+
downloadBlob(blob, "dfgraph.png");
28
28
+
});
29
29
+
}
30
30
+
31
31
+
export function copyPng(cy: cytoscape.Core): void {
32
32
+
const pngPromise: Promise<Blob> = (cy as any).png({
33
33
+
full: true,
34
34
+
output: "blob-promise",
35
35
+
scale: 2,
36
36
+
});
37
37
+
pngPromise.then((blob: Blob) => {
38
38
+
const item = new ClipboardItem({ "image/png": blob });
39
39
+
navigator.clipboard.write([item]);
40
40
+
});
41
41
+
}