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

Add support for converting Vega and Vega-Lite specs to Vega editor URLs #104

Merged
merged 4 commits into from
Sep 14, 2023

Conversation

jonmmease
Copy link
Collaborator

Closes #103

Adds Rust, Python, and CLI APIs for converting Vega and Vega-Lite specs into URLs that can be used to open the spec in the Vega editor.

Python example:

import vl_convert as vlc
import altair as alt
import pandas as pd

source = pd.DataFrame({
    'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
    'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
})

chart = alt.Chart(source).mark_bar().encode(
    x='a',
    y='b'
)
chart

visualization (1)

print(vlc.vegalite_to_url(chart.to_json()))

https://vega.github.io/editor/#/url/vega-lite/N4IgJAzgxgFgpgWwIYgFwhgF0wBwqgegIDc4BzJAOjIEtMYBXAI0poHsDp5kTykBaADZ04JAKyUAjABYplAFYQ2AOxAAaEFBUAzGmTShiNOAHcDmlZhrKGbBhAAScPVjQBmAAweNW5VZt2EADqNAAm9O5eAL5RGqFImCiooMpICHBoIPGJ-FAATEhucAAcAJxMSKWhYqGSAGzFAOzVJfnFoXWeSB5ubiCxWQlIEHCYEObZAvmFJeWV1bUNzWKtee2dHt29aADaoEkgAILqIExoa7H7mQBCJ2eoYmKXIAcAwndo0m7PBwAiH6hSpIfpkAKIA4rAtRXdAAMQBYm+0JemQA4gDJKUQegHBDGtiQABJBF5KIAXQGcGUWlC1n0yRAAA9zLo4IJQpkUBpMABPHAZdDKNgIaxIQT9DQ8lnGdmZM7cvkCkAARwYSD8dASNFI-QGyAATgBrcy8-lypD63VAA

@jonmmease
Copy link
Collaborator Author

Oh, and if we add a /view suffix the chart opens in full screen. This should be an option to the url export functions

@NickCrews
Copy link

In case Vega editor changes their URL API to use a different compression algorithm from this LZ string one that you have here, do you want to add some version argument or method argument or name this method like .to_lz_url()? If we don't do that then we have already used up this name and we won't be able to use it for the long-term function.

@NickCrews
Copy link

Or at least I think we should at least wait for someone to chime in on the Vega editor issue so we get a sense of what their long-term plan is. I think we can wait a couple days to add this feature and that will be worth it

@jonmmease
Copy link
Collaborator Author

In case Vega editor changes their URL API to use a different compression algorithm from this LZ string one that you have here, do you want to add some version argument or method argument or name this method like .to_lz_url()?

I don't think this is something we need to do right now for future compatibility. The editor is going to need to support the current lz encoding indefinitely to maintain compatibility with all of the share URLs that have already been generated, even if an additional encoding option is added in the future. If a new better encoding is added, like your brotli proposal, then we can add a version kwarg to vlc.vegalite_to_url (e.g. vlc.vegalite_to_url(version="2")), and we can even make that the default. Basically the idea would be for vlc.vegalite_to_url to return the best URL that is compatible with the current deployed editor, and allow the use of a version kwarg to opt in to older versions.

Does that make sense?

@NickCrews
Copy link

yes, thanks for walking me through that!

@jonmmease jonmmease merged commit 06d6d4c into main Sep 14, 2023
@jonmmease jonmmease deleted the jonmmease/export_url branch September 14, 2023 23:21
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.

Support converting Vega specs to Vega-editor compatible URLs
2 participants