1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/parsers/SVGChart.py Sun May 29 01:54:00 2011 +0200
1.3 @@ -0,0 +1,48 @@
1.4 +# -*- coding: iso-8859-1 -*-
1.5 +"""
1.6 + MoinMoin - SVGChart
1.7 +
1.8 + @copyright: 2011 by Paul Boddie <paul@boddie.org.uk>
1.9 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.10 +"""
1.11 +
1.12 +from MoinMoin.action import cache
1.13 +from SVGChartSupport import get_chart
1.14 +
1.15 +Dependencies = ["pages"]
1.16 +
1.17 +# Parser support.
1.18 +
1.19 +class Parser:
1.20 +
1.21 + "Format CSV-like data as an SVG chart."
1.22 +
1.23 + extensions = [".csv"]
1.24 +
1.25 + def __init__(self, raw, request, **kw):
1.26 + self.raw = raw
1.27 + self.request = request
1.28 + self.data = [row.split() for row in raw.split("\n")]
1.29 +
1.30 + def format(self, fmt):
1.31 +
1.32 + "Format a chart using the given formatter 'fmt'."
1.33 +
1.34 + request = self.request
1.35 + page = request.page
1.36 + _ = request.getText
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 + if not cache.exists(request, cache_key):
1.42 + chart = get_chart(self.data, styles_url="%s/%s/css/svgchart.css" % (request.cfg.url_prefix_static, request.theme.name))
1.43 + cache.put(request, cache_key, chart, content_type="image/svg+xml")
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.text(_("SVG chart of CSV data.")))
1.48 + request.write(fmt.transclusion(0))
1.49 + request.write(fmt.div(0))
1.50 +
1.51 +# vim: tabstop=4 expandtab shiftwidth=4