vega / vl-convert

Utilities for converting Vega-Lite specs from the command line and Python
BSD 3-Clause "New" or "Revised" License
100 stars 12 forks source link

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

Closed jonmmease closed 1 year ago

jonmmease commented 1 year ago

Closes https://github.com/vega/vl-convert/issues/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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

yes, thanks for walking me through that!