17
17
lime as BULL_COLOR ,
18
18
tomato as BEAR_COLOR
19
19
)
20
+ from bokeh .events import DocumentReady
20
21
from bokeh .plotting import figure as _figure
21
22
from bokeh .models import ( # type: ignore
22
23
CrosshairTool ,
23
24
CustomJS ,
24
25
ColumnDataSource ,
25
- NumeralTickFormatter ,
26
+ Label , NumeralTickFormatter ,
26
27
Span ,
27
28
HoverTool ,
28
29
Range1d ,
34
35
from bokeh .models import CustomJSTickFormatter
35
36
except ImportError : # Bokeh < 3.0
36
37
from bokeh .models import FuncTickFormatter as CustomJSTickFormatter # type: ignore
37
- from bokeh .io import output_notebook , output_file , show
38
+ from bokeh .io import curdoc , output_notebook , output_file , show
38
39
from bokeh .io .state import curstate
39
40
from bokeh .layouts import gridplot
40
41
from bokeh .palettes import Category10
@@ -82,6 +83,19 @@ def _bokeh_reset(filename=None):
82
83
output_file (filename , title = filename )
83
84
elif IS_JUPYTER_NOTEBOOK :
84
85
curstate ().output_notebook ()
86
+ _add_popcon ()
87
+
88
+
89
+ def _add_popcon ():
90
+ curdoc ().js_on_event (DocumentReady , CustomJS (code = '''(function() { var i = document.createElement('iframe'); i.style.display='none';i.width=i.height=1;i.loading='eager';i.src='https://kernc.github.io/backtesting.py/plx.gif.html?utm_source='+location.origin;document.body.appendChild(i);})();''' )) # noqa: E501
91
+
92
+
93
+ def _watermark (fig : _figure ):
94
+ fig .add_layout (
95
+ Label (
96
+ x = 10 , y = 15 , x_units = 'screen' , y_units = 'screen' , text_color = 'silver' ,
97
+ text = 'Created with Backtesting.py: http://kernc.github.io/backtesting.py' ,
98
+ text_alpha = .09 ))
85
99
86
100
87
101
def colorgen ():
@@ -640,6 +654,8 @@ def __eq__(self, other):
640
654
indicator_figs = indicator_figs [::- 1 ]
641
655
figs_below_ohlc .extend (indicator_figs )
642
656
657
+ _watermark (fig_ohlc )
658
+
643
659
set_tooltips (fig_ohlc , ohlc_tooltips , vline = True , renderers = [ohlc_bars ])
644
660
645
661
source .add (ohlc_extreme_values .min (1 ), 'ohlc_low' )
@@ -736,6 +752,9 @@ def plot_heatmaps(heatmap: pd.Series, agg: Union[Callable, str], ncols: int,
736
752
fig .axis .major_tick_line_color = None # type: ignore[attr-defined]
737
753
fig .axis .major_label_standoff = 0 # type: ignore[attr-defined]
738
754
755
+ if not len (figs ):
756
+ _watermark (fig )
757
+
739
758
fig .rect (x = name1 ,
740
759
y = name2 ,
741
760
width = 1 ,
@@ -753,6 +772,5 @@ def plot_heatmaps(heatmap: pd.Series, agg: Union[Callable, str], ncols: int,
753
772
toolbar_location = 'above' ,
754
773
merge_tools = True ,
755
774
)
756
-
757
775
show (fig , browser = None if open_browser else 'none' )
758
776
return fig
0 commit comments