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

Add buttons for exporting the plot in various image formats #8

Open
gflegar opened this issue Nov 21, 2018 · 3 comments
Open

Add buttons for exporting the plot in various image formats #8

gflegar opened this issue Nov 21, 2018 · 3 comments
Labels
Enhancement An improvement of an existing feature. Help wanted Need ideas on how to solve this.

Comments

@gflegar
Copy link
Member

gflegar commented Nov 21, 2018

This one might be more trickier. The <canvas> html element used to draw the plot may have some method to get the raster data, which can then be converted to JPG, PNG or an image embedded in a PDF, but the resolution of such a plot will be limited to whatever is the resolution of the canvas (and that is not very large).

We could try converting it to SVG using something like canvas2svg. From there it should not be very difficult to support other formats.

@gflegar gflegar added Enhancement An improvement of an existing feature. Help wanted Need ideas on how to solve this. labels Nov 21, 2018
@gflegar
Copy link
Member Author

gflegar commented Dec 30, 2018

Tried doing something based on the answers here.
Doesn't seem to work properly - the points, the axes and the text are generated correctly, but the lines and polygons seem to be missing. Could be that canvas2svg is buggy. You can check the current progress on this in the convert_to_svg branch.

@gflegar
Copy link
Member Author

gflegar commented Dec 30, 2018

Switching to the newer (unofficial) version of canvas2svg fixes some problems, but the generated SVG is still far from perfect (e.g. it does not honor the range of the axes set in the configuration). Not sure why that would have anything to do with the underlying implementation of the 2D context, but its obviously related somehow.

I've merged it to master for now, since it's starting to generate something useful, but its still quite experimental.

@gflegar
Copy link
Member Author

gflegar commented Dec 30, 2018

I've added support for exporting to PNG. This one uses the generated image, so you will get exactly what you see in GPE. The only problem can be low resolution, since this is raster graphics. Chart.js's devicePixelRatio option can be used as a workaround to artificially increase the resolution when rendering the image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement An improvement of an existing feature. Help wanted Need ideas on how to solve this.
Projects
None yet
Development

No branches or pull requests

1 participant