Skip to content

Commit c40e84d

Browse files
add wave_table get/set; improve auto scale algorithm
1 parent 26c289b commit c40e84d

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

cedargrove_waveviz.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ def height(self):
9999
"""The height of the plotted image in pixels."""
100100
return self._height
101101

102+
@property
103+
def wave_table(self):
104+
"""The synthio waveform array object."""
105+
return self._wave_table
106+
107+
@wave_table.setter
108+
def wave_table(self, new_wave_table):
109+
self._wave_table = new_wave_table
110+
# Instantiate the target bitmap
111+
self._bmp.fill(0)
112+
113+
# Plot grid and wave table
114+
self._plot_grid() # Plot the grid
115+
self._plot_wave() # Plot the wave table
116+
102117
def _plot_wave(self):
103118
"""Plot the wave_table as a bitmap. Extract samples from the wave
104119
table to fill the bitmap object's x-axis. Y-axis scale factor is
@@ -115,9 +130,13 @@ def _plot_wave(self):
115130
# Update the final point
116131
y_points[-1] = self._wave_table[-1]
117132

133+
# pylint: disable=nested-min-max
118134
# Calculate the y-axis scale factor and adjust y values
119-
self._max_sample_value = max(y_points)
120-
self._scale_y = self._height / self._max_sample_value / 2
135+
self._max_sample_value = max(max(y_points), abs(min(y_points)))
136+
if self._max_sample_value != 0:
137+
self._scale_y = self._height / self._max_sample_value / 2
138+
else:
139+
self._scale_y = 1
121140
for y in range(self._width):
122141
y_points[y] = self._y_offset - int(y_points[y] * self._scale_y)
123142

0 commit comments

Comments
 (0)