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

How to get the canvas element of a force-graph instance? #322

Closed
GwokHiujin opened this issue May 24, 2023 · 2 comments
Closed

How to get the canvas element of a force-graph instance? #322

GwokHiujin opened this issue May 24, 2023 · 2 comments

Comments

@GwokHiujin
Copy link

GwokHiujin commented May 24, 2023

Hello, this project is really excellent and useful! Thank you very much for developing it. ✨

I'm recently deploying it in my own project and trying to add an "export as image" feature to it. Since the image is rendered in a canvas element, I think I need to use a method like toDataURL to do the export, but I can't find a corresponding interface that allows me to get the canvas element in the page. Is there a method I can call?

@vasturiano
Copy link
Owner

@GwokHiujin thanks for reaching out.

If you have a reference to the DOM element where you mounted the graph (f.e. myElem), you can simply query for a child canvas element, like so:

myElem.querySelector('canvas')

@GwokHiujin
Copy link
Author

@GwokHiujin thanks for reaching out.

If you have a reference to the DOM element where you mounted the graph (f.e. myElem), you can simply query for a child canvas element, like so:

myElem.querySelector('canvas')

Thank you for your reply! This solves my problem nicely :)

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

No branches or pull requests

2 participants