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

Adding: Export Button #42

Merged
merged 5 commits into from
Mar 8, 2018
Merged

Adding: Export Button #42

merged 5 commits into from
Mar 8, 2018

Conversation

ydlamba
Copy link
Member

@ydlamba ydlamba commented Mar 6, 2018

Adding: Export Button

  • Using export button one can export the chart as png or svg depending upon the renderer.

Fixes #5.

var link = document.createElement('a');
link.setAttribute('href', url);
link.setAttribute('target', '_blank');
link.setAttribute('download', 'export.'+ ext);
Copy link
Member

Choose a reason for hiding this comment

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

instead of downloading, can we just open it in a new tab?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, View API gives URI for png whose support is removed by many browsers in a new tab, they did it for security reasons. Now we have the only option of downloading it. Still, we can open SVG in a new tab.

Copy link
Member

Choose a reason for hiding this comment

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

I think for SVG it's more important. My use case is that I want to print the SVG as PDF. It's not important for PNGs.

if (this.props.export) {
const ext = this.props.renderer === 'canvas' ? 'png' : 'svg';
const url = view.toImageURL(ext);
url.then(function(url) {
Copy link
Member

Choose a reason for hiding this comment

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

=> instead of function

@domoritz
Copy link
Member

domoritz commented Mar 6, 2018

This is a great start. Can you try an interactive example and make sure that the exported visualization is the of the current state, not the initial state?

@ydlamba ydlamba changed the title Adding: Export Button [WIP] Adding: Export Button Mar 6, 2018
@ydlamba
Copy link
Member Author

ydlamba commented Mar 7, 2018

Currently, the current state (after interaction) is not stored that's why it is exporting the initial state.

@ydlamba
Copy link
Member Author

ydlamba commented Mar 7, 2018

To fix this we need to set a new state that preserves the user interactions. But I am not getting which vega module is doing the interaction part.

@domoritz
Copy link
Member

domoritz commented Mar 7, 2018

What happens if you use the existing Vega view instead of creating a new one? Does that contain the interactive state?

@ydlamba
Copy link
Member Author

ydlamba commented Mar 7, 2018

I am already using the existing one but it gets reset each time as component updates. Now I am trying by storing view as a state.

@ydlamba ydlamba changed the title [WIP] Adding: Export Button Adding: Export Button Mar 7, 2018
@ydlamba
Copy link
Member Author

ydlamba commented Mar 7, 2018

@domoritz Using the existing view is perfectly exporting with interactive states so setting view as a state doesn't make a point plus requested changes are done. You can have a look.

@ydlamba ydlamba force-pushed the ydl/export-button branch 2 times, most recently from 46e2b51 to 5a7a2d8 Compare March 7, 2018 23:10
Copy link
Member

@domoritz domoritz left a comment

Choose a reason for hiding this comment

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

One last bug I found. When I export an interactive visualization, the state of the visualization in the editor gets lost, even though the right one is exported.

};

export default class Editor extends React.Component<Props> {
static view: any;
Copy link
Member

Choose a reason for hiding this comment

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

The type can be vega.View

@@ -55,6 +62,9 @@ export default class Toolbar extends React.Component<Props> {
<div className='renderer-toggle' onClick={this.props.cycleRenderer}>
{`Renderer: ${this.props.renderer}`}
</div>
<div className='vega-export' onClick={() => this.props.exportVega(true)}>
{`Export`}
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this Export SVG and Export PNG depending on whether the Canvas or SVG renderer are active.

@ydlamba
Copy link
Member Author

ydlamba commented Mar 8, 2018

@domoritz Changes done.

@domoritz domoritz merged commit 6c37833 into vega:master Mar 8, 2018
@ydlamba ydlamba deleted the ydl/export-button branch March 8, 2018 02:34
@ydlamba ydlamba restored the ydl/export-button branch April 6, 2018 00:15
@ydlamba ydlamba deleted the ydl/export-button branch April 6, 2018 00:15
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.

None yet

2 participants