|
Revision 169, 1.8 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.line |
|---|
| 23 | |
|---|
| 24 | from lines import lines |
|---|
| 25 | |
|---|
| 26 | def lineChart(output): |
|---|
| 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 | }, |
|---|
| 38 | 'y': { |
|---|
| 39 | 'tickCount': 4, |
|---|
| 40 | } |
|---|
| 41 | }, |
|---|
| 42 | 'background': { |
|---|
| 43 | 'color': '#eeeeff', |
|---|
| 44 | 'lineColor': '#444444' |
|---|
| 45 | }, |
|---|
| 46 | 'colorScheme': { |
|---|
| 47 | 'name': 'gradient', |
|---|
| 48 | 'args': { |
|---|
| 49 | 'initialColor': 'blue', |
|---|
| 50 | }, |
|---|
| 51 | }, |
|---|
| 52 | 'legend': { |
|---|
| 53 | 'hide': True, |
|---|
| 54 | }, |
|---|
| 55 | 'padding': { |
|---|
| 56 | 'left': 55, |
|---|
| 57 | 'bottom': 40, |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | chart = pycha.line.LineChart(surface, options) |
|---|
| 61 | |
|---|
| 62 | chart.addDataset(dataSet) |
|---|
| 63 | chart.render() |
|---|
| 64 | |
|---|
| 65 | surface.write_to_png(output) |
|---|
| 66 | |
|---|
| 67 | if __name__ == '__main__': |
|---|
| 68 | if len(sys.argv) > 1: |
|---|
| 69 | output = sys.argv[1] |
|---|
| 70 | else: |
|---|
| 71 | output = 'linechart.png' |
|---|
| 72 | lineChart(output) |
|---|