vega / vega-lite-api

A JavaScript API for Vega-Lite.
https://observablehq.com/@vega/vega-lite-api
BSD 3-Clause "New" or "Revised" License
211 stars 18 forks source link

Confused by the predicate in `vl.color().condition()` #459

Open mhkeller opened 1 year ago

mhkeller commented 1 year ago

The docs for vl.color().condition() say:

A field definition or one or more value definition(s) with a parameter predicate.

I'm trying to replicate the point_invalid_color using Vega Lite API and based on the language in the doc I would have thought I would do:

vl.color().condition(
  'datum[\'IMDB Rating\'] === null || datum[\'Rotten Tomatoes Rating\'] === null',
  '#aaa'
)

That compiles to:

"color": {
  "condition": [
    "datum['IMDB Rating'] === null || datum['Rotten Tomatoes Rating'] === null"
    "#aaa"
  ]
}

I have to do this instead:

vl.color().condition({
  test: 'datum[\'IMDB Rating\'] === null || datum[\'Rotten Tomatoes Rating\'] === null',
  value: '#aaa'
})

Is this the desired API? If so, I would expect the docs to describe an object with keys of test and value.