Changeset 70:3a19cb44ebdf
- Timestamp:
- 10/30/08 05:03:36 (17 months ago)
- Author:
- Nicolas ?vrard <nicoe@…>
- Branch:
- default
- Message:
-
Follow PyCha? official interface instead of my own
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r63
|
r70
|
|
| 2 | 2 | width: 600 |
| 3 | 3 | height: 500 |
| 4 | | output_type: svg |
| 5 | 4 | legend: |
| 6 | 5 | hide: false |
| … |
… |
|
| 20 | 19 | chart: |
| 21 | 20 | type: hbar |
| | 21 | output_type: svg |
| 22 | 22 | dataset: |
| 23 | 23 | - - Sales |
-
|
r63
|
r70
|
|
| 2 | 2 | width: 600 |
| 3 | 3 | height: 500 |
| 4 | | output_type: png |
| 5 | 4 | legend: |
| 6 | 5 | hide: false |
| … |
… |
|
| 20 | 19 | chart: |
| 21 | 20 | type: line |
| | 21 | output_type: png |
| 22 | 22 | dataset: |
| 23 | 23 | - - Sales |
-
|
r63
|
r70
|
|
| 2 | 2 | width: 600 |
| 3 | 3 | height: 400 |
| 4 | | output_type: png |
| 5 | 4 | background: {hide: true} |
| 6 | 5 | legend: {hide: true} |
| … |
… |
|
| 8 | 7 | chart: |
| 9 | 8 | type: pie |
| | 9 | output_type: png |
| 10 | 10 | dataset: |
| 11 | 11 | {% for line in o.lines %} |
-
|
r63
|
r70
|
|
| 2 | 2 | width: 600 |
| 3 | 3 | height: 500 |
| 4 | | output_type: svg |
| 5 | 4 | legend: |
| 6 | 5 | hide: false |
| … |
… |
|
| 20 | 19 | chart: |
| 21 | 20 | type: vbar |
| | 21 | output_type: svg |
| 22 | 22 | dataset: |
| 23 | 23 | - - Sales |
-
|
r63
|
r70
|
|
| 30 | 30 | from relatorio.templates import RelatorioStream |
| 31 | 31 | |
| | 32 | import cairo |
| 32 | 33 | import pycha |
| 33 | 34 | import pycha.pie |
| … |
… |
|
| 41 | 42 | } |
| 42 | 43 | _encode = genshi.output.encode |
| | 44 | |
| 43 | 45 | |
| 44 | 46 | class Template(NewTextTemplate): |
| … |
… |
|
| 62 | 64 | |
| 63 | 65 | def __call__(self, stream): |
| | 66 | result = StringIO() |
| 64 | 67 | yml = StringIO(_encode(self.text_serializer(stream))) |
| 65 | 68 | chart_yaml = yaml.load(yml.read()) |
| 66 | 69 | chart_info = chart_yaml['chart'] |
| 67 | | chart = PYCHA_TYPE[chart_info['type']](chart_yaml['options']) |
| | 70 | chart_type = chart_info['output_type'] |
| | 71 | if chart_type == 'png': |
| | 72 | surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, |
| | 73 | chart_yaml['options']['width'], |
| | 74 | chart_yaml['options']['height']) |
| | 75 | elif chart_type == 'svg': |
| | 76 | surface = cairo.SVGSurface(result, chart_yaml['options']['width'], |
| | 77 | chart_yaml['options']['height']) |
| | 78 | else: |
| | 79 | raise NotImplementedError |
| | 80 | |
| | 81 | chart = PYCHA_TYPE[chart_info['type']](surface, chart_yaml['options']) |
| 68 | 82 | chart.addDataset(chart_info['dataset']) |
| 69 | | return chart.render() |
| | 83 | chart.render() |
| | 84 | |
| | 85 | if chart_type == 'png': |
| | 86 | surface.write_to_png(result) |
| | 87 | elif chart_type == 'svg': |
| | 88 | surface.finish() |
| 70 | 89 | |
| | 90 | return result |
| | 91 | |