vega/vega-tooltip

Hide undefined tooltip attributes

fxwiegand opened this issue · 19 comments

I am working on a vega-lite visualization with data that can have quite a few attributes. Not all of my data needs to have all attributes set so some could be undefined. My data could look like this:

[
    {"a":1, "b":"A", "c":"U"},
    {"a":3, "b":"X"},
    {"a":2, "c":"Z", "d":"bar"}
]

I would like to display all fields (that are actually defined and hide the undefined values) in the tooltip like this:

    "tooltip": [
      {"field": "a", "type": "quantitative"},
      {"field": "b", "type": "nominal"},
      {"field": "c", "type": "nominal"},
      {"field": "d", "type": "nominal"}
    ] 

As i understand, the vega-tooltip handler checks every field for null or empty, but before that, vega-Lite somehow sets not existing keys to the value "undefined" that is then displayed.

See an example in the vega online editor here.

Maybe we stringify undefined. Sounds like a small issue somewhere that should be fixed. Do you want to take a stab at it?

I think this is a vega-tooltip issue since Vega-Lite doesn't control how to display with value = undefined.

(Transferred to vega-tooltip)

I think this is also a vega-lite issue since vega-lite itself sets the non existing fields to (the string) undefined and not even the value undefined.
The possible vega-tooltip issue is not checking for the value undefined right here.

I agree it could be both. Do you want to step through the code and see what needs to change?

I just found out that the line I referenced above is checking for undefined with value == null (explanation here).

The possible vega-tooltip issue is not checking for the value undefined right here.

Since the tooltip handler is displaying the string undefined it must have been stringified by vega-lite somewhere (maybe here?). For that i would suggest moving this issue back to vega-lite.

I'd like to dive deeper into finding the problem where undefined is stringified but i am currently working on by bachelor thesis which is quite time consuming.

Is the vega online editor still using an old version? The issue with the example I mentioned when i started the issue is still there.

See an example in the vega online editor here.

I also get the same problem in my own project using vega-lite 4 and vega-tooltip 0.19.1.

Vega-Tooltip now ignores undefined properties. However, Vega-Lite converts undefined to "undefined" so that users don't accidentally miss it. See vega/vega-lite#5147 for the discussion about this.

Here is an example in Vega that hides undefined values (I just modified the expression in the generated Vega).

So there is currently no way using only Vega-Lite to hide properties that are not defined for every mark?

So I cannot use Vega-Lite for displaying data sets that only share some attributes. No chance the conversion from undefined to "undefined" could be modified to be optional so that users are able to choose for themselves what will be displayed and what will be hidden. I don't think that my given example is very uncommon and something that will never happen (in fact in my case of building a web-based genome viewer it does happen).

See an example in the vega online editor here.

In the discussion in #5147 @kanitw also mentioned to have a config where the user can choose to show or hide the undefined values.

It's probably better to have a config to choose to display undefined or not in all places?

I'm happy to revise the behavior. I don't have the cycles to think through all the alternatives and implement them but I would be thrilled if you took a stab at laying out the design space, define what the expected behavior in different cases is, how we ensure compatibility with axes, and decide whether Vega-Lite or Vega-Tooltip need to change. How does that sound? I would really appreciate your help here!

Any Updates in this?
I am also facing the similar issue. Is there any way to hide the tooltip values that are not available in the data source?
I am stuck in development because of this.

See my comment above. I’d love to have some help on thinking though the design space.

I am interested to see if there is any news about it.

See the notes above.

🚀 Issue was released in v0.27.0 🚀

I'm currently on vega-tooltip v0.27.0 and still experiencing the issue, is this still waiting to be resolved, or am I missing something?

See my comment in #251 (comment)

See my comment in #251 (comment)

Looks like my version of vega-lite parses undefined fields to NaN - so adding an isNaN(value) check to the aforementioned line of code in vega-tooltip would negate. Not sure how this would effect your "ensure compatibility with axes" point, but I feel like excluding the field, rather than showing <field>: NaN in the tooltip would be desirable for my use case (and probably others).