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

Allow to customize toolbars with any UI components #13571

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

Conversation

mattpap
Copy link
Contributor

@mattpap mattpap commented Dec 2, 2023

This is an early preview PR. This PR continues work started in PR #12417, by exposing the ability of configuring tool buttons instead of just tools to bokeh. It however expands on that work, allowing toolbar to include any UI elements (e.g. select boxes).

image

import numpy as np

from bokeh.plotting import figure, show
from bokeh.models import Toolbar, PaletteSelect
import bokeh.models.tools as t

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")

select = PaletteSelect(
    value="Red",
    items=[("Red", ["red"]), ("Green", ["green"]), ("Blue", ["blue"])],
    swatch_width=20,
)

children = [
    t.OnOffButton(tool=t.PanTool()),
    t.OnOffButton(tool=t.BoxSelectTool(persistent=True)),
    None,
    select,
    None,
    t.ClickButton(tool=t.ZoomInTool()),
    t.ClickButton(tool=t.ZoomOutTool()),
    None, # or Divider()
    t.ClickButton(tool=t.ResetTool()),
]

tb = Toolbar(children=children)
p = figure(toolbar=tb, toolbar_location="above", width=400, height=400)

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

Continues work on #8153, which was partially addressed by PR #13593.

@mattpap mattpap added this to the 3.4 milestone Dec 2, 2023
Copy link

codecov bot commented Dec 2, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

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

❗ Current head 109d1a8 differs from pull request most recent head 6ceb35e. Consider uploading reports for the commit 6ceb35e to get more accurate results

Additional details and impacted files
@@              Coverage Diff               @@
##           branch-3.5   #13571      +/-   ##
==============================================
+ Coverage       91.57%   92.59%   +1.01%     
==============================================
  Files             326      325       -1     
  Lines           20737    20744       +7     
==============================================
+ Hits            18990    19207     +217     
+ Misses           1747     1537     -210     

@mattpap
Copy link
Contributor Author

mattpap commented Feb 18, 2024

A complete example (examples/basic/ui/toolbar_buttons_and_UIs.py) showing a toolbar with a custom button layout and a select widget (used for data filtering):

Screencast.from.18.02.2024.11.37.15.webm

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.

None yet

1 participant