예제 #1
0
    def draw(self):
        if 0:
            assert isinstance(self.canv, pdfgen.canvas.Canvas)
        self.canv.setFont("Times-Roman", 10)
        # mean
        mean = flowables.Box(self.mean_width, self.mean_height, self.box_depth)
        mean.transparent = 0
        mean.fill = 1
        mean.fill_color = (0.6, 0.6, 0.6)
        mean.drawOn(
            self.canv, self.offset + (self.mean - 0.5) * self.box_width -
            self.mean_width / 2.0, self.marks_height)
        # values
        for i, value in enumerate(self.values):
            self.canv.drawCentredString(
                self.offset + (i + 0.5) * self.box_width +
                self.box_depth * 0.5, self.marks_height + self.skala_height +
                self.bars_height + self.values_gap, '%.2f %%' % (value * 100))
        # bars
        for i, value in enumerate(self.values):
            box = flowables.Box(self.box_width, value * self.box_height,
                                self.box_depth)
            box.transparent = 0
            box.fill = 1
            box.fill_color = (0.6, 0.6, 0.6)
            box.drawOn(self.canv, self.offset + i * self.box_width,
                       self.marks_height + self.skala_height)
        # skala
        for i in range((len(self.values) - 1) * 10 + 1):
            if i % 10 == 0:
                self.canv.setLineWidth(0.2)
                self.canv.line(self.offset + (i / 10.0 + 0.5) * self.box_width,
                               1 + self.marks_height,
                               self.offset + (i / 10.0 + 0.5) * self.box_width,
                               5 + self.marks_height)
            elif i % 5 == 0:
                self.canv.line(self.offset + (i / 10.0 + 0.5) * self.box_width,
                               1.5 + self.marks_height,
                               self.offset + (i / 10.0 + 0.5) * self.box_width,
                               4.5 + self.marks_height)
            else:
                self.canv.line(self.offset + (i / 10.0 + 0.5) * self.box_width,
                               2 + self.marks_height,
                               self.offset + (i / 10.0 + 0.5) * self.box_width,
                               4 + self.marks_height)
            if i % 10 == 0:
                self.canv.setLineWidth(0.1)
        # marks
        for i in range(1, len(self.values) + 1):
            self.canv.drawCentredString(
                self.offset + (i - 0.5) * self.box_width, 0, '%i' % i)

        # statistics
        y_pos = self.marks_height + self.skala_height + self.bars_height + \
                self.values_gap + self.values_height
        self.answers_paragraph.drawOn(self.canv, self.left_margin, y_pos - 15)
        self.count_paragraph.drawOn(self.canv, self.left_margin, y_pos - 27)
        self.mean_paragraph.drawOn(self.canv, self.left_margin, y_pos - 39)
        self.stdd_paragraph.drawOn(self.canv, self.left_margin, y_pos - 51)
예제 #2
0
 def __init__(self, answer, value, significant=0):
     platypus.Flowable.__init__(self)
     if significant:
         stylesheet_name = 'Right_Highlight'
     else:
         stylesheet_name = 'Right'
     self.answer = platypus.Paragraph(escape(answer),
                                      stylesheet[stylesheet_name])
     self.value = platypus.Paragraph(u'%.2f %%' % (value * 100),
                                     stylesheet[stylesheet_name])
     self.black_box = flowables.Box(value * self.box_width, self.box_height,
                                    self.box_depth, self.box_margin)
     self.black_box.transparent = 0
     self.black_box.fill = 1
     self.black_box.fill_color = (0.6, 0.6, 0.6)
     self.white_box = flowables.Box((1 - value) * self.box_width,
                                    self.box_height, self.box_depth,
                                    self.box_margin)