instroke
This commit is contained in:
@@ -4070,6 +4070,107 @@ def interactive_streamchart(id=0, promember=0):
|
||||
|
||||
return [script, div]
|
||||
|
||||
def instroke_interactive_chart(df,metric, workout, spm_min, spm_max):
|
||||
df_pos = (df+abs(df))/2.
|
||||
df_min = -(-df+abs(-df))/2.
|
||||
|
||||
mean_vals = df.median()
|
||||
q75 = df_pos.quantile(q=0.75).replace(0,np.nan)
|
||||
q25 = df_pos.quantile(q=0.25).replace(0,np.nan)
|
||||
q75min = df_min.quantile(q=0.75).replace(0,np.nan)
|
||||
q25min = df_min.quantile(q=0.25).replace(0,np.nan)
|
||||
|
||||
|
||||
|
||||
xvals = np.arange(len(mean_vals))
|
||||
|
||||
df_plot = pd.DataFrame({
|
||||
'x':xvals,
|
||||
'median':mean_vals,
|
||||
'high':q75,
|
||||
'low':q75min,
|
||||
'high 2':q25min,
|
||||
'low 2': q25,
|
||||
})
|
||||
|
||||
df_plot['high'].update(df_plot.pop('high 2'))
|
||||
df_plot['low'].update(df_plot.pop('low 2'))
|
||||
df_plot.interpolate(axis=1,inplace=True)
|
||||
|
||||
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,crosshair'
|
||||
plot = Figure(plot_width=920,tools=TOOLS,
|
||||
toolbar_location='above',
|
||||
toolbar_sticky=False)
|
||||
|
||||
plot.sizing_mode = 'stretch_both'
|
||||
|
||||
plot.title.text = str(workout) + ' - ' + metric
|
||||
|
||||
# add watermark
|
||||
watermarkurl = "/static/img/logo7.png"
|
||||
|
||||
watermarkrange = Range1d(start=0, end=1)
|
||||
watermarkalpha = 0.6
|
||||
watermarkx = 0.99
|
||||
watermarky = 0.01
|
||||
watermarkw = 184
|
||||
watermarkh = 35
|
||||
watermarkanchor = 'bottom_right'
|
||||
plot.extra_y_ranges = {"watermark": watermarkrange}
|
||||
plot.extra_x_ranges = {"watermark": watermarkrange}
|
||||
|
||||
plot.image_url([watermarkurl], watermarkx, watermarky,
|
||||
watermarkw, watermarkh,
|
||||
global_alpha=watermarkalpha,
|
||||
w_units='screen',
|
||||
h_units='screen',
|
||||
anchor=watermarkanchor,
|
||||
dilate=True,
|
||||
x_range_name="watermark",
|
||||
y_range_name="watermark",
|
||||
)
|
||||
|
||||
|
||||
source = ColumnDataSource(
|
||||
df_plot
|
||||
)
|
||||
|
||||
TIPS = OrderedDict([
|
||||
('x','@x'),
|
||||
('median','@median'),
|
||||
('high','@high'),
|
||||
('low','@low')
|
||||
])
|
||||
|
||||
hover = plot.select(type=HoverTool)
|
||||
hover.tooltips = TIPS
|
||||
|
||||
s = 'SPM: {spm_min} - {spm_max}'.format(
|
||||
spm_min = spm_min,
|
||||
spm_max = spm_max,
|
||||
)
|
||||
|
||||
label = Label(x=50, y=450, x_units='screen',y_units='screen',
|
||||
text=s,
|
||||
background_fill_alpha=0.7,
|
||||
background_fill_color='white',
|
||||
text_color='black',
|
||||
)
|
||||
|
||||
plot.add_layout(label)
|
||||
|
||||
plot.varea('x', y1='high', y2='low',source=source,fill_color="lightgray",alpha=0.5)
|
||||
|
||||
plot.line('x','median',source=source,legend_label='median',color="black",
|
||||
line_width=3)
|
||||
|
||||
plot.add_tools(HoverTool(tooltips=TIPS))
|
||||
|
||||
script, div = components(plot)
|
||||
|
||||
return (script, div)
|
||||
|
||||
|
||||
|
||||
def interactive_chart(id=0, promember=0, intervaldata={}):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user