|
Revision 169, 1.9 kB
(checked in by lgs, 17 months ago)
|
|
Big refactor about how the colors scheme are created and used. See #29
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | import sys |
|---|
| 19 | |
|---|
| 20 | import cairo |
|---|
| 21 | |
|---|
| 22 | import pycha.stackedbar |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | def stackedBarChart(output, chartFactory): |
|---|
| 26 | surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 400, 200) |
|---|
| 27 | |
|---|
| 28 | dataSet = ( |
|---|
| 29 | ('internal', [(0, 8), (1, 10), (2, 5), (3, 6)]), |
|---|
| 30 | ('external', [(0, 5), (1, 2), (2, 4), (3, 8)]), |
|---|
| 31 | ) |
|---|
| 32 | |
|---|
| 33 | options = { |
|---|
| 34 | 'background': { |
|---|
| 35 | 'chartColor': '#ffeeff', |
|---|
| 36 | 'baseColor': '#ffffff', |
|---|
| 37 | 'lineColor': '#444444', |
|---|
| 38 | }, |
|---|
| 39 | 'colorScheme': { |
|---|
| 40 | 'name': 'gradient', |
|---|
| 41 | 'args': { |
|---|
| 42 | 'initialColor': 'red', |
|---|
| 43 | }, |
|---|
| 44 | }, |
|---|
| 45 | 'legend': { |
|---|
| 46 | 'hide': True, |
|---|
| 47 | }, |
|---|
| 48 | 'padding': { |
|---|
| 49 | 'left': 75, |
|---|
| 50 | 'bottom': 55, |
|---|
| 51 | }, |
|---|
| 52 | 'title': 'Sample Chart' |
|---|
| 53 | } |
|---|
| 54 | chart = chartFactory(surface, options) |
|---|
| 55 | |
|---|
| 56 | chart.addDataset(dataSet) |
|---|
| 57 | chart.render() |
|---|
| 58 | |
|---|
| 59 | surface.write_to_png(output) |
|---|
| 60 | |
|---|
| 61 | if __name__ == '__main__': |
|---|
| 62 | if len(sys.argv) > 1: |
|---|
| 63 | output = sys.argv[1] |
|---|
| 64 | else: |
|---|
| 65 | output = 'stackedbarchart.png' |
|---|
| 66 | stackedBarChart('v' + output, pycha.stackedbar.StackedVerticalBarChart) |
|---|
| 67 | stackedBarChart('h' + output, pycha.stackedbar.StackedHorizontalBarChart) |
|---|