def draw(self): self.get_maximum_by_stack() StackedArea.__base__.draw(self) if not self.has_gdata: return dl = DrawableList() self.x_increment = self.graph_width / float(self.column_count - 1) dl.append(DrawableStrokeColor('transparent')) height = [0 for i in range(self.column_count)] data_points = None if self.last_series_goes_on_bottom: self.norm_data.reverse() for data_row in self.norm_data: prev_data_points = data_points data_points = [] dl.append(DrawableFillColor(Color(data_row['color']))) for index, data_point in enumerate(data_row['values']): # Use incremented x and scaled y new_x = self.graph_left + (self.x_increment * index) new_y = self.graph_top + (self.graph_height - data_point * \ self.graph_height - height[index]) height[index] += (data_point * self.graph_height) data_points.append(new_x) data_points.append(new_y) self.draw_label(new_x, index) if prev_data_points: poly_points = copy.copy(data_points) tmp_max_point = len(prev_data_points) / 2 - 1 for i in range(tmp_max_point, -1, -1): poly_points.append(prev_data_points[2 * i]) poly_points.append(prev_data_points[2 * i + 1]) poly_points.append(data_points[0]) poly_points.append(data_points[1]) else: poly_points = copy.copy(data_points) poly_points.append(self.graph_right) poly_points.append(self.graph_bottom - 1) poly_points.append(self.graph_left) poly_points.append(self.graph_bottom - 1) poly_points.append(data_points[0]) poly_points.append(data_points[1]) # generate CoordinateList coordinates = [Coordinate(poly_points[i], poly_points[i + 1]) \ for i in range(0, len(poly_points), 2)] cl = CoordinateList() for c in coordinates: cl.append(c) dl.append(DrawablePolyline(cl)) dl.append(DrawableScaling(self.scale, self.scale)) self.base_image.draw(dl)
def _draw_bezier(self): self.x_increment = self.graph_width / float(self.column_count - 1) dl = DrawableList() for data_row in self.norm_data: poly_points = CoordinateList() dl.append(DrawableFillColor(data_row['color'])) for index, data_point in enumerate(data_row['values']): # Use incremented x and scaled y new_x = self.graph_left + (self.x_increment * index) new_y = self.graph_top + ( self.graph_height - data_point * self.graph_height) if index == 0: poly_points.append(Coordinate(self.graph_left, self.graph_bottom - 1)) poly_points.append(Coordinate(new_x, new_y)) self.draw_label(new_x, index) dl.append(DrawableFillOpacity(0.0)) dl.append(DrawableStrokeColor(data_row['color'])) dl.append(DrawableStrokeWidth(self.clip_value_if_greater_than(self.columns / (len(self.norm_data[0]['values']) * 4), 5.0))) dl.append(DrawableBezier(poly_points)) self.base_image.draw(dl)
def draw(self): """override to draw() method in Base Class.""" Area.__base__.draw(self) if not self.has_gdata: return x_increment = self.graph_width / float(self.column_count - 1) dl = DrawableList() dl.append(DrawableStrokeColor(Color('transparent'))) for data_row in self.norm_data: poly_points = CoordinateList() prev_x = prev_y = 0.0 dl.append(DrawableFillColor(Color(data_row['color']))) if type(self.transparent) is float: dl.append(DrawableFillOpacity(self.transparent)) elif self.transparent is True: dl.append(DrawableFillOpacity(base.DEFAULT_TRANSPARENCY)) for index, data_point in enumerate(data_row['values']): # Use incremented x and scaled y new_x = self.graph_left + (x_increment * index) new_y = self.graph_top + \ (self.graph_height - data_point * self.graph_height) if prev_x > 0 and prev_y > 0: poly_points.append(Coordinate(new_x, new_y)) else: poly_points.append(Coordinate(self.graph_left, self.graph_bottom - 1)) poly_points.append(Coordinate(new_x, new_y)) self.draw_label(new_x, index) prev_x = new_x prev_y = new_y # Add closing points, draw polygon poly_points.append(Coordinate(self.graph_right, self.graph_bottom - 1)) poly_points.append(Coordinate(self.graph_left, self.graph_bottom - 1)) dl.append(DrawablePolyline(poly_points)) dl.append(DrawableScaling(self.scale, self.scale)) self.base_image.draw(dl)
from pgmagick import Image, Geometry, Color, Coordinate, CoordinateList, \ DrawableBezier im = Image(Geometry(300, 200), Color("white")) cdl = CoordinateList() cdl.append(Coordinate(20, 20)) cdl.append(Coordinate(100, 50)) cdl.append(Coordinate(50, 100)) cdl.append(Coordinate(160, 160)) db = DrawableBezier(cdl) im.draw(db) im.display()