Home | History | Annotate | Download | only in pattern_tools

Lines Matching refs:SVG

36 _default_fileName = "tmp.svg"
43 """Create an SVG color string "#xxyyzz" from r, g, and b.
68 class SVG:
69 """A tree representation of an SVG image or image fragment.
71 SVG(t, sub, sub, sub..., attribute=value)
73 t required SVG type name
74 sub optional list nested SVG elements or text/Unicode
75 attribute=value pairs optional keywords SVG attributes
79 SVG in XML
86 SVG in Python
88 >>> svg = SVG("g", SVG("rect", x=1, y=1, width=2, height=2), \
89 ... SVG("rect", x=3, y=3, width=2, height=2), \
94 >>> svg = SVG("text", SVG("tspan", "hello there"), stroke="none", fill="black")
95 >>> svg[0]
97 >>> svg[0, 0]
99 >>> svg["fill"]
104 >>> svg = SVG("g", SVG("g", SVG("line", x1=0, y1=0, x2=1, y2=1)), \
105 ... SVG("text", SVG("tspan", "hello again")))
107 >>> for ti, s in svg:
122 >>> print svg
131 raise TypeError, "SVG element must have a t (SVG type)"
133 # first argument is t (SVG type)
139 # need to preprocess to handle differences between SVG and Python syntax
185 """x in svg == True iff x is an attribute in svg."""
189 """x == y iff x represents the same SVG as y."""
192 return (isinstance(other, SVG) and
196 """x != y iff x does not represent the same SVG as y."""
214 """Deep copy of SVG tree. Set shallow=True for a shallow copy."""
222 """Manages SVG iteration."""
224 def __init__(self, svg, ti, depth_limit):
225 self.svg = svg
237 return self.ti, self.svg
239 if not isinstance(self.svg, SVG):
246 for i, s in enumerate(self.svg.sub):
248 for k, s in self.svg.attr.items():
256 """Returns a depth-first generator over the SVG. If depth_limit
263 Returns a breadth-first generator over the SVG. If depth_limit
351 """Get an XML representation of the SVG.
358 print svg.xml()
375 if isinstance(s, SVG):
389 """Get an XML representation of the SVG that can be saved/rendered.
395 if self.t == "svg":
401 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
426 if isinstance(s, SVG):
446 """Save to a file for viewing. Note that svg.save() overwrites the file named _default_fileName.
515 "xmlns": "http://www.w3.org/2000/svg",
528 """Creates a top-level SVG object, allowing the user to control the
533 sub optional list nested SVG elements or text/Unicode
534 attribute=value pairs optional keywords SVG attributes
541 xmlns "http://www.w3.org/2000/svg"
551 return SVG("svg", **attributes)
553 return SVG("svg", *sub, **attributes)
558 svg = canvas(*sub, **attr)
559 match = re.match(r"[, \t]*([0-9e.+\-]+)[, \t]+([0-9e.+\-]+)[, \t]+([0-9e.+\-]+)[, \t]+([0-9e.+\-]+)[, \t]*", svg["viewBox"])
563 svg.prepend(SVG("rect", x=x, y=y, width=width, height=height, stroke="none", fill="cornsilk"))
564 svg.append(SVG("rect", x=x, y=y, width=width, height=height, stroke="black", fill="none"))
565 return svg
567 def template(fileName, svg, replaceme="REPLACEME"):
568 """Loads an SVG image from a file, replacing instances of
569 <REPLACEME /> with a given svg object.
571 fileName required name of the template SVG
572 svg required SVG object for replacement
573 replaceme default="REPLACEME" fake SVG element to be replaced by the given object
575 >>> print load("template.svg")
576 None <svg (2 sub) style=u'stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoi
580 >>> print template("template.svg", SVG("circle", cx=50, cy=50, r=30))
581 None <svg (2 sub) style=u'stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoi
587 if isinstance(s, SVG) and s.t == replaceme:
588 output[ti] = svg
594 """Loads an SVG image from a file."""
598 """Loads an SVG image from a stream (can be a string or a file object)."""
610 s = SVG(name)
629 if (isinstance(last, SVG) and last.t == "style" and
788 >>> print fig.SVG().xml()
793 >>> print Fig(fig, trans="x/2., y/2.").SVG().xml()
818 def SVG(self, trans=None):
819 """Apply the transformation "trans" and return an SVG object.
829 output = SVG("g")
831 if isinstance(s, SVG):
846 output.sub += s.SVG(subtrans).sub
852 output.append(s.SVG(trans))
870 x, y 5, 5 upper-left corner of the Plot in SVG coordinates
871 width, height 90, 90 width and height of the Plot in SVG coordinates
936 def SVG(self, trans=None):
937 """Apply the transformation "trans" and return an SVG object."""
954 return Fig(Fig(*d, **{"trans": trans})).SVG(self.last_window)
983 x, y 20, 5 upper-left corner of the Frame in SVG coordinates
984 width, height 75, 80 width and height of the Frame in SVG coordinates
1044 def SVG(self):
1045 """Apply the window transformation and return an SVG object."""
1087 output = Fig(*self.d).SVG(self.last_window)
1088 output.prepend(left.SVG(self.last_window))
1089 output.prepend(bottom.SVG(self.last_window))
1090 output.prepend(right.SVG(self.last_window))
1091 output.prepend(top.SVG(self.last_window))
1094 output.append(SVG("text", self.xtitle, transform="translate(%g, %g)" % ((self.x + self.width/2.), (self.y + self.height + self.text_xtitle_offset)), dominant_baseline="text-before-edge", **self.text_attr))
1096 output.append(SVG("text", self.ytitle, transform="translate(%g, %g) rotate(-90)" % ((self.x - self.text_ytitle_offset), (self.y + self.height/2.)), **self.text_attr))
1101 def pathtoPath(svg):
1102 """Converts SVG("path", d="...") into Path(d=[...])."""
1103 if not isinstance(svg, SVG) or svg.t != "path":
1104 raise TypeError, "Only SVG <path /> objects can be converted into Paths"
1105 attr = dict(svg.attr)
1117 """Path represents an SVG path, an arbitrary set of curves and
1118 straight segments. Unlike SVG("path", d="..."), Path stores
1125 attribute=value pairs keyword list SVG attributes
1127 See http://www.w3.org/TR/SVG/paths.html for specification of paths
1338 def SVG(self, trans=None):
1339 """Apply the transformation "trans" and return an SVG object."""
1566 return SVG("path", d="".join(output), **self.attr)
1638 attribute=value pairs keyword list SVG attributes
1719 discontinuities. Called by SVG()."""
1797 def SVG(self, trans=None):
1798 """Apply the transformation "trans" and return an SVG object."""
1799 return self.Path(trans).SVG()
1844 attribute=value pairs keyword list SVG attributes
1852 preceed (x,y), as in SVG paths). If (c1x,c1y) and
1883 def SVG(self, trans=None):
1884 """Apply the transformation "trans" and return an SVG object."""
1885 return self.Path(trans).SVG()
2030 attribute=value pairs keyword list SVG attributes
2045 def SVG(self, trans=None):
2046 """Apply the transformation "trans" and return an SVG object."""
2053 return SVG("text", self.d, x=X, y=Y, **self.attr)
2061 attribute=value pairs keyword list SVG attributes
2075 def SVG(self, trans=None):
2076 """Apply the transformation "trans" and return an SVG object."""
2077 return SVG("text", self.d, x=self.x, y=self.y, **self.attr)
2081 _symbol_templates = {"dot": SVG("symbol", SVG("circle", cx=0, cy=0, r=1, stroke="none", fill="black"), viewBox="0 0 1 1", overflow="visible"),
2082 "box": SVG("symbol", SVG("rect", x1=-1, y1=-1, x2=1, y2=1, stroke="none", fill="black"), viewBox="0 0 1 1", overflow="visible"),
2083 "uptri": SVG("symbol", SVG("path", d="M -1 0.866 L 1 0.866 L 0 -0.866 Z", stroke="none", fill="black"), viewBox="0 0 1 1", overflow="visible"),
2084 "downtri": SVG("symbol", SVG("path", d="M -1 -0.866 L 1 -0.866 L 0 0.866 Z", stroke="none", fill="black"), viewBox="0 0 1 1", overflow="visible"),
2088 """Creates a new instance of an SVG symbol to avoid cross-linking objects.
2092 attribute=value list keyword list modify the SVG attributes of the new symbol
2104 """Dots draws SVG symbols at a set of points.
2107 symbol default=None SVG symbol or a new identifier to
2111 in SVG coordinates
2112 attribute=value pairs keyword list SVG attributes
2129 elif isinstance(symbol, SVG):
2134 def SVG(self, trans=None):
2135 """Apply the transformation "trans" and return an SVG object."""
2139 output = SVG("g", SVG("defs", self.symbol))
2150 item = SVG("use", x=X, y=Y, xlink__href=id)
2161 _marker_templates = {"arrow_start": SVG("marker", SVG("path", d="M 9 3.6 L 10.5 0 L 0 3.6 L 10.5 7.2 L 9 3.6 Z"), viewBox="0 0 10.5 7.2", refX="9", refY="3.6", markerWidth="10.5", markerHeight="7.2", markerUnits="strokeWidth", orient="auto", stroke="none", fill="black"),
2162 "arrow_end": SVG("marker", SVG("path", d="M 1.5 3.6 L 0 0 L 10.5 3.6 L 0 7.2 L 1.5 3.6 Z"), viewBox="0 0 10.5 7.2", refX="1.5", refY="3.6", markerWidth="10.5", markerHeight="7.2", markerUnits="strokeWidth", orient="auto", stroke="none", fill="black"),
2166 """Creates a new instance of an SVG marker to avoid cross-linking objects.
2170 attribute=value list keyword list modify the SVG attributes of the new marker
2191 attribute=value pairs keyword list SVG attributes
2206 def SVG(self, trans=None):
2207 """Apply the transformation "trans" and return an SVG object."""
2209 line = self.Path(trans).SVG()
2213 defs = SVG("defs")
2216 if isinstance(self.arrow_start, SVG):
2226 if isinstance(self.arrow_end, SVG):
2235 return SVG("g", defs, line)
2271 attribute=value pairs keyword list SVG attributes
2293 def SVG(self, trans=None):
2294 """Apply the transformation "trans" and return an SVG object."""
2305 line = SVG("path", d="M%s %s L%s %s" % (X1, Y1, X2, Y2), **self.attr)
2309 defs = SVG("defs")
2312 if isinstance(self.arrow_start, SVG):
2322 if isinstance(self.arrow_end, SVG):
2331 return SVG("g", defs, line)
2343 attribute=value pairs keyword list SVG attributes
2372 attribute=value pairs keyword list SVG attributes
2402 attribute=value pairs keyword list SVG attributes
2416 def SVG(self, trans=None):
2417 """Apply the transformation "trans" and return an SVG object."""
2418 return self.Path(trans).SVG()
2463 attribute=value pairs keyword list SVG attributes
2480 def SVG(self, trans=None):
2481 """Apply the transformation "trans" and return an SVG object."""
2482 return self.Path(trans).SVG()
2565 that identifier; if an SVG marker object,
2569 that identifier; if an SVG marker object,
2571 text_attr default={} SVG attributes for the text labels
2572 attribute=value pairs keyword list SVG attributes for the tick marks
2664 def SVG(self, trans=None):
2665 """Apply the transformation "trans" and return an SVG object."""
2672 output = SVG("g")
2676 defs = SVG("defs")
2679 if isinstance(self.arrow_start, SVG):
2687 if isinstance(self.arrow_end, SVG):
2719 output.append(SVG("text", label, transform="translate(%g, %g) rotate(%g)" %
2736 output.prepend(tickmarks.SVG(trans))
2737 output.prepend(minitickmarks.SVG(trans))
3078 SVG marker object, use that marker
3082 SVG marker object, use that marker
3083 text_attr default={} SVG attributes for the text labels
3084 attribute=value pairs keyword list SVG attributes
3100 def SVG(self, trans=None):
3101 """Apply the transformation "trans" and return an SVG object."""
3102 func = Curve.SVG(self, trans)
3103 ticks = Ticks.SVG(self, trans) # returns a <g />
3140 that identifier; if an SVG marker object,
3144 that identifier; if an SVG marker object,
3146 text_attr default={} SVG attributes for the text labels
3147 attribute=value pairs keyword list SVG attributes
3184 def SVG(self, trans=None):
3185 """Apply the transformation "trans" and return an SVG object."""
3186 line = Line.SVG(self, trans) # must be evaluated first, to set self.f, self.low, self.high
3205 ticks = Ticks.SVG(self, trans) # returns a <g />
3228 that identifier; if an SVG marker object,
3232 that identifier; if an SVG marker object,
3236 text_attr default={} SVG attributes for the text labels
3237 attribute=value pairs keyword list SVG attributes for all lines
3258 def SVG(self, trans=None):
3259 """Apply the transformation "trans" and return an SVG object."""
3262 return LineAxis.SVG(self, trans)
3283 that identifier; if an SVG marker object,
3287 that identifier; if an SVG marker object,
3291 text_attr default={} SVG attributes for the text labels
3292 attribute=value pairs keyword list SVG attributes for all lines
3313 def SVG(self, trans=None):
3314 """Apply the transformation "trans" and return an SVG object."""
3317 return LineAxis.SVG(self, trans)
3349 text_attr default={} SVG attributes for the text labels
3350 attribute=value pairs keyword list SVG attributes for all lines
3376 def SVG(self, trans=None):
3377 """Apply the transformation "trans" and return an SVG object."""
3402 xaxis = XAxis(self.xmin, self.xmax, aty, self.xticks, self.xminiticks, self.xlabels, self.xlogbase, xarrow_start, xarrow_end, exclude=xexclude, text_attr=self.text_attr, **self.attr).SVG(trans)
3403 yaxis = YAxis(self.ymin, self.ymax, atx, self.yticks, self.yminiticks, self.ylabels, self.ylogbase, yarrow_start, yarrow_end, exclude=yexclude, text_attr=self.text_attr, **self.attr).SVG(trans)
3404 return SVG("g", *(xaxis.sub + yaxis.sub))
3423 mini_attr default={} SVG attributes for the minitick-lines
3425 attribute=value pairs keyword list SVG attributes for the major tick lines
3445 def SVG(self, trans=None):
3446 """Apply the transformation "trans" and return an SVG object."""
3457 return SVG("g", Path(d=ticksd, **self.attr).SVG(), Path(d=miniticksd, **self.mini_attr).SVG())
3475 mini_attr default={} SVG attributes for the minitick-lines
3477 attribute=value pairs keyword list SVG attributes for the major tick lines
3497 def SVG(self, trans=None):
3498 """Apply the transformation "trans" and return an SVG object."""
3509 return SVG("g", Path(d=ticksd, **self.attr).SVG(), Path(d=miniticksd, **self.mini_attr).SVG())
3526 mini_attr default={} SVG attributes for the minitick-lines
3528 attribute=value pairs keyword list SVG attributes for the major tick lines
3549 def SVG
3550 """Apply the transformation "trans" and return an SVG object."""
3568 return SVG("g", Path(d=ticksd, **self.attr).SVG(), Path(d=miniticksd, **self.mini_attr).SVG())
3579 attribute=value pairs keyword list SVG attributes
3602 def SVG(self, trans=None):
3603 """Apply the transformation "trans" and return an SVG object."""
3607 output = SVG("g")
3617 output.append(LineAxis(start, y, end, y, start, end, bars, False, False, **self.attr).SVG(trans))
3629 attribute=value pairs keyword list SVG attributes
3652 def SVG(self, trans=None):
3653 """Apply the transformation "trans" and return an SVG object."""
3657 output = SVG("g")
3667 output.append(LineAxis(x, start, x, end, start, end, bars, False, False, **self.attr).SVG(trans))