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.64k stars 604 forks source link

Default stops for gradients #5284

Open jwoLondon opened 5 years ago

jwoLondon commented 5 years ago

Currently with the new (VL4) gradient specification, there is a default left-to-right direction for linear gradients (i.e. defaults of "x1": 0, "x2": 1, "y1": 1, "y2": 1). However there appears to be no default for the stops setting. For example, following spec generates the error Cannot read property 'length' of undefined and prevents rendering:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "data": {"url": "https://vega.github.io/vega-lite/data/stocks.csv"},
  "transform": [{"filter": "datum.symbol === 'GOOG'"}],
  "encoding": {
    "x": {"field": "date", "type": "temporal", "axis": {"format": "%Y"}},
    "y": {"field": "price", "type": "quantitative"}
  },
  "mark": {"type": "area", "color": {"gradient": "linear"}}
}

Would it make sense to provide default stops settings to prevent this? Perhaps a white to default blue, equivalent to

"stops": [
    {"offset": 0, "color": "white"},
    {"offset": 1, "color": "#4682b4"}
]
jwoLondon commented 5 years ago

Related, but minor: I wonder if a better set of X and Y defaults would be for a vertical rather than horizontal gradient. This, I suspect, would be the most common orientation for marks that are likely to have a gradient fill (in a ratio of 2:1 in the example gallery).