Пример #1
0
 def _draw_text(self):
     if self.text == '' or self.text is None:
         self.text_cursor.x_plus(self.max_width)
     elif hasattr(self, 'text_list'):
         self.text_cursor.y_plus(-self.padding_bottom -
                                 ((len(self.text_list) - 1) *
                                  (self.line_size + self.line_space)) -
                                 self.diff_bottom)
         i = 0
         for item in self.text_list:
             self.text_cursor.x_plus(self.padding_left +
                                     self.width_diff_l[i])
             self.text_object = PDFText(self.table.session, self.table.page,
                                        item, self.font, self.text_color,
                                        self.text_cursor)
             self.text_cursor.x_plus(-self.font._string_width(item) -
                                     self.width_diff_l[i])
             self.text_cursor.y_plus(self.line_space + self.line_size)
             i += 1
         self.text_cursor.x_plus(
             self.font._string_width(self.text_list[-1]) +
             self.padding_right + self.width_diff_right +
             self.width_diff_l[-1])
         self.text_cursor.y_plus(self.padding_bottom + self.diff_bottom -
                                 self.line_space - self.line_size)
     else:
         self.text_cursor.y_plus(-(self.padding_bottom + self.diff_bottom))
         self.text_cursor.x_plus(self.padding_left + self.width_diff_left)
         self.text_object = PDFText(self.table.session, self.table.page,
                                    self.text, self.font, self.text_color,
                                    self.text_cursor)
         self.text_cursor.x_plus(self.padding_right + self.width_diff_right)
         self.text_cursor.y_plus(self.padding_bottom + self.diff_bottom)
Пример #2
0
    def draw_axis_titles(self, x_title=None, y_title=None):
        if x_title is not None:
            label_cursor_x = PDFCursor(self.origin.x + (self.width - self.padding[0])/ 2.0, self.origin.y + 0.8 * self.padding[1])
            PDFText(self.session, self.page, x_title, cursor=label_cursor_x)

        if y_title is not None:
            if self.padding[0] == 0:
                self.padding = (self.width * 0.12, self.padding[1])
            label_cursor_y = PDFCursor(self.origin.x - 0.8 * self.padding[0], self.origin.y - (self.height / 2.0) - 0.8 * self.padding[1])
            text = PDFText(self.session, self.page, None, cursor=label_cursor_y)
            text.text_rotate(-90)
            text._text(y_title)
Пример #3
0
    def _draw_legend_title(self, legend_title="Legend"):
        text_width = self.session.parent.document.font._string_width(legend_title)
        text_height = self.session.parent.document.font.font_size
        text_cursor = PDFCursor(self.legend_start_cursor.x + (self.legend_width - text_width) / 2.0, self.legend_start_cursor.y + 1.2 * text_height)
        legend_title = PDFText(self.session, self.page, "Legend", cursor=text_cursor)

        self.legend_data_start = PDFCursor(self.legend_start_cursor.x + 10, self.legend_start_cursor.y + 3 * text_height)
Пример #4
0
 def _draw_title(self):
     if self.title is not None:
         save_font = self.font
         self.session.parent.document.set_font(save_font.family, "b", save_font.font_size * 1.2)
         title_cursor = PDFCursor(self.origin.x + (self.width - self.session.parent.document.font._string_width(self.title))/ 2.0, self.origin.y - self.height - (self.padding[1] * 0.4))
         title = PDFText(self.session, self.page, self.title, cursor=title_cursor, color=self.base_color)
         self.session.parent.document.set_font(font=save_font)
Пример #5
0
    def draw_y_label(self, i, k, x1, y1):
        if self.axis_labels is None:
            return
        elif self.axis_labels is "Auto":
            text = i
        else:
            text = self.axis_labels["y"][k]

        cursor = PDFCursor(x1 - self.font._string_width(text) - 1, y1 + 2)
        label = PDFText(self.session, self.page, '%s' % text, cursor=cursor)
Пример #6
0
 def _draw_legend_line(self, index, series_name):
     end = PDFCursor(self.legend_data_start.x + 10, self.legend_data_start.y + 10)
     box = PDFRectangle(self.session, self.page, self.legend_data_start, end, None, self.fill_colors[index], style="F", stroke="solid")
     box._draw()
     end.x_plus(10)
     text = PDFText(self.session, self.page, series_name, cursor=end, color=self.base_color)
     w = end.x + 4
     if w > self.max_x:
         self.max_x = w
     self.legend_data_start.y_plus(1.75 * self._legend_line_height)
Пример #7
0
    def draw_axis_titles(self, x_title=None, y_title=None):
        if x_title is not None:
            label_cursor_x = PDFCursor(self.origin.x + (self.width - self.padding[0])/ 2.0, self.origin.y + 0.8 * self.padding[1])
            PDFText(self.session, self.page, x_title, cursor=label_cursor_x)

        if y_title is not None:
            if self.padding[0] == 0:
                self.padding = (self.width * 0.12, self.padding[1])
            label_cursor_y = PDFCursor(self.origin.x - 0.8 * self.padding[0], self.origin.y - (self.height / 2.0) - 0.8 * self.padding[1])
            text = PDFText(self.session, self.page, None, cursor=label_cursor_y)
            text.text_rotate(-90)
            text._text(y_title)
Пример #8
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)
Пример #9
0
    def draw_label(self, text):
        self.session.parent.document.set_font_size(10)
        if self.test_angle < 90:
            self.point_cursor.x_plus(-3)
        if self.test_angle > 90 and self.test_angle < 250:
            width = self.session.parent.document.font._string_width(text)
            self.point_cursor.x_plus(-(width))
        if self.test_angle > 180 and self.test_angle < 250:
            self.point_cursor.x_plus(-4)
            self.point_cursor.y_plus(2)
        if self.test_angle > 250 and self.test_angle < 270:
            self.point_cursor.y_plus(12)
        if self.test_angle > 270 and self.test_angle < 360:
            self.point_cursor.y_plus(8)
            self.point_cursor.x_plus(2)

        PDFText(self.session, self.page, text, color=self.base_color, cursor=self.point_cursor)
Пример #10
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()
Пример #11
0
 def draw_x_label(self, i, k, x1, y1):
     text = self.data[k][0]
     cursor = PDFCursor(
         x1 - (self.x_delta + self.font._string_width(text)) / 2.0, y1 + 9)
     label = PDFText(self.session, self.page, '%s' % text, cursor=cursor)