|
Revision 169, 2.1 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.bar |
|---|
| 23 | |
|---|
| 24 | from lines import lines |
|---|
| 25 | |
|---|
| 26 | def barChart(output, chartFactory): |
|---|
| 27 | surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 400, 200) |
|---|
| 28 | |
|---|
| 29 | dataSet = ( |
|---|
| 30 | ('lines', [(i, l[1]) for i, l in enumerate(lines)]), |
|---|
| 31 | ) |
|---|
| 32 | |
|---|
| 33 | options = { |
|---|
| 34 | 'axis': { |
|---|
| 35 | 'x': { |
|---|
| 36 | 'ticks': [dict(v=i, label=l[0]) for i, l in enumerate(lines)], |
|---|
| 37 | 'label': 'Files', |
|---|
| 38 | 'rotate': 25, |
|---|
| 39 | }, |
|---|
| 40 | 'y': { |
|---|
| 41 | 'tickCount': 4, |
|---|
| 42 | 'rotate': 25, |
|---|
| 43 | 'label': 'Lines' |
|---|
| 44 | } |
|---|
| 45 | }, |
|---|
| 46 | 'background': { |
|---|
| 47 | 'chartColor': '#ffeeff', |
|---|
| 48 | 'baseColor': '#ffffff', |
|---|
| 49 | 'lineColor': '#444444' |
|---|
| 50 | }, |
|---|
| 51 | 'colorScheme': { |
|---|
| 52 | 'name': 'gradient', |
|---|
| 53 | 'args': { |
|---|
| 54 | 'initialColor': 'red', |
|---|
| 55 | }, |
|---|
| 56 | }, |
|---|
| 57 | 'legend': { |
|---|
| 58 | 'hide': True, |
|---|
| 59 | }, |
|---|
| 60 | 'padding': { |
|---|
| 61 | 'left': 75, |
|---|
| 62 | 'bottom': 55, |
|---|
| 63 | }, |
|---|
| 64 | 'title': 'Sample Chart' |
|---|
| 65 | } |
|---|
| 66 | chart = chartFactory(surface, options) |
|---|
| 67 | |
|---|
| 68 | chart.addDataset(dataSet) |
|---|
| 69 | chart.render() |
|---|
| 70 | |
|---|
| 71 | surface.write_to_png(output) |
|---|
| 72 | |
|---|
| 73 | if __name__ == '__main__': |
|---|
| 74 | if len(sys.argv) > 1: |
|---|
| 75 | output = sys.argv[1] |
|---|
| 76 | else: |
|---|
| 77 | output = 'barchart.png' |
|---|
| 78 | barChart('v' + output, pycha.bar.VerticalBarChart) |
|---|
| 79 | barChart('h' + output, pycha.bar.HorizontalBarChart) |
|---|