This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpygal.py
103 lines (89 loc) · 2.54 KB
/
pygal.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from pyscript import window
import json
_colors = [
[255, 89, 149], [182, 227, 84], [254, 237, 108], [140, 237, 255],
[158, 111, 254], [137, 156, 161], [248, 248, 242], [191, 70, 70],
[81, 96, 131], [249, 38, 114], [130, 180, 20], [253, 151, 31],
[86, 194, 214], [128, 131, 132], [140, 84, 254], [70, 84, 87]
]
class _Chart:
def __init__(self, type, _plot_options={}):
self.title = ""
self.x_labels = ""
self._data = []
self._type = type
self._plot_options = _plot_options
def add(self, name, data):
self._data.append({
"name": name,
"color": f"rgba({','.join(map(str, _colors[len(self._data)%len(_colors)]))}, 0.75)",
"data": data
})
def render(self):
options = {
"chart": {
"type": self._type,
"height": 300,
"width": 400
},
"credits": {
"enabled": False
},
"title": {
"text": self.title
},
"xAxis": {
"categories": list(self.x_labels)
},
"legend": {
"layout": "vertical",
"align": "left",
"verticalAlign": "top",
"y": 50,
"borderWidth": 0
},
"yAxis": {
},
"series": self._data,
"plotOptions": self._plot_options
}
window.renderChart(json.dumps(options))
class Line(_Chart):
def __init__(self):
super().__init__("line")
class StackedLine(_Chart):
def __init__(self):
super().__init__("line", {
"area": {
"stacking": "percent"
},
"series": {
"stacking": "percent"
}
})
class Bar(_Chart):
def __init__(self):
super().__init__("column")
class StackedBar(_Chart):
def __init__(self):
super().__init__("column", {
"column": {
"stacking": "percent"
}
})
class HorizontalBar(_Chart):
def __init__(self):
super().__init__("bar")
class StackedHorizontalBar(_Chart):
def __init__(self):
super().__init__("bar", {
"bar": {
"stacking": "percent"
}
})
class XY(_Chart):
def __init__(self):
super().__init__("scatter")
class Pie(_Chart):
def __init__(self):
super().__init__("pie")