예제 #1
0
파일: graph.py 프로젝트: luchaoshuai/tryton
 def setColorScheme(self):
     keys = self._getDatasKeys()
     color = self.attrs.get('color', 'blue')
     r, g, b = hex2rgb(COLOR_SCHEMES.get(color, color))
     maxcolor = max(max(r, g), b)
     self.colorScheme = generateColorscheme(color, keys,
                                            maxcolor / (len(keys) or 1))
     for yfield in self.yfields:
         if yfield.get('color'):
             self.colorScheme[yfield.get('key', yfield['name'])] = hex2rgb(
                 COLOR_SCHEMES.get(yfield['color'], yfield['color']))
예제 #2
0
 def setColorScheme(self):
     keys = self._getDatasKeys()
     color = self.attrs.get('color', 'blue')
     r, g, b = hex2rgb(COLOR_SCHEMES.get(color, color))
     maxcolor = max(max(r, g), b)
     self.colorScheme = generateColorscheme(color, keys,
             maxcolor / (len(keys) or 1))
     for yfield in self.yfields:
         if yfield.get('color'):
             self.colorScheme[yfield.get('key', yfield['name'])] = hex2rgb(
                     COLOR_SCHEMES.get(yfield['color'], yfield['color']))
예제 #3
0
    def drawAxis(self, cr, width, height):
        cr.set_source_rgb(*common.hex2rgb('#000000'))

        for slice in self.slices:
            normalisedAngle = slice.normalisedAngle()

            labelx = self.centerx + \
                math.sin(normalisedAngle) * (self.radius + 10)
            labely = self.centery - \
                math.cos(normalisedAngle) * (self.radius + 10)

            label = '%s (%s%%)' % (self.labels[slice.xname],
                                   locale.format('%.2f', slice.fraction * 100))
            extents = cr.text_extents(label)
            labelWidth = extents[2]
            labelHeight = extents[3]

            x = y = 0

            if normalisedAngle <= math.pi * 0.5:
                x = labelx
                y = labely - labelHeight
            elif math.pi / 2 < normalisedAngle <= math.pi:
                x = labelx
                y = labely
            elif math.pi < normalisedAngle <= math.pi * 1.5:
                x = labelx - labelWidth
                y = labely
            else:
                x = labelx - labelWidth
                y = labely - labelHeight

            cr.move_to(x, y)
            cr.show_text(label)
예제 #4
0
    def drawAxis(self, cr, width, height):
        cr.set_source_rgb(*hex2rgb('#000000'))

        for slice in self.slices:
            normalisedAngle = slice.normalisedAngle()

            labelx = self.centerx + \
                math.sin(normalisedAngle) * (self.radius + 10)
            labely = self.centery - \
                math.cos(normalisedAngle) * (self.radius + 10)

            label = '%s (%s%%)' % (self.labels[slice.xname],
                    locale.format('%.2f', slice.fraction * 100))
            extents = cr.text_extents(label)
            labelWidth = extents[2]
            labelHeight = extents[3]

            x = y = 0

            if normalisedAngle <= math.pi * 0.5:
                x = labelx
                y = labely - labelHeight
            elif math.pi / 2 < normalisedAngle <= math.pi:
                x = labelx
                y = labely
            elif math.pi < normalisedAngle <= math.pi * 1.5:
                x = labelx - labelWidth
                y = labely
            else:
                x = labelx - labelWidth
                y = labely - labelHeight

            cr.move_to(x, y)
            cr.show_text(label)
