1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
21
from mx.DateTime import RelativeDateTime, now, DateTime, localtime
24
from report.misc import choice_colors
29
class GanttCanvas(object):
30
def __init__(self, io, convertors=(lambda x:x,lambda x:x)):
32
self._canvas = canvas.init(fname=io, format='pdf')
33
self._canvas.set_author("Open ERP")
35
self._conv = convertors
39
def add(self, user, name, datas):
40
if hasattr(user, 'replace'):
41
user=user.replace('/', '//')
42
if hasattr(name, 'replace'):
43
name=name.replace('/', '//')
44
name = name.encode('ascii', 'ignore')
45
if user not in self._datas:
46
self._datas[user] = []
48
x = map(self._conv[0], f)
49
if x[0]<self._min or not self._min:
51
if x[1]>self._max or not self._max:
53
self._datas[user].append( (name, x))
54
self._names.setdefault(name, x[0])
57
colors = choice_colors(len(self._datas.keys()))
59
for user in self._datas.keys():
60
user_color[user] = colors.pop()
64
names.append((self._names[n], n))
67
def _interval_get(*args):
70
d = localtime(self._min + (((self._max-self._min)/20)*(i+1)))
71
res = DateTime(d.year, d.month, d.day).ticks()
72
if (not result) or result[-1]<>res:
76
ar = area.T(y_coord = category_coord.T(names, 1),
77
x_grid_style=line_style.gray50_dash1,
78
x_grid_interval=_interval_get,
79
x_range = (self._min,self._max),
80
x_axis=axis.X(label="Date", format=self._conv[1]),
81
y_axis=axis.Y(label="Tasks"),
82
legend = legend.T(), size = (680,450))
84
for user in self._datas:
85
chart_object.set_defaults(interval_bar_plot.T, direction="horizontal", data=self._datas[user])
86
f = fill_style.Plain()
87
f.bgcolor = user_color[user]
88
ar.add_plot(interval_bar_plot.T(fill_styles = [f, None], label=user, cluster=(0,1)))
95
if __name__ == '__main__':
96
date_to_int = lambda x: int(x.ticks())
97
int_to_date = lambda x: '/a60{}'+localtime(x).strftime('%d %m %Y')
98
gt = GanttCanvas('test.pdf', convertors=(date_to_int, int_to_date))
99
gt.add('nicoe', 'Graphe de gantt', [(DateTime(2005,6,12), DateTime(2005,6,13))])
100
gt.add('nicoe', 'Tarifs', [(DateTime(2005,6,19), DateTime(2005,6,21))])
101
gt.add('gaetan', 'Calcul des prix', [(DateTime(2005,6,12), DateTime(2005,6,13))])
102
gt.add('nico', 'Mise a jour du site', [(DateTime(2005,6,13), DateTime(2005,6,16))])
103
gt.add('tom', 'Coucou', [(DateTime(2005,6,11), DateTime(2005,6,12))])
107
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: