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
parameters added to a layer should be serialised outside the scope of the layer #2597
Comments
Thanks for bringing this up @mattijn. I'm pretty confident we can control this on the Altair end, so I think it's just a matter of having a clear idea of what we want. Since the beginning of this update, getting parameters to work correctly with multi-view charts has been one of the biggest hurdles. I might not have a chance to look at this until the weekend. |
Thanks again for bringing this up @mattijn! I'm hopeful that whatever we want to do will be easy to accomplish. I think the difficult part is deciding what we're supposed to do. In a lot of cases I just copied the old Altair code. For example, here is some Altair v3 code for the Here is some Altair v3 code for the @mattijn, do you agree that my copying this old To me it's not obvious what to do. I think the most elegant solution would be to get rid of all this "add to all subcharts" functionality, but that would break a lot of old examples. One idea is we could keep that functionality for the deprecated In case we've all forgotten they exist, here are some possibly(??) related issues: Anyway, I'm hopeful the coding can be done fairly easily. If you give me precise instructions for what should happen when |
I agree that just copying the current Eg: import altair as alt
from vega_datasets import data
import geopandas as gpd
# load data
gdf_quakies = gpd.read_file(data.earthquakes.url, driver='GeoJSON')
gdf_world = gpd.read_file(data.world_110m.url, driver='TopoJSON')
# define parameters
range0 = alt.binding_range(min=-180, max=180, step=5)
rotate0 = alt.parameter(value=120, bind=range0, name='rotate0')
hover = alt.selection_point(on='mouseover', clear='mouseout')
# world disk
sphere = alt.Chart(alt.sphere()).mark_geoshape(
fill='aliceblue',
stroke='black',
strokeWidth=1.5
)
# countries as shapes
world = alt.Chart(gdf_world).mark_geoshape(
fill='mintcream',
stroke='black',
strokeWidth=0.35
)
# earthquakes as circles with fill for depth and size for magnitude
# the hover param is added on the mar_circle only
quakes = alt.Chart(gdf_quakies).mark_circle(
opacity=0.35,
tooltip=True,
stroke='black'
).transform_calculate(
lon="datum.geometry.coordinates[0]",
lat="datum.geometry.coordinates[1]",
depth="datum.geometry.coordinates[2]"
).transform_filter('''
(rotate0 * -1) - 90 < datum.lon && datum.lon < (rotate0 * -1) + 90
'''
).encode(
longitude='lon:Q',
latitude='lat:Q',
strokeWidth=alt.condition(hover, alt.value(1, empty=False), alt.value(0)),
size=alt.Size('mag:Q', scale=alt.Scale(type='pow', range=[1,1000], domain=[0,6], exponent=4)),
fill=alt.Fill('depth:Q', scale=alt.Scale(scheme='lightorange', domain=[0,400]))
).add_parameter(hover)
# define projection and add the rotation param for all layers
comb = alt.layer(sphere, world, quakes).project(
'orthographic',
rotate=[90, 0, 0]
).add_parameter(rotate0)
# temporary changing params to top-level
# and defining the rotate reference expression on compiled VL directly
chart_vl = comb.to_dict()
chart_vl['params'] = chart_vl['layer'][0].pop('params')
chart_vl['projection']['rotate'] = {'expr':'[rotate0, 0, 0]'}
alt.Chart().from_dict(chart_vl) Here, I had to add the It somehow make sense, but I can imagine that people will expect that the parameters will work, no matter where added. |
My vote is that What do you think? I don't think there is a clear solution... this is just one possibility. |
From a VL perspective I agree. But the current behavior of altair was quite convenient though, no need to think all this thorough. I'm not sure if it is intended and by design that defined local and global parameters do not resolve or interplay smoothly with each other. Maybe it's good to discuss this first a bit more at the VL repo with some minimal spec-examples, since the current cases are a bit scattered and lengthy (my bad). |
A single chart object works with parameters
Now I like to combine the graticules with a sphere, so I layer them. First without parameters (this still works):
But it breaks if I add the parameters on the layered chart:
It is because the
params
are added to the first feature in thelayer
instead of being serialised outside the scope of the layer. Here I would expect it to create a globalparams
definition. I think the later is what I would expect if I add parameters toalt.layer()
, so I don't feel that vega/vega-lite#7812 applies here.I can manually override, what I think is wrongly behaviour, with the following:
Side note: the
.project()
is also defined on thealt.layer()
, but is serialised correctly outside the scope of the layer (here globally)cc: @ChristopherDavisUCI, what you think? Do we have control over this in Altair, or it happens in the VL-serialization?
The text was updated successfully, but these errors were encountered: