Skip to content

Conversation

mattpap
Copy link
Contributor

@mattpap mattpap commented Apr 27, 2025

For example:

Screencast.from.2025-04-27.13-15-12.webm
Code
from bokeh.core.enums import MarkerType
from bokeh.models import CustomJS
from bokeh.plotting import figure, show

p = figure(width=400, height=400, title="Click on legend entries to change\nmarkers of the corresponding glyphs")
p.add_tools("toggle_text_selection")

p.scatter(x=[0, 1, 2], y=[1, 2, 3], size=[10, 20, 30], marker="circle", color="red", fill_alpha=0.5, legend_label="Red item")
p.scatter(x=[0, 1, 2], y=[2, 3, 4], size=[10, 20, 30], marker="circle", color="green", fill_alpha=0.5, legend_label="Green item")
p.scatter(x=[0, 1, 2], y=[3, 4, 5], size=[10, 20, 30], marker="circle", color="blue", fill_alpha=0.5, legend_label="Blue item")

callback = CustomJS(
    args=dict(markers=list(MarkerType)),
    code="""
export default ({markers}, {item}) => {
    for (const renderer of item.renderers) {
        const {value: marker} = renderer.glyph.marker
        const i = markers.indexOf(marker)
        const j = (i + 1) % markers.length
        renderer.glyph.marker = {value: markers[j]}
    }
}
    """,
)
p.legend.js_on_click(callback)
p.legend.location = "top_left"

show(p)

There are two bugs to fix, possibly separately. A major one is that selecting text causes also click events to be handled by legend items. Second is wrong cursor when text selection is disabled.

fixes #14449

@mattpap mattpap added status: WIP grant: CZI R6 Funded by CZI Round 6 grant labels Apr 27, 2025
@mattpap mattpap added this to the 3.8 milestone Apr 27, 2025
@mattpap mattpap force-pushed the mattpap/14449_toggle_seletable_text branch 2 times, most recently from ff2ef53 to 79986b9 Compare April 28, 2025 06:41
@mattpap
Copy link
Contributor Author

mattpap commented Apr 28, 2025

This PR is tentatively ready. It needs tests though.

@mattpap mattpap force-pushed the mattpap/14449_toggle_seletable_text branch from 79986b9 to e6223b0 Compare July 29, 2025 06:37
@mattpap mattpap requested review from gabalafou and pavithraes July 29, 2025 06:37
@gabalafou
Copy link
Contributor

There are two bugs to fix, possibly separately. A major one is that selecting text causes also click events to be handled by legend items. Second is wrong cursor when text selection is disabled.

This PR does not currently address either of these bugs, is that correct? Because when I load this PR, I see that selecting text causes click events to be handled. I also see an arrow cursor instead of a pointing hand cursor when text selection is disabled and I'm hovering over the legend text. I assume it should be a pointing hand?

It really bums me out to allow text selection to be disabled. Are we one thousand percent sure this is necessary?

@mattpap mattpap modified the milestones: 3.8, 3.9 Aug 26, 2025
@mattpap mattpap changed the base branch from branch-3.8 to branch-3.9 August 29, 2025 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
grant: CZI R6 Funded by CZI Round 6 grant status: ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to toggle text selectability on the canvas
2 participants