示例#1
0
 def add(self, t, mark, angle=0., dx=0., dy=0.):
     if not isinstance(mark, basestring):
         mark = trans.transform(
             lambda x, y: (dx + math.cos(angle) * x - math.sin(angle) * y,
                           dy + math.sin(angle) * x + math.cos(angle) * y),
             mark)
     self.marks.append((t, mark))
示例#2
0
    def svg(self):
        obj = new.instance(svg.SVG)
        obj.__dict__["tag"] = "path"
        obj.__dict__["attrib"] = self.attrib
        obj.__dict__["children"] = self.children
        obj.__dict__["_svg"] = obj
        obj.attrib["d"] = self.d()

        if self.marks == []:
            output = obj
        else:
            output = svg.SVG("g", obj)

            lowX, lowY = self(self.low)
            highX, highY = self(self.high)

            for item in self.marks:
                if isinstance(item, (int, long, float)):
                    t, mark = item, glyphs.tick
                else:
                    t, mark = item  # marks should be (pos, mark) pairs or just pos

                X, Y = self(t)
                if (self.low <= t <= self.high
                        or math.sqrt((X - lowX)**2 +
                                     (Y - lowY)**2) < trans.epsilon
                        or math.sqrt((X - highX)**2 +
                                     (Y - highY)**2) < trans.epsilon):

                    angle = self.angle(t)

                    if isinstance(mark, basestring):
                        mark = self._render_text(X, Y, angle, mark)

                    else:
                        mark = trans.transform(
                            lambda x, y:
                            (X + math.cos(angle) * x - math.sin(angle) * y, Y +
                             math.sin(angle) * x + math.cos(angle) * y), mark)
                    output.append(mark)

        self._svg = output
示例#3
0
    def svg(self):
        obj = new.instance(svg.SVG)
        obj.__dict__["tag"] = "path"
        obj.__dict__["attrib"] = self.attrib
        obj.__dict__["children"] = self.children
        obj.__dict__["_svg"] = obj
        obj.attrib["d"] = self.d()

        if self.marks == []:
            output = obj
        else:
            output = svg.SVG("g", obj)

            lowX, lowY = self(self.low)
            highX, highY = self(self.high)

            for item in self.marks:
                if isinstance(item, (int, long, float)):
                    t, mark = item, glyphs.tick
                else:
                    t, mark = item # marks should be (pos, mark) pairs or just pos

                X, Y = self(t)
                if (self.low <= t <= self.high or
                    math.sqrt((X - lowX)**2 + (Y - lowY)**2) < trans.epsilon or
                    math.sqrt((X - highX)**2 + (Y - highY)**2) < trans.epsilon):

                    angle = self.angle(t)

                    if isinstance(mark, basestring):
                        mark = self._render_text(X, Y, angle, mark)

                    else:
                        mark = trans.transform(lambda x, y: (X + math.cos(angle)*x - math.sin(angle)*y,
                                                             Y + math.sin(angle)*x + math.cos(angle)*y), mark)
                    output.append(mark)

        self._svg = output
示例#4
0
    def svg(self):
        if (self.xmin is not None and self.xmax is not None
                and self.ymin is not None and self.ymax is not None):
            self.trans = trans.window(
                self.xmin,
                self.xmax,
                self.ymin,
                self.ymax,
                x=self.x,
                y=self.y,
                width=self.width,
                height=self.height,
                xlogbase=self.xlogbase,
                ylogbase=self.ylogbase,
                minusInfinityX=(self.x - 10. * self.width),
                minusInfinityY=(self.y - 10. * self.height),
                flipx=self.flipx,
                flipy=self.flipy)
        else:
            self.fit()

        self._svg = new.instance(svg.SVG)
        self._svg.__dict__["tag"] = "g"
        self._svg.__dict__["attrib"] = self.attrib
        self._svg.__dict__["_svg"] = self._svg

        self._svg.__dict__["children"] = []
        for child in self.children:
            self._svg.__dict__["children"].append(
                trans.transform(self.trans, child))

        if self.clip:
            clipPath = svg.SVG("clipPath", id=svg.randomid("clip-"))(svg.SVG(
                "rect", self.x, self.y, self.width, self.height))
            self._svg["clip-path"] = "url(#%s)" % clipPath["id"]
            self._svg = svg.SVG("g", clipPath, self._svg)
示例#5
0
    def svg(self):
        if (self.xmin is not None and self.xmax is not None and
            self.ymin is not None and self.ymax is not None):
            self.trans = trans.window(self.xmin, self.xmax, self.ymin, self.ymax,
                                      x=self.x, y=self.y, width=self.width, height=self.height,
                                      xlogbase=self.xlogbase, ylogbase=self.ylogbase,
                                      minusInfinityX=(self.x - 10.*self.width), minusInfinityY=(self.y - 10.*self.height),
                                      flipx=self.flipx, flipy=self.flipy)
        else:
            self.fit()

        self._svg = new.instance(svg.SVG)
        self._svg.__dict__["tag"] = "g"
        self._svg.__dict__["attrib"] = self.attrib
        self._svg.__dict__["_svg"] = self._svg

        self._svg.__dict__["children"] = []
        for child in self.children:
            self._svg.__dict__["children"].append(trans.transform(self.trans, child))

        if self.clip:
            clipPath = svg.SVG("clipPath", id=svg.randomid("clip-"))(svg.SVG("rect", self.x, self.y, self.width, self.height))
            self._svg["clip-path"] = "url(#%s)" % clipPath["id"]
            self._svg = svg.SVG("g", clipPath, self._svg)
示例#6
0
 def add(self, t, mark, angle=0., dx=0., dy=0.):
     if not isinstance(mark, basestring):
         mark = trans.transform(lambda x, y: (dx + math.cos(angle)*x - math.sin(angle)*y,
                                              dy + math.sin(angle)*x + math.cos(angle)*y), mark)
     self.marks.append((t, mark))