Add support for grouping tools in plots#14259
Conversation
f39d709 to
66cff8e
Compare
|
Tentatively ready for review. I need to add tests. |
There was a problem hiding this comment.
TapTool does not seem to behave as expected:
Screencast.From.2025-02-03.16-41-34.mp4
code
from bokeh.layouts import column, row
from bokeh.models import CustomJS, Div, HoverTool, Switch, TapTool
from bokeh.plotting import figure, show
plot = figure(width=400, height=400, tools=["pan", "box_select", "save", "reset"])
cr1 = plot.scatter([1, 2, 3], [3, 3, 3], size=30, color="red")
cr2 = plot.scatter([1, 2, 3], [2, 2, 2], size=30, color="green")
cr3 = plot.scatter([1, 2, 3], [1, 1, 1], size=30, color="blue")
plot.add_tools(HoverTool(renderers=[cr1], description="Hover over red"))
plot.add_tools(HoverTool(renderers=[cr2], description="Hover over green"))
plot.add_tools(HoverTool(renderers=[cr3], description="Hover over blue"))
plot.add_tools(TapTool(renderers=[cr1], description="Tap on red"))
plot.add_tools(TapTool(renderers=[cr2], description="Tap on green"))
plot.add_tools(TapTool(renderers=[cr3], description="Tap on blue"))
text = Div(text="Group tools:")
switch = Switch(active=plot.toolbar.group)
switch.js_on_change("active", CustomJS(args=dict(plot=plot), code="""
export default ({plot}, {active: group}) => {
plot.toolbar.group = group
}
"""))
layout = column([row([text, switch]), plot])
show(layout)Also, is there a way to group two out of three hover tools? It's a bit hard to tell if this is the case.
I forgot that you can't have multiple tap tools active at the same time (issue #3804). I suppose I will fix that next. |
66cff8e to
4cacc50
Compare
Currently not. Any suggestions regarding the API for this? |
At the top of my head, it would be something like this: plot.add_tools(HoverTool(renderers=[cr1], description="Hover over red", group="one"))
plot.add_tools(HoverTool(renderers=[cr2], description="Hover over green", group="one"))
plot.add_tools(HoverTool(renderers=[cr3], description="Hover over blue", group="two"))The same |
I was going to do exactly that. |
4cacc50 to
2f34e02
Compare
|
I added support for Screencast.from.2025-02-04.12-14-49.webmI also added support for indication of the number of tools being grouped. |
I think this should be disabled by default (if it is not already). From a user perspective, it would confuse as there is nothing the user can do with the information. |
6683a65 to
998b396
Compare
This gives the user indication that they work with multiple tools at once. This will be more useful when I will implement implement partial active state (for when only a subset of tool group's tools is active) and a menu with access to individual tools. Note that this doesn't affect proxies in grid plot (etc.) toolbars. |
8d59acf to
a38c0ba
Compare
|
I hid the tool tool counter for now. I will revisit this when implementing individual tool access in tool group buttons via a menu. |
a38c0ba to
4abde69
Compare
hoxbro
left a comment
There was a problem hiding this comment.
LGTM
Very happy to see the added comments in the code 👍
| cr4 = plot.scatter([1, 2, 3], [2, 2, 2], size=30, color="purple") | ||
| cr5 = plot.scatter([1, 2, 3], [1, 1, 1], size=30, color="yellow") | ||
|
|
||
| plot.add_tools( |
There was a problem hiding this comment.
| plot.add_tools( | |
| # The description will be shown when hovering over the tool icon | |
| plot.add_tools( |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Allows to group common tools in plots and figures (in bokehjs). Adds new
Toolbar.groupandToolbar.group_typesproperties. See the newexample/interaction/tools/tool_grouping.pyexample:Screencast.from.2025-01-31.10-52-08.webm
fixes #5497