question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extended tooltip support?

See original GitHub issue

This issue proposes to extend Vega’s tooltip support with convenience options that should also facilitate downstream configuration (by Vega-Lite, Altair, etc.). It relates to altair-viz/altair#240 and vega/vega-lite#3560; cc: @kanitw, @domoritz, @jakevdp. Comments welcomed!

Currently Vega supports a tooltip encoding channel, which expects a string (or string-coercible) value, and displays it within a tooltip by setting the HTML "title" attribute of the primary SVG or Canvas element. This basic mechanism can be extended by overriding the handleTooltip method of the base scenegraph Handler class.

Part 1: Tooltip Specification

The main proposal is to provide tooltip specification options beyond a single string:

  1. If the tooltip channel resolves to null or undefined, then no tooltip should be shown.
  2. If the tooltip channel resolves to an Object value (other than Date or Array), then all key-value pairs in the object should be included in the tooltip, one per line (e.g., "key1: value1\nkey2: value2").
  3. If the tooltip channel resolves to an Array, contained values will be recursively processed, with appended brackets ([, ]).
  4. If the tooltip channel resolves to any other value (e.g., boolean, number, string, date) it should be coerced to a string and shown.

Note that the above proposal easily accommodates showing all properties in a data object by setting the tooltip channel value to the backing datum. For example, "tooltip": {"signal": "datum"}.

Part 2: Extensible Tooltip Rendering

The core Vega library will leverage built-in browser support for tooltips via the HTML "title" attribute. More sophisticated approaches (e.g., tooltips shown within custom HTML elements) will remain the responsibility of third-party extensions. Custom tooltip handlers will be responsible for appropriately handling the tooltip channel values passed in by Vega. The additions above are intended to make it easier for extensions to “plug-in” while leveraging spec-level configuration support.

To facilitate local registration of custom tooltip handlers, the Vega View object will be extended with support for setting a custom tooltip handler on a per-View basis. Clients will be able to pass a tooltip handler as an option to the constructor, or potentially using a getter/setter method. See below for an example. These additions will allow individual views to directly employ customized tooltips, without the need for global registration by overriding the Handler prototype chain. (That said, global registration will still be a viable option if desired!)

Issues to Resolve

Recursion: Should we support arbitrary levels of nesting (e.g., due to tooltip values containing sub-arrays or sub-objects)? My inclination is to have Vega’s default support limit the depth to one level only to prevent massive, unreadable tooltips.

Array formatting: Should array values be formatted on a single line of text or on separate lines? I lean towards a single line. Browser tooltips should automatically word-wrap as needed.

Automatic value formatting: Tooltip values explicitly defined within a Vega spec can be formatted (e.g., number and date formats) using signal expressions. However, when passing raw values (or objects containing raw values), standard string coercion will not always produce desirable values (e.g., numbers with too many significant digits, full date strings, etc.) Should Vega provide built-in support for more automatic formatting? If so, how? As a starting point I lean towards no built-in “automagic” support, but would be happy to consider workable proposals.

Tooltip handler registration: Currently a tooltip handler is a single method that gets invoked in response to encoded tooltip values. As an instance method of the Handler class, it has access to the DOM Canvas or SVG element via the this context. Is more context needed, such as a reference to the overarching View instance or some other means of accessing configuration information? My default position is to keep the design as-is, as third-party code could instantiate custom tooltip handlers with access to config information (via closures, etc.). For example, if custom configuration was included in the usermeta field of a Vega spec, third party code might access that spec and return an appropriately configured tooltip handler to include as a View constructor option. However, I’m open to hearing alternative points of view!

Example

For clarity, here is an example of what I have in mind:

// Vega JSON spec
const spec;

// Instantiate a custom tooltip handler (3rd party code)
// The handler generator may access spec.usermeta.tooltip (or similar) as needed
const tooltipHandler = tooltipHandler(spec);

// Instantiate the Vega View
const view = new vega.View(
  vega.parse(spec),
  {tooltipHandler: tooltipHandler} // register custom tooltip handler
);

Perhaps vega-embed can be extended to support a tooltip generator like that above, and perform this registration as needed? In that case vega-embed would not need to bundle a custom tooltip provider, but could be easily configured to include one when desired.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
domoritzcommented, Apr 21, 2018

We are working on bringing extended tooltip support to Vega-Lite and update Vega-Tooltip.

2reactions
jheercommented, Apr 20, 2018

Added in v3.3.0! Documentation for adding custom tooltip handlers is included in the View API docs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

About Tooltips and Extended Tooltips for Commands
Tooltips are descriptive messages that are displayed near the cursor when it hovers over a toolbar or ribbon panel button.
Read more >
Extended Tooltips - ContentDB - Minetest
This mod extends the support of tooltip for items to make it possible for mods to add more informative texts.
Read more >
Adding an Extended Tooltip to a Variable - ServiceNow
Hello, I was wondering if there was a way to create an extended tooltip to a checkbox variable. Currently, the tooltip field located...
Read more >
Extend visuals with report page tooltips - Power BI
Page tooltips don't support interactivity. If you want your report users to interact, create a drillthrough page instead.
Read more >
8 Tooltip Examples to Inspire You in 2022 - Userpilot
Looking for a collection of great tooltip examples that you can replicate in your SaaS? ... they can be part of an extended...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found