Skip to content

Commit

Permalink
Auto-scale Y-axis for indicators when zooming kernc#356
Browse files Browse the repository at this point in the history
  • Loading branch information
zlpatel authored May 23, 2021
1 parent 0a76e96 commit 0581c55
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backtesting/_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,12 @@ def __eq__(self, other):
colors = colors and cycle(_as_list(colors)) or (
cycle([next(ohlc_colors)]) if is_overlay else colorgen())
legend_label = LegendStr(value.name)

indicator_max=value.df.max(axis='columns')
indicator_min=value.df.min(axis='columns')
source.add(indicator_max, f'indicator_{j}_range_max')
source.add(indicator_min,f'indicator_{j}_range_min')

for j, arr in enumerate(value, 1):
color = next(colors)
source_name = f'{legend_label}_{i}_{j}'
Expand Down Expand Up @@ -609,6 +615,12 @@ def __eq__(self, other):
source=source)
if plot_volume:
custom_js_args.update(volume_range=fig_volume.y_range)

indicator_ranges = {}
for idx,indicator in enumerate(indicator_figs):
indicator_range_key = f'indicator_{idx}_range'
indicator_ranges.update({indicator_range_key:indicator.y_range})
custom_js_args.update({'indicator_ranges':indicator_ranges})

fig_ohlc.x_range.js_on_change('end', CustomJS(args=custom_js_args,
code=_AUTOSCALE_JS_CALLBACK))
Expand Down

0 comments on commit 0581c55

Please sign in to comment.