Changeset 70:3a19cb44ebdf

Show
Ignore:
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:
5 modified

Legend:

Unmodified
Added
Removed
  • examples/hbar_chart

    r63 r70  
    22  width: 600 
    33  height: 500 
    4   output_type: svg 
    54  legend:  
    65    hide: false 
     
    2019chart: 
    2120  type: hbar 
     21  output_type: svg 
    2222  dataset: 
    2323    - - Sales 
  • examples/line_chart

    r63 r70  
    22  width: 600 
    33  height: 500 
    4   output_type: png 
    54  legend:  
    65    hide: false 
     
    2019chart: 
    2120  type: line 
     21  output_type: png 
    2222  dataset: 
    2323    - - Sales 
  • examples/pie_chart

    r63 r70  
    22    width: 600 
    33    height: 400 
    4     output_type: png 
    54    background: {hide: true} 
    65    legend: {hide: true} 
     
    87chart: 
    98    type: pie 
     9    output_type: png 
    1010    dataset: 
    1111    {% for line in o.lines %} 
  • examples/vbar_chart

    r63 r70  
    22  width: 600 
    33  height: 500 
    4   output_type: svg 
    54  legend:  
    65    hide: false 
     
    2019chart: 
    2120  type: vbar 
     21  output_type: svg 
    2222  dataset: 
    2323    - - Sales 
  • relatorio/templates/chart.py

    r63 r70  
    3030from relatorio.templates import RelatorioStream 
    3131 
     32import cairo 
    3233import pycha 
    3334import pycha.pie 
     
    4142             } 
    4243_encode = genshi.output.encode 
     44 
    4345 
    4446class Template(NewTextTemplate): 
     
    6264 
    6365    def __call__(self, stream): 
     66        result = StringIO() 
    6467        yml = StringIO(_encode(self.text_serializer(stream))) 
    6568        chart_yaml = yaml.load(yml.read()) 
    6669        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']) 
    6882        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() 
    7089 
     90        return result 
     91