예제 #5
0
파일: graph.py 프로젝트: luchaoshuai/tryton
    def drawAxis(self, cr, width, height):
        cr.set_source_rgb(*hex2rgb('#000000'))
        cr.set_line_width(0.5)

        # Y axis
        def drawYLabel(h, label):
            x = self.area.x
            y = self.area.y + self.area.h - h * self.area.h

            cr.new_path()
            cr.move_to(x, y)
            cr.line_to(x - 3.0, y)
            cr.close_path()
            cr.stroke()

            extends = cr.text_extents(label)
            labelWidth = extends[2]
            labelHeight = extends[3]
            if labelWidth <= self.area.x:
                cr.move_to(x - 3.0 - labelWidth - 5, y + labelHeight / 2.0)
                cr.show_text(label)

        for h, label in self.YLabels():
            drawYLabel(h, label)
        cr.new_path()
        cr.move_to(self.area.x, self.area.y)
        cr.line_to(self.area.x, self.area.y + self.area.h)
        cr.close_path()
        cr.stroke()

        # X axis
        def drawXLabel(w, label):
            x = self.area.x + w * self.area.w
            y = self.area.y + self.area.h

            cr.new_path()
            cr.move_to(x, y)
            cr.line_to(x, y + 3.0)
            cr.close_path()
            cr.stroke()

            extends = cr.text_extents(label)
            labelWidth = extends[2]
            labelHeight = extends[3]
            if labelWidth <= self.xscale * self.area.w:
                cr.move_to(x - labelWidth / 2.0, y + labelHeight + 5)
                cr.show_text(label)

        for w, label in self.XLabels():
            drawXLabel(w, label)
        cr.new_path()
        cr.move_to(self.area.x, self.area.y + self.area.h)
        cr.line_to(self.area.x + self.area.w, self.area.y + self.area.h)
        cr.close_path()
        cr.stroke()
예제 #6
0
    def drawAxis(self, cr, width, height):
        cr.set_source_rgb(*hex2rgb('#000000'))
        cr.set_line_width(1.5)

        # Y axis
        def drawYLabel(h, label):
            x = self.area.x
            y = self.area.y + self.area.h - h * self.area.h

            cr.new_path()
            cr.move_to(x, y)
            cr.line_to(x - 3.0, y)
            cr.close_path()
            cr.stroke()

            extends = cr.text_extents(label)
            labelWidth = extends[2]
            labelHeight = extends[3]
            if labelWidth <= self.area.x:
                cr.move_to(x - 3.0 - labelWidth - 5, y + labelHeight / 2.0)
                cr.show_text(label)

        for h, label in self.YLabels():
            drawYLabel(h, label)
        cr.new_path()
        cr.move_to(self.area.x, self.area.y)
        cr.line_to(self.area.x, self.area.y + self.area.h)
        cr.close_path()
        cr.stroke()

        # X axis
        def drawXLabel(w, label):
            x = self.area.x + w * self.area.w
            y = self.area.y + self.area.h

            cr.new_path()
            cr.move_to(x, y)
            cr.line_to(x, y + 3.0)
            cr.close_path()
            cr.stroke()

            extends = cr.text_extents(label)
            labelWidth = extends[2]
            labelHeight = extends[3]
            if labelWidth <= self.xscale * self.area.w:
                cr.move_to(x - labelWidth / 2.0, y + labelHeight + 5)
                cr.show_text(label)

        for w, label in self.XLabels():
            drawXLabel(w, label)
        cr.new_path()
        cr.move_to(self.area.x, self.area.y + self.area.h)
        cr.line_to(self.area.x + self.area.w, self.area.y + self.area.h)
        cr.close_path()
        cr.stroke()
