vega / vega

A visualization grammar.

Home Page:https://vega.github.io/vega

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vega lite - Cannot use datum expr in scale padding

nhannt201 opened this issue · comments

I'm having trouble utilizing "datum" within "expr" in vega-lite scale padding. I'm attempting to calculate the padding adjustment value but keep encountering the error "datum is not defined." I'm currently using vega-lite v5, and encountering this issue when applying the JSON code.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      {"x": 1, "y": 10},
      {"x": 2, "y": 5},
      {"x": 3, "y": -3},
      {"x": 4, "y": 8}
    ]
  },
  "mark": "point",
  "encoding": {
    "x": {
      "field": "x",
      "type": "quantitative",
      "scale": {"padding": {"expr": "datum.y < 3 ? 20 : 0"}}
    },
    "y": {"field": "y", "type": "quantitative"}
  }
}

The document below describes how I can use expr, but in fact, it does not fully support the expr syntax in the above case, specifically does not support "datum".

image

Is there any solution to solve the above problem?