def _draw(self, context, rectangle): self._legend.set_strings(map(lambda a: (a.get_legend(), a.get_color()), self._data_charts)) self._charts.set_data_charts(self._data_charts) legend_height = self._determine_legend_height(context, rectangle) legend_rectangle = copy_cairo_rectangle(rectangle) mesh_rectangle = copy_cairo_rectangle(rectangle) if self.get_legend_on_top(): legend_rectangle.height = legend_height mesh_rectangle.y += legend_height mesh_rectangle.height -= legend_height else: legend_rectangle.y += legend_rectangle.height - legend_height legend_rectangle.height = legend_height mesh_rectangle.height -= legend_height self._legend.draw(context, legend_rectangle) self._mesh.draw(context, mesh_rectangle) chart_rectangle = self._mesh.get_chart_area_rectangle() self._charts.draw(context, chart_rectangle)
def draw(self, context, rectangle): """\brief draw the mesh \param context - cairo context \param rectangle - cairo context rectangle """ if self._rectangle.get_lower_x_limit() == self._rectangle.get_upper_x_limit() or self._rectangle.get_lower_y_limit() == self._rectangle.get_upper_y_limit(): self._chart_area_rectangle = copy_cairo_rectangle(rectangle) return fextent = self.get_font_extent(context) if self._rectangle == None: raise od_exception('you must specify rectangle before drawing') if issubclass(self._rectangle.get_x_axis_type(), datetime): chartheight = rectangle.height - (2 * fextent[2]) - (4 * self._line_width) # height of the chart area numbers = trunc(chartheight / fextent[2]) # the max count of numbers can be displayed in vertical colon (y label) if numbers > 0: draw_numbers = self._generate_numbers(self._rectangle.get_lower_y_limit(), self._rectangle.get_upper_y_limit(), numbers) # generated numbers to draw chartwidth = rectangle.width - self._get_max_number_width(context, draw_numbers) - self._line_width * 2 # width of the chart area else: draw_numbers = [] chartwidth = rectangle.width self._chart_area_rectangle = cairo_rectangle(rectangle.x, rectangle.y, chartwidth, chartheight) y_numbers_coordinates = self._map_y_numbers_to_context(self._chart_area_rectangle, self._rectangle, draw_numbers) self._draw_vertical_colon_numbers(context, rectangle.x + chartwidth + self._line_width, y_numbers_coordinates, draw_numbers) context.set_source_rgb(*self._color) context.set_line_width(self._line_width * 0.5) context.set_dash([3, 7]) self._draw_horizontal_lines(context, rectangle.x, rectangle.x + chartwidth, y_numbers_coordinates) # draw dash lines in the chart area context.stroke() context.set_dash([1,0]) # draw rectangle and two horizontal lines at bottom of the chart context.set_line_width(self._line_width) context.rectangle(rectangle.x, rectangle.y, chartwidth, rectangle.height) line1y = rectangle.y + chartheight line2y = line1y + fextent[2] + (2 * self._line_width) context.move_to(rectangle.x, line1y) context.line_to(rectangle.x + chartwidth, line1y) context.move_to(rectangle.x, line2y) context.line_to(rectangle.x + chartwidth, line2y) context.stroke() context.set_dash([1,0]) # draw dates at bottom of the chart and vertical dash lines (small_coords, big_coords) = self._draw_horizontal_dates(context, self._chart_area_rectangle, line1y + self._line_width, line2y + self._line_width) # draw dates and return X coordinates of vertical lines in context coorinate system # draw vertical small lines context.stroke() context.set_line_width(self._line_width) context.set_source_rgb(*self._color) self._draw_vertical_lines(context, line1y, line2y, small_coords) # draw vertical big lines self._draw_vertical_lines(context, line2y, rectangle.y + rectangle.height, big_coords) context.stroke() # draw vertical dashes context.set_source_rgb(*self._color) context.set_line_width(self._line_width * 0.5) context.set_dash([3, 7]) self._draw_vertical_lines(context, rectangle.y, line1y, small_coords) context.stroke() context.set_dash([1,0]) else: raise NotImplementedError()