Private
Public Access
1
0

removing redundant code

This commit is contained in:
2024-03-22 13:20:17 +01:00
parent 82ec4c9d7c
commit 3cf663850a

View File

@@ -4006,291 +4006,6 @@ def interactive_flexchart_stacked(id, r, xparam='time',
return script, div
if xparam == 'time':
xaxmax = tseconds.max()
xaxmin = tseconds.min()
elif xparam == 'distance' or xparam == 'cumdist': # pragma: no cover
xaxmax = rowdata['x1'].max()
xaxmin = rowdata['x1'].min()
else: # pragma: no cover
try:
xaxmax = get_yaxmaxima(r, xparam, mode)
xaxmin = get_yaxminima(r, xparam, mode)
except KeyError:
xaxmax = rowdata['x1'].max()
xaxmin = rowdata['x1'].min()
x_axis_type = 'linear'
y1_axis_type = 'linear'
y2_axis_type = 'linear'
y3_axis_type = 'linear'
y4_axis_type = 'linear'
if xparam == 'time':
x_axis_type = 'datetime'
if yparam1 == 'pace': # pragma: no cover
y1_axis_type = 'datetime'
if yparam2 == 'pace': # pragma: no cover
y2_axis_type = 'datetime'
if yparam3 == 'pace': # pragma: no cover
y3_axis_type = 'datetime'
if yparam4 == 'pace': # pragma: no cover
y4_axis_type = 'datetime'
try:
rowdata['xname'] = axlabels[xparam]
except KeyError: # pragma: no cover
rowdata['xname'] = xparam
try:
rowdata['yname1'] = axlabels[yparam1]
except KeyError: # pragma: no cover
rowdata['yname1'] = yparam1
try:
rowdata['yname2'] = axlabels[yparam2]
except KeyError: # pragma: no cover
rowdata['yname2'] = yparam2
try:
rowdata['yname3'] = axlabels[yparam3]
except KeyError: # pragma: no cover
rowdata['yname3'] = yparam3
try:
rowdata['yname4'] = axlabels[yparam4]
except KeyError: # pragma: no cover
rowdata['yname4'] = yparam4
# prepare data
source = ColumnDataSource(
rowdata
)
TOOLS = 'box_zoom,wheel_zoom,reset,tap,hover'
TOOLS2 = 'box_zoom,hover'
plot1 = figure(x_axis_type=x_axis_type, y_axis_type=y1_axis_type, width=920, height=150,
tools=TOOLS, toolbar_location='above')
plot2 = figure(x_axis_type=x_axis_type, y_axis_type=y2_axis_type, width=920, height=150,
tools=TOOLS2, toolbar_location=None)
plot3 = figure(x_axis_type=x_axis_type, y_axis_type=y3_axis_type, width=920, height=150,
tools=TOOLS2, toolbar_location=None)
plot4 = figure(x_axis_type=x_axis_type, y_axis_type=y4_axis_type, width=920, height=150,
tools=TOOLS2, toolbar_location=None)
plot1.xaxis.visible = False
plot2.xaxis.visible = False
plot3.xaxis.visible = False
#plot1.sizing_mode = 'stretch_both'
#plot2.sizing_mode = 'stretch_both'
#plot3.sizing_mode = 'stretch_both'
#plot4.sizing_mode = 'stretch_both'
linked_crosshair = CrosshairTool(dimensions="height")
plot1.add_tools(linked_crosshair)
plot2.add_tools(linked_crosshair)
plot3.add_tools(linked_crosshair)
plot4.add_tools(linked_crosshair)
xaxlabel = axlabels.get(xparam, xparam)
yax1label = axlabels.get(yparam1, yparam1)
plot1.yaxis.axis_label = yax1label
yax2label = axlabels.get(yparam2, yparam2)
plot2.yaxis.axis_label = yax2label
yax3label = axlabels.get(yparam3, yparam3)
plot3.yaxis.axis_label = yax3label
yax4label = axlabels.get(yparam4, yparam4)
plot4.yaxis.axis_label = yax4label
plot4.xaxis.axis_label = xaxlabel
xrange1 = Range1d(start=xaxmin, end=xaxmax)
plot1.x_range = xrange1
plot2.x_range = xrange1
plot3.x_range = xrange1
plot4.x_range = xrange1
if xparam == 'time':
plot4.xaxis[0].formatter = DatetimeTickFormatter(
hours=["%H"],
minutes=["%M"],
seconds=["%S"],
days=["0"],
months=[""],
years=[""]
)
hover1 = plot1.select(dict(type=HoverTool))
hover2 = plot2.select(dict(type=HoverTool))
hover3 = plot3.select(dict(type=HoverTool))
hover4 = plot4.select(dict(type=HoverTool))
if yparam1 == 'pace':
y1tooltip = '@fpace'
elif yparam1 != 'None': # pragma: no cover
y1tooltip = '@{yparam1}'.format(yparam1=yparam1)
if metricsdicts[yparam1]['numtype'] == 'integer' or yparam1 == 'power':
y1tooltip += '{int}'
else: # pragma: no cover
y1tooltip += '{0.00}'
else: # pragma: no cover
y1tooltip = ''
comment = 'The metric in the first chart is only accessible with a Pro plan or higher'
if yparam2 == 'pace': # pragma: no cover
y2tooltip = '@fpace'
elif yparam2 != 'None':
y2tooltip = '@{yparam2}'.format(yparam2=yparam2)
if metricsdicts[yparam2]['numtype'] == 'integer' or yparam2 == 'power':
y2tooltip += '{int}'
else: # pragma: no cover
y2tooltip += '{0.00}'
else: # pragma: no cover
y2tooltip = ''
comment = 'The metric in the second chart is only accessible with a Pro plan or higher'
if yparam3 == 'pace': # pragma: no cover
y3tooltip = '@fpace'
elif yparam3 != 'None':
y3tooltip = '@{yparam3}'.format(yparam3=yparam3)
if metricsdicts[yparam3]['numtype'] == 'integer' or yparam3 == 'power':
y3tooltip += '{int}'
else: # pragma: no cover
y3tooltip += '{0.00}'
else: # pragma: no cover
y3tooltip = ''
comment = 'The metric in the third chart is only accessible with a Pro plan or higher'
if yparam4 == 'pace': # pragma: no cover
y4tooltip = '@fpace'
elif yparam4 != 'None':
y4tooltip = '@{yparam4}'.format(yparam4=yparam4)
if metricsdicts[yparam4]['numtype'] == 'integer' or yparam4 == 'power': # pragma: no cover
y4tooltip += '{int}'
else: # pragma: no cover
y4tooltip += '{0.00}'
else: # pragma: no cover
y4tooltip = ''
comment = 'The metric in the fourth chart is only accessible with a Pro plan or higher'
if yparam1 != 'None':
hover1.tooltips = OrderedDict([
('Time', '@ftime'),
('Distance', '@distance{int}'),
(axlabels[yparam1], y1tooltip),
(axlabels[yparam2], y2tooltip),
(axlabels[yparam3], y3tooltip),
(axlabels[yparam4], y4tooltip),
])
if yparam2 != 'None':
hover2.tooltips = OrderedDict([
('Time', '@ftime'),
('Distance', '@distance{int}'),
(axlabels[yparam1], y1tooltip),
(axlabels[yparam2], y2tooltip),
(axlabels[yparam3], y3tooltip),
(axlabels[yparam4], y4tooltip),
])
if yparam3 != 'None':
hover3.tooltips = OrderedDict([
('Time', '@ftime'),
('Distance', '@distance{int}'),
(axlabels[yparam1], y1tooltip),
(axlabels[yparam2], y2tooltip),
(axlabels[yparam3], y3tooltip),
(axlabels[yparam4], y4tooltip),
])
if yparam4 != 'None':
hover4.tooltips = OrderedDict([
('Time', '@ftime'),
('Distance', '@distance{int}'),
(axlabels[yparam1], y1tooltip),
(axlabels[yparam2], y2tooltip),
(axlabels[yparam3], y3tooltip),
(axlabels[yparam4], y4tooltip),
])
hover1.mode = 'vline'
hover2.mode = 'vline'
hover3.mode = 'vline'
hover4.mode = 'vline'
y1min = get_yaxminima(r, yparam1, mode)
y2min = get_yaxminima(r, yparam2, mode)
y3min = get_yaxminima(r, yparam3, mode)
y4min = get_yaxminima(r, yparam4, mode)
y1max = get_yaxmaxima(r, yparam1, mode)
y2max = get_yaxmaxima(r, yparam2, mode)
y3max = get_yaxmaxima(r, yparam3, mode)
y4max = get_yaxmaxima(r, yparam4, mode)
plot1.y_range = Range1d(start=y1min, end=y1max)
plot2.y_range = Range1d(start=y2min, end=y2max)
plot3.y_range = Range1d(start=y3min, end=y3max)
plot4.y_range = Range1d(start=y4min, end=y4max)
if yparam1 == 'pace':
plot1.yaxis[0].formatter = DatetimeTickFormatter(
seconds=["%S"],
minutes=["%M"]
)
plot1.y_range = Range1d(y1min, y1max)
if yparam2 == 'pace': # pragma: no cover
plot2.yaxis[0].formatter = DatetimeTickFormatter(
seconds=["%S"],
minutes=["%M"]
)
plot2.y_range = Range1d(y2min, y2max)
if yparam3 == 'pace': # pragma: no cover
plot3.yaxis[0].formatter = DatetimeTickFormatter(
seconds=["%S"],
minutes=["%M"]
)
plot3.y_range = Range1d(y3min, y3max)
if yparam4 == 'pace': # pragma: no cover
plot4.yaxis[0].formatter = DatetimeTickFormatter(
seconds=["%S"],
minutes=["%M"]
)
plot4.y_range = Range1d(y4min, y4max)
plot1.line('x1', 'y1', source=source, color=palette2[1])
plot2.line('x1', 'y2', source=source, color=palette2[3])
plot3.line('x1', 'y3', source=source, color=palette2[0])
plot4.line('x1', 'y4', source=source, color=palette2[2])
mylayout = layoutcolumn([
plot1,
plot2,
plot3,
plot4,
])
#mylayout.sizing_mode = 'stretch_both'
script, div = components(mylayout)
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
return script, div, js_resources, css_resources, comment
def interactive_flex_chart2(id, r, promember=0,