summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2011-12-01 15:36:43 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2011-12-01 15:36:43 (GMT)
commitbf078ff20ac0397c9ee2611b874fa3ecfae21fe8 (patch)
tree10c59d499f58bb9e9bae11e0176af2c65228c67b
parent2cc833255ea27971d7ed841c50d4ba6cca9b2de6 (diff)
downloadtabellio.webviews-bf078ff20ac0397c9ee2611b874fa3ecfae21fe8.zip
tabellio.webviews-bf078ff20ac0397c9ee2611b874fa3ecfae21fe8.tar.gz
tabellio.webviews-bf078ff20ac0397c9ee2611b874fa3ecfae21fe8.tar.bz2
get graph colours from settings (#1027)
-rw-r--r--tabellio/webviews/deputy.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/tabellio/webviews/deputy.py b/tabellio/webviews/deputy.py
index 7c4b512..a877f46 100644
--- a/tabellio/webviews/deputy.py
+++ b/tabellio/webviews/deputy.py
@@ -12,7 +12,9 @@ from zope import component
from zc.relation.interfaces import ICatalog
from zope.app.intid.interfaces import IIntIds
from Products.CMFCore.utils import getToolByName
+from plone.registry.interfaces import IRegistry
+from tabellio.config.interfaces import ITabellioSettings
import tabellio.config.utils
import cairoplot
@@ -217,7 +219,13 @@ class GenderStatsView(BrowserView):
x.Type() == 'Deputy' and x.sex == 'M' and x.active]),
u'Femmes': len([x for x in self.context.values() if
x.Type() == 'Deputy' and x.sex == 'F' and x.active])}
- series_colors = [ (0.77,0.92,0.94), (0.54,0.56,0.69) ]
+
+ settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
+ if settings.gender_colors:
+ series_colors = [ hexa_to_float(settings.gender_colors.split(',')[0]),
+ hexa_to_float(settings.gender_colors.split(',')[1])]
+ else:
+ series_colors = [ (0.77,0.92,0.94), (0.54,0.56,0.69) ]
surface = cairoplot.cairo.ImageSurface(cairoplot.cairo.FORMAT_ARGB32, 600, 320)
plot = cairoplot.DonutPlot(surface, data, 600, 320,
background=None,
@@ -250,6 +258,8 @@ class GenderStatsView(BrowserView):
surface.finish()
return fd.getvalue()
+def hexa_to_float(code):
+ return (int(code[1:3], 16)/255., int(code[3:5], 16)/255., int(code[5:7], 16)/255.)
class AgeStatsView(BrowserView):
def __call__(self):
@@ -261,7 +271,12 @@ class AgeStatsView(BrowserView):
for age in x_labels:
data.append(len([x for x in ageranges if x == age]))
x_labels = ('-30', '30-40', '40-50', '50-60', '60-70', '+70')
- series_colors = [ [0.54,0.56,0.69, 'solid'] ] * len(x_labels)
+
+ settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
+ if settings.ageranges_color:
+ series_colors = [ list(hexa_to_float(settings.ageranges_color) + ('solid',)) ] * len(x_labels)
+ else:
+ series_colors = [ [0.54,0.56,0.69, 'solid'] ] * len(x_labels)
increment = 5
y_bounds = [0, ((max(data)/increment)+1)*increment]
y_labels = [str(x) for x in range(0, y_bounds[1]+increment, increment)]