scikit-hep / vegascope

View Vega/Vega-Lite plots in your web browser from local or remote Python processes.
BSD 3-Clause "New" or "Revised" License
35 stars 4 forks source link

Upgrade to Vega-Lite 3 #5

Closed jakevdp closed 5 years ago

jakevdp commented 5 years ago

It would be nice to update the vega-lite source to version 3. Any plans to do this?

jpivarski commented 5 years ago

At first, I was wondering what you meant—vegascope doesn't inspect the Vega or Vega-Lite it receives, so it isn't version dependent. But you mean the minified Vega-Lite Javascript that ships with the module in case it can't access the internet? Sure, I can update that (Vega, too, if it's out of date).

Where should I get the minified versions? Point me to your preferred URLs and I'll copy-paste the contents in.

jakevdp commented 5 years ago

Thanks! I'd use https://cdnjs.cloudflare.com/ajax/libs/vega-lite/3.3.0/vega-lite.min.js and https://cdnjs.cloudflare.com/ajax/libs/vega/5.4.0/vega.min.js

At the same time, the associated entrypoint could be updated from v2 to v3: https://github.com/scikit-hep/vegascope/blob/bf5880e0931a4b114b6624c329b947b1dbec29e3/setup.py#L56

jakevdp commented 5 years ago

...might require a vega-embed upgrade as well: https://cdnjs.cloudflare.com/ajax/libs/vega-embed/4.2.0/vega-embed.min.js

jpivarski commented 5 years ago

Thanks! I found all the places where Vega/Vega-Lite/Vega-Embed version numbers are selected and updated them all. The PyPI version has been updated: https://pypi.org/project/vegascope/ Let me know if you have any problems.

jakevdp commented 5 years ago

Thanks!

alex-robbins commented 5 years ago

It looks like this isn't fixed in practice when using the entrypoint. The Javascript embedded in vegascope.py was updated, but the default version is still 2.5.2. As a result, when I use the vegascope entrypoint for viewing charts in the browser, I see the following in the Javascript console:

The input spec uses vega-lite v3.4.0, but the current version of Vega-Lite is 2.5.2.

Because of this, features that Altair expects to be available are not, and bugs that should be fixed are still present.

Seems like the default versions should also be updated like the embedded JS was.

@jakevdp: In the future, is there a way that Altair can communicate version information to entrypoint-style plugins? Or is the "v3" in the entry point group altair.vegalite.v3.renderer all we have? (I see for example that the colab renderer in Altair uses VEGALITE_VERSION, VEGA_VERSION and VEGAEMBED_VERSION from altair.vegalite.v3.display. Would it be appropriate for vegascope to use those as well, maybe by passing them to the LocalCanvas constructor in vegalite_renderer_entry_point?)

jakevdp commented 5 years ago

Altair v3 will use the v3 entrypoint to register recognized renderers. Beyond that, the renderers can do whatever they like, including importing altair and inspecting its contents.

jpivarski commented 5 years ago

Would PR #7 solve the issue? If so, I'll push this through as a new version.

Sorry about the incomplete update. VegaScope was created for a particle physics project, but a Matplotlib-based solution was chosen instead. I'm keeping VegaScope alive because I think Vega-Lite provides the right level of abstraction for plotting, but I'm not directly testing it in any of our work here.

alex-robbins commented 5 years ago

With #7, we would at least have the right major version of Vega-Lite, and the default versions would match the embedded JS (presumably—I didn't check).

That said, I think you should additionally consider importing Altair, getting the version strings from there, and passing those to the LocalCanvas __init__ function at vegascope.py:411. That way, the entrypoint canvas will always use the correct version of the JS libraries for whatever version of Altair is in use, even if Altair gets upgraded and Vegascope doesn't change. Even today, that would mean using vega-lite 3.4.0, instead of 3.3.0 from #7, which is a good thing.

jpivarski commented 5 years ago

The hard-coded version numbers match the embedded Vega, VegaLite, and VegaEmbed Javascript.

@alex-robbins I have added this.

If VegaScope is being loaded through the entrypoint, we can import altair without dependency issues (I'm assuming that only Altair would call VegaScope through this entrypoint) and get the Vega, VegaLite, and VegaEmbed versions from Altair. The Vega and VegaEmbed versions are only major version numbers, but https://cdn.jsdelivr.net/npm/vega-embed@ accepts a major version number.

>>> altair.VEGA_VERSION
'5'
>>> altair.VEGALITE_VERSION
'3.4.0'
>>> altair.VEGAEMBED_VERSION
'4'

Is this all you need? If so, I'll merge and deploy a new version of VegaScope.

alex-robbins commented 5 years ago

Yeah, that looks great.

The only thing I'd say is that if you're concerned about the switch from v3 to v4, you might want to use the version numbers from altair.v3 instead of just altair. Right now they're the same, but I assume that when v4 shows up, altair.VEGALITE_VERSION will switch to 4.something even though your entrypoint group is still for v3.

(I couldn't see anything in the Altair docs about using altair.v3 vs. altair.vegalite.v3 vs. altair.v3.api etc., but none of those have leading underscores, so I'm guessing we're meant to be able to use any of them reliably.)

jpivarski commented 5 years ago

I just changed it to altair.v3.VEGALITE_VERSION (and similar) and will be merging it now.

Thanks!

alex-robbins commented 5 years ago

Perfect. And thanks for maintaining Vegascope, by the way. It seems to be the best easy way to use Altair with IPython in a terminal (rather than the notebook-style options).

jpivarski commented 5 years ago

Great! I'm glad it can be useful.

aschoenauer-sebag commented 4 years ago

Hi all,

It seems my issue is related to this but I cannot figure out how to fix it based on this thread. I have

Furthermore I can find the following specs : altair.VEGA_VERSION, same as altair.v4.VEGA_VERSION 5 altair.VEGAEMBED_VERSION, same as altair.v4.VEGAEMBED_VERSION 6 altair.VEGALITE_VERSION same as altair.v4.VEGALITE_VERSION 4.0.2.

With all these, when I try to type the following commands in iPython import altair; altair.renderers.enable('vegascope') I get the error : ValueError: To use the 'vegascope' renderer, you must install the vegascope package; see http://github.com/diana-hep/vegascope/ for more information.

Any idea how to solve this would be much appreciated. Thanks!

jpivarski commented 4 years ago

@aschoenauer-sebag I moved this to a new issue because it's unrelated to the "Upgrade to Vega-Lite 3" issue.