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

Bug: Cannot use new geoScale Vega expression function #139

Closed binste closed 10 months ago

binste commented 10 months ago

In https://github.com/vega/vega/releases/tag/v5.26.0 I added a geoScale expression function which is needed for https://github.com/altair-viz/altair_tiles. However, although I use vl-convert 1.1.0 which uses Vega 5.26.1, I get an error that geoScale is not a function:

import altair as alt
import altair_tiles as til
import geopandas as gpd

url = "https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip"
gdf_ne = gpd.read_file(url)  # zipped shapefile
gdf_ne = gdf_ne[["NAME", "CONTINENT", "POP_EST", 'geometry']]
extent_roi = gdf_ne.query("CONTINENT == 'Africa'")

chart = alt.Chart(extent_roi).mark_geoshape(fillOpacity=0.1, stroke="green", strokeWidth=2).project(type='mercator')
til_chart = til.add_tiles(chart).properties(width=600, height=400)
til_chart.save("Test.svg")
ERROR TypeError: this.geoScale is not a function
    at Object.eval (eval at f (https://cdn.skypack.dev/-/vega-runtime@v6.1.4-aFKCWR0DKdVqzAheQZ7x/dist=es2020,mode=imports,min/optimized/vega-runtime.js:1:1317), <anonymous>:3:13)
    at g.evaluate (https://cdn.skypack.dev/-/vega-dataflow@v5.7.5-asKYS4gpPLMPf64pSozt/dist=es2020,mode=imports,min/optimized/vega-dataflow.js:1:4585)
    at g.run (https://cdn.skypack.dev/-/vega-dataflow@v5.7.5-asKYS4gpPLMPf64pSozt/dist=es2020,mode=imports,min/optimized/vega-dataflow.js:1:4799)
    at ne.Gt [as evaluate] (https://cdn.skypack.dev/-/vega-dataflow@v5.7.5-asKYS4gpPLMPf64pSozt/dist=es2020,mode=imports,min/optimized/vega-dataflow.js:1:12073)
    at ne.evaluate (https://cdn.skypack.dev/-/vega-view@v5.11.1-FQ9r1BvJOMHegkomXDyj/dist=es2020,mode=imports,min/optimized/vega-view.js:2:1621)
    at ne.Qt [as runAsync] (https://cdn.skypack.dev/-/vega-dataflow@v5.7.5-asKYS4gpPLMPf64pSozt/dist=es2020,mode=imports,min/optimized/vega-dataflow.js:1:12721)
    at j (https://cdn.skypack.dev/-/vega-view@v5.11.1-FQ9r1BvJOMHegkomXDyj/dist=es2020,mode=imports,min/optimized/vega-view.js:1:9851)
    at ne.rt [as toSVG] (https://cdn.skypack.dev/-/vega-view@v5.11.1-FQ9r1BvJOMHegkomXDyj/dist=es2020,mode=imports,min/optimized/vega-view.js:1:10308)
    at vegaToSvg (<anon>:34:27)
    at vegaLiteToSvg_v5_15 (<anon>:23:12)

Any idea what the issue could be? Is vl-convert somehow still using an older Vega version?

Saving this chart via the Vega Embed actions dropdown works.

jonmmease commented 10 months ago

Thanks for the report. I can confirm that something is off here and we are pulling in multiple versions of vega-functions (where geoScale is defined). I'll need to do some investigation

jonmmease commented 10 months ago

Here's a sketch of a solution...

A bit annoying, but it should work reliably and may also reduce the package size a little bit.

binste commented 10 months ago

I have no idea what all of this means but thank you very much for looking into it, it's really appreciated :)

jonmmease commented 10 months ago

Fix released in 1.2.0

binste commented 10 months ago

Works like a charm! Thanks for the super fast resolution 🥳