1 # -*- coding: iso-8859-1 -*- 2 """ 3 MoinMoin - SVGChart 4 5 @copyright: 2011 by Paul Boddie <paul@boddie.org.uk> 6 @license: GNU GPL (v2 or later), see COPYING.txt for details. 7 """ 8 9 from MoinMoin.action import cache 10 from SVGChartSupport import get_chart 11 12 Dependencies = ["pages"] 13 14 # Parser support. 15 16 class Parser: 17 18 "Format CSV-like data as an SVG chart." 19 20 extensions = [".csv"] 21 22 def __init__(self, raw, request, **kw): 23 self.raw = raw 24 self.request = request 25 self.data = [row.split() for row in raw.split("\n")] 26 27 def format(self, fmt): 28 29 "Format a chart using the given formatter 'fmt'." 30 31 request = self.request 32 page = request.page 33 _ = request.getText 34 35 # NOTE: Store and retrieve the width and height. 36 37 cache_key = cache.key(request, itemname=page.page_name, content=self.raw) 38 if not cache.exists(request, cache_key): 39 chart = get_chart(self.data, styles_url="%s/%s/css/svgchart.css" % (request.cfg.url_prefix_static, request.theme.name)) 40 cache.put(request, cache_key, chart, content_type="image/svg+xml") 41 42 request.write(fmt.div(1, css_class="svgchart")) 43 request.write(fmt.transclusion(1, data=cache.url(request, cache_key))) 44 request.write(fmt.text(_("SVG chart of CSV data."))) 45 request.write(fmt.transclusion(0)) 46 request.write(fmt.div(0)) 47 48 # vim: tabstop=4 expandtab shiftwidth=4