vega / vega-lite

A concise grammar of interactive graphics, built on Vega.
https://vega.github.io/vega-lite/
BSD 3-Clause "New" or "Revised" License
4.66k stars 607 forks source link

Area with lines are drawn in different layers #5726

Open domoritz opened 4 years ago

domoritz commented 4 years ago

Because we normalize to a layered spec, all the lines get drawn above all the areas. However, one would probably want the lines to be with the areas.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "width": 300, "height": 200,
  "data": {"url": "data/unemployment-across-industries.json"},
  "mark": {
    "type": "area",
    "line": true
  },
  "encoding": {
    "x": {
      "timeUnit": "yearmonth", "field": "date", "type": "temporal",
      "axis": {"format": "%Y"}
    },
    "y": {
      "aggregate": "sum", "field": "count", "type": "quantitative", "stack": null
    },
    "color": {
      "field": "series",
      "type": "nominal",
      "scale": {"scheme": "category20b"}
    }
  }
}

image

domoritz commented 4 years ago

We would get the right chart if we moved the line mark into the same group as the area mark. Maybe we can do this optimization.

image

kanitw commented 4 years ago

The only way to make this work is to move the line overlay logic to the mark compiler instead of using a macro / normalizer.

domoritz commented 4 years ago

Maybe there is another way to merge groups (may need an additional annotation so we don't always do it).

kanitw commented 4 years ago

Maybe there is another way to merge groups (may need an additional annotation so we don't always do it).

How? Having another separate path sounds quite hacky to me and there is no reason why they would want to not merge groups for area and line?