@@ -502,6 +502,7 @@ def __eq__(self, other):
502
502
503
503
ohlc_colors = colorgen ()
504
504
indicator_figs = []
505
+ non_overlay_indicator_idxs = []
505
506
506
507
for i , value in enumerate (indicators ):
507
508
value = np .atleast_2d (value )
@@ -518,11 +519,16 @@ def __eq__(self, other):
518
519
else :
519
520
fig = new_indicator_figure ()
520
521
indicator_figs .append (fig )
522
+ non_overlay_indicator_idxs .append (i )
521
523
tooltips = []
522
524
colors = value ._opts ['color' ]
523
525
colors = colors and cycle (_as_list (colors )) or (
524
526
cycle ([next (ohlc_colors )]) if is_overlay else colorgen ())
525
527
legend_label = LegendStr (value .name )
528
+ indicator_max = value .df .max (axis = 'columns' )
529
+ indicator_min = value .df .min (axis = 'columns' )
530
+ source .add (indicator_max , f'indicator_{ i } _range_max' )
531
+ source .add (indicator_min , f'indicator_{ i } _range_min' )
526
532
for j , arr in enumerate (value , 1 ):
527
533
color = next (colors )
528
534
source_name = f'{ legend_label } _{ i } _{ j } '
@@ -570,7 +576,7 @@ def __eq__(self, other):
570
576
# have the legend only contain text without the glyph
571
577
if len (value ) == 1 :
572
578
fig .legend .glyph_width = 0
573
- return indicator_figs
579
+ return ( indicator_figs , non_overlay_indicator_idxs )
574
580
575
581
# Construct figure ...
576
582
@@ -584,7 +590,8 @@ def __eq__(self, other):
584
590
figs_above_ohlc .append (_plot_drawdown_section ())
585
591
586
592
if plot_pl :
587
- figs_above_ohlc .append (_plot_pl_section ())
593
+ fig_pl = _plot_pl_section ()
594
+ figs_above_ohlc .append (fig_pl )
588
595
589
596
if plot_volume :
590
597
fig_volume = _plot_volume_section ()
@@ -595,9 +602,10 @@ def __eq__(self, other):
595
602
596
603
ohlc_bars = _plot_ohlc ()
597
604
_plot_ohlc_trades ()
598
- indicator_figs = _plot_indicators ()
605
+ indicator_figs , non_overlay_indicator_idxs = _plot_indicators ()
599
606
if reverse_indicators :
600
607
indicator_figs = indicator_figs [::- 1 ]
608
+ non_overlay_indicator_idxs = non_overlay_indicator_idxs [::- 1 ]
601
609
figs_below_ohlc .extend (indicator_figs )
602
610
603
611
set_tooltips (fig_ohlc , ohlc_tooltips , vline = True , renderers = [ohlc_bars ])
@@ -607,9 +615,16 @@ def __eq__(self, other):
607
615
608
616
custom_js_args = dict (ohlc_range = fig_ohlc .y_range ,
609
617
source = source )
618
+ if plot_pl :
619
+ custom_js_args .update (pl_range = fig_pl .y_range )
610
620
if plot_volume :
611
621
custom_js_args .update (volume_range = fig_volume .y_range )
612
-
622
+ indicator_ranges = {}
623
+ for idx , (indicator ,
624
+ indicator_idx ) in enumerate (zip (indicator_figs , non_overlay_indicator_idxs )):
625
+ indicator_range_key = f'indicator_{ indicator_idx } _range'
626
+ indicator_ranges .update ({indicator_range_key : indicator .y_range })
627
+ custom_js_args .update ({'indicator_ranges' : indicator_ranges })
613
628
fig_ohlc .x_range .js_on_change ('end' , CustomJS (args = custom_js_args ,
614
629
code = _AUTOSCALE_JS_CALLBACK ))
615
630
0 commit comments