feat: Support params to be passed inline to encodings#3993
feat: Support params to be passed inline to encodings#3993joelostblom wants to merge 4 commits intofeat/inline-calcfrom
Conversation
What I corrected/simplified:
- In FieldChannelMixin.to_dict (altair/vegalite/v6/schema/channels.py:163), I moved expression/variable-param handling before parsed-shorthand context setup.
- This removes the need for the previous context.pop("parsed_shorthand", None) workaround and avoids context leakage by design.
- Behavior is unchanged for normal field-string paths, but this is cleaner and less fragile.
What I added to tests:
- Added a missing regression test for the bare channel case:
- encode(x=param) (not just encode(x=alt.X(param, ...)))
- File: tests/vegalite/v6/test_api.py:2259
- This ensures _wrap_in_channel path for variable params is covered.
|
Great to have these (and other PRs) related to improving parameter and expressions in a pythonic way! Will this also mean that expression based examples like this one: https://altair-viz.github.io/user_guide/marks/geoshape.html#expressions can be simplified? |
|
Glad to hear you like it! Hmm, in that spec I don't think there is much simplification to be made. We could avoid the lon/lat/depth transform_calculate for encodings by using inline expressions directly in channels. But in this chart, lon is also reused in transform_filter, so keeping transform_calculate is still reasonable (compute once, reuse twice). We could move the other two inline but maybe it is more intuitive to see lat and lon computed in the same place. An example of a spec that will be improved is the one from the encoding channel docs, which can be rewritten as the example in my initial comment instead (I will update the docs on this PR next). |
I will rebase after #3990 and #3991, so let's wait with merging until that.
This PR layers inline variable-parameter support on top of existing inline-calc behavior, so users can pass variable params directly in encodings without manually writing
alt.datum[param].Syntax now supported:
Examples
Open the Chart in the Vega Editor
Open the Chart in the Vega Editor
Details: