1.1 --- a/parsers/SVGChart.py Sat Oct 08 22:36:01 2011 +0200
1.2 +++ b/parsers/SVGChart.py Sat Oct 08 22:41:09 2011 +0200
1.3 @@ -7,6 +7,7 @@
1.4 """
1.5
1.6 from MoinMoin.action import cache
1.7 +from MoinMoin import wikiutil
1.8 from SVGChartSupport import get_chart
1.9
1.10 Dependencies = ["pages"]
1.11 @@ -20,10 +21,24 @@
1.12 extensions = [".csv"]
1.13
1.14 def __init__(self, raw, request, **kw):
1.15 +
1.16 + """
1.17 + Initialise the parser with the given 'raw' data, 'request' and any
1.18 + keyword arguments that may have been supplied.
1.19 + """
1.20 +
1.21 self.raw = raw
1.22 self.request = request
1.23 self.data = [row.split() for row in raw.split("\n")]
1.24
1.25 + attrs, msg = wikiutil.parseAttributes(request, kw.get("format_args", ""))
1.26 +
1.27 + # The attributes returned from the formatting arguments are encoded like
1.28 + # strings.
1.29 +
1.30 + self.xorigin = float((attrs.get("xorigin") or '"0"')[1:-1])
1.31 + self.yorigin = float((attrs.get("yorigin") or '"0"')[1:-1])
1.32 +
1.33 def format(self, fmt):
1.34
1.35 "Format a chart using the given formatter 'fmt'."
1.36 @@ -34,9 +49,10 @@
1.37
1.38 # NOTE: Store and retrieve the width and height.
1.39
1.40 - cache_key = cache.key(request, itemname=page.page_name, content=self.raw)
1.41 + cache_key = cache.key(request, itemname=page.page_name, content="%s,%s,%s" % (self.xorigin, self.yorigin, self.raw))
1.42 if not cache.exists(request, cache_key):
1.43 - chart = get_chart(self.data, styles_url="%s/%s/css/svgchart.css" % (request.cfg.url_prefix_static, request.theme.name))
1.44 + chart = get_chart(self.data, xorigin=self.xorigin, yorigin=self.yorigin,
1.45 + styles_url="%s/%s/css/svgchart.css" % (request.cfg.url_prefix_static, request.theme.name))
1.46 cache.put(request, cache_key, chart, content_type="image/svg+xml")
1.47
1.48 request.write(fmt.div(1, css_class="svgchart"))