# HG changeset patch # User Paul Boddie # Date 1318106469 -7200 # Node ID b0f8e8bead248607ecc9fd7b66dbbf24e0174197 # Parent 87eb40178c3cd093a651c8d5288b01046ef36437 Added support for specifying the origin of the axes. diff -r 87eb40178c3c -r b0f8e8bead24 parsers/SVGChart.py --- a/parsers/SVGChart.py Sat Oct 08 22:36:01 2011 +0200 +++ b/parsers/SVGChart.py Sat Oct 08 22:41:09 2011 +0200 @@ -7,6 +7,7 @@ """ from MoinMoin.action import cache +from MoinMoin import wikiutil from SVGChartSupport import get_chart Dependencies = ["pages"] @@ -20,10 +21,24 @@ extensions = [".csv"] def __init__(self, raw, request, **kw): + + """ + Initialise the parser with the given 'raw' data, 'request' and any + keyword arguments that may have been supplied. + """ + self.raw = raw self.request = request self.data = [row.split() for row in raw.split("\n")] + attrs, msg = wikiutil.parseAttributes(request, kw.get("format_args", "")) + + # The attributes returned from the formatting arguments are encoded like + # strings. + + self.xorigin = float((attrs.get("xorigin") or '"0"')[1:-1]) + self.yorigin = float((attrs.get("yorigin") or '"0"')[1:-1]) + def format(self, fmt): "Format a chart using the given formatter 'fmt'." @@ -34,9 +49,10 @@ # NOTE: Store and retrieve the width and height. - cache_key = cache.key(request, itemname=page.page_name, content=self.raw) + cache_key = cache.key(request, itemname=page.page_name, content="%s,%s,%s" % (self.xorigin, self.yorigin, self.raw)) if not cache.exists(request, cache_key): - chart = get_chart(self.data, styles_url="%s/%s/css/svgchart.css" % (request.cfg.url_prefix_static, request.theme.name)) + chart = get_chart(self.data, xorigin=self.xorigin, yorigin=self.yorigin, + styles_url="%s/%s/css/svgchart.css" % (request.cfg.url_prefix_static, request.theme.name)) cache.put(request, cache_key, chart, content_type="image/svg+xml") request.write(fmt.div(1, css_class="svgchart"))