bokeh / bokeh

Interactive Data Visualization in the browser, from Python
https://bokeh.org
BSD 3-Clause "New" or "Revised" License
19.42k stars 4.19k forks source link

LabelSet's text color not updating properly on changing column data source #4996

Closed hkhare42 closed 8 years ago

hkhare42 commented 8 years ago

LabelSet's text_color value is not being updated properly when updating the column data source using a callback. Using the code snippet below, color of the glyphs and arrow annotation seem to be changing properly but the labelset's color is not reflecting properly after filtering.

from bokeh.plotting import show, output_file
from bokeh.models import Plot, Label, Circle, ColumnDataSource, DataRange1d, LinearAxis, CustomJS, LabelSet, Select, Triangle, Arrow
from bokeh.layouts import row, widgetbox

output_file('gitex.html')

xdr = DataRange1d()
ydr = DataRange1d()

p = Plot(x_range=xdr, y_range=ydr, plot_width=300, plot_height=300, background_fill_color='#F0F0F0')

source = ColumnDataSource(dict(x=[1.0, 2.0, 3.0], y=[2.0, 3.0, 1.0], text=['A', 'B', 'C'], textcol=['#FF0000','#00FF00','#0000FF']))
orig = ColumnDataSource(dict(x=[1.0, 2.0, 3.0], y=[2.0, 3.0, 1.0], text=['A', 'B', 'C'], textcol=['#FF0000','#00FF00','#0000FF']))

xaxis = LinearAxis()
p.add_layout(xaxis, 'below')

yaxis = LinearAxis()
p.add_layout(yaxis, 'left')

gly = Circle(x='x', y='y', fill_color='textcol', size=15)
p.add_glyph(source, gly)

p.add_layout(LabelSet(x='x', y='y', text='text', text_color='textcol', source=source))

gly2 = Triangle(x='x', y='y', fill_color='textcol', size=15)
p.add_glyph(source, gly2)

p.add_layout(Arrow(x_start='x', y_start='y', x_end='y', y_end='x', line_width=5, line_color='textcol', source=source))

sel = Select(title="Options:", value="All", options=["A", "B", "C", "All"])

arg_dct = dict(
    filtered_source=source,
    original_source=orig,
    element_type_select=sel
)

widget_callback_code = """
var filtered_data = filtered_source.get('data');
var original_data = original_source.get('data');

var element_type = element_type_select.get('value');

for (var key in original_data) {
    filtered_data[key] = [];
    for (var i = 0; i < original_data[key].length; ++i) {
        if ((element_type === "All" || original_data["text"][i] === element_type)) {
            filtered_data[key].push(original_data[key][i]);
        }
    console.log(key)
    console.log(filtered_data[key])
    }
}
filtered_source.trigger('change');
"""

generic_callback = CustomJS(args=arg_dct, code=widget_callback_code)
sel.callback = generic_callback

show(row(widgetbox(sel), p))

Discussed issue with @bryevdv here: https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/P_b8ddxL2DY

bryevdv commented 8 years ago

ping @canavandl

canavandl commented 8 years ago

@hkhare42 - I believe I fixed this bug in #5003. If you have a minute to try it out, that'd be awesome.

github-actions[bot] commented 1 month ago

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.