File: app.py

package info (click to toggle)
pycha 0.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 460 kB
  • ctags: 544
  • sloc: python: 4,476; makefile: 9
file content (173 lines) | stat: -rw-r--r-- 4,597 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Copyright(c) 2007-2010 by Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
#
# This file is part of Chavier.
#
# Chavier is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Chavier is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Chavier.  If not, see <http://www.gnu.org/licenses/>.

import cairo

from pycha.chart import DEFAULT_OPTIONS
from pycha.bar import HorizontalBarChart, VerticalBarChart
from pycha.line import LineChart
from pycha.pie import PieChart
from pycha.radial import RadialChart
from pycha.polygonal import PolygonalChart
from pycha.scatter import ScatterplotChart
from pycha.stackedbar import StackedVerticalBarChart, StackedHorizontalBarChart

from chavier.gui import GUI


class App(object):

    CHART_TYPES = (
        VerticalBarChart,
        HorizontalBarChart,
        LineChart,
        PieChart,
        RadialChart,
        PolygonalChart,
        ScatterplotChart,
        StackedVerticalBarChart,
        StackedHorizontalBarChart,
        )

    (VERTICAL_BAR_TYPE,
     HORIZONTAL_BAR_TYPE,
     LINE_TYPE,
     PIE_TYPE,
     RADIAL_TYPE,
     POLYGONAL_TYPE,
     SCATTER_TYPE,
     STACKED_VERTICAL_BAR_TYPE,
     STACKED_HORIZONTAL_BAR_TYPE) = range(len(CHART_TYPES))

    OPTIONS_TYPES = dict(
        axis=dict(
            lineWidth=float,
            lineColor=str,
            tickSize=float,
            labelColor=str,
            labelFont=str,
            labelFontSize=int,
            tickFont=str,
            tickFontSize=int,
            x=dict(
                hide=bool,
                ticks=list,
                tickCount=int,
                tickPrecision=int,
                range=list,
                rotate=float,
                label=unicode,
                interval=int,
                showLines=bool,
                ),
            y=dict(
                hide=bool,
                ticks=list,
                tickCount=int,
                tickPrecision=int,
                range=list,
                rotate=float,
                label=unicode,
                interval=int,
                showLines=bool,
                ),
            ),
        background=dict(
            hide=bool,
            baseColor=str,
            chartColor=str,
            lineColor=str,
            lineWidth=float,
            ),
        legend=dict(
            opacity=float,
            borderColor=str,
            borderWidth=int,
            hide=bool,
            legendFont=str,
            legendFontSize=str,
            position=dict(
                top=int,
                left=int,
                bottom=int,
                right=int,
                )
            ),
        padding=dict(
            left=int,
            right=int,
            top=int,
            bottom=int,
            ),
        stroke=dict(
            color=str,
            hide=bool,
            shadow=bool,
            width=int,
            ),
        yvals=dict(
            show=bool,
            inside=bool,
            fontSize=int,
            fontColor=str,
            skipSmallValues=bool,
            snapToOrigin=bool,
            renderer=str,
            ),
        fillOpacity=float,
        shouldFill=bool,
        barWidthFillFraction=float,
        pieRadius=float,
        colorScheme=dict(
            name=str,
            args=dict(
                initialColor=str,
                colors=list,
                ),
            ),
        title=unicode,
        titleColor=str,
        titleFont=str,
        titleFontSize=int,
        encoding=str,
        )

    def __init__(self):
        self.gui = GUI(self)

    def run(self):
        self.gui.run()

    def get_default_options(self):
        return DEFAULT_OPTIONS

    def get_chart(self, datasets, options, chart_type, width, height):
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
        chart_factory = self.CHART_TYPES[chart_type]
        chart = chart_factory(surface, options)
        chart.addDataset(datasets)
        chart.render()
        return chart


def main():
    app = App()
    app.run()
    return 0

if __name__ == '__main__':
    main()