예제 #7
0
파일: graph.py 프로젝트: luchaoshuai/tryton
 def drawBackground(self, cr, width, height):
     # Fill the background
     cr.save()
     r, g, b = hex2rgb(self.attrs.get('background', '#d5d5d5'))
     linear = cairo.LinearGradient(width // 2, 0, width // 2, height)
     linear.add_color_stop_rgb(0, 1, 1, 1)
     linear.add_color_stop_rgb(1, r, g, b)
     cr.set_source(linear)
     cr.rectangle(0, 0, width, height)
     cr.fill()
     cr.stroke()
     cr.restore()
예제 #8
0
 def drawBackground(self, cr, width, height):
     # Fill the background
     cr.save()
     r, g, b = hex2rgb(self.attrs.get('background', '#d5d5d5'))
     linear = cairo.LinearGradient(width // 2, 0, width // 2, height)
     linear.add_color_stop_rgb(0, 1, 1, 1)
     linear.add_color_stop_rgb(1, r, g, b)
     cr.set_source(linear)
     cr.rectangle(0, 0, width, height)
     cr.fill()
     cr.stroke()
     cr.restore()
예제 #9
0
파일: graph.py 프로젝트: luchaoshuai/tryton
    def drawLegend(self, cr, width, height):
        if not int(self.attrs.get('legend', 1)):
            return

        padding = 4
        bullet = 15
        width = 0
        height = padding
        keys = self._getDatasKeys()
        if not keys:
            return
        keys2txt = {}
        for yfield in self.yfields:
            keys2txt[yfield.get('key', yfield['name'])] = yfield['string']
        for key in keys:
            extents = cr.text_extents(keys2txt[key])
            width = max(extents[2], width)
            height += max(extents[3], bullet) + padding
        width = padding + bullet + padding + width + padding

        pos_x, pos_y = self._getLegendPosition(width, height)

        cr.save()
        cr.rectangle(pos_x, pos_y, width, height)
        cr.set_source_rgba(1, 1, 1, 0.8)
        cr.fill_preserve()
        cr.set_line_width(0.5)
        cr.set_source_rgb(*hex2rgb('#000000'))
        cr.stroke()

        def drawKey(key, x, y, text_height):
            cr.rectangle(x, y, bullet, bullet)
            cr.set_source_rgb(*self.colorScheme[key])
            cr.fill_preserve()
            cr.set_source_rgb(0, 0, 0)
            cr.stroke()
            cr.move_to(x + bullet + padding,
                       y + bullet / 2.0 + text_height / 2.0)
            cr.show_text(keys2txt[key])

        cr.set_line_width(0.5)
        x = pos_x + padding
        y = pos_y + padding
        for key in keys:
            extents = cr.text_extents(keys2txt[key])
            drawKey(key, x, y, extents[3])
            y += max(extents[3], bullet) + padding

        cr.restore()
예제 #10
0
    def drawLegend(self, cr, width, height):
        if not int(self.attrs.get('legend', 1)):
            return

        padding = 4
        bullet = 15
        width = 0
        height = padding
        keys = self._getDatasKeys()
        if not keys:
            return
        keys2txt = {}
        for yfield in self.yfields:
            keys2txt[yfield.get('key', yfield['name'])] = yfield['string']
        for key in keys:
            extents = cr.text_extents(keys2txt[key])
            width = max(extents[2], width)
            height += max(extents[3], bullet) + padding
        width = padding + bullet + padding + width + padding

        pos_x, pos_y = self._getLegendPosition(width, height)

        cr.save()
        cr.rectangle(pos_x, pos_y, width, height)
        cr.set_source_rgba(1, 1, 1, 0.8)
        cr.fill_preserve()
        cr.set_line_width(2)
        cr.set_source_rgb(*hex2rgb('#000000'))
        cr.stroke()

        def drawKey(key, x, y, text_height):
            cr.rectangle(x, y, bullet, bullet)
            cr.set_source_rgb(*self.colorScheme[key])
            cr.fill_preserve()
            cr.set_source_rgb(0, 0, 0)
            cr.stroke()
            cr.move_to(x + bullet + padding,
                    y + bullet / 2.0 + text_height / 2.0)
            cr.show_text(keys2txt[key])

        cr.set_line_width(1)
        x = pos_x + padding
        y = pos_y + padding
        for key in keys:
            extents = cr.text_extents(keys2txt[key])
            drawKey(key, x, y, extents[3])
            y += max(extents[3], bullet) + padding

        cr.restore()
예제 #11
0
 def drawLegend(self, cr, widht, height):
     super(Line, self).drawLegend(cr, widht, height)
     cr.save()
     for point in self.points:
         if point.highlight:
             cr.set_line_width(2)
             cr.set_source_rgb(*hex2rgb('#000000'))
             cr.move_to(point.x * self.area.w + self.area.x,
                        point.y * self.area.h + self.area.y)
             cr.arc(point.x * self.area.w + self.area.x,
                    point.y * self.area.h + self.area.y, 3, 0, 2 * math.pi)
             cr.stroke()
             cr.set_source_rgb(*self.colorScheme['__highlight'])
             cr.arc(point.x * self.area.w + self.area.x,
                    point.y * self.area.h + self.area.y, 3, 0, 2 * math.pi)
             cr.fill()
     cr.restore()
예제 #12
0
    def drawLine(self, cr, x, y):
        if x:
            x1 = x2 = self.area.x + x * self.area.w
            y1 = self.area.y
            y2 = y1 + self.area.h
        else:
            y1 = y2 = self.area.y + self.area.h - y * self.area.h
            x1 = self.area.x
            x2 = x1 + self.area.w

        cr.save()
        cr.set_source_rgb(*hex2rgb('#808080'))
        cr.set_line_width(1.5)
        cr.new_path()
        cr.move_to(x1, y1)
        cr.line_to(x2, y2)
        cr.close_path()
        cr.stroke()
        cr.restore()
예제 #13
0
    def drawGraph(self, cr, width, height):
        cr.set_line_join(cairo.LINE_JOIN_ROUND)

        cr.save()
        for slice in self.slices:
            if slice.isBigEnough():
                if bool(int(self.yfields[0].get('fill', 1))):
                    color = self.colorScheme[slice.xname]
                    if slice.highlight:
                        color = common.highlight_rgb(*color)
                    cr.set_source_rgba(*color)
                    slice.draw(cr, self.centerx, self.centery, self.radius)
                    cr.fill()
                cr.set_source_rgb(
                    *common.hex2rgb(self.attrs.get('background', '#f5f5f5')))
                slice.draw(cr, self.centerx, self.centery, self.radius)
                cr.set_line_width(2)
                cr.stroke()
        cr.restore()
예제 #14
0
 def drawLegend(self, cr, widht, height):
     super(Line, self).drawLegend(cr, widht, height)
     cr.save()
     for point in self.points:
         if point.highlight:
             cr.set_line_width(2)
             cr.set_source_rgb(*hex2rgb('#000000'))
             cr.move_to(point.x * self.area.w + self.area.x,
                     point.y * self.area.h + self.area.y)
             cr.arc(point.x * self.area.w + self.area.x,
                     point.y * self.area.h + self.area.y,
                     3, 0, 2 * math.pi)
             cr.stroke()
             cr.set_source_rgb(*self.colorScheme['__highlight'])
             cr.arc(point.x * self.area.w + self.area.x,
                     point.y * self.area.h + self.area.y,
                     3, 0, 2 * math.pi)
             cr.fill()
     cr.restore()
예제 #15
0
    def drawLine(self, cr, x, y):
        if x:
            x1 = x2 = self.area.x + x * self.area.w
            y1 = self.area.y
            y2 = y1 + self.area.h
        else:
            y1 = y2 = self.area.y + self.area.h - y * self.area.h
            x1 = self.area.x
            x2 = x1 + self.area.w

        cr.save()
        cr.set_source_rgb(*hex2rgb('#808080'))
        cr.set_line_width(1.5)
        cr.new_path()
        cr.move_to(x1, y1)
        cr.line_to(x2, y2)
        cr.close_path()
        cr.stroke()
        cr.restore()
예제 #16
0
    def drawGraph(self, cr, width, height):
        cr.set_line_join(cairo.LINE_JOIN_ROUND)

        cr.save()
        for slice in self.slices:
            if slice.isBigEnough():
                if bool(int(self.yfields[0].get('fill', 1))):
                    color = self.colorScheme[slice.xname]
                    if slice.highlight:
                        color = self.colorScheme['__highlight']
                    cr.set_source_rgba(*color)
                    slice.draw(cr, self.centerx, self.centery, self.radius)
                    cr.fill()
                cr.set_source_rgb(*hex2rgb(
                        self.attrs.get('background', '#f5f5f5')))
                slice.draw(cr, self.centerx, self.centery, self.radius)
                cr.set_line_width(2)
                cr.stroke()
        cr.restore()