vega-lite icon indicating copy to clipboard operation
vega-lite copied to clipboard

Support expression as a tooltip field

Open kanitw opened this issue 1 year ago • 1 comments

Currently, we can calculate expression as an entire tooltip inside mark.tooltip like this:

However, we don't support calculating expression as a field in tooltip like:

"tooltip": [
  {"field": "category", "type": "nominal"},
  {"datum": {"expr": "datum.value_end - datum.value_start"}, format: '.2%',  title: "test"} // See more design discussion below:
]

which would be useful.

Basically, we can consider extend tooltip to support datum and/or value

  • I think title should be required otherwise we don't know what's the right field title to get (except if we try to generate that from datum somehow, which is probably a bad idea).

  • {"value": {"expr": "format(datum.value_end - datum.value_start, '.2%')"}, "title": "test"} should be equivalent to: {"datum": {"expr": "datum.value_end - datum.value_start"}, "format": ".2%", "title": "test"}

    • Basically, we normally say value = doesn't go through scale/formatter (for text/tooltip) while datum would go through scale/formatter.
    • If we have to pick one, doing datum is probably better because datum should apply default formatter by default so it'll be more convenient.

cc: @domoritz @lsh

kanitw avatar Jul 18 '22 22:07 kanitw

Btw, note that I was trying to do this for pie, and I discovered that https://github.com/vega/vega-lite/issues/8301 would directly solve the problem more, but I'll leave this issue open since it seems still useful in general.

kanitw avatar Jul 18 '22 23:07 kanitw