-
Notifications
You must be signed in to change notification settings - Fork 89
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
Conversation
src/components/renderer/renderer.tsx
Outdated
var link = document.createElement('a'); | ||
link.setAttribute('href', url); | ||
link.setAttribute('target', '_blank'); | ||
link.setAttribute('download', 'export.'+ ext); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/components/renderer/renderer.tsx
Outdated
if (this.props.export) { | ||
const ext = this.props.renderer === 'canvas' ? 'png' : 'svg'; | ||
const url = view.toImageURL(ext); | ||
url.then(function(url) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> instead of function
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? |
Currently, the current state (after interaction) is not stored that's why it is exporting the initial state. |
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. |
What happens if you use the existing Vega view instead of creating a new one? Does that contain the interactive state? |
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. |
@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. |
46e2b51
to
5a7a2d8
Compare
There was a problem hiding this 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.
src/components/renderer/renderer.tsx
Outdated
}; | ||
|
||
export default class Editor extends React.Component<Props> { | ||
static view: any; |
There was a problem hiding this comment.
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
src/components/toolbar/renderer.tsx
Outdated
@@ -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`} |
There was a problem hiding this comment.
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.
5a7a2d8
to
8f3d9de
Compare
@domoritz Changes done. |
Adding: Export Button
png
orsvg
depending upon the renderer.Fixes #5.