Use linear gradiant for filling background, bars and lines

Highlight point over axis
Remove shadown on pie
This commit is contained in:
Cédric Krier committed 2008-07-01 12:16:59 +02:00
1 parent c75b42aa18
commit 8bd7074f1f
4 files changed
+38 -17

No files matched your search

@@ -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)
@@ -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()
@@ -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)
@@ -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():