blob: 2fb5eab5f5c047856e66aaf55cbada77d0045103 [file] [log] [blame]
Yulia Portnova6d72d7f2015-02-04 16:48:50 +02001from GChartWrapper import VerticalBarGroup
2from GChartWrapper import Line
3from GChartWrapper import constants
4
5
Yulia Portnova919f3be2015-02-06 12:49:22 +02006COLORS = ["1569C7", "81D8D0", "307D7E", "5CB3FF", "blue", "indigo"]
Yulia Portnova6d72d7f2015-02-04 16:48:50 +02007constants.MARKERS += 'E' # append E marker to available markers
8
9
10def render_vertical_bar(title, legend, dataset, width=700, height=400, scale_x=None,
11 scale_y=None):
12 """
13 Renders vertical bar group chart
14
15 :param legend - list of legend values.
16 Example: ['bar1', 'bar2', 'bar3']
17 :param dataset - list of values for each type (value, deviation)
18 Example:
19 [
20 [(10,(9,11)), (11, (3,12)), (10,(9,11))], # bar1 values
21 [(30,(29,33)),(35,(33,36)), (30,(29,33))], # bar2 values
22 [(20,(19,21)),(20,(13, 24)), (20,(19,21))] # bar 3 values
23 ]
24 :param width - width of chart
25 :param height - height of chart
26 :param scale_x - x ace scale
27 :param scale_y - y ace scale
28
29 :returns url to chart
30
31 dataset example:
32 {
33 'relese_1': {
34 'randr': (1, 0.1),
35 'randwr': (2, 0.2)
36 }
37 'release_2': {
38 'randr': (3, 0.3),
39 'randwr': (4, 0.4)
40 }
41 }
42 """
43 bar = VerticalBarGroup([], encoding='text')
44 bar.title(title)
45
46 values = []
47 deviations = []
48
49 for d in dataset:
50 val, dev = zip(*d)
51
52 display_dev = []
53 for i in range(len(val)):
54 display_dev.append((val[i]-dev[i], val[i]+dev[i]))
55 values.append(val)
56 # deviations.extend(zip(*dev))
57 deviations.extend(zip(*display_dev))
58
59 bar.dataset(values + deviations, series=len(values))
Yulia Portnova0d2bd0a2015-02-11 17:42:44 +020060 bar.axes.type('xyy')
61 bar.axes.label(2, None, 'kb/s')
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020062 if scale_x:
63 bar.axes.label(0, *scale_x)
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020064
Yulia Portnova919f3be2015-02-06 12:49:22 +020065 max_value = (max([max(l) for l in values + deviations]))
66 bar.axes.range(1, 0, max_value)
Yulia Portnova0d2bd0a2015-02-11 17:42:44 +020067 bar.axes.style(1, 'N*s*')
68
Yulia Portnova919f3be2015-02-06 12:49:22 +020069 bar.scale(0, max_value)
Yulia Portnova0d2bd0a2015-02-11 17:42:44 +020070
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020071 bar.bar('r', '.1', '1')
72 for i in range(len(legend)):
73 bar.marker('E', '000000', '%s:%s' % ((len(values) + i*2), i),
74 '', '1:10')
75 bar.legend(*legend)
76 bar.color(*COLORS[:len(values)])
77 bar.size(width, height)
78
Yulia Portnova919f3be2015-02-06 12:49:22 +020079 return bar
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020080
81
Yulia Portnova919f3be2015-02-06 12:49:22 +020082def render_lines(title, legend, dataset, scale_x, width=700, height=400):
83 line = Line([], encoding="text")
84 line.title(title)
85 line.dataset(dataset)
86
87 line.axes('xy')
88 max_value = (max([max(l) for l in dataset]))
89 line.axes.range(1, 0, max_value)
90 line.scale(0, max_value)
91 line.axes.label(0, *scale_x)
92 line.legend(*legend)
93 line.color(*COLORS[:len(legend)])
94 line.size(width, height)
95 return str(line)