diff --git a/.gitignore b/.gitignore index 52f9a5e..7db716e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -*.pyc -*.db +*.pyc +*.db *.sqlite3 \ No newline at end of file diff --git a/app.py b/app.py index dba506c..7761af2 100644 --- a/app.py +++ b/app.py @@ -1,13 +1,20 @@ -from flask import Flask, Response -from map import CynoMap - -app = Flask(__name__) - -@app.route('/cynos.svg') -def cynos(): - map = CynoMap(jumprange=13, keyid=525316, vcode="8jIZ4pjpLQOKQsUPY4cSpIy0Rtd4AcBh6HzOOzDC4qFlI0UO7dtJUVSkh7G7NhST").svg.standalone_xml() - return Response(mimetype='image/svg+xml', response=map) - - -if __name__ == '__main__': - app.run() \ No newline at end of file +import logging +from flask import Flask, Response +from map import CynoMap + +app = Flask(__name__) + +@app.route('/cynos.svg') +@app.route('/cynos-.svg') +def cynos(range=13): + logging.info('Range %s' % range) + map = CynoMap(jumprange=float(range), keyid=525316, vcode="8jIZ4pjpLQOKQsUPY4cSpIy0Rtd4AcBh6HzOOzDC4qFlI0UO7dtJUVSkh7G7NhST").svg.standalone_xml() + return Response(mimetype='image/svg+xml', response=map) + +@app.route('/') +def index(): + return """""" + +if __name__ == '__main__': + logging.basicConfig(level=logging.DEBUG) + app.run(host='0.0.0.0') diff --git a/map.py b/map.py index 7020d25..48c5272 100644 --- a/map.py +++ b/map.py @@ -55,7 +55,7 @@ class CynoMap(object): @staticmethod def calc_distance(sys1, sys2): """Calculate the distance between two sets of 3d coordinates""" - return sqrt((sys1['x']-sys2['x'])**2+(sys1['y']-sys2['y'])**2+(sys1['z']-sys2['z'])**2) / 10000000000000000 + return sqrt((sys1['x']-sys2['x'])**2+(sys1['y']-sys2['y'])**2+(sys1['z']-sys2['z'])**2) / 9460000000000000.0 @property def systems(self): @@ -142,15 +142,15 @@ class CynoMap(object): if not self.keyid or not self.vcode: return {} if not hasattr(self, '_cynochars'): auth = EVEAPIConnection(cacheHandler=DbCacheHandler()).auth(keyID=self.keyid, vCode=self.vcode) - chars = auth.account.Characters() - members = auth.corp.MemberTracking(characterID=chars.characters[0].characterID) + #chars = auth.account.APIKeyInfo() + members = auth.corp.MemberTracking(extended=1) self._cynochars = {} for member in members.members: loc = self.get_system_location(member.locationID) if not loc: continue - info = {'name': member.name } + info = member.name if not int(loc) in self._cynochars: self._cynochars[loc] = [info] else: @@ -194,12 +194,14 @@ class CynoMap(object): if sys['id'] in self.get_cyno_locations(): fill = 'red' radius = 5 + title = "%s (%s)" % (sys['name'], ', '.join(self.get_cyno_locations()[sys['id']])) else: fill = 'gray' for loc in self.get_cyno_locations(): if self.calc_distance(sys, self.systems[loc]) < self.jumprange: fill = 'blue' radius = 2 + title = sys['name'] @@ -207,7 +209,7 @@ class CynoMap(object): if lowz > sys['cz']: lowz = sys['cz'] if highx < sys['cx']: highx = sys['cx'] if highz < sys['cz']: highz = sys['cz'] - attrs = {'cx': sys['cx'], 'cy': -sys['cz'], 'r': radius, 'id': 'system-%s' % sys['id'], 'class': 'system', 'fill': fill, 'stroke-width': 0} + attrs = {'cx': sys['cx'], 'cy': -sys['cz'], 'r': radius, 'id': 'system-%s' % sys['id'], 'class': 'system', 'fill': fill, 'stroke-width': 0, 'title': title} svg = SVG('circle', **attrs) sysgroup.append(svg) @@ -232,4 +234,4 @@ class CynoMap(object): c = canvas() c.attr.update({'viewBox': '-1000 -1100 2000 2000', 'height': '2000', 'width': '2000'}) c.extend([jumpgroup, sysgroup, cynos]) - return c \ No newline at end of file + return c diff --git a/svgfig.py b/svgfig.py index e3cfea7..df3b9e1 100644 --- a/svgfig.py +++ b/svgfig.py @@ -38,9 +38,9 @@ _hacks["inkscape-text-vertical-shift"] = False def rgb(r, g, b, maximum=1.): """Create an SVG color string "#xxyyzz" from r, g, and b. - - r,g,b = 0 is black and r,g,b = maximum is white. - """ + + r,g,b = 0 is black and r,g,b = maximum is white. + """ return "#%02x%02x%02x" % (max(0, min(r*255./maximum, 255)), max(0, min(g*255./maximum, 255)), max(0, min(b*255./maximum, 255))) def attr_preprocess(attr): @@ -61,65 +61,65 @@ def attr_preprocess(attr): class SVG: """A tree representation of an SVG image or image fragment. - - SVG(t, sub, sub, sub..., attribute=value) - - t required SVG type name - sub optional list nested SVG elements or text/Unicode - attribute=value pairs optional keywords SVG attributes - - In attribute names, "__" becomes ":" and "_" becomes "-". - - SVG in XML - - - - - - - SVG in Python - - >>> svg = SVG("g", SVG("rect", x=1, y=1, width=2, height=2), \ - ... SVG("rect", x=3, y=3, width=2, height=2), \ - ... id="mygroup", fill="blue") - - Sub-elements and attributes may be accessed through tree-indexing: - - >>> svg = SVG("text", SVG("tspan", "hello there"), stroke="none", fill="black") - >>> svg[0] - - >>> svg[0, 0] - 'hello there' - >>> svg["fill"] - 'black' - - Iteration is depth-first: - - >>> svg = SVG("g", SVG("g", SVG("line", x1=0, y1=0, x2=1, y2=1)), \ - ... SVG("text", SVG("tspan", "hello again"))) - ... - >>> for ti, s in svg: - ... print ti, repr(s) - ... - (0,) - (0, 0) - (0, 0, 'x2') 1 - (0, 0, 'y1') 0 - (0, 0, 'x1') 0 - (0, 0, 'y2') 1 - (1,) - (1, 0) - (1, 0, 0) 'hello again' - - Use "print" to navigate: - - >>> print svg - None - [0] - [0, 0] - [1] - [1, 0] - """ + + SVG(t, sub, sub, sub..., attribute=value) + + t required SVG type name + sub optional list nested SVG elements or text/Unicode + attribute=value pairs optional keywords SVG attributes + + In attribute names, "__" becomes ":" and "_" becomes "-". + + SVG in XML + + + + + + + SVG in Python + + >>> svg = SVG("g", SVG("rect", x=1, y=1, width=2, height=2), \ + ... SVG("rect", x=3, y=3, width=2, height=2), \ + ... id="mygroup", fill="blue") + + Sub-elements and attributes may be accessed through tree-indexing: + + >>> svg = SVG("text", SVG("tspan", "hello there"), stroke="none", fill="black") + >>> svg[0] + + >>> svg[0, 0] + 'hello there' + >>> svg["fill"] + 'black' + + Iteration is depth-first: + + >>> svg = SVG("g", SVG("g", SVG("line", x1=0, y1=0, x2=1, y2=1)), \ + ... SVG("text", SVG("tspan", "hello again"))) + ... + >>> for ti, s in svg: + ... print ti, repr(s) + ... + (0,) + (0, 0) + (0, 0, 'x2') 1 + (0, 0, 'y1') 0 + (0, 0, 'x1') 0 + (0, 0, 'y2') 1 + (1,) + (1, 0) + (1, 0, 0) 'hello again' + + Use "print" to navigate: + + >>> print svg + None + [0] + [0, 0] + [1] + [1, 0] + """ def __init__(self, *t_sub, **attr): if len(t_sub) == 0: raise TypeError, "SVG element must have a t (SVG type)" @@ -290,13 +290,13 @@ class SVG: def tree(self, depth_limit=None, sub=True, attr=True, text=True, tree_width=20, obj_width=80): """Print (actually, return a string of) the tree in a form useful for browsing. - If depth_limit == a number, stop recursion at that depth. - If sub == False, do not show sub-elements. - If attr == False, do not show attributes. - If text == False, do not show text/Unicode sub-elements. - tree_width is the number of characters reserved for printing tree indexes. - obj_width is the number of characters reserved for printing sub-elements/attributes. - """ + If depth_limit == a number, stop recursion at that depth. + If sub == False, do not show sub-elements. + If attr == False, do not show attributes. + If text == False, do not show text/Unicode sub-elements. + tree_width is the number of characters reserved for printing tree indexes. + obj_width is the number of characters reserved for printing sub-elements/attributes. + """ output = [] @@ -318,14 +318,14 @@ class SVG: def xml(self, indent=" ", newl="\n", depth_limit=None, depth=0): """Get an XML representation of the SVG. - - indent string used for indenting - newl string used for newlines - If depth_limit == a number, stop recursion at that depth. - depth starting depth (not useful for users) - - print svg.xml() - """ + + indent string used for indenting + newl string used for newlines + If depth_limit == a number, stop recursion at that depth. + depth starting depth (not useful for users) + + print svg.xml() + """ attrstr = [] for n, v in self.attr.items(): @@ -356,17 +356,17 @@ class SVG: def standalone_xml(self, indent=" ", newl="\n"): """Get an XML representation of the SVG that can be saved/rendered. - - indent string used for indenting - newl string used for newlines - """ + + indent string used for indenting + newl string used for newlines + """ if self.t == "svg": top = self else: top = canvas(self) - return """\ - - - + return """\ + + + """ + ("".join(top.__standalone_xml(indent, newl))) # end of return statement def __standalone_xml(self, indent, newl): @@ -407,15 +407,15 @@ class SVG: def save(self, fileName=None, encoding="utf-8", compresslevel=None): """Save to a file for viewing. Note that svg.save() overwrites the file named _default_fileName. - - fileName default=None note that _default_fileName will be overwritten if - no fileName is specified. If the extension - is ".svgz" or ".gz", the output will be gzipped - encoding default="utf-8" file encoding (default is Unicode) - compresslevel default=None if a number, the output will be gzipped with that - compression level (1-9, 1 being fastest and 9 most - thorough) - """ + + fileName default=None note that _default_fileName will be overwritten if + no fileName is specified. If the extension + is ".svgz" or ".gz", the output will be gzipped + encoding default="utf-8" file encoding (default is Unicode) + compresslevel default=None if a number, the output will be gzipped with that + compression level (1-9, 1 being fastest and 9 most + thorough) + """ fileName = self.interpret_fileName(fileName) if compresslevel != None or re.search("\.svgz$", fileName, re.I) or re.search("\.gz$", fileName, re.I): @@ -436,36 +436,36 @@ class SVG: def inkview(self, fileName=None, encoding="utf-8"): """View in "inkview", assuming that program is available on your system. - - fileName default=None note that any file named _default_fileName will be - overwritten if no fileName is specified. If the extension - is ".svgz" or ".gz", the output will be gzipped - encoding default="utf-8" file encoding (default is Unicode) - """ + + fileName default=None note that any file named _default_fileName will be + overwritten if no fileName is specified. If the extension + is ".svgz" or ".gz", the output will be gzipped + encoding default="utf-8" file encoding (default is Unicode) + """ fileName = self.interpret_fileName(fileName) self.save(fileName, encoding) os.spawnvp(os.P_NOWAIT, "inkview", ("inkview", fileName)) def inkscape(self, fileName=None, encoding="utf-8"): """View in "inkscape", assuming that program is available on your system. - - fileName default=None note that any file named _default_fileName will be - overwritten if no fileName is specified. If the extension - is ".svgz" or ".gz", the output will be gzipped - encoding default="utf-8" file encoding (default is Unicode) - """ + + fileName default=None note that any file named _default_fileName will be + overwritten if no fileName is specified. If the extension + is ".svgz" or ".gz", the output will be gzipped + encoding default="utf-8" file encoding (default is Unicode) + """ fileName = self.interpret_fileName(fileName) self.save(fileName, encoding) os.spawnvp(os.P_NOWAIT, "inkscape", ("inkscape", fileName)) def firefox(self, fileName=None, encoding="utf-8"): """View in "firefox", assuming that program is available on your system. - - fileName default=None note that any file named _default_fileName will be - overwritten if no fileName is specified. If the extension - is ".svgz" or ".gz", the output will be gzipped - encoding default="utf-8" file encoding (default is Unicode) - """ + + fileName default=None note that any file named _default_fileName will be + overwritten if no fileName is specified. If the extension + is ".svgz" or ".gz", the output will be gzipped + encoding default="utf-8" file encoding (default is Unicode) + """ fileName = self.interpret_fileName(fileName) self.save(fileName, encoding) os.spawnvp(os.P_NOWAIT, "firefox", ("firefox", fileName)) @@ -480,24 +480,24 @@ _canvas_defaults = {"width": "400px", "height": "400px", "viewBox": "0 0 100 100 def canvas(*sub, **attr): """Creates a top-level SVG object, allowing the user to control the - image size and aspect ratio. - - canvas(sub, sub, sub..., attribute=value) - - sub optional list nested SVG elements or text/Unicode - attribute=value pairs optional keywords SVG attributes - - Default attribute values: - - width "400px" - height "400px" - viewBox "0 0 100 100" - xmlns "http://www.w3.org/2000/svg" - xmlns:xlink "http://www.w3.org/1999/xlink" - version "1.1" - style "stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoin:round; text-anchor:middle" - font-family "Helvetica,Arial,FreeSans?,Sans,sans,sans-serif" - """ + image size and aspect ratio. + + canvas(sub, sub, sub..., attribute=value) + + sub optional list nested SVG elements or text/Unicode + attribute=value pairs optional keywords SVG attributes + + Default attribute values: + + width "400px" + height "400px" + viewBox "0 0 100 100" + xmlns "http://www.w3.org/2000/svg" + xmlns:xlink "http://www.w3.org/1999/xlink" + version "1.1" + style "stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoin:round; text-anchor:middle" + font-family "Helvetica,Arial,FreeSans?,Sans,sans,sans-serif" + """ attributes = dict(_canvas_defaults) attributes.update(attr) @@ -519,22 +519,22 @@ def canvas_outline(*sub, **attr): def template(fileName, svg, replaceme="REPLACEME"): """Loads an SVG image from a file, replacing instances of - with a given svg object. - - fileName required name of the template SVG - svg required SVG object for replacement - replaceme default="REPLACEME" fake SVG element to be replaced by the given object - - >>> print load("template.svg") - None - >>> - >>> print template("template.svg", SVG("circle", cx=50, cy=50, r=30)) - None - """ + with a given svg object. + + fileName required name of the template SVG + svg required SVG object for replacement + replaceme default="REPLACEME" fake SVG element to be replaced by the given object + + >>> print load("template.svg") + None + >>> + >>> print template("template.svg", SVG("circle", cx=50, cy=50, r=30)) + None + """ output = load(fileName) for ti, s in output: if isinstance(s, SVG) and s.t == replaceme: @@ -597,15 +597,15 @@ def load_stream(stream): def totrans(expr, vars=("x", "y"), globals=None, locals=None): """Converts to a coordinate transformation (a function that accepts two arguments and returns two values). - - expr required a string expression or a function - of two real or one complex value - vars default=("x", "y") independent variable names; - a singleton ("z",) is interpreted - as complex - globals default=None dict of global variables - locals default=None dict of local variables - """ + + expr required a string expression or a function + of two real or one complex value + vars default=("x", "y") independent variable names; + a singleton ("z",) is interpreted + as complex + globals default=None dict of global variables + locals default=None dict of local variables + """ if callable(expr): if expr.func_code.co_argcount == 2: @@ -641,20 +641,20 @@ def totrans(expr, vars=("x", "y"), globals=None, locals=None): def window(xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True): """Creates and returns a coordinate transformation (a function that - accepts two arguments and returns two values) that transforms from - (xmin, ymin), (xmax, ymax) - to - (x, y), (x + width, y + height). - - xlogbase, ylogbase default=None, None if a number, transform - logarithmically with given base - minusInfinity default=-1000 what to return if - log(0 or negative) is attempted - flipx default=False if true, reverse the direction of x - flipy default=True if true, reverse the direction of y - - (When composing windows, be sure to set flipy=False.) - """ + accepts two arguments and returns two values) that transforms from + (xmin, ymin), (xmax, ymax) + to + (x, y), (x + width, y + height). + + xlogbase, ylogbase default=None, None if a number, transform + logarithmically with given base + minusInfinity default=-1000 what to return if + log(0 or negative) is attempted + flipx default=False if true, reverse the direction of x + flipy default=True if true, reverse the direction of y + + (When composing windows, be sure to set flipy=False.) + """ if flipx: ox1 = x + width @@ -709,26 +709,26 @@ def rotate(angle, cx=0, cy=0): class Fig: """Stores graphics primitive objects and applies a single coordinate - transformation to them. To compose coordinate systems, nest Fig - objects. - - Fig(obj, obj, obj..., trans=function) - - obj optional list a list of drawing primatives - trans default=None a coordinate transformation function - - >>> fig = Fig(Line(0,0,1,1), Rect(0.2,0.2,0.8,0.8), trans="2*x, 2*y") - >>> print fig.SVG().xml() - - - - - >>> print Fig(fig, trans="x/2., y/2.").SVG().xml() - - - - - """ + transformation to them. To compose coordinate systems, nest Fig + objects. + + Fig(obj, obj, obj..., trans=function) + + obj optional list a list of drawing primatives + trans default=None a coordinate transformation function + + >>> fig = Fig(Line(0,0,1,1), Rect(0.2,0.2,0.8,0.8), trans="2*x, 2*y") + >>> print fig.SVG().xml() + + + + + >>> print Fig(fig, trans="x/2., y/2.").SVG().xml() + + + + + """ def __repr__(self): if self.trans == None: @@ -751,8 +751,8 @@ class Fig: def SVG(self, trans=None): """Apply the transformation "trans" and return an SVG object. - Coordinate transformations in nested Figs will be composed. - """ + Coordinate transformations in nested Figs will be composed. + """ if trans == None: trans = self.trans if isinstance(trans, basestring): trans = totrans(trans) @@ -782,36 +782,36 @@ class Fig: class Plot: """Acts like Fig, but draws a coordinate axis. You also need to supply plot ranges. - Plot(xmin, xmax, ymin, ymax, obj, obj, obj..., keyword options...) - - xmin, xmax required minimum and maximum x values (in the objs' coordinates) - ymin, ymax required minimum and maximum y values (in the objs' coordinates) - obj optional list drawing primatives - keyword options keyword list options defined below - - The following are keyword options, with their default values: - - trans None transformation function - x, y 5, 5 upper-left corner of the Plot in SVG coordinates - width, height 90, 90 width and height of the Plot in SVG coordinates - flipx, flipy False, True flip the sign of the coordinate axis - minusInfinity -1000 if an axis is logarithmic and an object is plotted at 0 or - a negative value, -1000 will be used as a stand-in for NaN - atx, aty 0, 0 the place where the coordinate axes cross - xticks -10 request ticks according to the standard tick specification - (see help(Ticks)) - xminiticks True request miniticks according to the standard minitick - specification - xlabels True request tick labels according to the standard tick label - specification - xlogbase None if a number, the axis and transformation are logarithmic - with ticks at the given base (10 being the most common) - (same for y) - arrows None if a new identifier, create arrow markers and draw them - at the ends of the coordinate axes - text_attr {} a dictionary of attributes for label text - axis_attr {} a dictionary of attributes for the axis lines - """ + Plot(xmin, xmax, ymin, ymax, obj, obj, obj..., keyword options...) + + xmin, xmax required minimum and maximum x values (in the objs' coordinates) + ymin, ymax required minimum and maximum y values (in the objs' coordinates) + obj optional list drawing primatives + keyword options keyword list options defined below + + The following are keyword options, with their default values: + + trans None transformation function + x, y 5, 5 upper-left corner of the Plot in SVG coordinates + width, height 90, 90 width and height of the Plot in SVG coordinates + flipx, flipy False, True flip the sign of the coordinate axis + minusInfinity -1000 if an axis is logarithmic and an object is plotted at 0 or + a negative value, -1000 will be used as a stand-in for NaN + atx, aty 0, 0 the place where the coordinate axes cross + xticks -10 request ticks according to the standard tick specification + (see help(Ticks)) + xminiticks True request miniticks according to the standard minitick + specification + xlabels True request tick labels according to the standard tick label + specification + xlogbase None if a number, the axis and transformation are logarithmic + with ticks at the given base (10 being the most common) + (same for y) + arrows None if a new identifier, create arrow markers and draw them + at the ends of the coordinate axes + text_attr {} a dictionary of attributes for label text + axis_attr {} a dictionary of attributes for the axis lines + """ def __repr__(self): if self.trans == None: @@ -885,34 +885,34 @@ class Frame: def __init__(self, xmin, xmax, ymin, ymax, *d, **kwds): """Acts like Fig, but draws a coordinate frame around the data. You also need to supply plot ranges. - - Frame(xmin, xmax, ymin, ymax, obj, obj, obj..., keyword options...) - - xmin, xmax required minimum and maximum x values (in the objs' coordinates) - ymin, ymax required minimum and maximum y values (in the objs' coordinates) - obj optional list drawing primatives - keyword options keyword list options defined below - - The following are keyword options, with their default values: - - x, y 20, 5 upper-left corner of the Frame in SVG coordinates - width, height 75, 80 width and height of the Frame in SVG coordinates - flipx, flipy False, True flip the sign of the coordinate axis - minusInfinity -1000 if an axis is logarithmic and an object is plotted at 0 or - a negative value, -1000 will be used as a stand-in for NaN - xtitle None if a string, label the x axis - xticks -10 request ticks according to the standard tick specification - (see help(Ticks)) - xminiticks True request miniticks according to the standard minitick - specification - xlabels True request tick labels according to the standard tick label - specification - xlogbase None if a number, the axis and transformation are logarithmic - with ticks at the given base (10 being the most common) - (same for y) - text_attr {} a dictionary of attributes for label text - axis_attr {} a dictionary of attributes for the axis lines - """ + + Frame(xmin, xmax, ymin, ymax, obj, obj, obj..., keyword options...) + + xmin, xmax required minimum and maximum x values (in the objs' coordinates) + ymin, ymax required minimum and maximum y values (in the objs' coordinates) + obj optional list drawing primatives + keyword options keyword list options defined below + + The following are keyword options, with their default values: + + x, y 20, 5 upper-left corner of the Frame in SVG coordinates + width, height 75, 80 width and height of the Frame in SVG coordinates + flipx, flipy False, True flip the sign of the coordinate axis + minusInfinity -1000 if an axis is logarithmic and an object is plotted at 0 or + a negative value, -1000 will be used as a stand-in for NaN + xtitle None if a string, label the x axis + xticks -10 request ticks according to the standard tick specification + (see help(Ticks)) + xminiticks True request miniticks according to the standard minitick + specification + xlabels True request tick labels according to the standard tick label + specification + xlogbase None if a number, the axis and transformation are logarithmic + with ticks at the given base (10 being the most common) + (same for y) + text_attr {} a dictionary of attributes for label text + axis_attr {} a dictionary of attributes for the axis lines + """ self.xmin, self.xmax, self.ymin, self.ymax = xmin, xmax, ymin, ymax self.d = list(d) @@ -1019,41 +1019,41 @@ def pathtoPath(svg): class Path: """Path represents an SVG path, an arbitrary set of curves and - straight segments. Unlike SVG("path", d="..."), Path stores - coordinates as a list of numbers, rather than a string, so that it is - transformable in a Fig. - - Path(d, attribute=value) - - d required path data - attribute=value pairs keyword list SVG attributes - - See http://www.w3.org/TR/SVG/paths.html for specification of paths - from text. - - Internally, Path data is a list of tuples with these definitions: - - * ("Z/z",): close the current path - * ("H/h", x) or ("V/v", y): a horizontal or vertical line - segment to x or y - * ("M/m/L/l/T/t", x, y, global): moveto, lineto, or smooth - quadratic curveto point (x, y). If global=True, (x, y) should - not be transformed. - * ("S/sQ/q", cx, cy, cglobal, x, y, global): polybezier or - smooth quadratic curveto point (x, y) using (cx, cy) as a - control point. If cglobal or global=True, (cx, cy) or (x, y) - should not be transformed. - * ("C/c", c1x, c1y, c1global, c2x, c2y, c2global, x, y, global): - cubic curveto point (x, y) using (c1x, c1y) and (c2x, c2y) as - control points. If c1global, c2global, or global=True, (c1x, c1y), - (c2x, c2y), or (x, y) should not be transformed. - * ("A/a", rx, ry, rglobal, x-axis-rotation, angle, large-arc-flag, - sweep-flag, x, y, global): arcto point (x, y) using the - aforementioned parameters. - * (",/.", rx, ry, rglobal, angle, x, y, global): an ellipse at - point (x, y) with radii (rx, ry). If angle is 0, the whole - ellipse is drawn; otherwise, a partial ellipse is drawn. - """ + straight segments. Unlike SVG("path", d="..."), Path stores + coordinates as a list of numbers, rather than a string, so that it is + transformable in a Fig. + + Path(d, attribute=value) + + d required path data + attribute=value pairs keyword list SVG attributes + + See http://www.w3.org/TR/SVG/paths.html for specification of paths + from text. + + Internally, Path data is a list of tuples with these definitions: + + * ("Z/z",): close the current path + * ("H/h", x) or ("V/v", y): a horizontal or vertical line + segment to x or y + * ("M/m/L/l/T/t", x, y, global): moveto, lineto, or smooth + quadratic curveto point (x, y). If global=True, (x, y) should + not be transformed. + * ("S/sQ/q", cx, cy, cglobal, x, y, global): polybezier or + smooth quadratic curveto point (x, y) using (cx, cy) as a + control point. If cglobal or global=True, (cx, cy) or (x, y) + should not be transformed. + * ("C/c", c1x, c1y, c1global, c2x, c2y, c2global, x, y, global): + cubic curveto point (x, y) using (c1x, c1y) and (c2x, c2y) as + control points. If c1global, c2global, or global=True, (c1x, c1y), + (c2x, c2y), or (x, y) should not be transformed. + * ("A/a", rx, ry, rglobal, x-axis-rotation, angle, large-arc-flag, + sweep-flag, x, y, global): arcto point (x, y) using the + aforementioned parameters. + * (",/.", rx, ry, rglobal, angle, x, y, global): an ellipse at + point (x, y) with radii (rx, ry). If angle is 0, the whole + ellipse is drawn; otherwise, a partial ellipse is drawn. + """ defaults = {} def __repr__(self): @@ -1450,13 +1450,13 @@ class Path: def funcRtoC(expr, var="t", globals=None, locals=None): """Converts a complex "z(t)" string to a function acceptable for Curve. - - expr required string in the form "z(t)" - var default="t" name of the independent variable - globals default=None dict of global variables used in the expression; - you may want to use Python's builtin globals() - locals default=None dict of local variables - """ + + expr required string in the form "z(t)" + var default="t" name of the independent variable + globals default=None dict of global variables used in the expression; + you may want to use Python's builtin globals() + locals default=None dict of local variables + """ g = cmath.__dict__ if globals != None: g.update(globals) output = eval("lambda %s: (%s)" % (var, expr), g, locals) @@ -1467,13 +1467,13 @@ def funcRtoC(expr, var="t", globals=None, locals=None): def funcRtoR2(expr, var="t", globals=None, locals=None): """Converts a "f(t), g(t)" string to a function acceptable for Curve. - - expr required string in the form "f(t), g(t)" - var default="t" name of the independent variable - globals default=None dict of global variables used in the expression; - you may want to use Python's builtin globals() - locals default=None dict of local variables - """ + + expr required string in the form "f(t), g(t)" + var default="t" name of the independent variable + globals default=None dict of global variables used in the expression; + you may want to use Python's builtin globals() + locals default=None dict of local variables + """ g = math.__dict__ if globals != None: g.update(globals) output = eval("lambda %s: (%s)" % (var, expr), g, locals) @@ -1482,13 +1482,13 @@ def funcRtoR2(expr, var="t", globals=None, locals=None): def funcRtoR(expr, var="x", globals=None, locals=None): """Converts a "f(x)" string to a function acceptable for Curve. - - expr required string in the form "f(x)" - var default="x" name of the independent variable - globals default=None dict of global variables used in the expression; - you may want to use Python's builtin globals() - locals default=None dict of local variables - """ + + expr required string in the form "f(x)" + var default="x" name of the independent variable + globals default=None dict of global variables used in the expression; + you may want to use Python's builtin globals() + locals default=None dict of local variables + """ g = math.__dict__ if globals != None: g.update(globals) output = eval("lambda %s: (%s, %s)" % (var, var, expr), g, locals) @@ -1497,15 +1497,15 @@ def funcRtoR(expr, var="x", globals=None, locals=None): class Curve: """Draws a parametric function as a path. - - Curve(f, low, high, loop, attribute=value) - - f required a Python callable or string in - the form "f(t), g(t)" - low, high required left and right endpoints - loop default=False if True, connect the endpoints - attribute=value pairs keyword list SVG attributes - """ + + Curve(f, low, high, loop, attribute=value) + + f required a Python callable or string in + the form "f(t), g(t)" + low, high required left and right endpoints + loop default=False if True, connect the endpoints + attribute=value pairs keyword list SVG attributes + """ defaults = {} random_sampling = True recursion_limit = 15 @@ -1574,8 +1574,8 @@ class Curve: def sample(self, trans=None): """Adaptive-sampling algorithm that chooses the best sample points - for a parametric curve between two endpoints and detects - discontinuities. Called by SVG().""" + for a parametric curve between two endpoints and detects + discontinuities. Called by SVG().""" oldrecursionlimit = sys.getrecursionlimit() sys.setrecursionlimit(self.recursion_limit + 100) try: @@ -1652,8 +1652,8 @@ class Curve: def Path(self, trans=None, local=False): """Apply the transformation "trans" and return a Path object in - global coordinates. If local=True, return a Path in local coordinates - (which must be transformed again).""" + global coordinates. If local=True, return a Path in local coordinates + (which must be transformed again).""" if isinstance(trans, basestring): trans = totrans(trans) if isinstance(self.f, basestring): self.f = funcRtoR2(self.f) @@ -1678,41 +1678,41 @@ class Curve: class Poly: """Draws a curve specified by a sequence of points. The curve may be - piecewise linear, like a polygon, or a Bezier curve. - - Poly(d, mode, loop, attribute=value) - - d required list of tuples representing points - and possibly control points - mode default="L" "lines", "bezier", "velocity", - "foreback", "smooth", or an abbreviation - loop default=False if True, connect the first and last - point, closing the loop - attribute=value pairs keyword list SVG attributes - - The format of the tuples in d depends on the mode. - - "lines"/"L" d=[(x,y), (x,y), ...] - piecewise-linear segments joining the (x,y) points - "bezier"/"B" d=[(x, y, c1x, c1y, c2x, c2y), ...] - Bezier curve with two control points (control points - preceed (x,y), as in SVG paths). If (c1x,c1y) and - (c2x,c2y) both equal (x,y), you get a linear - interpolation ("lines") - "velocity"/"V" d=[(x, y, vx, vy), ...] - curve that passes through (x,y) with velocity (vx,vy) - (one unit of arclength per unit time); in other words, - (vx,vy) is the tangent vector at (x,y). If (vx,vy) is - (0,0), you get a linear interpolation ("lines"). - "foreback"/"F" d=[(x, y, bx, by, fx, fy), ...] - like "velocity" except that there is a left derivative - (bx,by) and a right derivative (fx,fy). If (bx,by) - equals (fx,fy) (with no minus sign), you get a - "velocity" curve - "smooth"/"S" d=[(x,y), (x,y), ...] - a "velocity" interpolation with (vx,vy)[i] equal to - ((x,y)[i+1] - (x,y)[i-1])/2: the minimal derivative - """ + piecewise linear, like a polygon, or a Bezier curve. + + Poly(d, mode, loop, attribute=value) + + d required list of tuples representing points + and possibly control points + mode default="L" "lines", "bezier", "velocity", + "foreback", "smooth", or an abbreviation + loop default=False if True, connect the first and last + point, closing the loop + attribute=value pairs keyword list SVG attributes + + The format of the tuples in d depends on the mode. + + "lines"/"L" d=[(x,y), (x,y), ...] + piecewise-linear segments joining the (x,y) points + "bezier"/"B" d=[(x, y, c1x, c1y, c2x, c2y), ...] + Bezier curve with two control points (control points + preceed (x,y), as in SVG paths). If (c1x,c1y) and + (c2x,c2y) both equal (x,y), you get a linear + interpolation ("lines") + "velocity"/"V" d=[(x, y, vx, vy), ...] + curve that passes through (x,y) with velocity (vx,vy) + (one unit of arclength per unit time); in other words, + (vx,vy) is the tangent vector at (x,y). If (vx,vy) is + (0,0), you get a linear interpolation ("lines"). + "foreback"/"F" d=[(x, y, bx, by, fx, fy), ...] + like "velocity" except that there is a left derivative + (bx,by) and a right derivative (fx,fy). If (bx,by) + equals (fx,fy) (with no minus sign), you get a + "velocity" curve + "smooth"/"S" d=[(x,y), (x,y), ...] + a "velocity" interpolation with (vx,vy)[i] equal to + ((x,y)[i+1] - (x,y)[i-1])/2: the minimal derivative + """ defaults = {} def __repr__(self): @@ -1834,10 +1834,10 @@ class Poly: class Text: """Draws at text string at a specified point in local coordinates. - x, y required location of the point in local coordinates - d required text/Unicode string - attribute=value pairs keyword list SVG attributes - """ + x, y required location of the point in local coordinates + d required text/Unicode string + attribute=value pairs keyword list SVG attributes + """ defaults = {"stroke":"none", "fill":"black", "font-size":5} @@ -1861,11 +1861,11 @@ class Text: class TextGlobal: """Draws at text string at a specified point in global coordinates. - - x, y required location of the point in global coordinates - d required text/Unicode string - attribute=value pairs keyword list SVG attributes - """ + + x, y required location of the point in global coordinates + d required text/Unicode string + attribute=value pairs keyword list SVG attributes + """ defaults = {"stroke":"none", "fill":"black", "font-size":5} def __repr__(self): @@ -1893,10 +1893,10 @@ _symbol_templates = {"dot": SVG("symbol", SVG("circle", cx=0, cy=0, r=1, stroke= def make_symbol(id, shape="dot", **attr): """Creates a new instance of an SVG symbol to avoid cross-linking objects. - id required a new identifier (string/Unicode) - shape default="dot" the shape name from _symbol_templates - attribute=value list keyword list modify the SVG attributes of the new symbol - """ + id required a new identifier (string/Unicode) + shape default="dot" the shape name from _symbol_templates + attribute=value list keyword list modify the SVG attributes of the new symbol + """ output = copy.deepcopy(_symbol_templates[shape]) for i in output.sub: i.attr.update(attr_preprocess(attr)) output["id"] = id @@ -1906,15 +1906,15 @@ _circular_dot = make_symbol("circular_dot") class Dots: """Dots draws SVG symbols at a set of points. - - d required list of (x,y) points - symbol default=None SVG symbol or a new identifier to - label an auto-generated symbol; - if None, use pre-defined _circular_dot - width, height default=1, 1 width and height of the symbols - in SVG coordinates - attribute=value pairs keyword list SVG attributes - """ + + d required list of (x,y) points + symbol default=None SVG symbol or a new identifier to + label an auto-generated symbol; + if None, use pre-defined _circular_dot + width, height default=1, 1 width and height of the symbols + in SVG coordinates + attribute=value pairs keyword list SVG attributes + """ defaults = {} def __repr__(self): @@ -1963,11 +1963,11 @@ _marker_templates = {"arrow_start": SVG("marker", SVG("path", d="M 9 3.6 L 10.5 def make_marker(id, shape, **attr): """Creates a new instance of an SVG marker to avoid cross-linking objects. - - id required a new identifier (string/Unicode) - shape required the shape name from _marker_templates - attribute=value list keyword list modify the SVG attributes of the new marker - """ + + id required a new identifier (string/Unicode) + shape required the shape name from _marker_templates + attribute=value list keyword list modify the SVG attributes of the new marker + """ output = copy.deepcopy(_marker_templates[shape]) for i in output.sub: i.attr.update(attr_preprocess(attr)) output["id"] = id @@ -1975,18 +1975,18 @@ def make_marker(id, shape, **attr): class Line(Curve): """Draws a line between two points. - - Line(x1, y1, x2, y2, arrow_start, arrow_end, attribute=value) - - x1, y1 required the starting point - x2, y2 required the ending point - arrow_start default=None if an identifier string/Unicode, - draw a new arrow object at the - beginning of the line; if a marker, - draw that marker instead - arrow_end default=None same for the end of the line - attribute=value pairs keyword list SVG attributes - """ + + Line(x1, y1, x2, y2, arrow_start, arrow_end, attribute=value) + + x1, y1 required the starting point + x2, y2 required the ending point + arrow_start default=None if an identifier string/Unicode, + draw a new arrow object at the + beginning of the line; if a marker, + draw that marker instead + arrow_end default=None same for the end of the line + attribute=value pairs keyword list SVG attributes + """ defaults = {} def __repr__(self): @@ -2033,8 +2033,8 @@ class Line(Curve): def Path(self, trans=None, local=False): """Apply the transformation "trans" and return a Path object in - global coordinates. If local=True, return a Path in local coordinates - (which must be transformed again).""" + global coordinates. If local=True, return a Path in local coordinates + (which must be transformed again).""" self.f = lambda t: (self.x1 + t*(self.x2 - self.x1), self.y1 + t*(self.y2 - self.y1)) self.low = 0. self.high = 1. @@ -2049,21 +2049,21 @@ class LineGlobal: """Draws a line between two points, one or both of which is in global coordinates. - Line(x1, y1, x2, y2, lcoal1, local2, arrow_start, arrow_end, attribute=value) - - x1, y1 required the starting point - x2, y2 required the ending point - local1 default=False if True, interpret first point as a - local coordinate (apply transform) - local2 default=False if True, interpret second point as a - local coordinate (apply transform) - arrow_start default=None if an identifier string/Unicode, - draw a new arrow object at the - beginning of the line; if a marker, - draw that marker instead - arrow_end default=None same for the end of the line - attribute=value pairs keyword list SVG attributes - """ + Line(x1, y1, x2, y2, lcoal1, local2, arrow_start, arrow_end, attribute=value) + + x1, y1 required the starting point + x2, y2 required the ending point + local1 default=False if True, interpret first point as a + local coordinate (apply transform) + local2 default=False if True, interpret second point as a + local coordinate (apply transform) + arrow_start default=None if an identifier string/Unicode, + draw a new arrow object at the + beginning of the line; if a marker, + draw that marker instead + arrow_end default=None same for the end of the line + attribute=value pairs keyword list SVG attributes + """ defaults = {} def __repr__(self): @@ -2122,12 +2122,12 @@ class LineGlobal: class VLine(Line): """Draws a vertical line. - VLine(y1, y2, x, attribute=value) - - y1, y2 required y range - x required x position - attribute=value pairs keyword list SVG attributes - """ + VLine(y1, y2, x, attribute=value) + + y1, y2 required y range + x required x position + attribute=value pairs keyword list SVG attributes + """ defaults = {} def __repr__(self): @@ -2141,8 +2141,8 @@ class VLine(Line): def Path(self, trans=None, local=False): """Apply the transformation "trans" and return a Path object in - global coordinates. If local=True, return a Path in local coordinates - (which must be transformed again).""" + global coordinates. If local=True, return a Path in local coordinates + (which must be transformed again).""" self.x1 = self.x self.x2 = self.x return Line.Path(self, trans, local) @@ -2150,12 +2150,12 @@ class VLine(Line): class HLine(Line): """Draws a horizontal line. - HLine(x1, x2, y, attribute=value) - - x1, x2 required x range - y required y position - attribute=value pairs keyword list SVG attributes - """ + HLine(x1, x2, y, attribute=value) + + x1, x2 required x range + y required y position + attribute=value pairs keyword list SVG attributes + """ defaults = {} def __repr__(self): @@ -2169,8 +2169,8 @@ class HLine(Line): def Path(self, trans=None, local=False): """Apply the transformation "trans" and return a Path object in - global coordinates. If local=True, return a Path in local coordinates - (which must be transformed again).""" + global coordinates. If local=True, return a Path in local coordinates + (which must be transformed again).""" self.y1 = self.y self.y2 = self.y return Line.Path(self, trans, local) @@ -2179,13 +2179,13 @@ class HLine(Line): class Rect(Curve): """Draws a rectangle. - - Rect(x1, y1, x2, y2, attribute=value) - - x1, y1 required the starting point - x2, y2 required the ending point - attribute=value pairs keyword list SVG attributes - """ + + Rect(x1, y1, x2, y2, attribute=value) + + x1, y1 required the starting point + x2, y2 required the ending point + attribute=value pairs keyword list SVG attributes + """ defaults = {} def __repr__(self): @@ -2203,8 +2203,8 @@ class Rect(Curve): def Path(self, trans=None, local=False): """Apply the transformation "trans" and return a Path object in - global coordinates. If local=True, return a Path in local coordinates - (which must be transformed again).""" + global coordinates. If local=True, return a Path in local coordinates + (which must be transformed again).""" if trans == None: return Path([("M", self.x1, self.y1, not local), ("L", self.x2, self.y1, not local), ("L", self.x2, self.y2, not local), ("L", self.x1, self.y2, not local), ("Z",)], **self.attr) @@ -2234,21 +2234,21 @@ class Rect(Curve): class Ellipse(Curve): """Draws an ellipse from a semimajor vector (ax,ay) and a semiminor - length (b). - - Ellipse(x, y, ax, ay, b, attribute=value) - - x, y required the center of the ellipse/circle - ax, ay required a vector indicating the length - and direction of the semimajor axis - b required the length of the semiminor axis. - If equal to sqrt(ax2 + ay2), the - ellipse is a circle - attribute=value pairs keyword list SVG attributes - - (If sqrt(ax**2 + ay**2) is less than b, then (ax,ay) is actually the - semiminor axis.) - """ + length (b). + + Ellipse(x, y, ax, ay, b, attribute=value) + + x, y required the center of the ellipse/circle + ax, ay required a vector indicating the length + and direction of the semimajor axis + b required the length of the semiminor axis. + If equal to sqrt(ax2 + ay2), the + ellipse is a circle + attribute=value pairs keyword list SVG attributes + + (If sqrt(ax**2 + ay**2) is less than b, then (ax,ay) is actually the + semiminor axis.) + """ defaults = {} def __repr__(self): @@ -2266,8 +2266,8 @@ class Ellipse(Curve): def Path(self, trans=None, local=False): """Apply the transformation "trans" and return a Path object in - global coordinates. If local=True, return a Path in local coordinates - (which must be transformed again).""" + global coordinates. If local=True, return a Path in local coordinates + (which must be transformed again).""" angle = math.atan2(self.ay, self.ax) + math.pi/2. bx = self.b * math.cos(angle) by = self.b * math.sin(angle) @@ -2282,8 +2282,8 @@ class Ellipse(Curve): def unumber(x): """Converts numbers to a Unicode string, taking advantage of special - Unicode characters to make nice minus signs and scientific notation. - """ + Unicode characters to make nice minus signs and scientific notation. + """ output = u"%g" % x if output[0] == u"-": @@ -2319,63 +2319,63 @@ def unumber(x): class Ticks: """Superclass for all graphics primatives that draw ticks, - miniticks, and tick labels. This class only draws the ticks. - - Ticks(f, low, high, ticks, miniticks, labels, logbase, arrow_start, - arrow_end, text_attr, attribute=value) - - f required parametric function along which ticks - will be drawn; has the same format as - the function used in Curve - low, high required range of the independent variable - ticks default=-10 request ticks according to the standard - tick specification (see below) - miniticks default=True request miniticks according to the - standard minitick specification (below) - labels True request tick labels according to the - standard tick label specification (below) - logbase default=None if a number, the axis is logarithmic with - ticks at the given base (usually 10) - arrow_start default=None if a new string identifier, draw an arrow - at the low-end of the axis, referenced by - that identifier; if an SVG marker object, - use that marker - arrow_end default=None if a new string identifier, draw an arrow - at the high-end of the axis, referenced by - that identifier; if an SVG marker object, - use that marker - text_attr default={} SVG attributes for the text labels - attribute=value pairs keyword list SVG attributes for the tick marks - - Standard tick specification: - - * True: same as -10 (below). - * Positive number N: draw exactly N ticks, including the endpoints. To - subdivide an axis into 10 equal-sized segments, ask for 11 ticks. - * Negative number -N: draw at least N ticks. Ticks will be chosen with - "natural" values, multiples of 2 or 5. - * List of values: draw a tick mark at each value. - * Dict of value, label pairs: draw a tick mark at each value, labeling - it with the given string. This lets you say things like {3.14159: "pi"}. - * False or None: no ticks. - - Standard minitick specification: - - * True: draw miniticks with "natural" values, more closely spaced than - the ticks. - * Positive number N: draw exactly N miniticks, including the endpoints. - To subdivide an axis into 100 equal-sized segments, ask for 101 miniticks. - * Negative number -N: draw at least N miniticks. - * List of values: draw a minitick mark at each value. - * False or None: no miniticks. - - Standard tick label specification: - - * True: use the unumber function (described below) - * Format string: standard format strings, e.g. "%5.2f" for 12.34 - * Python callable: function that converts numbers to strings - * False or None: no labels - """ + miniticks, and tick labels. This class only draws the ticks. + + Ticks(f, low, high, ticks, miniticks, labels, logbase, arrow_start, + arrow_end, text_attr, attribute=value) + + f required parametric function along which ticks + will be drawn; has the same format as + the function used in Curve + low, high required range of the independent variable + ticks default=-10 request ticks according to the standard + tick specification (see below) + miniticks default=True request miniticks according to the + standard minitick specification (below) + labels True request tick labels according to the + standard tick label specification (below) + logbase default=None if a number, the axis is logarithmic with + ticks at the given base (usually 10) + arrow_start default=None if a new string identifier, draw an arrow + at the low-end of the axis, referenced by + that identifier; if an SVG marker object, + use that marker + arrow_end default=None if a new string identifier, draw an arrow + at the high-end of the axis, referenced by + that identifier; if an SVG marker object, + use that marker + text_attr default={} SVG attributes for the text labels + attribute=value pairs keyword list SVG attributes for the tick marks + + Standard tick specification: + + * True: same as -10 (below). + * Positive number N: draw exactly N ticks, including the endpoints. To + subdivide an axis into 10 equal-sized segments, ask for 11 ticks. + * Negative number -N: draw at least N ticks. Ticks will be chosen with + "natural" values, multiples of 2 or 5. + * List of values: draw a tick mark at each value. + * Dict of value, label pairs: draw a tick mark at each value, labeling + it with the given string. This lets you say things like {3.14159: "pi"}. + * False or None: no ticks. + + Standard minitick specification: + + * True: draw miniticks with "natural" values, more closely spaced than + the ticks. + * Positive number N: draw exactly N miniticks, including the endpoints. + To subdivide an axis into 100 equal-sized segments, ask for 101 miniticks. + * Negative number -N: draw at least N miniticks. + * List of values: draw a minitick mark at each value. + * False or None: no miniticks. + + Standard tick label specification: + + * True: use the unumber function (described below) + * Format string: standard format strings, e.g. "%5.2f" for 12.34 + * Python callable: function that converts numbers to strings + * False or None: no labels + """ defaults = {"stroke-width":"0.25pt"} text_defaults = {"stroke":"none", "fill":"black", "font-size":5} tick_start = -1.5 @@ -2407,10 +2407,10 @@ class Ticks: def orient_tickmark(self, t, trans=None): """Return the position, normalized local x vector, normalized - local y vector, and angle of a tick at position t. - - Normally only used internally. - """ + local y vector, and angle of a tick at position t. + + Normally only used internally. + """ if isinstance(trans, basestring): trans = totrans(trans) if trans == None: f = self.f @@ -2506,10 +2506,10 @@ class Ticks: def interpret(self): """Evaluate and return optimal ticks and miniticks according to - the standard minitick specification. - - Normally only used internally. - """ + the standard minitick specification. + + Normally only used internally. + """ if self.labels == None or self.labels == False: format = lambda x: "" @@ -2601,8 +2601,8 @@ class Ticks: def compute_ticks(self, N, format): """Return less than -N or exactly N optimal linear ticks. - Normally only used internally. - """ + Normally only used internally. + """ if self.low >= self.high: raise ValueError, "low must be less than high" if N == 1: raise ValueError, "N can be 0 or >1 to specify the exact number of ticks or negative to specify a maximum" @@ -2677,8 +2677,8 @@ class Ticks: def regular_miniticks(self, N): """Return exactly N linear ticks. - Normally only used internally. - """ + Normally only used internally. + """ output = [] x = self.low for i in xrange(N): @@ -2689,8 +2689,8 @@ class Ticks: def compute_miniticks(self, original_ticks): """Return optimal linear miniticks, given a set of ticks. - Normally only used internally. - """ + Normally only used internally. + """ if len(original_ticks) < 2: original_ticks = ticks(self.low, self.high) original_ticks = original_ticks.keys() original_ticks.sort() @@ -2718,8 +2718,8 @@ class Ticks: def compute_logticks(self, base, N, format): """Return less than -N or exactly N optimal logarithmic ticks. - Normally only used internally. - """ + Normally only used internally. + """ if self.low >= self.high: raise ValueError, "low must be less than high" if N == 1: raise ValueError, "N can be 0 or >1 to specify the exact number of ticks or negative to specify a maximum" @@ -2769,8 +2769,8 @@ class Ticks: def compute_logminiticks(self, base): """Return optimal logarithmic miniticks, given a set of ticks. - Normally only used internally. - """ + Normally only used internally. + """ if self.low >= self.high: raise ValueError, "low must be less than high" lowN = math.floor(math.log(self.low, base)) @@ -2792,32 +2792,32 @@ class Ticks: class CurveAxis(Curve, Ticks): """Draw an axis with tick marks along a parametric curve. - CurveAxis(f, low, high, ticks, miniticks, labels, logbase, arrow_start, arrow_end, - text_attr, attribute=value) - - f required a Python callable or string in - the form "f(t), g(t)", just like Curve - low, high required left and right endpoints - ticks default=-10 request ticks according to the standard - tick specification (see help(Ticks)) - miniticks default=True request miniticks according to the - standard minitick specification - labels True request tick labels according to the - standard tick label specification - logbase default=None if a number, the x axis is logarithmic - with ticks at the given base (10 being - the most common) - arrow_start default=None if a new string identifier, draw an - arrow at the low-end of the axis, - referenced by that identifier; if an - SVG marker object, use that marker - arrow_end default=None if a new string identifier, draw an - arrow at the high-end of the axis, - referenced by that identifier; if an - SVG marker object, use that marker - text_attr default={} SVG attributes for the text labels - attribute=value pairs keyword list SVG attributes - """ + CurveAxis(f, low, high, ticks, miniticks, labels, logbase, arrow_start, arrow_end, + text_attr, attribute=value) + + f required a Python callable or string in + the form "f(t), g(t)", just like Curve + low, high required left and right endpoints + ticks default=-10 request ticks according to the standard + tick specification (see help(Ticks)) + miniticks default=True request miniticks according to the + standard minitick specification + labels True request tick labels according to the + standard tick label specification + logbase default=None if a number, the x axis is logarithmic + with ticks at the given base (10 being + the most common) + arrow_start default=None if a new string identifier, draw an + arrow at the low-end of the axis, + referenced by that identifier; if an + SVG marker object, use that marker + arrow_end default=None if a new string identifier, draw an + arrow at the high-end of the axis, + referenced by that identifier; if an + SVG marker object, use that marker + text_attr default={} SVG attributes for the text labels + attribute=value pairs keyword list SVG attributes + """ defaults = {"stroke-width":"0.25pt"} text_defaults = {"stroke":"none", "fill":"black", "font-size":5} @@ -2852,32 +2852,32 @@ class CurveAxis(Curve, Ticks): class LineAxis(Line, Ticks): """Draws an axis with tick marks along a line. - - LineAxis(x1, y1, x2, y2, start, end, ticks, miniticks, labels, logbase, - arrow_start, arrow_end, text_attr, attribute=value) - - x1, y1 required starting point - x2, y2 required ending point - start, end default=0, 1 values to start and end labeling - ticks default=-10 request ticks according to the standard - tick specification (see help(Ticks)) - miniticks default=True request miniticks according to the - standard minitick specification - labels True request tick labels according to the - standard tick label specification - logbase default=None if a number, the x axis is logarithmic - with ticks at the given base (usually 10) - arrow_start default=None if a new string identifier, draw an arrow - at the low-end of the axis, referenced by - that identifier; if an SVG marker object, - use that marker - arrow_end default=None if a new string identifier, draw an arrow - at the high-end of the axis, referenced by - that identifier; if an SVG marker object, - use that marker - text_attr default={} SVG attributes for the text labels - attribute=value pairs keyword list SVG attributes - """ + + LineAxis(x1, y1, x2, y2, start, end, ticks, miniticks, labels, logbase, + arrow_start, arrow_end, text_attr, attribute=value) + + x1, y1 required starting point + x2, y2 required ending point + start, end default=0, 1 values to start and end labeling + ticks default=-10 request ticks according to the standard + tick specification (see help(Ticks)) + miniticks default=True request miniticks according to the + standard minitick specification + labels True request tick labels according to the + standard tick label specification + logbase default=None if a number, the x axis is logarithmic + with ticks at the given base (usually 10) + arrow_start default=None if a new string identifier, draw an arrow + at the low-end of the axis, referenced by + that identifier; if an SVG marker object, + use that marker + arrow_end default=None if a new string identifier, draw an arrow + at the high-end of the axis, referenced by + that identifier; if an SVG marker object, + use that marker + text_attr default={} SVG attributes for the text labels + attribute=value pairs keyword list SVG attributes + """ defaults = {"stroke-width":"0.25pt"} text_defaults = {"stroke":"none", "fill":"black", "font-size":5} @@ -2937,36 +2937,36 @@ class LineAxis(Line, Ticks): class XAxis(LineAxis): """Draws an x axis with tick marks. - - XAxis(xmin, xmax, aty, ticks, miniticks, labels, logbase, arrow_start, arrow_end, - exclude, text_attr, attribute=value) - - xmin, xmax required the x range - aty default=0 y position to draw the axis - ticks default=-10 request ticks according to the standard - tick specification (see help(Ticks)) - miniticks default=True request miniticks according to the - standard minitick specification - labels True request tick labels according to the - standard tick label specification - logbase default=None if a number, the x axis is logarithmic - with ticks at the given base (usually 10) - arrow_start default=None if a new string identifier, draw an arrow - at the low-end of the axis, referenced by - that identifier; if an SVG marker object, - use that marker - arrow_end default=None if a new string identifier, draw an arrow - at the high-end of the axis, referenced by - that identifier; if an SVG marker object, - use that marker - exclude default=None if a (low, high) pair, don't draw text - labels within this range - text_attr default={} SVG attributes for the text labels - attribute=value pairs keyword list SVG attributes for all lines - - The exclude option is provided for Axes to keep text from overlapping - where the axes cross. Normal users are not likely to need it. - """ + + XAxis(xmin, xmax, aty, ticks, miniticks, labels, logbase, arrow_start, arrow_end, + exclude, text_attr, attribute=value) + + xmin, xmax required the x range + aty default=0 y position to draw the axis + ticks default=-10 request ticks according to the standard + tick specification (see help(Ticks)) + miniticks default=True request miniticks according to the + standard minitick specification + labels True request tick labels according to the + standard tick label specification + logbase default=None if a number, the x axis is logarithmic + with ticks at the given base (usually 10) + arrow_start default=None if a new string identifier, draw an arrow + at the low-end of the axis, referenced by + that identifier; if an SVG marker object, + use that marker + arrow_end default=None if a new string identifier, draw an arrow + at the high-end of the axis, referenced by + that identifier; if an SVG marker object, + use that marker + exclude default=None if a (low, high) pair, don't draw text + labels within this range + text_attr default={} SVG attributes for the text labels + attribute=value pairs keyword list SVG attributes for all lines + + The exclude option is provided for Axes to keep text from overlapping + where the axes cross. Normal users are not likely to need it. + """ defaults = {"stroke-width":"0.25pt"} text_defaults = {"stroke":"none", "fill":"black", "font-size":5, "dominant-baseline":"text-before-edge"} text_start = -1. @@ -2989,36 +2989,36 @@ class XAxis(LineAxis): class YAxis(LineAxis): """Draws a y axis with tick marks. - - YAxis(ymin, ymax, atx, ticks, miniticks, labels, logbase, arrow_start, arrow_end, - exclude, text_attr, attribute=value) - - ymin, ymax required the y range - atx default=0 x position to draw the axis - ticks default=-10 request ticks according to the standard - tick specification (see help(Ticks)) - miniticks default=True request miniticks according to the - standard minitick specification - labels True request tick labels according to the - standard tick label specification - logbase default=None if a number, the y axis is logarithmic - with ticks at the given base (usually 10) - arrow_start default=None if a new string identifier, draw an arrow - at the low-end of the axis, referenced by - that identifier; if an SVG marker object, - use that marker - arrow_end default=None if a new string identifier, draw an arrow - at the high-end of the axis, referenced by - that identifier; if an SVG marker object, - use that marker - exclude default=None if a (low, high) pair, don't draw text - labels within this range - text_attr default={} SVG attributes for the text labels - attribute=value pairs keyword list SVG attributes for all lines - - The exclude option is provided for Axes to keep text from overlapping - where the axes cross. Normal users are not likely to need it. - """ + + YAxis(ymin, ymax, atx, ticks, miniticks, labels, logbase, arrow_start, arrow_end, + exclude, text_attr, attribute=value) + + ymin, ymax required the y range + atx default=0 x position to draw the axis + ticks default=-10 request ticks according to the standard + tick specification (see help(Ticks)) + miniticks default=True request miniticks according to the + standard minitick specification + labels True request tick labels according to the + standard tick label specification + logbase default=None if a number, the y axis is logarithmic + with ticks at the given base (usually 10) + arrow_start default=None if a new string identifier, draw an arrow + at the low-end of the axis, referenced by + that identifier; if an SVG marker object, + use that marker + arrow_end default=None if a new string identifier, draw an arrow + at the high-end of the axis, referenced by + that identifier; if an SVG marker object, + use that marker + exclude default=None if a (low, high) pair, don't draw text + labels within this range + text_attr default={} SVG attributes for the text labels + attribute=value pairs keyword list SVG attributes for all lines + + The exclude option is provided for Axes to keep text from overlapping + where the axes cross. Normal users are not likely to need it. + """ defaults = {"stroke-width":"0.25pt"} text_defaults = {"stroke":"none", "fill":"black", "font-size":5, "text-anchor":"end", "dominant-baseline":"middle"} text_start = 2.5 @@ -3041,36 +3041,36 @@ class YAxis(LineAxis): class Axes: """Draw a pair of intersecting x-y axes. - - Axes(xmin, xmax, ymin, ymax, atx, aty, xticks, xminiticks, xlabels, xlogbase, - yticks, yminiticks, ylabels, ylogbase, arrows, text_attr, attribute=value) - - xmin, xmax required the x range - ymin, ymax required the y range - atx, aty default=0, 0 point where the axes try to cross; - if outside the range, the axes will - cross at the closest corner - xticks default=-10 request ticks according to the standard - tick specification (see help(Ticks)) - xminiticks default=True request miniticks according to the - standard minitick specification - xlabels True request tick labels according to the - standard tick label specification - xlogbase default=None if a number, the x axis is logarithmic - with ticks at the given base (usually 10) - yticks default=-10 request ticks according to the standard - tick specification - yminiticks default=True request miniticks according to the - standard minitick specification - ylabels True request tick labels according to the - standard tick label specification - ylogbase default=None if a number, the y axis is logarithmic - with ticks at the given base (usually 10) - arrows default=None if a new string identifier, draw arrows - referenced by that identifier - text_attr default={} SVG attributes for the text labels - attribute=value pairs keyword list SVG attributes for all lines - """ + + Axes(xmin, xmax, ymin, ymax, atx, aty, xticks, xminiticks, xlabels, xlogbase, + yticks, yminiticks, ylabels, ylogbase, arrows, text_attr, attribute=value) + + xmin, xmax required the x range + ymin, ymax required the y range + atx, aty default=0, 0 point where the axes try to cross; + if outside the range, the axes will + cross at the closest corner + xticks default=-10 request ticks according to the standard + tick specification (see help(Ticks)) + xminiticks default=True request miniticks according to the + standard minitick specification + xlabels True request tick labels according to the + standard tick label specification + xlogbase default=None if a number, the x axis is logarithmic + with ticks at the given base (usually 10) + yticks default=-10 request ticks according to the standard + tick specification + yminiticks default=True request miniticks according to the + standard minitick specification + ylabels True request tick labels according to the + standard tick label specification + ylogbase default=None if a number, the y axis is logarithmic + with ticks at the given base (usually 10) + arrows default=None if a new string identifier, draw arrows + referenced by that identifier + text_attr default={} SVG attributes for the text labels + attribute=value pairs keyword list SVG attributes for all lines + """ defaults = {"stroke-width":"0.25pt"} text_defaults = {"stroke":"none", "fill":"black", "font-size":5} @@ -3121,23 +3121,23 @@ class Axes: class HGrid(Ticks): """Draws the horizontal lines of a grid over a specified region - using the standard tick specification (see help(Ticks)) to place the - grid lines. - - HGrid(xmin, xmax, low, high, ticks, miniticks, logbase, mini_attr, attribute=value) - - xmin, xmax required the x range - low, high required the y range - ticks default=-10 request ticks according to the standard - tick specification (see help(Ticks)) - miniticks default=False request miniticks according to the - standard minitick specification - logbase default=None if a number, the axis is logarithmic - with ticks at the given base (usually 10) - mini_attr default={} SVG attributes for the minitick-lines - (if miniticks != False) - attribute=value pairs keyword list SVG attributes for the major tick lines - """ + using the standard tick specification (see help(Ticks)) to place the + grid lines. + + HGrid(xmin, xmax, low, high, ticks, miniticks, logbase, mini_attr, attribute=value) + + xmin, xmax required the x range + low, high required the y range + ticks default=-10 request ticks according to the standard + tick specification (see help(Ticks)) + miniticks default=False request miniticks according to the + standard minitick specification + logbase default=None if a number, the axis is logarithmic + with ticks at the given base (usually 10) + mini_attr default={} SVG attributes for the minitick-lines + (if miniticks != False) + attribute=value pairs keyword list SVG attributes for the major tick lines + """ defaults = {"stroke-width":"0.25pt", "stroke":"gray"} mini_defaults = {"stroke-width":"0.25pt", "stroke":"lightgray", "stroke-dasharray":"1,1"} @@ -3171,23 +3171,23 @@ class HGrid(Ticks): class VGrid(Ticks): """Draws the vertical lines of a grid over a specified region - using the standard tick specification (see help(Ticks)) to place the - grid lines. - - HGrid(ymin, ymax, low, high, ticks, miniticks, logbase, mini_attr, attribute=value) - - ymin, ymax required the y range - low, high required the x range - ticks default=-10 request ticks according to the standard - tick specification (see help(Ticks)) - miniticks default=False request miniticks according to the - standard minitick specification - logbase default=None if a number, the axis is logarithmic - with ticks at the given base (usually 10) - mini_attr default={} SVG attributes for the minitick-lines - (if miniticks != False) - attribute=value pairs keyword list SVG attributes for the major tick lines - """ + using the standard tick specification (see help(Ticks)) to place the + grid lines. + + HGrid(ymin, ymax, low, high, ticks, miniticks, logbase, mini_attr, attribute=value) + + ymin, ymax required the y range + low, high required the x range + ticks default=-10 request ticks according to the standard + tick specification (see help(Ticks)) + miniticks default=False request miniticks according to the + standard minitick specification + logbase default=None if a number, the axis is logarithmic + with ticks at the given base (usually 10) + mini_attr default={} SVG attributes for the minitick-lines + (if miniticks != False) + attribute=value pairs keyword list SVG attributes for the major tick lines + """ defaults = {"stroke-width":"0.25pt", "stroke":"gray"} mini_defaults = {"stroke-width":"0.25pt", "stroke":"lightgray", "stroke-dasharray":"1,1"} @@ -3221,22 +3221,22 @@ class VGrid(Ticks): class Grid(Ticks): """Draws a grid over a specified region using the standard tick - specification (see help(Ticks)) to place the grid lines. - - Grid(xmin, xmax, ymin, ymax, ticks, miniticks, logbase, mini_attr, attribute=value) - - xmin, xmax required the x range - ymin, ymax required the y range - ticks default=-10 request ticks according to the standard - tick specification (see help(Ticks)) - miniticks default=False request miniticks according to the - standard minitick specification - logbase default=None if a number, the axis is logarithmic - with ticks at the given base (usually 10) - mini_attr default={} SVG attributes for the minitick-lines - (if miniticks != False) - attribute=value pairs keyword list SVG attributes for the major tick lines - """ + specification (see help(Ticks)) to place the grid lines. + + Grid(xmin, xmax, ymin, ymax, ticks, miniticks, logbase, mini_attr, attribute=value) + + xmin, xmax required the x range + ymin, ymax required the y range + ticks default=-10 request ticks according to the standard + tick specification (see help(Ticks)) + miniticks default=False request miniticks according to the + standard minitick specification + logbase default=None if a number, the axis is logarithmic + with ticks at the given base (usually 10) + mini_attr default={} SVG attributes for the minitick-lines + (if miniticks != False) + attribute=value pairs keyword list SVG attributes for the major tick lines + """ defaults = {"stroke-width":"0.25pt", "stroke":"gray"} mini_defaults = {"stroke-width":"0.25pt", "stroke":"lightgray", "stroke-dasharray":"1,1"} @@ -3280,23 +3280,23 @@ class Grid(Ticks): class XErrorBars: """Draws x error bars at a set of points. This is usually used - before (under) a set of Dots at the same points. - - XErrorBars(d, attribute=value) - - d required list of (x,y,xerr...) points - attribute=value pairs keyword list SVG attributes - - If points in d have - - * 3 elements, the third is the symmetric error bar - * 4 elements, the third and fourth are the asymmetric lower and - upper error bar. The third element should be negative, - e.g. (5, 5, -1, 2) is a bar from 4 to 7. - * more than 4, a tick mark is placed at each value. This lets - you nest errors from different sources, correlated and - uncorrelated, statistical and systematic, etc. - """ + before (under) a set of Dots at the same points. + + XErrorBars(d, attribute=value) + + d required list of (x,y,xerr...) points + attribute=value pairs keyword list SVG attributes + + If points in d have + + * 3 elements, the third is the symmetric error bar + * 4 elements, the third and fourth are the asymmetric lower and + upper error bar. The third element should be negative, + e.g. (5, 5, -1, 2) is a bar from 4 to 7. + * more than 4, a tick mark is placed at each value. This lets + you nest errors from different sources, correlated and + uncorrelated, statistical and systematic, etc. + """ defaults = {"stroke-width":"0.25pt"} def __repr__(self): @@ -3326,23 +3326,23 @@ class XErrorBars: class YErrorBars: """Draws y error bars at a set of points. This is usually used - before (under) a set of Dots at the same points. - - YErrorBars(d, attribute=value) - - d required list of (x,y,yerr...) points - attribute=value pairs keyword list SVG attributes - - If points in d have - - * 3 elements, the third is the symmetric error bar - * 4 elements, the third and fourth are the asymmetric lower and - upper error bar. The third element should be negative, - e.g. (5, 5, -1, 2) is a bar from 4 to 7. - * more than 4, a tick mark is placed at each value. This lets - you nest errors from different sources, correlated and - uncorrelated, statistical and systematic, etc. - """ + before (under) a set of Dots at the same points. + + YErrorBars(d, attribute=value) + + d required list of (x,y,yerr...) points + attribute=value pairs keyword list SVG attributes + + If points in d have + + * 3 elements, the third is the symmetric error bar + * 4 elements, the third and fourth are the asymmetric lower and + upper error bar. The third element should be negative, + e.g. (5, 5, -1, 2) is a bar from 4 to 7. + * more than 4, a tick mark is placed at each value. This lets + you nest errors from different sources, correlated and + uncorrelated, statistical and systematic, etc. + """ defaults = {"stroke-width":"0.25pt"} def __repr__(self):