[ui/plots] fixing error if nothing has been plotted, the gui could not close

This commit is contained in:
wendtalexander 2024-10-23 11:08:54 +02:00
parent 75619cf1c8
commit 574e9a8110

View File

@ -16,6 +16,7 @@ class Continously:
self.figure = figure self.figure = figure
self.buffer = buffer self.buffer = buffer
self.last_plotted_index = 0 self.last_plotted_index = 0
self.timer = QTimer()
def plot(self, *args, **kwargs): def plot(self, *args, **kwargs):
self.figure.setBackground("w") self.figure.setBackground("w")
@ -36,7 +37,6 @@ class Continously:
) )
# self.plot_index = 0 # self.plot_index = 0
self.timer = QTimer()
self.CHUNK_PLOT = int(self.buffer.samplerate / 6) self.CHUNK_PLOT = int(self.buffer.samplerate / 6)
self.PLOT_HISTORY = 500_000 # The amount of data you want to keep on screen self.PLOT_HISTORY = 500_000 # The amount of data you want to keep on screen
self.timer.setInterval(150) self.timer.setInterval(150)
@ -70,18 +70,19 @@ class Continously:
def stop_plotting(self): def stop_plotting(self):
self.timer.stop() self.timer.stop()
total_count = self.buffer.totalcount() if self.last_plotted_index > 0:
times, items = self.buffer.read( total_count = self.buffer.totalcount()
self.last_plotted_index, times, items = self.buffer.read(
extend=total_count - self.last_plotted_index, self.last_plotted_index,
) extend=total_count - self.last_plotted_index,
self.time = np.concatenate((self.time, times))[-self.PLOT_HISTORY :] )
self.data = np.concatenate((self.data, items))[-self.PLOT_HISTORY :] self.time = np.concatenate((self.time, times))[-self.PLOT_HISTORY :]
self.line.setData( self.data = np.concatenate((self.data, items))[-self.PLOT_HISTORY :]
self.time, self.line.setData(
self.data, self.time,
) self.data,
self.last_plotted_index += total_count - self.last_plotted_index )
self.last_plotted_index += total_count - self.last_plotted_index
def refresh(self): def refresh(self):
self.continous_ax.enableAutoRange() self.continous_ax.enableAutoRange()