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.62k stars 598 forks source link

Expr does not work for guide title #7264

Open mattijn opened 3 years ago

mattijn commented 3 years ago

I've the following chart that renders correctly, even though it issues a schema validation warning.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "url": "https://vega.github.io/vega-lite/data/us-10m.json",
    "format": {"type": "topojson", "feature": "states"}
  },
  "params": [
    {
      "name": "selection",
      "select": {"type": "point", "fields": ["key"]},
      "value": [{"key": "hurricanes"}],
      "bind": {
        "input": "select",
        "options": ["population", "engineers", "hurricanes"]
      }
    }
  ],
  "transform": [
    {
      "lookup": "id",
      "from": {
        "data": {"url": "data/population_engineers_hurricanes.csv"},
        "key": "id",
        "fields": ["population", "engineers", "hurricanes"]
      }
    },
    {"fold": ["population", "engineers", "hurricanes"]},
    {"filter": {"param": "selection"}}
  ],
  "projection": {"type": "albersUsa"},
  "mark": "geoshape",
  "encoding": {
    "color": {
      "field": "value",
      "type": "quantitative",
      "legend": {"title": {"signal": "selection_key"}}
    }
  }
}

signal_legend The schema validation comes from this line:

"legend": {"title": {"signal": "selection_key"}}

While reading the new docs (congrats again!) I have the feeling that I should be able to replace the signal with an expr, as such:

"legend": {"title": {"expr": "selection"}}

but then the legend title does not render anymore. expr_legend

Is this something that could/should be supported with an expr?


spec using signal Open the Chart in the Vega Editor

spec using expr Open the Chart in the Vega Editor

domoritz commented 3 years ago

Done in https://github.com/vega/vega-lite/pull/7265

mattijn commented 3 years ago

Awesome

domoritz commented 3 years ago

Reopening until the pull request is merged

liquidcarbon commented 4 months ago

Any update on expr in titles? I'd like to be able to change Y axis title dynamically

image

liquidcarbon commented 4 months ago

~Looks like it's already working in VegaLite, but not yet implemented in Altair.~ https://github.com/vega/altair/issues/3417

Correction: it's working but with a warning, as explained in the Altair thread. The true solution is to implement it here on the Vega side.