Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for formatters to ValueRef #13650

Open
wants to merge 4 commits into
base: branch-3.5
Choose a base branch
from

Conversation

mattpap
Copy link
Contributor

@mattpap mattpap commented Jan 17, 2024

Example (side-by-side comparison):

Screenshot from 2024-01-17 15-12-58

import numpy as np

from bokeh.plotting import figure, show

N = 4000
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
radii = np.random.random(size=N) * 1.5
colors = np.array([(r, g, 150) for r, g in zip(50+2*x, 30+2*y)], dtype="uint8")

TOOLS="crosshair,pan,wheel_zoom,zoom_in,zoom_out,box_zoom,undo,redo,reset,tap,save,box_select,poly_select,lasso_select,examine,help"

p = figure(tools=TOOLS)

p.circle(x, y, radius=radii, fill_color=colors, fill_alpha=0.6, line_color=None)

from bokeh.models import HoverTool, Styles
from bokeh.models.dom import Div, ValueRef, Index, Template

style = Styles(
    display="grid",
    grid_template_columns="auto auto",
    column_gap="10px",
)
grid = Div(style=style)
grid.children = [
    "index",  Div(children=["#", Index()]),
    "(x, y)", Div(children=["(", ValueRef(field="x"), ", ", ValueRef(field="y")]),
    "radius", ValueRef(field="radius", format="%.2f", formatter="printf"),
]

hover0 = HoverTool(
    tooltips=Template(children=[grid]),
    attachment="left",
)
p.add_tools(hover0)

hover1 = HoverTool(
    tooltips=[
        ("index", "$index"),
        ("(x,y)", "(@x, @y)"),
        ("radius", "@radius{%.2f}"),
    ],
    formatters={
        "@radius": "printf",
    },
    attachment="right",

)
p.add_tools(hover1)

fixes #13599

@mattpap mattpap added this to the 3.4 milestone Jan 17, 2024
@mattpap
Copy link
Contributor Author

mattpap commented Jan 17, 2024

When working on this I noticed that the template case only renders tooltip entry for the last selected index, not all of the selected indices as in the default (tuple) case.

Copy link

codecov bot commented Jan 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.59%. Comparing base (e61219b) to head (b5ba116).
Report is 49 commits behind head on branch-3.5.

Current head b5ba116 differs from pull request most recent head bbe2610

Please upload reports for the commit bbe2610 to get more accurate results.

Additional details and impacted files
@@              Coverage Diff               @@
##           branch-3.5   #13650      +/-   ##
==============================================
+ Coverage       91.57%   92.59%   +1.02%     
==============================================
  Files             326      325       -1     
  Lines           20737    20733       -4     
==============================================
+ Hits            18990    19198     +208     
+ Misses           1747     1535     -212     

@mattpap mattpap force-pushed the mattpap/13599_ValueRef_formatters branch from 5e5d5b8 to 5bf80e4 Compare January 18, 2024 01:05
@mattpap mattpap force-pushed the mattpap/13599_ValueRef_formatters branch 2 times, most recently from 5606cb2 to fbc9362 Compare February 20, 2024 01:13
@mattpap mattpap force-pushed the mattpap/13599_ValueRef_formatters branch 2 times, most recently from fe501ce to b5ba116 Compare February 28, 2024 08:51
@mattpap mattpap modified the milestones: 3.4, 3.5 Feb 28, 2024
@mattpap mattpap changed the base branch from branch-3.4 to branch-3.5 March 14, 2024 16:50
@mattpap mattpap force-pushed the mattpap/13599_ValueRef_formatters branch from b5ba116 to bbe2610 Compare May 30, 2024 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Support formatters when using Template as HoverTool
1 participant