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

Facet of concat does not work #5261

Open
jakevdp opened this issue Aug 4, 2019 · 3 comments
Open

Facet of concat does not work #5261

jakevdp opened this issue Aug 4, 2019 · 3 comments
Labels
Area - View Composition Bug 🐛 P3 Should be fixed at some point

Comments

@jakevdp
Copy link
Contributor

jakevdp commented Aug 4, 2019

Faceting of concatenated charts appears to be supported by the renderer, but not allowed by the schema. This means that tools like Altair, which require schema-validated chart specifications, cannot create this type of chart.

Here is an example (vega editor):

{
  "spec": {
    "vconcat": [
      {
        "mark": "point",
        "encoding": {
          "x": {"field": "Horsepower", "type": "quantitative"},
          "y": {"field": "Miles_per_Gallon", "type": "quantitative"}
        }
      },
      {
        "mark": "tick",
        "encoding": {
          "x": {"field": "Horsepower", "type": "quantitative"}
        }
      }
    ]
  },
  "data": {"url": "data/cars.json"},
  "facet": {"field": "Origin", "type": "nominal"}
}

visualization - 2019-08-04T065511 933

It renders as expected, however the specification does not meet the schema requirements:

# python 3
from urllib.request import urlopen
import json
import jsonschema

schema = json.load(urlopen("https://raw.githubusercontent.com/vega/schema/master/vega-lite/v3.4.0.json"))
spec = json.loads("""
{
  "spec": {
    "vconcat": [
      {
        "mark": "point",
        "encoding": {
          "x": {"field": "Horsepower", "type": "quantitative"},
          "y": {"field": "Miles_per_Gallon", "type": "quantitative"}
        }
      },
      {
        "mark": "tick",
        "encoding": {
          "x": {"field": "Horsepower", "type": "quantitative"}
        }
      }
    ]
  },
  "data": {"url": "data/cars.json"},
  "facet": {"field": "Origin", "type": "nominal"}
}
""")
jsonschema.validate(spec, schema)
---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
<ipython-input-6-df00bc6f0e25> in <module>()
     27 }
     28 """)
---> 29 jsonschema.validate(spec, schema)

1 frames
/usr/local/lib/python3.6/dist-packages/jsonschema/validators.py in validate(self, *args, **kwargs)
    128         def validate(self, *args, **kwargs):
    129             for error in self.iter_errors(*args, **kwargs):
--> 130                 raise error
    131 
    132         def is_type(self, instance, type):

ValidationError: {'spec': {'vconcat': [{'mark': 'point', 'encoding': {'x': {'field': 'Horsepower', 'type': 'quantitative'}, 'y': {'field': 'Miles_per_Gallon', 'type': 'quantitative'}}}, {'mark': 'tick', 'encoding': {'x': {'field': 'Horsepower', 'type': 'quantitative'}}}]}, 'data': {'url': 'data/cars.json'}, 'facet': {'field': 'Origin', 'type': 'nominal'}} is not valid under any of the given schemas

Failed validating 'anyOf' in schema:
    {'anyOf': [{'$ref': '#/definitions/TopLevelUnitSpec'},
               {'$ref': '#/definitions/TopLevelFacetSpec'},
               {'$ref': '#/definitions/TopLevelLayerSpec'},
               {'$ref': '#/definitions/TopLevelRepeatSpec'},
               {'$ref': '#/definitions/TopLevelConcatSpec'},
               {'$ref': '#/definitions/TopLevelVConcatSpec'},
               {'$ref': '#/definitions/TopLevelHConcatSpec'}],
     'description': 'A Vega-Lite top-level specification.\n'
                    'This is the root class for all Vega-Lite '
                    'specifications.\n'
                    '(The json schema is generated from this type.)'}
@domoritz
Copy link
Member

domoritz commented Aug 4, 2019

We only support unit and layer inside facet right now since there are some complicated layout issues to solve otherwise. We are tracking this issue in #2760.

For now, you are supposed to swap concat and facet but somehow this breaks:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "data": {"url": "data/cars.json"},
  "vconcat": [
    {
      "facet": {"field": "Origin", "type": "nominal"},
      "spec": {
        "mark": "point",
        "encoding": {
          "x": {"field": "Horsepower", "type": "quantitative"},
          "y": {"field": "Miles_per_Gallon", "type": "quantitative"}
        }
      }
    },
    {
      "facet": {"field": "Origin", "type": "nominal"},
      "spec": {
        "mark": "tick",
        "encoding": {
          "x": {"field": "Horsepower", "type": "quantitative"}
        }
      }
    }
  ]
}

We can tackle these issues (and in particular #2760) after refactoring repeat: #4947.

@domoritz domoritz changed the title Faceting of concatenated charts not allowed by the schema Concat of facet and facet of concat do not work Aug 4, 2019
@domoritz domoritz added the P3 Should be fixed at some point label Aug 4, 2019
@joelostblom
Copy link
Contributor

Just a note here that concat of facet works since #7639 so updating the title of this issue.

@joelostblom joelostblom changed the title Concat of facet and facet of concat do not work Facet of concat does not work Feb 22, 2023
@domoritz
Copy link
Member

Thank you. Facet of concat is a lot tricker to get right and less important imo. I'm glad we got concat of X working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area - View Composition Bug 🐛 P3 Should be fixed at some point
Projects
None yet
Development

No branches or pull requests

4 participants