-
Notifications
You must be signed in to change notification settings - Fork 86
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 embed option exportDataSet to set the data used when opening source/opening in editor #720
Conversation
6dce5b0
to
56759ee
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.
Thanks for the pull request. I think this solution is too brittle as it only works for Vega-Lite.
Instead, we should send the view state via postMessage to the editor.
Thanks for taking a look! Isn't this what the |
56759ee
to
c5ebc12
Compare
I've just pushed an updated version which does at least work with
Hopefully this makes it less brittle, but I'm happy to change the way it sends the message to the editor as you mentioned - I'm just not clear exactly what I need to change there yet. |
If set, this is used to populate the data when opening in Vega editor or viewing Vega source
c5ebc12
to
a38ab2e
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.
This isn't an easy issue so I don't want you to get too hung up when working on it and I will help where I can.
When I say send the state, I mean use https://vega.github.io/vega/docs/api/view/#view_getState in embed and https://vega.github.io/vega/docs/api/view/#view_setState in the editor. You will need to send a pull request to the editor as well.
I had issues with serializing state before so maybe we also need to change Vega to make this approach work.
if (mode === 'vega') { | ||
exportSpec.data = [exportSpecData]; | ||
} else if (mode === 'vega-lite') { | ||
exportSpec.data = exportSpecData; |
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.
Data can be nested in a spec so this code won't work in general.
Please send a new pull request. |
Closes #719
This PR adds a new optional embed option
exportDataSet
. If it is set, then when the "Open Source" and "Open in Vega Editor" actions are used the data set given is used as thedata.values
of the spec before it is opened.This means that it is possible to use Vega's changeset functionality to modify the data, and then open source/editor to eg. extract the latest data or to iterate on the chart in the editor with the latest data available.
I've also added an example file
test-changeset.html
which demonstrates this feature (and changesets more widely). This is based on the streaming demo: https://vega.github.io/vega-lite/tutorials/streaming.htmlHere's a short video showing this working. Note that without this PR the data would be empty in both cases and the editor wouldn't render any data.
vega-embed-export-dataset.mov