コード例 #1
0
    def getElement(self):
        """Returns the shapes of the y axis."""

        ticks = self.ticks()
        lines = [
            Line(start=Coordinate(self.x, self.start),
                 end=Coordinate(self.x, self.end),
                 id=self.baseid,
                 classes=self.baseclasses)
        ]
        labels = []
        majorcount, minorcount = (0, 0)
        for tick in ticks:
            if tick['type'] is 'major':
                majorcount += 1

                if tick['value'] == self.max:
                    labeladjustment = self.labelsize / 2
                elif tick['value'] == self.min:
                    labeladjustment = -self.labelsize / 2
                else:
                    labeladjustment = 0

                lines.append(
                    Line(start=Coordinate(self.x, tick['coord']),
                         end=Coordinate(self.x + self.majorlength,
                                        tick['coord']),
                         id=u'{}-{:d}'.format(self.majoridprefix, majorcount),
                         classes=self.majorclasses))
                labels.append(
                    Text(position=Coordinate(
                        self.x - self.labelmargin,
                        tick['coord'] + labeladjustment + self.labelsize / 2),
                         text=self.labelformat % tick['value'],
                         fontsize=self.labelsize,
                         id=u'{}-{:d}'.format(self.labelidprefix, majorcount),
                         classes=self.labelclasses))
            else:
                minorcount += 1
                lines.append(
                    Line(start=Coordinate(self.x, tick['coord']),
                         end=Coordinate(self.x + self.minorlength,
                                        tick['coord']),
                         id=u'{}-{:d}'.format(self.minoridprefix, minorcount),
                         classes=self.minorclasses))

        lines = ShapeGroup(lines,
                           id=u'{}-lines'.format(self.id),
                           classes=self.classes)
        labels = ShapeGroup(labels,
                            id=u'{}-labels'.format(self.labelidprefix),
                            classes=self.labelclasses)

        return ShapeGroup([lines, labels], id=self.id, classes=self.classes)
コード例 #2
0
ファイル: Legend.py プロジェクト: agold/svgchart
    def getElement(self):
        """Returns the shapes of the legend."""

        startx = self.x + 2.0
        starty = self.y + self.titlesize + 1.0
        legend = []
        if self.border:
            legend.append(
                Rectangle(Coordinate(self.x, self.y),
                          width=self.width,
                          height=self.height,
                          id=self.borderid,
                          classes=self.borderclasses))

        legend.append(
            Text(text=self.title,
                 position=Coordinate(startx + self.width / 2, starty),
                 fontsize=self.titlesize,
                 id=self.titleid,
                 classes=self.titleclasses))

        entrycount = 0
        for entry in self.entries:
            entrycount += 1

            shapename = entry["symbol"]["shape"].capitalize()
            text = entry["label"]
            shape = __import__('lib.shapes.' + shapename, globals(), locals(),
                               [shapename])
            shape = getattr(shape, shapename)()

            shape.id = entry["legend-entry"]["symbol"]["id"]
            shape.classes = entry["legend-entry"]["symbol"]["class"]
            shape.fit(height=self.entryheight)
            shape.translateTo(
                Coordinate(
                    startx, starty + self.titlesize + (entrycount - 1) *
                    (self.entryheight + self.entrymargin)))

            textelem = Text(position=Coordinate(
                startx + shape.width, shape.position.y + self.entryheight - 1),
                            text=text,
                            fontsize=self.entryheight,
                            id=entry["legend-entry"]["label"]["id"],
                            classes=entry["legend-entry"]["label"]["class"])
            legendentry = ShapeGroup([shape, textelem],
                                     id=entry["legend-entry"]["id"],
                                     classes=entry["legend-entry"]["class"])
            legend.append(legendentry)

        return ShapeGroup(legend, id=self.id, classes=self.classes)
コード例 #3
0
    def getDataField(self):
        """Returns the datafield element."""

        id = self.settings["datafield"]["id"]
        classes = self.settings["datafield"]["class"]
        width = float(self.settings["datafield"]["width"])
        height = float(self.settings["datafield"]["height"])
        x = float(self.settings["datafield"]["x"])
        y = float(self.settings["datafield"]["y"])

        shapes = []
        try:
            border = self.settings["datafield"]["border"]
            try:
                borderid = border["id"]
            except:
                borderid = None
            try:
                borderclasses = border["class"]
            except:
                borderclasses = None
            shapes.append(
                Rectangle(Coordinate(x, y),
                          width=width,
                          height=height,
                          id=borderid,
                          classes=borderclasses))
        except:
            pass

        shapes.append(self.getDataSets())
        return ShapeGroup(shapes, id=id, classes=classes)
