Skip to content

download plotly image as PNG #373

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

Merged
merged 2 commits into from
May 4, 2017
Merged

download plotly image as PNG #373

merged 2 commits into from
May 4, 2017

Conversation

tgoldina
Copy link
Contributor

@tgoldina tgoldina commented May 3, 2017

Added save icon to download plotly chart as a png image.
The size of the images will match the size on display.

Known issue: in Safari, an image is not downloaded, but opened in the browser, it can be saved from there. Plotly team says it behaves this way because download attribute is not supported in Safari (http://caniuse.com/#feat=download) and they open the link instead.

Link to the ticket:
https://jira.lsstcorp.org/browse/DM-10275
(As discussed at SUIT meeting, we want to save PNG without an extra dialog and we prefer png to jpeg because it is lossless.)

Copy link
Contributor

@loitly loitly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feature works great. I tried it on a later version of safari(10.1) and it worked as expected. I would suggest making changes to the filename, but that's just my opinion. Feel free to merge otherwise.

downloadCounter++;
Plotly.downloadImage(chartDiv, {
format: 'png',
filename: `plotly-${chartId.replace(/\-.*$/, downloadCounter)}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 'replace' and counter tracking is unnecessary. Even 'plotly', I don't think it's needed.
Filename should be chart.title or chart.chartId if title not available.

@tgoldina tgoldina merged commit 634ace1 into dev May 4, 2017
@tgoldina tgoldina deleted the DM-10275_plotly_png branch May 4, 2017 18:23
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

Successfully merging this pull request may close these issues.

2 participants