Adding Swatch + Multiple Columns in a Single Tooltip Field

I have a simple CDS with two columns (title and fill_color)

I want to create a hover tooltip like the below (one single line with the title and swatch).

tooltips=[("Title", "@title $swatch:fill_color")]

This produces a tooltip with just the swatch, is there anyway to have the title in the same line as the swatch?

The swatch capability is pretty ancient has never gotten much attention, this seems like a previously unknown limitation. [1] I’d suggest you file a GitHub Issue with full details, most especially a complete Minimal Reproducible Example.


  1. glancing at the codepath it appears that if a swatch specification is found then further processing of the former string stops. ↩︎

Noting that these days it might also be possible to draw a similar color element using a CustomJSHover.

Edit: well, perhaps {custom} and {safe} cannot currently be combined.

Thanks @Bryan
I’ve submitted the bug report: [BUG] Tooltip Doesn't Display Multiple Fields with Swatch · Issue #14045 · bokeh/bokeh · GitHub

This is my first time submitting an official bug, and since it seems like a fairly simple one, is there anyway I can help fix it? Do I need to wait for the bug to be placed on the task list?

This would be my first time attempting to contribute, so I want to get my feet wet with something relatively light.

I really appreciate your enthusiasm @Gen! In this case, however, I actually plan to open a discussion about deprecating and removing the $swatch special variable, and replacing it with techniques that are are more in line with modern Bokeh. The old $swatch has a number of deficiencies:

  • not configurable at all (size, shape, etc)
  • has obscure syntax that is hard to document/discover
  • adds complexity internally that is undesirable

Better would be to make CustomJSHover a workable option so that users can self-serve any needs they have, or else add actual formatter models for color values, that can be used in the same way that all other custom formatters work these days.

If you want to join the Bokeh dev slack we can try to chat about other possible issues based on you interests/experience.

@Bryan Thanks!
I’ll join the devstack…I just want to slowly work my way up thru the codebase.

Regarding $swatch, completely understood. I thought it was fairly clunky that this, and only this, $swatch field needed a colon to another color column. Removing/rewriting it seems correct (at least from the user perspective, haven’t looked at the code)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.