Change Hover title depending on positive and negative X and Y values

I’m wondering if it is possible to change titles for @x and @y values depending if they are possitive or negative.
This is what I have

TOOLTIPS = [("Point ", "$index"), (pressure, "@y"), (axial_force, "@x")]
fig = figure(sizing_mode='stretch_both', tooltips=TOOLTIPS)

And this is what I need:

if @x>0:
    pressure = "Internal Pressure"
else:
    pressure = "External Pressure"

if @y>0:
    axial_force = "Tension"
else:
    axial_force = "Compression"

Check out this very recent thread: Hover Tool dynamic fields - #5 by gmerritt123

You can basically set up your tooltips in a dictionary, one for each case, pass that tooltip dict, the hovertool, and the datasource to CustomJS that is trigged on source inspected indices.change (i.e. on hover). The CustomJS looks at the value of the inspected index, and depending on the value, assigns the tooltip you want to display.

1 Like

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