root/trunk/chavier/app.py

Revision 175, 4.1 kB (checked in by lgs, 3 years ago)

Allow to specify the font of the ticks. Based on a patch by ged_AT_openhex.org. Fixes #26

Line 
1# Copyright(c) 2007-2009 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
21from pycha.bar import HorizontalBarChart, VerticalBarChart
22from pycha.line import LineChart
23from pycha.pie import PieChart
24from pycha.scatter import ScatterplotChart
25from pycha.stackedbar import StackedVerticalBarChart, StackedHorizontalBarChart
26
27from chavier.gui import GUI
28
29
30class App(object):
31
32    CHART_TYPES = (
33        VerticalBarChart,
34        HorizontalBarChart,
35        LineChart,
36        PieChart,
37        ScatterplotChart,
38        StackedVerticalBarChart,
39        StackedHorizontalBarChart,
40        )
41
42    (VERTICAL_BAR_TYPE,
43     HORIZONTAL_BAR_TYPE,
44     LINE_TYPE,
45     PIE_TYPE,
46     SCATTER_TYPE,
47     STACKED_VERTICAL_BAR_TYPE,
48     STACKED_HORIZONTAL_BAR_TYPE) = range(len(CHART_TYPES))
49
50    OPTIONS_TYPES = dict(
51        axis=dict(
52            lineWidth=float,
53            lineColor=str,
54            tickSize=float,
55            labelColor=str,
56            labelFont=str,
57            labelFontSize=int,
58            labelWidth=float,
59            tickFont=str,
60            tickFontSize=int,
61            x=dict(
62                hide=bool,
63                ticks=list,
64                tickCount=int,
65                tickPrecision=int,
66                range=list,
67                rotate=float,
68                label=unicode,
69                interval=int,
70                ),
71            y=dict(
72                hide=bool,
73                ticks=list,
74                tickCount=int,
75                tickPrecision=int,
76                range=list,
77                rotate=float,
78                label=unicode,
79                interval=int,
80                ),
81            ),
82        background=dict(
83            hide=bool,
84            baseColor=str,
85            chartColor=str,
86            lineColor=str,
87            lineWidth=float,
88            ),
89        legend=dict(
90            opacity=float,
91            borderColor=str,
92            hide=bool,
93            position=dict(
94                top=int,
95                left=int,
96                bottom=int,
97                right=int,
98                )
99            ),
100        padding=dict(
101            left=int,
102            right=int,
103            top=int,
104            bottom=int,
105            ),
106        stroke=dict(
107            color=str,
108            hide=bool,
109            shadow=bool,
110            width=int,
111            ),
112        yvals=dict(
113            show=bool,
114            inside=bool,
115            fontSize=int,
116            fontColor=str
117            ),
118        fillOpacity=float,
119        shouldFill=bool,
120        barWidthFillFraction=float,
121        pieRadius=float,
122        colorScheme=dict(
123            name=str,
124            args=dict(
125                initialColor=str,
126                colors=list,
127                ),
128            ),
129        title=unicode,
130        titleFont=str,
131        titleFontSize=int,
132        )
133
134    def __init__(self):
135        self.gui = GUI(self)
136
137    def run(self):
138        self.gui.run()
139
140    def get_default_options(self):
141        return DEFAULT_OPTIONS
142
143    def get_chart(self, datasets, options, chart_type, width, height):
144        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
145        chart_factory = self.CHART_TYPES[chart_type]
146        chart = chart_factory(surface, options)
147        chart.addDataset(datasets)
148        chart.render()
149        return chart
150
151
152def main():
153    app = App()
154    app.run()
155    return 0
156
157if __name__ == '__main__':
158    main()
Note: See TracBrowser for help on using the browser.