Hi,
I don’t know if this is a bug or something else I’m doing wrong. But, a dropdown call back (or any callback) seems to be resetting the Y-size on the second plot. Please see the image.
I have the following setup to call my update()
on change:
mavg = Select(title='Moving Average', value=SMA, options=[SMA, EMA])
mavg.on_change('value', lambda attr, old, new: update(task='mavg'))
Then I have the following two JS
callback that fit the Y-axis size for the currently visible range:
callback_top = CustomJS(args={'y_range': p1.y_range, 'source': source}, code='''
clearTimeout(window._autoscale_timeout_top_plot);
var Index = source.data.time,
Low = source.data.candle_bound_min,
High = source.data.candle_bound_max,
start = cb_obj.start,
end = cb_obj.end,
min = Infinity,
max = -Infinity;
for (var i=0; i < Index.length; ++i) {
if (start <= Index[i] && Index[i] <= end) {
max = Math.max(High[i], max);
min = Math.min(Low[i], min);
}
}
console.log(`[top_plot] min: ${min}, max: ${max}`);
//console.log(`index: ${Index}`);
console.log(`[top_plot] start: ${start}, end: ${end}`);
var pad = (max - min) * .05;
window._autoscale_timeout_top_plot = setTimeout(function() {
y_range.start = min - pad;
y_range.end = max + pad;
});
''')
callback_bottom = CustomJS(args={'y_range': p2.y_range, 'source': source}, code='''
clearTimeout(window._autoscale_timeout_bottom_plot);
var Index = source.data.time,
Low = source.data.macd_bound_min,
High = source.data.macd_bound_max,
start = cb_obj.start,
end = cb_obj.end,
min = Infinity,
max = -Infinity;
for (var i=0; i < Index.length; ++i) {
if (start <= Index[i] && Index[i] <= end) {
max = Math.max(High[i], max);
min = Math.min(Low[i], min);
}
}
console.log(`[bottom_plot] min: ${min}, max: ${max}`);
//console.log(`index: ${Index}`);
console.log(`[bottom_plot] start: ${start}, end: ${end}`);
var pad = (max - min) * .05;
window._autoscale_timeout_bottom_plot = setTimeout(function() {
y_range.start = min - pad;
y_range.end = max + pad;
});
''')
The JS
are working, the Y-size is adjusted as I scroll. However, the moment I switch my dropdown menu, the update triggers a reset on the ‘Y-axis’ of the lower plot.