-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
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!