From 8bd7074f1f850246558cc4a30f58e37cfb335b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 1 Jul 2008 12:16:59 +0200 Subject: [PATCH] Use linear gradiant for filling background, bars and lines Highlight point over axis Remove shadown on pie --- .../window/view_form/view/graph_gtk/bar.py | 13 ++++++++--- .../window/view_form/view/graph_gtk/graph.py | 8 +++++-- .../window/view_form/view/graph_gtk/line.py | 23 ++++++++++++++++++- .../window/view_form/view/graph_gtk/pie.py | 11 --------- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/tryton/gui/window/view_form/view/graph_gtk/bar.py b/tryton/gui/window/view_form/view/graph_gtk/bar.py index 55679c28a1..2e6b73e946 100644 --- a/tryton/gui/window/view_form/view/graph_gtk/bar.py +++ b/tryton/gui/window/view_form/view/graph_gtk/bar.py @@ -3,6 +3,7 @@ from graph import Graph from tryton.common import hex2rgb, lighten import locale import math +import cairo class Bar(Graph): @@ -26,10 +27,10 @@ class Bar(Graph): cr.fill() self.drawRectangle(cr, x, y, w, h) - color = self.colorScheme[bar.yname] + r, g, b = self.colorScheme[bar.yname] if bar.highlight: - color = self.colorScheme['__highlight'] - cr.set_source_rgb(*color) + r, g, b = self.colorScheme['__highlight'] + cr.set_source(self.sourceRectangle(x, y, w, h, r, g, b)) cr.fill_preserve() cr.stroke() @@ -46,6 +47,12 @@ class Bar(Graph): cr.rectangle(x + 5, y, w - 10, h) cr.rectangle(x, y + 5, w, h - 10) + def sourceRectangle(self, x, y, w, h, r, g, b): + linear = cairo.LinearGradient((x + w) / 2, y, (x + w) / 2, y + h) + linear.add_color_stop_rgb(0, 3.5 * r / 5.0, 3.5 * g / 5.0, 3.5 * b / 5.0) + linear.add_color_stop_rgb(1, r, g, b) + return linear + def motion(self, widget, event): super(Bar, self).motion(widget, event) diff --git a/tryton/gui/window/view_form/view/graph_gtk/graph.py b/tryton/gui/window/view_form/view/graph_gtk/graph.py index 51de479adf..ea80a9c25b 100644 --- a/tryton/gui/window/view_form/view/graph_gtk/graph.py +++ b/tryton/gui/window/view_form/view/graph_gtk/graph.py @@ -141,9 +141,13 @@ class Graph(gtk.DrawingArea): }, context=ctx, warning=False) def drawBackground(self, cr, width, height): - # Fill the background with gray + # Fill the background cr.save() - cr.set_source_rgb(*hex2rgb(self.attrs.get('background', '#f5f5f5'))) + r, g, b = hex2rgb(self.attrs.get('background', '#d5d5d5')) + linear = cairo.LinearGradient(width / 2, 0, width / 2, height) + linear.add_color_stop_rgb(0, 1, 1, 1) + linear.add_color_stop_rgb(1, r, g, b) + cr.set_source(linear) cr.rectangle(0, 0, width, height) cr.fill() cr.stroke() diff --git a/tryton/gui/window/view_form/view/graph_gtk/line.py b/tryton/gui/window/view_form/view/graph_gtk/line.py index 9bec350ed2..33e79362f5 100644 --- a/tryton/gui/window/view_form/view/graph_gtk/line.py +++ b/tryton/gui/window/view_form/view/graph_gtk/line.py @@ -3,6 +3,7 @@ from graph import Graph from tryton.common import hex2rgb import locale import math +import cairo class Line(Graph): @@ -73,11 +74,31 @@ class Line(Graph): cr.fill() cr.restore() - cr.set_source_rgb(*self.colorScheme[key]) + r, g, b = self.colorScheme[key] + linear = cairo.LinearGradient(width / 2, 0, width / 2, height) + linear.add_color_stop_rgb(0, + 3.5 * r / 5.0, 3.5 * g / 5.0, 3.5 * b / 5.0) + linear.add_color_stop_rgb(1, r, g, b) + cr.set_source(linear) preparePath(key) cr.fill() else: preparePath(key) + + for point in self.points: + if key2fill[point.yname]: + continue + cr.set_source_rgb(*self.colorScheme[point.yname]) + cr.arc(point.x * self.area.w + self.area.x, + point.y * self.area.h + self.area.y, + 3, 0, 2 * math.pi) + cr.fill() + + cr.restore() + + def drawLegend(self, cr, widht, height): + super(Line, self).drawLegend(cr, widht, height) + cr.save() for point in self.points: if point.highlight: cr.set_line_width(2) diff --git a/tryton/gui/window/view_form/view/graph_gtk/pie.py b/tryton/gui/window/view_form/view/graph_gtk/pie.py index d1df4ac47b..e23df12068 100644 --- a/tryton/gui/window/view_form/view/graph_gtk/pie.py +++ b/tryton/gui/window/view_form/view/graph_gtk/pie.py @@ -84,17 +84,6 @@ class Pie(Graph): def drawGraph(self, cr, width, height): cr.set_line_join(cairo.LINE_JOIN_ROUND) - cr.save() - cr.set_source_rgba(0, 0, 0, 0.15) - cr.new_path() - cr.move_to(self.centerx, self.centery) - cr.arc(self.centerx + 1, self.centery + 2, self.radius + 1, 0, - 2 * math.pi) - cr.line_to(self.centerx, self.centery) - cr.close_path() - cr.fill() - cr.restore() - cr.save() for slice in self.slices: if slice.isBigEnough():