2024-11-14 13:45:57 +03:00
|
|
|
import pandas as pd
|
|
|
|
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout
|
|
|
|
|
import pyqtgraph as pg
|
|
|
|
|
|
|
|
|
|
from base.base import BasePlotWidget
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PlotWidget(BasePlotWidget):
|
|
|
|
|
|
|
|
|
|
def _create_widget(self, dataframe: pd.DataFrame) -> QWidget:
|
|
|
|
|
widget = QWidget()
|
|
|
|
|
layout = QVBoxLayout()
|
|
|
|
|
|
|
|
|
|
time_axis = dataframe["time"]
|
|
|
|
|
|
|
|
|
|
for channel, signals in self._plot_channels.items():
|
|
|
|
|
plot_widget = pg.PlotWidget(title=channel)
|
|
|
|
|
plot_widget.showGrid(x=True, y=True)
|
|
|
|
|
legend = pg.LegendItem((80, 60), offset=(70, 20))
|
|
|
|
|
legend.setParentItem(plot_widget.graphicsItem())
|
|
|
|
|
|
|
|
|
|
for signal in signals:
|
|
|
|
|
plot = plot_widget.plot(time_axis, dataframe[signal["name"]], pen=signal["pen"])
|
2024-11-14 16:56:45 +03:00
|
|
|
if signal["zoom"]:
|
|
|
|
|
max_value = max(dataframe[signal["name"]])
|
|
|
|
|
plot_widget.setYRange(max_value - 150, max_value)
|
|
|
|
|
plot_widget.setInteractive(False)
|
2024-11-14 13:45:57 +03:00
|
|
|
legend.addItem(plot, signal["name"])
|
|
|
|
|
|
|
|
|
|
layout.addWidget(plot_widget)
|
|
|
|
|
|
|
|
|
|
widget.setLayout(layout)
|
|
|
|
|
return widget
|
|
|
|
|
|
|
|
|
|
def build(self, data: list[pd.DataFrame]) -> None:
|
|
|
|
|
widgets = [self._create_widget(data_sample) for data_sample in data]
|
|
|
|
|
self._mediator.notify(self, widgets)
|