diff --git a/Modules/Graph/Graph.cpp b/Modules/Graph/Graph.cpp index 37da61de630bbf0a58b49d6fa598ef40036821c2..7e78bba76b9343aeba2a629e3f38b7fd8ae113ea 100644 --- a/Modules/Graph/Graph.cpp +++ b/Modules/Graph/Graph.cpp @@ -93,8 +93,7 @@ void Graph::onClearClicked() { for (auto graph : graphs) graph->data()->clear(); - - // plot->replot(); + plot->replot(); } void Graph::onStopClicked(bool checked) @@ -125,14 +124,21 @@ void Graph::onSubscriptionAdded(const TopicAndFieldFilter& filter) graphs.append(graph); buffersX.append(QVector<double>()); buffersY.append(QVector<double>()); + + qDebug() << "Graph index:" << graphs.indexOf(graph); } } void Graph::onSubscriptionRemoved(const TopicAndFieldFilter& filter) { + qDebug() << "Removing filter" << filter.toString(); if (filters.contains(filter)) { int index = filters.indexOf(filter); + qDebug() << "Filter found, index:" << index; + + plot->removeGraph(graphs[index]); + plot->replot(); filters.removeAt(index); graphs.removeAt(index); @@ -202,8 +208,20 @@ void Graph::onMsgReceived(const ModuleMessage& msg) double x = msg.getField("timestamp").getUInteger(0) / 1e6; double y = value.getDouble(0); - bufferX.append(x); - bufferY.append(y); + // Check if the timestamp resets + if (bufferX.last() < x) + { + bufferX.append(x); + bufferY.append(y); + } + else + { + bufferX.clear(); + bufferY.clear(); + + auto graph = graphs[index]; + graph->data()->clear(); + } } } } diff --git a/Modules/Graph/Graph.h b/Modules/Graph/Graph.h index e595a701c2d5688c1dca609e221790ac37dc8938..041cede4c1078ea80e9017ea0ecb419411eeb9c1 100644 --- a/Modules/Graph/Graph.h +++ b/Modules/Graph/Graph.h @@ -47,7 +47,7 @@ private: QList<QVector<double>> buffersY; QTimer updaterTimer; - int updatePeriod = 1000 / 10; + int updatePeriod = 1000 / 5; // 5fps bool stopped = false; bool following = true;