1.1 --- a/parsers/SVGChart.py Sat Oct 08 22:41:09 2011 +0200
1.2 +++ b/parsers/SVGChart.py Sun Oct 09 01:30:41 2011 +0200
1.3 @@ -8,7 +8,7 @@
1.4
1.5 from MoinMoin.action import cache
1.6 from MoinMoin import wikiutil
1.7 -from SVGChartSupport import get_chart
1.8 +from SVGChartSupport import get_chart, get_dimensions
1.9
1.10 Dependencies = ["pages"]
1.11
1.12 @@ -36,8 +36,13 @@
1.13 # The attributes returned from the formatting arguments are encoded like
1.14 # strings.
1.15
1.16 - self.xorigin = float((attrs.get("xorigin") or '"0"')[1:-1])
1.17 - self.yorigin = float((attrs.get("yorigin") or '"0"')[1:-1])
1.18 + quotes = '"' + "'"
1.19 + self.xorigin = float((attrs.get("xorigin") or '0').strip(quotes))
1.20 + self.yorigin = float((attrs.get("yorigin") or '0').strip(quotes))
1.21 + width = (attrs.get("width") or '').strip(quotes) or None
1.22 + height = (attrs.get("height") or '').strip(quotes) or None
1.23 + self.width = width and int(width)
1.24 + self.height = height and int(height)
1.25
1.26 def format(self, fmt):
1.27
1.28 @@ -47,16 +52,18 @@
1.29 page = request.page
1.30 _ = request.getText
1.31
1.32 - # NOTE: Store and retrieve the width and height.
1.33 + cache_key = cache.key(request, itemname=page.page_name, content="%s,%s,%s,%s,%s" % (
1.34 + self.width, self.height, self.xorigin, self.yorigin, self.raw))
1.35
1.36 - cache_key = cache.key(request, itemname=page.page_name, content="%s,%s,%s" % (self.xorigin, self.yorigin, self.raw))
1.37 if not cache.exists(request, cache_key):
1.38 - chart = get_chart(self.data, xorigin=self.xorigin, yorigin=self.yorigin,
1.39 + width, height, chart = get_chart(self.data, self.width, self.height, self.xorigin, self.yorigin,
1.40 styles_url="%s/%s/css/svgchart.css" % (request.cfg.url_prefix_static, request.theme.name))
1.41 cache.put(request, cache_key, chart, content_type="image/svg+xml")
1.42 + else:
1.43 + width, height = get_dimensions(self.data, self.width, self.height, self.xorigin, self.yorigin)
1.44
1.45 request.write(fmt.div(1, css_class="svgchart"))
1.46 - request.write(fmt.transclusion(1, data=cache.url(request, cache_key)))
1.47 + request.write(fmt.transclusion(1, data=cache.url(request, cache_key), width=width, height=height))
1.48 request.write(fmt.text(_("SVG chart of CSV data.")))
1.49 request.write(fmt.transclusion(0))
1.50 request.write(fmt.div(0))