-
Notifications
You must be signed in to change notification settings - Fork 654
Expand file tree
/
Copy pathexample_1.py
More file actions
160 lines (147 loc) · 3.61 KB
/
example_1.py
File metadata and controls
160 lines (147 loc) · 3.61 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import random
import flet as ft
import flet_charts as ftc
class MySpot(ftc.ScatterChartSpot):
def __init__(
self,
x: float,
y: float,
radius: float = 8.0,
color: ft.Colors = None,
show_tooltip: bool = False,
):
super().__init__(
x=x,
y=y,
radius=radius,
color=color,
show_tooltip=show_tooltip,
selected=y == 43,
)
flutter_logo_spots = [
MySpot(20, 14.5),
MySpot(20, 14.5),
MySpot(22, 16.5),
MySpot(24, 18.5),
MySpot(22, 12.5),
MySpot(24, 14.5),
MySpot(26, 16.5),
MySpot(24, 10.5),
MySpot(26, 12.5),
MySpot(28, 14.5),
MySpot(26, 8.5),
MySpot(28, 10.5),
MySpot(30, 12.5),
MySpot(28, 6.5),
MySpot(30, 8.5),
MySpot(32, 10.5),
MySpot(30, 4.5),
MySpot(32, 6.5),
MySpot(34, 8.5),
MySpot(34, 4.5),
MySpot(36, 6.5),
MySpot(38, 4.5),
# section 2
MySpot(20, 14.5),
MySpot(22, 12.5),
MySpot(24, 10.5),
MySpot(22, 16.5),
MySpot(24, 14.5),
MySpot(26, 12.5),
MySpot(24, 18.5),
MySpot(26, 16.5),
MySpot(28, 14.5),
MySpot(26, 20.5),
MySpot(28, 18.5),
MySpot(30, 16.5),
MySpot(28, 22.5),
MySpot(30, 20.5),
MySpot(32, 18.5),
MySpot(30, 24.5),
MySpot(32, 22.5),
MySpot(34, 20.5),
MySpot(34, 24.5),
MySpot(36, 22.5),
MySpot(38, 24.5),
# section 3
MySpot(10, 25),
MySpot(12, 23),
MySpot(14, 21),
MySpot(12, 27),
MySpot(14, 25),
MySpot(16, 23),
MySpot(14, 29),
MySpot(16, 27),
MySpot(18, 25),
MySpot(16, 31),
MySpot(18, 29),
MySpot(20, 27),
MySpot(18, 33),
MySpot(20, 31),
MySpot(22, 29),
MySpot(20, 35),
MySpot(22, 33),
MySpot(24, 31),
MySpot(22, 37),
MySpot(24, 35),
MySpot(26, 33),
MySpot(24, 39),
MySpot(26, 37),
MySpot(28, 35),
MySpot(26, 41),
MySpot(28, 39),
MySpot(30, 37),
MySpot(28, 43),
MySpot(30, 41),
MySpot(32, 39),
MySpot(30, 45),
MySpot(32, 43),
MySpot(34, 41),
MySpot(34, 45),
MySpot(36, 43),
MySpot(38, 45),
]
def get_random_spots():
"""Generates random spots for the scatter chart."""
return [
MySpot(
x=random.uniform(4, 50),
y=random.uniform(4, 50),
radius=random.uniform(4, 20),
)
for _ in range(len(flutter_logo_spots))
]
def main(page: ft.Page):
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
def handle_event(e: ftc.ScatterChartEvent):
if e.type == ftc.ChartEventType.TAP_DOWN:
e.control.spots = (
flutter_logo_spots
if (e.control.spots != flutter_logo_spots)
else get_random_spots()
)
page.add(
ft.Text(
"Tap on the chart to toggle between random spots and Flutter logo spots."
),
ftc.ScatterChart(
expand=True,
aspect_ratio=1.0,
min_x=0.0,
max_x=50.0,
min_y=0.0,
max_y=50.0,
left_axis=ftc.ChartAxis(show_labels=False),
right_axis=ftc.ChartAxis(show_labels=False),
top_axis=ftc.ChartAxis(show_labels=False),
bottom_axis=ftc.ChartAxis(show_labels=False),
show_tooltips_for_selected_spots_only=False,
on_event=handle_event,
animation=ft.Animation(
duration=ft.Duration(milliseconds=600),
curve=ft.AnimationCurve.FAST_OUT_SLOWIN,
),
spots=flutter_logo_spots,
),
)
ft.run(main)