From bf078ff20ac0397c9ee2611b874fa3ecfae21fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 1 Dec 2011 16:36:43 +0100 Subject: [PATCH] get graph colours from settings (#1027) --- tabellio/webviews/deputy.py | 19 +++++++++++++++++-- 1 file 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)]