altair
altair copied to clipboard
Extend candidate aliases
As was originally posted by @mattijn in https://github.com/altair-viz/altair/issues/2732#issuecomment-1335673267:
There are more candidate aliases I think?
import requests as r
import re
vl_scheme = r.get('https://vega.github.io/schema/vega-lite/v5.json').json()
scheme_str = str(vl_scheme['definitions'])
col = []
for word in re.findall(r"\w+", scheme_str):
if 'Params' in word:
col.append(word)
list(set(col))
Returns 10 candidates:
['TimeUnitParams',
'TitleParams',
'SchemeParams',
'GraticuleParams',
'SequenceParams',
'BinParams',
'ImputeParams',
'ScaleBinParams',
'ScaleInterpolateParams',
'AutoSizeParams']
I think we can extend the aliases to all of these. I was trying:
alt.Color('value:Q').scale(scheme=alt.Scheme('viridis'))
But hit an:
AttributeError: module 'altair' has no attribute 'Scheme'
Hi @mattijn, that sounds fine to me. The reason I proposed aliases for some of these like BinParams but not others was just for symmetry with the Property Setters. For example, I believe there is a bin Property Setter, but not a scheme Property Setter. No other opinion on my end, just wanted to record this.
Thanks for the clarification @ChristopherDavisUCI, that make sense for #2732. The remaining properties are indeed not available as Property Setter, but it is still useful to have an alias I think.
In addition to what @ChristopherDavisUCI mentioned, I think it does make sense to include alias for the classes that we expect users to directly interface with (and maybe hiding the *Params version from tab completion for those that have shortcuts?). For example, do we need aliases for 'GraticuleParams', 'SequenceParams', since there is already alt.sequence and alt.graticule?
Maybe we should also consider adding shortcuts for some of the *Config classes? Maybe not as important but I just learned in https://github.com/altair-viz/altair/issues/3216#issuecomment-1747437368 that we can do something like
alt.Chart(iris, view=alt.ViewConfig(strokeWidth=0))
Which might seem inconsistent with that if we modify say the height we can use alt.Step instead of alt.StepConfig
alt.Chart(iris, height=alt.Step(40))
So I wonder if it should also be called just alt.View. However, there are a lot of these config options, so maybe there is a chance of name collisions with other objects and maybe Config is fundamentally something different so it makes sense to be explicit in the name?
import requests as r
import re
vl_scheme = r.get('https://vega.github.io/schema/vega-lite/v5.json').json()
scheme_str = str(vl_scheme['definitions'])
col = []
for word in re.findall(r"\w+", scheme_str):
if 'Config' in word:
col.append(word)
list(set(col))
['RectConfig',
'ProjectionConfig',
'BarConfig',
'LegendConfig',
'AreaConfig',
'PointSelectionConfig',
'AnyMarkConfig',
'MarkConfig',
'HeaderConfig',
'ScaleConfig',
'ErrorBarConfig',
'BrushConfig',
'BoxPlotConfig',
'TitleConfig',
'PointSelectionConfigWithoutType',
'IntervalSelectionConfigWithoutType',
'Config',
'CompositionConfig',
'SelectionConfig',
'LineConfig',
'AxisConfig',
'ErrorBandConfig',
'FormatConfig',
'TickConfig',
'StyleConfigIndex',
'IntervalSelectionConfig',
'RangeConfig',
'ViewConfig']