-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackedbar.py
More file actions
executable file
·34 lines (22 loc) · 1.03 KB
/
stackedbar.py
File metadata and controls
executable file
·34 lines (22 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from barchart import Barchart
class StackedBar(Barchart):
"""A class for creating stacked bar charts."""
def get_data_max(self):
summed_series = [sum(x) for x in zip(*self.data)]
return max(summed_series)
def get_position(self, series_index, datum_index, groups, series_count):
total_parts = groups
bar_width = self.bar_width
x = series_index
space_per_group = bar_width + self.group_gap
x_start = self.start_gap + (datum_index * space_per_group)
return x_start, x_start + bar_width
def get_y_position(self, series_index, datum_index, groups, series_count):
y_start = 0
for i in range(series_index):
y_start += self.data[i][datum_index]
return y_start, y_start + self.data[series_index][datum_index]
def get_total_width(self):
groups = self.count_groups()
series_count = len(self.data)
return self.start_gap + self.end_gap + (groups * self.bar_width) + ((groups - 1) * self.group_gap)