Added sliders to Flex Plot (including mean)
This commit is contained in:
@@ -21,6 +21,7 @@ from bokeh.models import (
|
||||
GMapPlot, GMapOptions, ColumnDataSource, Circle,
|
||||
DataRange1d, PanTool, WheelZoomTool, BoxSelectTool,
|
||||
SaveTool, ResizeTool, ResetTool, TapTool,CrosshairTool,BoxZoomTool,
|
||||
Span,
|
||||
)
|
||||
#from bokeh.models.widgets import Slider, Select, TextInput
|
||||
from bokeh.core.properties import value
|
||||
@@ -1394,29 +1395,26 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
xaxmax = get_datetimes([xaxmax],tzinfo=1)[0]
|
||||
xaxmin = get_datetimes([xaxmin],tzinfo=1)[0]
|
||||
x1 = get_datetimes(x1,tzinfo=1)
|
||||
|
||||
if xparam=='distance':
|
||||
elif xparam=='distance':
|
||||
xaxmax = x1.max()
|
||||
xaxmin = x1.min()
|
||||
else:
|
||||
xaxmax = yaxmaxima[xparam]
|
||||
xaxmin = yaxminima[xparam]
|
||||
|
||||
# average values
|
||||
y1mean = y1.mean()+0.0*np.arange(100)
|
||||
y2mean = y2.mean()+0.0*np.arange(100)
|
||||
if xparam != 'time':
|
||||
x1mean = x1.mean()+0.0*np.arange(100)
|
||||
x1mean = x1.mean()
|
||||
else:
|
||||
x1mean = 0+0.0*np.arange(100)
|
||||
x1mean = 0
|
||||
|
||||
y1mean = y1.mean()
|
||||
y2mean = y2.mean()
|
||||
|
||||
|
||||
|
||||
if xparam != 'time' and xparam != 'distance' and yparam1 != 'pace':
|
||||
xvals = yaxminima[xparam]+np.arange(100)*(yaxmaxima[xparam]-yaxminima[xparam])/100.
|
||||
y1vals = yaxminima[yparam1]+np.arange(100)*(yaxmaxima[yparam1]-yaxminima[yparam1])/100.
|
||||
if xparam != 'time':
|
||||
xvals = xaxmin+np.arange(100)*(xaxmax-xaxmin)/100.
|
||||
else:
|
||||
xvals = np.arange(100)
|
||||
y1vals = np.arange(100)
|
||||
|
||||
|
||||
|
||||
# constant power plot
|
||||
if yparam1 == 'driveenergy':
|
||||
@@ -1466,11 +1464,10 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
spmc=np.rint(10*spm)/10.,
|
||||
distance=distance,
|
||||
power=power,
|
||||
xvals=xvals,
|
||||
y1mean=y1mean,
|
||||
y2mean=y2mean,
|
||||
x1mean=x1mean,
|
||||
y1vals=y1vals,
|
||||
# xvals=xvals,
|
||||
y1mean=[y1mean,y1mean],
|
||||
y2mean=[y2mean,y2mean],
|
||||
x1mean=[x1mean,x1mean],
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1487,11 +1484,10 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
spmc=np.rint(10*spm)/10.,
|
||||
distance=distance,
|
||||
power=power,
|
||||
xvals=xvals,
|
||||
y1mean=y1mean,
|
||||
y2mean=y2mean,
|
||||
x1mean=x1mean,
|
||||
y1vals=y1vals,
|
||||
# xvals=xvals,
|
||||
y1mean=[y1mean,y1mean],
|
||||
y2mean=[y2mean,y2mean],
|
||||
x1mean=[x1mean,x1mean],
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1510,9 +1506,109 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
toolbar_sticky=False,
|
||||
# plot_width=900,
|
||||
)
|
||||
x1means = Span(location=x1mean,dimension='height',line_color='green',
|
||||
line_dash=[6,6], line_width=2)
|
||||
|
||||
y1means = Span(location=y1mean,dimension='width',line_color='blue',
|
||||
line_dash=[6,6],line_width=2)
|
||||
y2means = y1means
|
||||
|
||||
if (xparam != 'time') and (xparam != 'distance'):
|
||||
plot.add_layout(x1means)
|
||||
|
||||
plot.add_layout(y1means)
|
||||
|
||||
|
||||
callback = CustomJS(args = dict(source=source,source2=source2), code="""
|
||||
|
||||
# average values
|
||||
if yparam1 == 'driveenergy':
|
||||
if xparam == 'spm':
|
||||
plot.line(xvals,yconstantpower,color="green",legend="Constant Power")
|
||||
|
||||
if plottype=='line':
|
||||
plot.line('x1','y1',source=source2,legend=axlabels[yparam1])
|
||||
elif plottype=='scatter':
|
||||
# plot.circle('x1','y1',source=source2,legend=yparam1,size=3)
|
||||
plot.scatter('x1','y1',source=source2,legend=axlabels[yparam1],fill_alpha=0.4,
|
||||
line_color=None)
|
||||
|
||||
plot.title.text = row.name
|
||||
plot.title.text_font_size=value("1.0em")
|
||||
plot.xaxis.axis_label = axlabels[xparam]
|
||||
plot.yaxis.axis_label = axlabels[yparam1]
|
||||
|
||||
|
||||
|
||||
yrange1 = Range1d(start=yaxminima[yparam1],end=yaxmaxima[yparam1])
|
||||
plot.y_range = yrange1
|
||||
|
||||
if (xparam != 'time') and (xparam != 'distance'):
|
||||
xrange1 = Range1d(start=yaxminima[xparam],end=yaxmaxima[xparam])
|
||||
plot.x_range = xrange1
|
||||
|
||||
if xparam == 'time':
|
||||
xrange1 = Range1d(start=xaxmin,end=xaxmax)
|
||||
plot.x_range = xrange1
|
||||
plot.xaxis[0].formatter = DatetimeTickFormatter(
|
||||
hours = ["%H"],
|
||||
minutes = ["%M"],
|
||||
seconds = ["%S"],
|
||||
days = ["0"],
|
||||
months = [""],
|
||||
years = [""]
|
||||
)
|
||||
|
||||
|
||||
if yparam1 == 'pace':
|
||||
plot.y_range = Range1d(ymin,ymax)
|
||||
plot.yaxis[0].formatter = DatetimeTickFormatter(
|
||||
seconds = ["%S"],
|
||||
minutes = ["%M"]
|
||||
)
|
||||
|
||||
if yparam2 != 'None':
|
||||
yrange2 = Range1d(start=yaxminima[yparam2],end=yaxmaxima[yparam2])
|
||||
plot.extra_y_ranges = {"yax2": yrange2}
|
||||
|
||||
if plottype=='line':
|
||||
plot.line('x1','y2',color="red",y_range_name="yax2",
|
||||
legend=axlabels[yparam2],
|
||||
source=source2)
|
||||
|
||||
elif plottype=='scatter':
|
||||
# plot.circle(x1,y2,color="red",y_range_name="yax2",legend=yparam2,
|
||||
# source=source,size=3)
|
||||
plot.scatter('x1','y2',source=source2,legend=axlabels[yparam2]
|
||||
,fill_alpha=0.4,
|
||||
line_color=None,color="red",y_range_name="yax2")
|
||||
|
||||
plot.add_layout(LinearAxis(y_range_name="yax2",
|
||||
axis_label=axlabels[yparam2]),'right')
|
||||
|
||||
y2means = Span(location=y2mean,dimension='width',line_color='red',
|
||||
line_dash=[6,6],line_width=2,y_range_name="yax2")
|
||||
|
||||
|
||||
plot.add_layout(y2means)
|
||||
|
||||
hover = plot.select(dict(type=HoverTool))
|
||||
|
||||
|
||||
hover.tooltips = OrderedDict([
|
||||
('Time','@time'),
|
||||
('Distance','@distance'),
|
||||
('Pace','@pace'),
|
||||
('HR','@hr'),
|
||||
('SPM','@spmc{1.1}'),
|
||||
('Power','@power{int}'),
|
||||
])
|
||||
|
||||
hover.mode = 'mouse'
|
||||
|
||||
callback = CustomJS(args = dict(source=source,source2=source2,
|
||||
x1means=x1means,
|
||||
y1means=y1means,
|
||||
y2means=y2means), code="""
|
||||
var data = source.data
|
||||
var data2 = source2.data
|
||||
var x1 = data['x1']
|
||||
@@ -1568,6 +1664,7 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
xm += x1[i]
|
||||
ym1 += y1[i]
|
||||
ym2 += y2[i]
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1579,10 +1676,9 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
data2['x1mean'] = [xm,xm]
|
||||
data2['y1mean'] = [ym1,ym1]
|
||||
data2['y2mean'] = [ym2,ym2]
|
||||
|
||||
data2['xvals'] = [0,3e4]
|
||||
data2['y1vals'] = [0,3e4]
|
||||
data2['y2vals'] = [0,3e4]
|
||||
x1means.location = xm
|
||||
y1means.location = ym1
|
||||
y2means.location = ym2
|
||||
|
||||
source2.trigger('change');
|
||||
""")
|
||||
@@ -1606,89 +1702,6 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
step=1,
|
||||
title="Max Distance",callback=callback)
|
||||
callback.args["maxdist"] = slider_dist_max
|
||||
|
||||
# average values
|
||||
plot.line('xvals','y1mean',color="black",source=source2)
|
||||
plot.line('x1mean','y1vals',color="black",source=source2)
|
||||
if yparam1 == 'driveenergy':
|
||||
if xparam == 'spm':
|
||||
plot.line(xvals,yconstantpower,color="green",legend="Constant Power")
|
||||
|
||||
if plottype=='line':
|
||||
plot.line('x1','y1',source=source2,legend=axlabels[yparam1])
|
||||
elif plottype=='scatter':
|
||||
# plot.circle('x1','y1',source=source2,legend=yparam1,size=3)
|
||||
plot.scatter('x1','y1',source=source2,legend=axlabels[yparam1],fill_alpha=0.4,
|
||||
line_color=None)
|
||||
|
||||
plot.title.text = row.name
|
||||
plot.title.text_font_size=value("1.0em")
|
||||
plot.xaxis.axis_label = axlabels[xparam]
|
||||
plot.yaxis.axis_label = axlabels[yparam1]
|
||||
|
||||
|
||||
yrange1 = Range1d(start=yaxminima[yparam1],end=yaxmaxima[yparam1])
|
||||
plot.y_range = yrange1
|
||||
|
||||
if (xparam != 'time') and (xparam != 'distance'):
|
||||
xrange1 = Range1d(start=yaxminima[xparam],end=yaxmaxima[xparam])
|
||||
plot.x_range = xrange1
|
||||
|
||||
if xparam == 'time':
|
||||
xrange1 = Range1d(start=xaxmin,end=xaxmax)
|
||||
plot.x_range = xrange1
|
||||
plot.xaxis[0].formatter = DatetimeTickFormatter(
|
||||
hours = ["%H"],
|
||||
minutes = ["%M"],
|
||||
seconds = ["%S"],
|
||||
days = ["0"],
|
||||
months = [""],
|
||||
years = [""]
|
||||
)
|
||||
|
||||
|
||||
if yparam1 == 'pace':
|
||||
plot.y_range = Range1d(ymin,ymax)
|
||||
plot.yaxis[0].formatter = DatetimeTickFormatter(
|
||||
seconds = ["%S"],
|
||||
minutes = ["%M"]
|
||||
)
|
||||
|
||||
if yparam2 != 'None':
|
||||
yrange2 = Range1d(start=yaxminima[yparam2],end=yaxmaxima[yparam2])
|
||||
plot.extra_y_ranges = {"yax2": yrange2}
|
||||
plot.line('xvals','y2mean',color="black",y_range_name="yax2",
|
||||
source=source2)
|
||||
|
||||
if plottype=='line':
|
||||
plot.line('x1','y2',color="red",y_range_name="yax2",
|
||||
legend=axlabels[yparam2],
|
||||
source=source2)
|
||||
|
||||
elif plottype=='scatter':
|
||||
# plot.circle(x1,y2,color="red",y_range_name="yax2",legend=yparam2,
|
||||
# source=source,size=3)
|
||||
plot.scatter('x1','y2',source=source2,legend=axlabels[yparam2]
|
||||
,fill_alpha=0.4,
|
||||
line_color=None,color="red",y_range_name="yax2")
|
||||
|
||||
plot.add_layout(LinearAxis(y_range_name="yax2",
|
||||
axis_label=axlabels[yparam2]),'right')
|
||||
|
||||
|
||||
hover = plot.select(dict(type=HoverTool))
|
||||
|
||||
|
||||
hover.tooltips = OrderedDict([
|
||||
('Time','@time'),
|
||||
('Distance','@distance'),
|
||||
('Pace','@pace'),
|
||||
('HR','@hr'),
|
||||
('SPM','@spmc{1.1}'),
|
||||
('Power','@power{int}'),
|
||||
])
|
||||
|
||||
hover.mode = 'mouse'
|
||||
|
||||
layout = layoutrow([layoutcolumn([slider_spm_min,
|
||||
slider_spm_max,
|
||||
|
||||
Reference in New Issue
Block a user