-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot_base.py
More file actions
72 lines (45 loc) · 1.95 KB
/
plot_base.py
File metadata and controls
72 lines (45 loc) · 1.95 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
"""Provides a buffer class to plot values"""
class PlotValueChannel:
"""Class for holding a specific number of values and handling minimum/maximum"""
def __init__(self, max_value_count: int):
self._x_data: list[float] = []
self._y_data: list[float] = []
self._max_value_count = max_value_count
self._counter = 0
def append_value(self, value: float):
"""Appends a value and returns updated minimum and maximum for plot"""
self._x_data.append(self._counter)
self._counter += 1
if len(self._x_data) > self._max_value_count:
self._x_data.pop(0)
self._y_data.append(value)
if len(self._y_data) > self._max_value_count:
self._y_data.pop(0)
def update_plot(self):
"""Function to update values to plot"""
@property
def data(self) -> tuple[list[float], list[float]]:
"""Returns x and y values"""
return [self._x_data, self._y_data]
class PlotHelper:
"""Class to handle values for plotting"""
def __init__(self):
self._data: dict[int, PlotValueChannel] = {}
@property
def data(self) -> dict[int, PlotValueChannel]:
"""Returns data with PlotValueChannels"""
return self._data
def append_value(self, channel: int, value: float):
"""Append value to channel buffer"""
self._data[channel].append_value(value)
def append_values(self, channel: int, values: list[float]):
"""Append values to channel buffer"""
for x in values:
self.append_value(channel, x)
def update(self):
"""Update plot"""
def _calc_layout_dimension(self, channel_count: int) -> tuple[int, int]:
"""Calculates layout for a specific number of channels, tries to grow
equal in both directions"""
layouts = {1: [1, 1], 2: [2, 1], 3: [3, 1], 4: [2, 2], 5: [3, 2], 6: [3, 2], 7: [4, 2], 8: [4, 2]}
return layouts[channel_count]