コード例 #4
0
ファイル: XAxis.py プロジェクト: agold/svgchart
    def getElement(self):
        """Returns the shapes of the x axis."""

        ticks = self.ticks()
        lines = [
            Line(start=Coordinate(self.start, self.y),
                 end=Coordinate(self.end, self.y),
                 id=self.baseid,
                 classes=self.baseclasses)
        ]
        labels = []
        majorcount, minorcount = 0, 0
        for tick in ticks:
            if tick['type'] is 'major':
                majorcount += 1
                lines.append(
                    Line(start=Coordinate(tick['coord'], self.y),
                         end=Coordinate(tick['coord'],
                                        self.y - self.majorlength),
                         id=u'{}-{:d}'.format(self.majoridprefix, majorcount),
                         classes=self.majorclasses))
                labels.append(
                    Text(position=Coordinate(
                        tick['coord'],
                        self.y + self.labelmargin + self.labelsize),
                         text=self.labelformat % tick['value'],
                         fontsize=self.labelsize,
                         id=u'{}-{:d}'.format(self.labelidprefix, majorcount),
                         classes=self.labelclasses))
            else:
                minorcount += 1
                lines.append(
                    Line(start=Coordinate(tick['coord'], self.y),
                         end=Coordinate(tick['coord'],
                                        self.y - self.minorlength),
                         id=u'{}-{:d}'.format(self.minoridprefix, minorcount),
                         classes=self.minorclasses))

        lines = ShapeGroup(lines,
                           id=u'{}-lines'.format(self.id),
                           classes=self.classes)
        labels = ShapeGroup(labels,
                            id=u'{}-labels'.format(self.labelidprefix),
                            classes=self.labelclasses)
        return ShapeGroup([lines, labels], id=self.id, classes=self.classes)
コード例 #5
0
    def getDataSets(self):
        """Returns the element containing all datasets of the chart."""

        id = self.settings["datasets"]["id"]
        classes = self.settings["datasets"]["class"]
        datasets = []
        for dataset in self.data["set"]:
            setid = dataset["id"]

            for setting in self.settings["datasets"]["set"]:
                if setting["id"] == setid:
                    break

            setclasses = setting["class"]

            datasetelements = self.getDataSetElements(dataset, setting)

            datasetgroup = ShapeGroup(datasetelements,
                                      id=setid,
                                      classes=setclasses)
            datasets.append(datasetgroup)

        return ShapeGroup(datasets, id=id, classes=classes)
コード例 #6
0
ファイル: VerticalGrid.py プロジェクト: agold/svgchart
    def getElement(self):
        """Returns the shapes of the y axis."""

        lines = []
        linecount = 0
        for point in self.points:
            if point != self.start and point != self.end:
                linecount += 1
                lines.append(
                    Line(start=Coordinate(point, self.top),
                         end=Coordinate(point, self.bottom),
                         id=u'{}-{:d}'.format(self.lineidprefix, linecount),
                         classes=self.lineclasses))

        return ShapeGroup(shapes=lines, id=self.id, classes=self.classes)
コード例 #7
0
    def getElement(self):
        """Returns the shapes of the y axis."""

        elements = []

        if self.border:
            border = Rectangle(position=Coordinate(self.x, self.y),
                               width=self.width,
                               height=self.height,
                               id=self.borderid,
                               classes=self.borderclasses)
            elements.append(border)

        if not self.subtitle:
            titleelem = Text(text=self.title,
                             id=self.titleid,
                             classes=self.titleclasses)
            vcenter = self.y + self.height / 2
            hcenter = self.x + self.width / 2
            titleelem.position = Coordinate(hcenter, vcenter)
            elements.append(titleelem)
        else:
            titleelem = Text(text=self.title,
                             id=self.titleid,
                             classes=self.titleclasses)
            subtitleelem = Text(text=self.subtitle,
                                id=self.subtitleid,
                                classes=self.subtitleclasses)
            totalheight = titleelem.height + subtitleelem.height
            vcenter = self.y + self.height / 2
            hcenter = self.x + self.width / 2
            titleelem.position = Coordinate(hcenter, vcenter - totalheight / 2)
            subtitleelem.position = Coordinate(hcenter,
                                               vcenter + totalheight / 2)
            elements += [titleelem, subtitleelem]

        return ShapeGroup(elements, id=self.id, classes=self.classes)