-
Notifications
You must be signed in to change notification settings - Fork 2
/
plot_handler.py
146 lines (100 loc) · 4.71 KB
/
plot_handler.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
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
from typing import List, Tuple
from widgets.new_widgets.themed_plot import ThemedPlot
from PyQt6.QtWidgets import *
from PyQt6.QtGui import *
from PyQt6.QtCore import *
from widgets.new_widgets.time_range_picker import TimeRangePicker
class PlotHandler:
plots: List[ThemedPlot] = []
time_range = (0, 0)
plot_height = 80
moving_average_seconds = 1
aggregation_interval = 1
horizontal_label_count = 15
vertical_label_count = 10
vertical_label_interval = 0.5
def add_plot(plot: ThemedPlot):
PlotHandler.plots.append(plot)
plot.set_time_range(*PlotHandler.time_range)
plot.set_height(PlotHandler.plot_height)
plot.set_moving_average(PlotHandler.moving_average_seconds)
plot.set_aggregation_interval(PlotHandler.aggregation_interval)
plot.set_labels(PlotHandler.horizontal_label_count, PlotHandler.vertical_label_count, PlotHandler.vertical_label_interval)
def add_plots(plots: List[ThemedPlot]):
PlotHandler.plots.extend(plots)
for plot in plots:
plot.set_time_range(*PlotHandler.time_range)
plot.set_height(PlotHandler.plot_height)
plot.set_moving_average(PlotHandler.moving_average_seconds)
plot.set_aggregation_interval(PlotHandler.aggregation_interval)
plot.set_labels(PlotHandler.horizontal_label_count, PlotHandler.vertical_label_count, PlotHandler.vertical_label_interval)
def remove_plot(plot: ThemedPlot):
plot.deleteLater()
PlotHandler.plots.remove(plot)
def remove_plot_at(index: int):
PlotHandler.plots[index].deleteLater()
PlotHandler.plots.pop(index)
def get_plot(index: int) -> ThemedPlot:
return PlotHandler.plots[index]
def plot_count() -> int:
return len(PlotHandler.plots)
def clear_plots():
for plot in PlotHandler.plots:
plot.deleteLater()
PlotHandler.plots.clear()
def erase_plots():
for plot in PlotHandler.plots:
plot.erase()
def redraw_plots():
# start = time.perf_counter_ns()
for plot in PlotHandler.plots:
plot.render_plot()
# print(f"Regenerated plots in {time.perf_counter_ns() - start} ns")
def regenerate_plots():
# start = time.perf_counter_ns()
for plot in PlotHandler.plots:
plot.set_moving_average(PlotHandler.moving_average_seconds)
# print(f"Regenerated plots in {time.perf_counter_ns() - start} ns")
def set_time_range(time_range: Tuple[int, int]):
if time_range == PlotHandler.time_range or time_range[0] > time_range[1]:
return
# start = time.perf_counter_ns()
PlotHandler.time_range = time_range
for plot in PlotHandler.plots:
plot.set_time_range(*time_range)
# print(f"Set time range in {time.perf_counter_ns() - start} ns")
def set_plot_height(height: int):
if height == PlotHandler.plot_height or height < 1:
return
PlotHandler.plot_height = height
for plot in PlotHandler.plots:
plot.set_height(height)
def set_aggregation_interval(interval: int):
if interval == PlotHandler.aggregation_interval or interval < 1:
return
PlotHandler.aggregation_interval = interval
for plot in PlotHandler.plots:
plot.set_aggregation_interval(interval)
def set_moving_average(moving_average_seconds: int):
if moving_average_seconds == PlotHandler.moving_average_seconds or moving_average_seconds < 1:
return
PlotHandler.moving_average_seconds = moving_average_seconds
for plot in PlotHandler.plots:
plot.set_moving_average(moving_average_seconds)
def set_labels(max_horizontal: int, max_vertical: int, vertical_interval: int):
if (max_horizontal == PlotHandler.horizontal_label_count and
max_vertical == PlotHandler.vertical_label_count and
vertical_interval == PlotHandler.vertical_label_interval):
return
PlotHandler.horizontal_label_count = max_horizontal
PlotHandler.vertical_label_count = max_vertical
PlotHandler.vertical_label_interval = vertical_interval
for plot in PlotHandler.plots:
plot.set_labels(max_horizontal, max_vertical, vertical_interval)
def convert_local_timezone(convert: bool):
for plot in PlotHandler.plots:
plot.convert_to_local_time = convert
plot.generate_labels()
if(TimeRangePicker.instance is not None):
TimeRangePicker.instance.convert_to_local_time = convert
TimeRangePicker.instance.update()