|
Revision 113, 3.4 kB
(checked in by lgs, 4 years ago)
|
|
Entry point for chavier
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | import cairo |
|---|
| 19 | |
|---|
| 20 | from pycha.chart import DEFAULT_OPTIONS |
|---|
| 21 | import pycha.bar |
|---|
| 22 | import pycha.line |
|---|
| 23 | import pycha.pie |
|---|
| 24 | import pycha.scatter |
|---|
| 25 | |
|---|
| 26 | from chavier.gui import GUI |
|---|
| 27 | |
|---|
| 28 | class 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 | |
|---|
| 129 | def main(): |
|---|
| 130 | app = App() |
|---|
| 131 | app.run() |
|---|
| 132 | return 0 |
|---|
| 133 | |
|---|
| 134 | if __name__ == '__main__': |
|---|
| 135 | main() |
|---|