Skip to content

Commit

Permalink
Change chart data storage to a list of QPointF
Browse files Browse the repository at this point in the history
  • Loading branch information
ThunderTecke committed Apr 2, 2023
1 parent 8f9ed60 commit 6b1f8aa
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions PID_Py/SetupTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from PySide6.QtGui import QPainter, QActionGroup
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QDoubleSpinBox, QLabel, QFrame, QCheckBox, QTimeEdit, QScrollArea, QMenuBar, QMenu, QMessageBox
from PySide6.QtWidgets import QHBoxLayout, QGridLayout
from PySide6.QtCharts import QChart, QChartView, QLineSeries, QValueAxis
from PySide6.QtCore import QTimer, Qt, QTime
from PySide6.QtCharts import QChart, QChartView, QLineSeries, QValueAxis
from PySide6.QtCore import QTimer, Qt, QTime, QPointF

import logging

Expand Down Expand Up @@ -76,6 +76,8 @@ def __init__(self, pid: PID) -> None:
self.serie = QLineSeries()
self.serie.setName("SIN")

self.serieData = []

self.alpha = 0

self.chart.addSeries(self.serie)
Expand Down Expand Up @@ -388,22 +390,24 @@ def __init__(self, pid: PID) -> None:
# ===== Refreshing timer =====
self.refreshTimer = QTimer(self)
self.refreshTimer.timeout.connect(self.refreshData)
self.refreshTimer.start(25)
self.refreshTimer.start(1000)

self.logger.debug("SetupTool initialized")

def refreshData(self):
if (self.alpha < 2*np.pi):
self.xAxis.setRange(0, 2*np.pi)

self.serie.append(self.alpha, np.sin(self.alpha))
self.serieData.append(QPointF(self.alpha, np.sin(self.alpha)))
else:
self.xAxis.setRange(self.alpha - 2*np.pi, self.alpha)

self.serie.replace(self.serie.pointsVector()[1:])
self.serie.append(self.alpha, np.sin(self.alpha))
self.serieData.pop(0)
self.serieData.append(QPointF(self.alpha, np.sin(self.alpha)))

self.serie.replace(self.serieData)

self.alpha += 0.03
self.alpha += 0.05

def kpSetEnabled(self, enabled):
self.kpLabel.setEnabled(enabled)
Expand Down

0 comments on commit 6b1f8aa

Please sign in to comment.