From 7b99fe8cb105db6c011e130cd7f3ff821d828f5e Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Tue, 11 Jul 2017 15:48:19 +0200 Subject: [PATCH] palette picker multiflex --- rowers/forms.py | 10 ++++++- rowers/interactiveplots.py | 5 +++- rowers/utils.py | 53 +++++++++++++++++++++++++++++++++----- rowers/views.py | 15 ++++++++--- 4 files changed, 71 insertions(+), 12 deletions(-) diff --git a/rowers/forms.py b/rowers/forms.py index 412087b1..4e199518 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -327,6 +327,11 @@ formaxlabelsmultiflex.pop('distance') formaxlabelsmultiflex['workoutid'] = 'Workout' parchoicesmultiflex = list(sorted(formaxlabelsmultiflex.items(), key = lambda x:x[1])) +from utils import palettes +#palettechoices = { key:key for key, value in palettes.iteritems() } + +palettechoices = tuple((p,p) for p in palettes.keys()) + class MultiFlexChoiceForm(forms.Form): xparam = forms.ChoiceField(choices=parchoicesmultiflex, @@ -352,7 +357,10 @@ class MultiFlexChoiceForm(forms.Form): includereststrokes = forms.BooleanField(initial=False, required=False, label='Include Rest Strokes') - + palette = forms.ChoiceField(choices=palettechoices, + label = 'Color Scheme', + initial='monochrome_blue') + class ChartParamChoiceForm(forms.Form): plotchoices = ( ('line','Line Plot'), diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 0a4b2abc..b6f19b46 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -1307,6 +1307,7 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='', 'line_color':"#969696", 'size':"groupsize", 'fill_color':"color", + 'fill_alpha':1.0, }, ) @@ -1319,7 +1320,9 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='', top_units='screen', left_units='screen', right_units='screen', - fill_color=color) + fill_color=color, + fill_alpha=1.0, + line_color=color) legendlabel = Label(x=571,y=503-20*nr,x_units='screen', y_units='screen', text = "{gvalue:3.0f}".format(gvalue=gvalue), diff --git a/rowers/utils.py b/rowers/utils.py index 51339a53..c6052de6 100644 --- a/rowers/utils.py +++ b/rowers/utils.py @@ -5,15 +5,54 @@ import colorsys lbstoN = 4.44822 -def range_to_color_hex(groupcols): - rgb = [colorsys.hsv_to_rgb((207-4*x)/360., - 0.06+0.89*x, - 1-0.38*x) for x in groupcols] +def trcolors(r1,g1,b1,r2,g2,b2): + r1 = r1/255. + r2 = r2/255. + g1 = g1/255. + g2 = g2/255. + b2 = b2/255. + b1 = b1/255. + h1,s1,v1 = colorsys.rgb_to_hsv(r1,g1,b1) + h2,s2,v2 = colorsys.rgb_to_hsv(r2,g2,b2) - RGB = [(int(255.*r),int(255.*g),int(255.*b)) for (r, g, b) in rgb] - colors = ["#%02x%02x%02x" % (r, g, b) for (r, g, b) in RGB] + + return 360*h1,360*(h2-h1),s1,(s2-s1),v1,(v2-v1) - return colors +palettes = { + 'monochrome_blue':(207,-4,0.06,0.89,1.0,-0.38), + 'gold_sunset':(47,-31,.26,-0.12,0.94,-0.5), + 'blue_red':(207,-200,.85,0,.74,-.24), + 'blue_green':(207,-120,.85,0,.75,.25), + 'cyan_green':(192,-50,.08,.65,.98,-.34), + 'cyan_purple':trcolors(237,248,251,136,65,157), + 'green_blue':trcolors(240,249,232,8,104,172), + 'orange_red':trcolors(254,240,217,179,0,0), + 'cyan_blue':trcolors(241,238,246,4,90,141), + 'cyan_green':trcolors(246,239,247,1,108,89), + 'cyan_magenta':trcolors(241,238,246,152,0,67), + 'beige_magenta':trcolors(254,235,226,122,1,119), + 'yellow_green':trcolors(255,255,204,0,104,55), + 'yellow_blue':trcolors(255,255,205,37,52,148), + 'autumn':trcolors(255,255,212,153,52,4), + 'yellow_red':trcolors(255,255,178,189,0,39) +} + + +def range_to_color_hex(groupcols,palette='monochrome_blue'): + + try: + plt = palettes[palette] + except KeyErro: + plt = palettes['monochrome_blue'] + + rgb = [colorsys.hsv_to_rgb((plt[0]+plt[1]*x)/360., + plt[2]+plt[3]*x, + plt[4]+plt[5]*x) for x in groupcols] + + RGB = [(int(255.*r),int(255.*g),int(255.*b)) for (r, g, b) in rgb] + colors = ["#%02x%02x%02x" % (r, g, b) for (r, g, b) in RGB] + + return colors def str2bool(v): return v.lower() in ("yes", "true", "t", "1") diff --git a/rowers/views.py b/rowers/views.py index c4f274bd..2e600225 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -3435,6 +3435,11 @@ def multiflex_view(request,userid=0, ploterrorbars = options['ploterrorbars'] except KeyError: ploterrorbars = False + + try: + palette = options['palette'] + except KeyError: + palette = 'blue_green' workstrokesonly = not includereststrokes @@ -3454,7 +3459,9 @@ def multiflex_view(request,userid=0, request.session['ploterrorbars'] = ploterrorbars request.session['includereststrokes'] = includereststrokes workstrokesonly = not includereststrokes - + palette = chartform.cleaned_data['palette'] + request.session['palette'] = palette + groupby = chartform.cleaned_data['groupby'] binsize = chartform.cleaned_data['binsize'] if binsize <= 0: @@ -3482,6 +3489,8 @@ def multiflex_view(request,userid=0, request.session['ploterrorbars'] = ploterrorbars request.session['includereststrokes'] = includereststrokes workstrokesonly = not includereststrokes + palette = chartform.cleaned_data['palette'] + request.session['palette'] = palette groupby = chartform.cleaned_data['groupby'] binsize = chartform.cleaned_data['binsize'] @@ -3608,12 +3617,12 @@ def multiflex_view(request,userid=0, groupcols = np.array([1.]) - colors = range_to_color_hex(groupcols) + colors = range_to_color_hex(groupcols,palette=palette) df['color'] = colors clegendx = np.arange(0,1.2,.2) - legcolors = range_to_color_hex(clegendx) + legcolors = range_to_color_hex(clegendx,palette=palette) clegendy = df['groupval'].min()+clegendx*(df['groupval'].max()-df['groupval'].min())