Skip to content

Add support for toggling selectable text #14472

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

Open
wants to merge 1 commit into
base: branch-3.8
Choose a base branch
from

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 from d3ea3d0 to ff2ef53 Compare April 27, 2025 23:41
@mattpap mattpap force-pushed the mattpap/14449_toggle_seletable_text branch 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.

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 selecability on the canvas
1 participant