get graph colours from settings (#1027)

This commit is contained in:
Frédéric Péters 2011-12-01 16:36:43 +01:00
parent 2cc833255e
commit bf078ff20a
1 changed files with 17 additions and 2 deletions

View File

@ -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)]