Skip to content

Commit cae3c3c

Browse files
committed
png export fixed, json export now has auto downloader
1 parent cfe5a07 commit cae3c3c

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

javascript/knet-menu.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function onHover(thisBtn) {
2929
// Export the graph as a JSON object in a new Tab and allow users to save it.
3030
function exportAsJson() {
3131
var cy= $('#cy').cytoscape('get'); // now we have a global reference to `cy`
32+
3233
var exportJson= cy.json(); // get JSON object for the network graph.
3334

3435
// Display in a new blank browser tab, e.g, window.open().document.write("text"); // for text data
@@ -44,21 +45,34 @@ function onHover(thisBtn) {
4445
// Export the graph as a .png image and allow users to save it.
4546
function exportAsImage() {
4647
var cy= $('#cy').cytoscape('get'); // now we have a global reference to `cy`
48+
4749
// Export as .png image
4850
var png64= cy.png(); // .setAttribute('crossOrigin', 'anonymous');
51+
4952
// Display the exported image in a new window.
50-
window.open(png64,'Image','width=1200px,height=600px,resizable=1');
53+
//window.open(png64, 'Image', 'width=1200px,height=600px,resizable=1'); // Blocked on some browsers
5154

5255
// use FileSaver.js to save using file downloader; fails (creates corrupted png)
5356
/*cy_image= new Image();
54-
cy_image.src=png64;
55-
var canvas= document.getElementById('my-canvas'); // use canvas
56-
context= canvas.getContext('2d');
57-
context.drawImage(cy_image, 0,0); // draw image on canvas
57+
cy_image.src= png64;
58+
var knet_canvas= document.getElementById('cy'); // use canvas
59+
knet_context= knet_canvas.getContext('2d');
60+
knet_context.drawImage(cy_image, 0,0); // draw image on canvas
5861
// convert canvas to Blob & save using FileSaver.js.
59-
canvas.toBlob(function(blob) {
60-
saveAs(blob, "kNetwork.png");
62+
knet_canvas.toBlob(function(blob) {
63+
saveAs(knet_blob, "kNetwork.png");
6164
}, "image/png");*/
65+
66+
// Use IFrame to open png image in a new browser tab
67+
var cy_width= $('#cy').width();
68+
var cy_height= $('#cy').height();
69+
var knet_iframe_style= "border:1px solid black; top:0px; left:0px; bottom:0px; right:0px; width:"+ cy_width +"; height:"+ cy_height +";";
70+
var knet_iframe = '<iframe src="'+ png64 +'" frameborder="0" style="'+ knet_iframe_style +'" allowfullscreen></iframe>';
71+
var pngTab= window.open();
72+
pngTab.document.open();
73+
pngTab.document.write(knet_iframe);
74+
pngTab.document.title="kNet_png";
75+
pngTab.document.close();
6276
}
6377

6478
// Remove hidden effect from nodes/ edges, if hidden.

0 commit comments

Comments
 (0)