-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcharts.py
65 lines (56 loc) · 1.55 KB
/
charts.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
from castella import (
App,
CheckBox,
Text,
TextAlign,
Column,
Row,
Spacer,
State,
)
from castella.frame import Frame
from castella.bar_chart import BarChart, BarChartState
from castella.pie_chart import PieChart, PieChartState
bar_chart_state = BarChartState(label=[], value=[])
pie_chart_state = PieChartState(label=[], value=[])
foo = State(True)
bar = State(True)
def update_chart_state(ev=None) -> None:
label = []
value = []
if foo.value():
label.append("Foo")
value.append(50)
if bar.value():
label.append("Bar")
value.append(100)
bar_chart_state.set(label, value)
pie_chart_state.set(label, value)
foo.on_update(update_chart_state)
bar.on_update(update_chart_state)
update_chart_state()
App(
Frame("Chart", 1500, 500),
Column(
Spacer().fixed_height(10),
Row(
Column(
Row(
Text("Foo", align=TextAlign.RIGHT).erase_border(),
CheckBox(foo).fixed_width(40),
Spacer().fixed_width(10),
).fixed_height(40),
Row(
Text("Bar", align=TextAlign.RIGHT).erase_border(),
CheckBox(bar).fixed_width(40),
Spacer().fixed_width(10),
).fixed_height(40),
)
.fixed_width(100)
.spacing(10),
BarChart(bar_chart_state),
Spacer().fixed_width(10),
PieChart(pie_chart_state),
).fixed_width(1400),
),
).run()