Hi,
I was expecting that these two apps will have the same behavior as far as updating the y_range. If this is the correct behavior, is there a way to make example 2 behave like example 1? (update y_axis when glyph is not visible?)
Thanks!
# example 1
from bokeh.io import show, output_file
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, Button, CustomJS
from bokeh.layouts import column
x = [0, 1, 2, 3, 4]
y1 = [5, 6, 7, 8, 9]
y2 = 5*[10]
source = ColumnDataSource(data=dict(x=x, y1=y1, y2=y2))
p = figure()
p.line('x', 'y1', source=source)
callback = CustomJS(args=dict(source=source),
code="""
var data = source.data;
var temp;
for (var i=0; i < data["x"].length; i++){
temp = data['y1'][i];
data["y1"][i] = data["y2"][i];
data["y2"][i] = temp;
console.log(temp)
}
source.change.emit();
""")
button = Button(label='change y')
button.js_on_click(callback)
output_file('example1.html')
show(column(button, p))
# example 2
from bokeh.io import show, output_file
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, Button, CustomJS
from bokeh.layouts import column
x = [0, 1, 2, 3, 4]
y1 = [5, 6, 7, 8, 9]
y2 = 5*[10]
source = ColumnDataSource(data=dict(x=x, y1=y1, y2=y2))
p = figure()
line1 = p.line('x', 'y1', source=source, visible=True)
line2 = p.line('x', 'y2', source=source, visible=False)
callback = CustomJS(args=dict(line1=line1, line2=line2),
code="""
line1.visible = !line1.visible;
line2.visible = !line1.visible;
""")
button = Button(label='change y')
button.js_on_click(callback)
output_file('example2.html')
show(column(button, p))