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 background, border, padding, etc. to Text glyph #12529

Closed
monadandan opened this issue Oct 31, 2022 · 6 comments · Fixed by #12655
Closed

Add support for background, border, padding, etc. to Text glyph #12529

monadandan opened this issue Oct 31, 2022 · 6 comments · Fixed by #12655

Comments

@monadandan
Copy link

monadandan commented Oct 31, 2022

Problem description

When I select a point, the other points become faded, but their corresponding labels do not become faded.

Here is a small example to demonstrate:

from bokeh.models import TapTool, ColumnDataSource, LabelSet
from bokeh.plotting import figure, show

source = ColumnDataSource({
    'x': [1, 2, 3],
    'y': ['a', 'b', 'c'],
    'text': ['apple', 'banana', 'cherry']
})
plot = figure(width=300, height=300, y_range=['a', 'b', 'c'])
plot.scatter(x='x', y='y', source=source, size=20)
label_set = LabelSet(x='x', y='y', text='text', source=source, text_align='center', y_offset=10,
                     background_fill_color='whitesmoke')
plot.add_layout(label_set)
plot.add_tools(TapTool())
show(plot)

Feature description

I would like LabelSet to have a selection/non-selection visual option

Potential alternatives

The potential alternative to avoid this problem is to use a text glyph instead of a labelset, but LabelSet has some useful options that Text does not have (background_fill_alpha, background_fill_color, border_line_alpha, border_line_cap, border_line_dash, border_line_dash_offset, border_line_join, border_line_color, border_line_width).

The current alternative is to add a square glyph behind the Text glyph, as mentioned in this StackOverflow thread.

Here is a the example with the workaround implemented. The rectangles' widths could be tricky to set depending on the usage, which is a downside.

from bokeh.models import TapTool, ColumnDataSource
from bokeh.plotting import figure, show

source = ColumnDataSource({
    'x': [1, 2, 3],
    'y': ['a', 'b', 'c'],
    'text': ['apple', 'banana', 'cherry'],
    'box_y': [('a', 0.2), ('b', 0.2), ('c', 0.2)],
    'box_w': [0.75] * 3,
    'box_h': [0.15] * 3,
})
plot = figure(width=300, height=300, y_range=['a', 'b', 'c'])
plot.scatter(x='x', y='y', source=source, size=20)
plot.rect(x='x', y='box_y', width='box_w', height='box_h', source=source,
                    color='whitesmoke')
plot.text(x='x', y='y', source=source, text='text', text_align='center', y_offset=-10)
plot.add_tools(TapTool())
show(plot)

Additional information

I am using Bokeh 2.4.2 in the example.

Thank you in advance!

@bryevdv
Copy link
Member

bryevdv commented Oct 31, 2022

Hi @monadandan thanks for the issue! I am going to hold off on triaging this just yet. There is some clutter and duplication around label, labelset, and text currently. We'd like to plan a path to reduce that over time, so this will need to be a part of that wider discussion.

@mattpap mattpap changed the title [FEATURE] LabelSet selection/non-selection visual option Add support for background, border, padding, etc. to Text glyph Jan 6, 2023
@mattpap mattpap added this to the 3.1 milestone Jan 6, 2023
@mattpap
Copy link
Contributor

mattpap commented Jan 6, 2023

@monadandan, support for additional styling was added in PR #12655, so in bokeh 3.1 you will able to use Text glyph in place of LabelSet annotation, and configure selection/non-selection overrides.

@mattpap
Copy link
Contributor

mattpap commented Jan 6, 2023

In the long term we will probably deprecate LabelSet, though that's a topic for a separate discussion, assuming:

  1. it will be possible to use subcoordinates to position Text glyphs in screen space (it's already possible just not convenient)
  2. remove a glyph from auto-ranging (it's possible, but one has to modify a range, and it cannot be configured on a glyph)

@bryevdv
Copy link
Member

bryevdv commented Jan 6, 2023

in bokeh 3.1 you will able to use Text glyph in place of LabelSet

No one will know to do this without documentation, though, so an issue for updating the docs to present and demonstrate this possibility would be advised.

@monadandan
Copy link
Author

Thank you so much! looking forward to bokeh 3.1! 😄

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants