Exemple #1
0
 def draw_tick(self, x1, y1, x2, y2):
     x = PDFCursor(x1, y1)
     y = PDFCursor(x2, y2)
     if self.axis:
         tick = PDFLine(self.session, self.page, x, y, self.base_color,
                        "solid")
         tick._draw()
Exemple #2
0
    def draw_y_axis(self, zero=True):
        # Draw y axis ticks
        self.y_array = [(self.y_range[0], self.origin.y)]
        try:
            y_delta = self.height / (float(self.y_range[1] - self.y_range[0]) /
                                     float(self.frequency[1]))
        except ZeroDivisionError:
            y_delta = self.height / 2.0
        x_delta = 3
        tick_y = self.origin.y
        j = self.y_range[0]
        k = 0
        self.draw_tick(self.origin.x, tick_y, self.origin.x - x_delta, tick_y)
        if zero:
            self.draw_y_label(j, k, self.origin.x - x_delta, tick_y)
        while j < self.y_range[1]:
            j += self.frequency[1]
            tick_y -= y_delta
            self.y_array.append((j, tick_y))
            self.draw_tick(self.origin.x, tick_y, self.origin.x - x_delta,
                           tick_y)
            self.draw_y_label(j, k, self.origin.x - x_delta, tick_y)
            k += 1

        # Draw axis lines
        cursor1 = PDFCursor(self.origin.x, tick_y)
        if self.axis:
            yaxis = PDFLine(self.session,
                            self.page,
                            cursor1,
                            self.origin,
                            self.base_color,
                            stroke="solid")
            yaxis._draw()
Exemple #3
0
    def draw_x_axis(self, zero=True):
        # Draw x axis ticks
        self.x_array = [(0, self.origin.x)]
        try:
            x_delta = self.width / (float(self.x_range[1] - self.x_range[0]) /
                                    float(self.frequency[0]))
        except ZeroDivisionError:
            x_delta = self.width / 2.0
        self.x_delta = x_delta
        y_delta = 3
        tick_x = self.origin.x
        i = self.x_range[0]
        k = 0
        self.draw_tick(tick_x, self.origin.y, tick_x, self.origin.y + y_delta)
        if zero:
            self.draw_x_label(i, k, tick_x, self.origin.y)
        while i < self.x_range[1]:
            i += self.frequency[0]
            tick_x += x_delta
            self.x_array.append((i, tick_x))
            self.draw_tick(tick_x, self.origin.y, tick_x,
                           self.origin.y + y_delta)
            self.draw_x_label(i, k, tick_x, self.origin.y)
            k += 1

        cursor2 = PDFCursor(tick_x, self.origin.y)
        if self.axis:
            xaxis = PDFLine(self.session,
                            self.page,
                            self.origin,
                            cursor2,
                            self.base_color,
                            stroke="solid")
            xaxis._draw()
Exemple #4
0
 def _draw_legend_line(self, index, series_name):
     line_height = self.session.parent.document.font.font_size
     end = PDFCursor(self.legend_data_start.x + 15,
                     self.legend_data_start.y)
     line = PDFLine(self.session,
                    self.page,
                    self.legend_data_start,
                    end,
                    color=self.line_colors[index])
     line._draw()
     end.x_plus(10)
     end.y_plus(0.25 * line_height)
     text = PDFText(self.session, self.page, series_name, cursor=end)
     self.legend_data_start.y_plus(1.75 * line_height)
Exemple #5
0
 def _set_borders(self):
     self._get_points()
     self._get_border_formats()
     if self.style['bottom'] is not None:
         self.bottom_line = PDFLine(self.table.session, self.table.page,
                                    self.point_sw, self.point_se,
                                    self.format['bottom_color'],
                                    self.style['bottom'],
                                    self.size['bottom'])
     if self.style['right'] is not None:
         self.right_line = PDFLine(self.table.session, self.table.page,
                                   self.point_se, self.point_ne,
                                   self.format['right_color'],
                                   self.style['right'], self.size['right'])
     if self.style['left'] is not None:
         self.left_line = PDFLine(self.table.session, self.table.page,
                                  self.point_sw, self.point_nw,
                                  self.format['left_color'],
                                  self.style['left'], self.size['left'])
     if self.style['top'] is not None:
         self.top_line = PDFLine(self.table.session, self.table.page,
                                 self.point_ne, self.point_nw,
                                 self.format['top_color'],
                                 self.style['top'], self.size['top'])
Exemple #6
0
    def draw_data(self):
        if self.legend is not None:
            self._draw_legend_title()

        i = 0
        for series in self.data:
            if self.legend is not None:
                self._draw_legend_line(i, series.keys()[0])
            series = series.values()[0]
            self._set_color(i)
            self.line = LinearRegressionLine()
            i += 1

            cursors = []
            for value in series:
                cursor = self.get_coord(value)
                cursors.append(cursor)
                self.line.add_data(value)
            self._draw_dots(cursors)

            if self.linear_regression:
                self.line.calculate_line()
                cursor1, cursor2 = self.line.get_cursors(cursors)
                trend = PDFLine(self.session, self.page, cursor1, cursor2)
                trend._draw()
                if self.linear_regression_equation:
                    text = self.line.get_equation()
                    text_width = self.session.parent.document.font._string_width(
                        text)
                    text_height = self.session.parent.document.font.font_size * 1.2
                    x = cursor2.x + (-text_width)
                    y = self.line._get_y_at_x(x) + text_height
                    PDFText(self.session,
                            self.page,
                            text,
                            cursor=PDFCursor(x, y))

        if self.legend is not None:
            self._draw_legend_box()