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

feat: add PNG export #451

Merged
merged 12 commits into from
Nov 22, 2019
Merged

feat: add PNG export #451

merged 12 commits into from
Nov 22, 2019

Conversation

rshen91
Copy link
Contributor

@rshen91 rshen91 commented Nov 14, 2019

Summary

Thank you Marco for the help on this! This PR will close #82 and allows PNG export of charts:

aintnopartylikeapngparty

A PNG export story was added under the heading Interactions.
Additionally, in the playground.tsx from this PR the following implements the PNG export functionality:

...
export class Playground extends React.Component {
  chartRef: React.RefObject<Chart> = React.createRef();
  onSnapshot = () => {
    if (!this.chartRef.current) {
      return;
    }
    const snapshot = this.chartRef.current.getPNGSnapshot({
// can specify a background color or default is transparent
      backgroundColor: 'white',
      pixelRatio: 2,
    });
    if (!snapshot) {
      return;
    }
    const fileName = 'chart.png';
    switch (snapshot.browser) {
      case 'IE11':
        return navigator.msSaveBlob(snapshot.blobOrDataUrl, fileName);
      default:
        const link = document.createElement('a');
        link.download = fileName;
        link.href = snapshot.blobOrDataUrl;
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
    }
  };
...

Next steps:

  • add the legend from the chart to the PNG (html2canvas library)

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

  • Any consumer-facing exports were added to src/index.ts (and stories only import from ../src except for test data & storybook)
  • This was checked for cross-browser compatibility, including a check against IE11
  • Proper documentation or storybook story was added for features that require explanation or tutorials
  • Unit tests were updated or added to match the most common scenarios
  • Each commit follows the convention

@rshen91 rshen91 changed the title feat: add png export feat: add PNG export Nov 14, 2019
@codecov-io
Copy link

codecov-io commented Nov 14, 2019

Codecov Report

Merging #451 into master will increase coverage by 0.18%.
The diff coverage is 27.27%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #451      +/-   ##
=========================================
+ Coverage   77.91%   78.1%   +0.18%     
=========================================
  Files          81      91      +10     
  Lines        4189    4320     +131     
  Branches      891     908      +17     
=========================================
+ Hits         3264    3374     +110     
- Misses        913     933      +20     
- Partials       12      13       +1
Impacted Files Coverage Δ
src/components/react_canvas/reactive_chart.tsx 11.62% <ø> (ø) ⬆️
src/components/react_canvas/chart_container.tsx 40% <ø> (ø) ⬆️
src/components/chart.tsx 46.47% <27.27%> (+7.26%) ⬆️
src/mocks/series/series.ts 81.96% <0%> (ø)
src/mocks/specs/specs.ts 96% <0%> (ø)
src/mocks/scale/index.ts 100% <0%> (ø)
src/mocks/index.ts 100% <0%> (ø)
src/mocks/series/index.ts 100% <0%> (ø)
src/mocks/series/data.ts 100% <0%> (ø)
src/mocks/scale/scale.ts 87.5% <0%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7738aa9...fd354c6. Read the comment docs.

@rshen91 rshen91 marked this pull request as ready for review November 19, 2019 16:25
@rshen91 rshen91 requested review from markov00 and monfera November 20, 2019 14:55
@markov00 markov00 added enhancement New feature or request wip work in progress labels Nov 21, 2019
Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

LGTM, I've left just few comments

src/components/chart.tsx Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
.playground/playgroud.tsx Outdated Show resolved Hide resolved
.playground/playgroud.tsx Outdated Show resolved Hide resolved
@@ -635,4 +635,61 @@ storiesOf('Interactions', module)
{
info: 'Sends an event every time the cursor changes. This is provided to sync cursors between multiple charts.',
},
);
)
.add('PNG export action', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a description on how to get the snapshot and is a default implementation?
Check storybook API/docs to find a way to add info to the story.
I think we should start add some text on every story we add

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call - I've added an info section to the story in fd354c6. I'll open up an issue to track adding a Docs tab such as in https://www.learnstorybook.com/design-systems-for-developers/react/en/document/ where we can configure and clarify each story 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opened issue #457

This was referenced Nov 22, 2019
@rshen91 rshen91 merged commit e844687 into elastic:master Nov 22, 2019
@rshen91 rshen91 deleted the rshen-PNG branch November 22, 2019 16:34
markov00 pushed a commit that referenced this pull request Nov 25, 2019
# [14.2.0](v14.1.0...v14.2.0) (2019-11-25)

### Features

* add PNG export ([#451](#451)) ([e844687](e844687)), closes [#82](#82)
@markov00
Copy link
Member

🎉 This PR is included in version 14.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Nov 25, 2019
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released Issue released publicly wip work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export as PNG function
3 participants