Skip to content
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

Different structure for TopLevelRepeatSpec since v4.9 #7775

Closed
mattijn opened this issue Oct 30, 2021 · 3 comments
Closed

Different structure for TopLevelRepeatSpec since v4.9 #7775

mattijn opened this issue Oct 30, 2021 · 3 comments
Labels

Comments

@mattijn
Copy link
Contributor

mattijn commented Oct 30, 2021

While reviewing https://github.com/ChristopherDavisUCI/altair/pull/1/files#diff-26bb768d345282c152ff21c1581804be0e84fdfaba9e8f530600d9ff068bd7d8L609 I thought one should not overrule the Vega-Lite schema, but upon closer inspection I cannot see why the TopLevelRepeatSpec follows a different structure since vega-lite 4.9 onwards?

Observe:

import re
import requests

vlv = ['v4.8.1', 'v4.9.0', 'v4.17.0', 'v5.1.0']

for vl in vlv:
    print(vl)
    r = requests.get(f'https://raw.githubusercontent.com/vega/schema/master/vega-lite/{vl}.json')
    schema = r.json()
    defs = schema['definitions']

    r = re.compile("TopLevel.*")
    toplevels = list(filter(r.match, list(defs.keys())))

    for tl in toplevels:
        if tl == 'TopLevelRepeatSpec':
            att = list(defs[tl].keys())
            print(f'{tl}: {att}')
v4.8.1
TopLevelRepeatSpec: ['additionalProperties', 'properties', 'required', 'type']
v4.9.0
TopLevelRepeatSpec: ['anyOf']
v4.17.0
TopLevelRepeatSpec: ['anyOf']
v5.1.0
TopLevelRepeatSpec: ['anyOf']

Excluding TopLevelSpec, all other TopLevel*Spec's keep respecting the ['additionalProperties', 'properties', 'required', 'type'] structure:

v4.8.1
TopLevelNormalizedConcatSpec<GenericSpec>: ['additionalProperties', 'properties', 'required', 'type']
TopLevelNormalizedHConcatSpec<GenericSpec>: ['additionalProperties', 'properties', 'required', 'type']
TopLevelNormalizedVConcatSpec<GenericSpec>: ['additionalProperties', 'properties', 'required', 'type']
TopLevelLayerSpec: ['additionalProperties', 'properties', 'required', 'type']
TopLevelRepeatSpec: ['additionalProperties', 'properties', 'required', 'type']
TopLevelFacetSpec: ['additionalProperties', 'properties', 'required', 'type']
TopLevelSpec: ['anyOf', 'description']
TopLevelUnitSpec: ['additionalProperties', 'properties', 'required', 'type']
v4.9.0
TopLevelNormalizedConcatSpec<GenericSpec>: ['additionalProperties', 'properties', 'required', 'type']
TopLevelNormalizedHConcatSpec<GenericSpec>: ['additionalProperties', 'properties', 'required', 'type']
TopLevelNormalizedVConcatSpec<GenericSpec>: ['additionalProperties', 'properties', 'required', 'type']
TopLevelLayerSpec: ['additionalProperties', 'properties', 'required', 'type']
TopLevelRepeatSpec: ['anyOf']
TopLevelFacetSpec: ['additionalProperties', 'properties', 'required', 'type']
TopLevelSpec: ['anyOf', 'description']
TopLevelUnitSpec: ['additionalProperties', 'properties', 'required', 'type']
v4.17.0
TopLevelNormalizedConcatSpec<GenericSpec>: ['additionalProperties', 'properties', 'required', 'type']
TopLevelNormalizedHConcatSpec<GenericSpec>: ['additionalProperties', 'properties', 'required', 'type']
TopLevelNormalizedVConcatSpec<GenericSpec>: ['additionalProperties', 'properties', 'required', 'type']
TopLevelLayerSpec: ['additionalProperties', 'properties', 'required', 'type']
TopLevelRepeatSpec: ['anyOf']
TopLevelFacetSpec: ['additionalProperties', 'properties', 'required', 'type']
TopLevelSpec: ['anyOf', 'description']
TopLevelUnitSpec: ['additionalProperties', 'properties', 'required', 'type']
v5.1.0
TopLevelConcatSpec: ['additionalProperties', 'properties', 'required', 'type']
TopLevelHConcatSpec: ['additionalProperties', 'properties', 'required', 'type']
TopLevelVConcatSpec: ['additionalProperties', 'properties', 'required', 'type']
TopLevelLayerSpec: ['additionalProperties', 'properties', 'required', 'type']
TopLevelRepeatSpec: ['anyOf']
TopLevelFacetSpec: ['additionalProperties', 'properties', 'required', 'type']
TopLevelSelectionParameter: ['additionalProperties', 'properties', 'required', 'type']
TopLevelSpec: ['anyOf', 'description']
TopLevelUnitSpec: ['additionalProperties', 'properties', 'required', 'type']
@mattijn
Copy link
Contributor Author

mattijn commented Oct 30, 2021

I'm no TypeScript user, but this line looks like to make it an anyOf:

export type RepeatSpec = NonLayerRepeatSpec | LayerRepeatSpec;

Not sure if this is really necessary this way. It would be great if not.

Altair context:
It currently makes generating the Altair wrapper failing for some specs when trying updating to 4.17.0. Not per se for repeating charts by itself, but for resolving the color scale independently of a repeating chart. For eg.

import altair as alt
from vega_datasets import data
df = data.population_engineers_hurricanes()

chart = alt.Chart(df[0:20]).mark_bar().encode(
    alt.Y('state:N'),
    alt.X(alt.repeat('column'), type='quantitative'),
    alt.Color('count()')
).properties(
    width=50,
    height=200
).repeat(
    column=['population', 'engineers', 'hurricanes']  
).resolve_scale(color='independent')
chart
ValueError: <class 'altair.vegalite.v4.api.RepeatChart'> object has no attribute 'resolve'

When the .resolve_scale(color='independent') is removed the repeated chart renders fine

Manually setting, will work though:

chart.resolve = alt.Resolve(scale=alt.ScaleResolveMap(color='independent'))
chart

@ChristopherDavisUCI
Copy link
Contributor

Thank you @mattijn for posting that link to the relevant portion of the typescript file; it helped me better understand the structure of TopLevelRepeatSpec. For whatever it's worth, I'm confident that a suitable work-around can eventually be found in the Altair side. (There is a workaround currently in what's written, but it's not a longterm solution.)

I used to think there was a bug somewhere on the Vega-Lite side, but I'm no longer convinced of that. There is an inconsistency somewhere between the TopLevelRepeatSpec definition and what Altair expects, but I haven't been able to understand why this definition in particular is causing problems. (I see how TopLevelRepeatSpec is different from the other TopLevel... objects, but not how it's different from the other 400-ish definitions.)

Anyway I just wanted to post something, because I think this issue was raised for my benefit. I will post an update if I get my issues resolved. Thanks!

@mattijn
Copy link
Contributor Author

mattijn commented Nov 3, 2021

Sorry for the noise here; closing

@mattijn mattijn closed this as completed Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants