Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export node-html to jpeg #13

Open
aminPolimi opened this issue Aug 6, 2018 · 5 comments
Open

export node-html to jpeg #13

aminPolimi opened this issue Aug 6, 2018 · 5 comments

Comments

@aminPolimi
Copy link

I am going to export my network to image(jpeg).
How can I export cytoscape-node-html-label by cy.jpeg?
Thanks

@morficus
Copy link

morficus commented Oct 8, 2018

I'm running in to this same issue so I started to dig in a bit.
The HTML-labels are not actually part of the <canvas> element created by cytoscape, but are <div>'s that are positioned absolutely.
Cytoscape is using the canvas.toDataURL() API to generate the image... hence why the HTML-labels are not part of the image :-(

@kaluginserg
Copy link
Owner

You can try use html2canvas.
This library can create jpg from html content.

@jeppebm
Copy link

jeppebm commented Mar 25, 2020

Would also love this feature, but I doubt that it's possible using the current approach. Using html2canvas seems to be troublesome since the elements are absolutely positioned, which is not supported by html2canvas.

@aledwassell
Copy link
Contributor

The only way I have found to get html2canvas working it to use html2canvas on the entire canvas and it does export the HTML node labels, the only thing is it obviously wont allow any native cytoscape.png/jpeg options.

@paulks-software
Copy link

the only way i could get a usable result is when scaling div artificially cy is cytoscape

cy.center();
cy.fit();
const div = document.querySelector('.scaledDiv');
div.style.transform = 'scale(2)';

then something :

// Use html2canvas to capture the screenshot
html2canvas(div).then(function(canvas) {

// Convert the canvas to a data URL
const screenshotDataURL = canvas.toDataURL('image/png');

// Create a download link for the screenshot
const a = document.createElement('a');
a.href = screenshotDataURL;
a.download = 'screenshot.png'; // Specify the filename for the image
a.style.display = 'none';

// Add the download link to the document and trigger the click event
document.body.appendChild(a);
a.click();

// Clean up
document.body.removeChild(a);
div.style.transform = 'scale(1)';

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants