From 64cb556730980d9f5f922d965b50b9b5f4f17ce5 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Sun, 31 Mar 2019 17:07:44 +0200 Subject: [PATCH] adding slider annotation to box chart --- rowers/interactiveplots.py | 24 ++++++++++++++---------- rowers/views/analysisviews.py | 3 ++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 7fec35b5..4ddceb58 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -164,7 +164,8 @@ def tailwind(bearing,vwind,winddir): from rowers.dataprep import nicepaceformat,niceformat from rowers.dataprep import timedeltaconv -def interactive_boxchart(datadf,fieldname,extratitle=''): +def interactive_boxchart(datadf,fieldname,extratitle='', + spmmin=0,spmmax=0,workmin=0,workmax=0): if datadf.empty: return '','It looks like there are no data matching your filter' @@ -186,15 +187,6 @@ def interactive_boxchart(datadf,fieldname,extratitle=''): plot = hv.render(boxwhiskers) - #plot = BoxPlot(datadf, values=fieldname, label='date', - # legend=False, - # title=axlabels[fieldname]+' '+extratitle, - # outliers=False, - # tools=TOOLS, - # toolbar_location="above", - # toolbar_sticky=False, - # x_mapper_type='datetime',plot_width=920) - yrange1 = Range1d(start=yaxminima[fieldname],end=yaxmaxima[fieldname]) plot.y_range = yrange1 plot.sizing_mode = 'scale_width' @@ -221,6 +213,18 @@ def interactive_boxchart(datadf,fieldname,extratitle=''): plot.plot_width=920 plot.plot_height=600 + slidertext = 'SPM: {:.0f}-{:.0f}, WpS: {:.0f}-{:.0f}'.format( + spmmin,spmmax,workmin,workmax + ) + sliderlabel = Label(x=50,y=20,x_units='screen',y_units='screen', + text=slidertext, + background_fill_alpha=0.7, + background_fill_color='white', + text_color='black',text_font_size='10pt', + ) + + plot.add_layout(sliderlabel) + script, div = components(plot) return script,div diff --git a/rowers/views/analysisviews.py b/rowers/views/analysisviews.py index 895e7d77..a5f815e2 100644 --- a/rowers/views/analysisviews.py +++ b/rowers/views/analysisviews.py @@ -3087,7 +3087,8 @@ def boxplot_view_data(request,userid=0, script,div = interactive_boxchart(datadf,plotfield, - extratitle=extratitle) + extratitle=extratitle, + spmmin=spmmin,spmmax=spmmax,workmin=workmin,workmax=workmax) scripta = script.split('\n')[2:-1] script = ''.join(scripta)