|
| 1 | +if (!window._bt_scale_range) { |
| 2 | + window._bt_scale_range = function (range, min, max, pad) { |
| 3 | + "use strict"; |
| 4 | + if (min !== Infinity && max !== -Infinity) { |
| 5 | + pad = pad ? (max - min) * .03 : 0; |
| 6 | + range.start = min - pad; |
| 7 | + range.end = max + pad; |
| 8 | + } else console.error('backtesting: scale range error:', min, max, range); |
| 9 | + }; |
| 10 | +} |
| 11 | + |
| 12 | +clearTimeout(window._bt_autoscale_timeout); |
| 13 | + |
| 14 | +window._bt_autoscale_timeout = setTimeout(function () { |
| 15 | + /** |
| 16 | + * @variable cb_obj `fig_ohlc.x_range`. |
| 17 | + * @variable source `ColumnDataSource` |
| 18 | + * @variable ohlc_range `fig_ohlc.y_range`. |
| 19 | + * @variable volume_range `fig_volume.y_range`. |
| 20 | + */ |
| 21 | + "use strict"; |
| 22 | + |
| 23 | + let i = Math.max(Math.floor(cb_obj.start), 0), |
| 24 | + j = Math.min(Math.ceil(cb_obj.end), source.data['ohlc_high'].length); |
| 25 | + |
| 26 | + let max = Math.max.apply(null, source.data['ohlc_high'].slice(i, j)), |
| 27 | + min = Math.min.apply(null, source.data['ohlc_low'].slice(i, j)); |
| 28 | + _bt_scale_range(ohlc_range, min, max, true); |
| 29 | + |
| 30 | + if (volume_range) { |
| 31 | + max = Math.max.apply(null, source.data['Volume'].slice(i, j)); |
| 32 | + _bt_scale_range(volume_range, 0, max * 1.03, false); |
| 33 | + } |
| 34 | + |
| 35 | +}, 50); |
0 commit comments