root/tags/0.4.1/chavier/app.py

Revision 113, 3.4 kB (checked in by lgs, 4 years ago)

Entry point for chavier

Line 
1# Copyright (c) 2007-2008 by Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
2#
3# This file is part of Chavier.
4#
5# Chavier is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# Chavier is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with Chavier.  If not, see <http://www.gnu.org/licenses/>.
17
18import cairo
19
20from pycha.chart import DEFAULT_OPTIONS
21import pycha.bar
22import pycha.line
23import pycha.pie
24import pycha.scatter
25
26from chavier.gui import GUI
27
28class App(object):
29
30    CHART_TYPES = (
31        pycha.bar.VerticalBarChart,
32        pycha.bar.HorizontalBarChart,
33        pycha.line.LineChart,
34        pycha.pie.PieChart,
35        pycha.scatter.ScatterplotChart,
36        )
37
38    (VERTICAL_BAR_TYPE,
39     HORIZONTAL_BAR_TYPE,
40     LINE_TYPE,
41     PIE_TYPE,
42     SCATTER_TYPE) = range(len(CHART_TYPES))
43
44    OPTIONS_TYPES = dict(
45        axis=dict(
46            lineWidth=float,
47            lineColor=str,
48            tickSize=float,
49            labelColor=str,
50            labelFont=str,
51            labelFontSize=int,
52            labelWidth=float,
53            x=dict(
54                hide=bool,
55                ticks=list,
56                tickCount=int,
57                tickPrecision=int,
58                range=list,
59                rotate=float,
60                label=unicode,
61                ),
62            y=dict(
63                hide=bool,
64                ticks=list,
65                tickCount=int,
66                tickPrecision=int,
67                range=list,
68                rotate=float,
69                label=unicode,
70                ),
71            ),
72        background=dict(
73            hide=bool,
74            baseColor=str,
75            chartColor=str,
76            lineColor=str,
77            lineWidth=float,
78            ),
79        legend=dict(
80            opacity=float,
81            borderColor=str,
82            hide=bool,
83            position=dict(
84                top=int,
85                left=int,
86                bottom=int,
87                right=int,
88                )
89            ),
90        padding=dict(
91            left=int,
92            right=int,
93            top=int,
94            bottom=int,
95            ),
96        stroke=dict(
97            color=str,
98            hide=bool,
99            shadow=bool,
100            width=int,
101            ),
102        fillOpacity=float,
103        shouldFill=bool,
104        barWidthFillFraction=float,
105        pieRadius=float,
106        colorScheme=str,
107        title=unicode,
108        titleFont=str,
109        titleFontSize=int,
110        )
111
112    def __init__(self):
113        self.gui = GUI(self)
114
115    def run(self):
116        self.gui.run()
117
118    def get_default_options(self):
119        return DEFAULT_OPTIONS
120
121    def get_chart(self, datasets, options, chart_type, width, height):
122        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
123        chart_factory = self.CHART_TYPES[chart_type]
124        chart = chart_factory(surface, options)
125        chart.addDataset(datasets)
126        chart.render()
127        return chart
128
129def main():
130    app = App()
131    app.run()
132    return 0
133   
134if __name__ == '__main__':
135    main()
Note: See TracBrowser for help on using the browser.