def updateGraph(self): yfield2attrs = {} for yfield in self.yfields: yfield2attrs[yfield.get('key', yfield['name'])] = yfield self.points = [] i = 0 keys = self.datas.keys() keys.sort() for xfield in keys: j = 0 for yfield in self.datas[xfield]: xval = i yval = self.datas[xfield][yfield] x = (xval - self.minxval) * self.xscale y = 1.0 - (yval - self.minyval) * self.yscale if self.xrange == 0: x = 1.0 if (not bool(safe_eval(yfield2attrs[yfield].get('empty', '1'))) and yval == 0): continue point = Point(x, y, xval, yval, xfield, yfield) if (0.0 <= point.x <= 1.0) and (0.0 <= point.y <= 1.0): self.points.append(point) j += 1 i += 1
def drawGraph(self, cr, width, height): key2fill = {} for yfield in self.yfields: key2fill[yfield.get('key', yfield['name'])] = \ bool(safe_eval(yfield.get('fill', '0'))) def preparePath(key): cr.new_path() cr.move_to(self.area.x, self.area.y + self.area.h) for point in self.points: if point.yname == key: cr.line_to(point.x * self.area.w + self.area.x, point.y * self.area.h + self.area.y) cr.line_to(self.area.x + self.area.w, self.area.y + self.area.h) cr.move_to(self.area.x, self.area.y + self.area.h) if key2fill[key]: cr.close_path() else: cr.set_source_rgb(*self.colorScheme[key]) cr.stroke() cr.save() cr.set_line_width(2) for key in self._getDatasKeys(): if key2fill[key]: cr.save() cr.set_source_rgba(0, 0, 0, 0.15) cr.translate(2, -2) preparePath(key) cr.fill() cr.restore() 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.move_to(point.x * self.area.w + self.area.x, point.y * self.area.h + self.area.y) 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 drawGraph(self, cr, width, height): cr.set_line_join(cairo.LINE_JOIN_ROUND) cr.save() for slice in self.slices: if slice.isBigEnough(): if bool(safe_eval(self.yfields[0].get('fill', '1'))): color = self.colorScheme[slice.xname] if slice.highlight: color = self.colorScheme['__highlight'] cr.set_source_rgba(*color) slice.draw(cr, self.centerx, self.centery, self.radius) cr.fill() cr.set_source_rgb(*hex2rgb( self.attrs.get('background', '#f5f5f5'))) slice.draw(cr, self.centerx, self.centery, self.radius) cr.set_line_width(2) cr.stroke() cr.restore()