Skip to content

Commit 229bd2b

Browse files
committed
live plot improvements
1 parent 1d02ff1 commit 229bd2b

6 files changed

Lines changed: 53 additions & 9 deletions

File tree

xbot2_gui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ find_package(Qt6 COMPONENTS
1818
ShaderTools
1919
DataVisualization
2020
TextToSpeech
21+
Charts
2122
REQUIRED)
2223

2324
if(NOT EMSCRIPTEN)

xbot2_gui/LivePlot/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ qt_add_qml_module(xbot2_gui_liveplot
77
Plotter.qml
88
PlotterLegend.qml
99
Plot.qml
10+
SOURCES plotrebuilder.h plotrebuilder.cpp
1011
)
1112

13+
target_link_libraries(xbot2_gui_liveplot PRIVATE Qt6::Charts)
14+
1215
target_link_libraries(xbot2_gui PRIVATE xbot2_gui_liveplotplugin)

xbot2_gui/LivePlot/Plot.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ MultiPaneResponsiveLayout {
6363
spacing: 3
6464

6565
Button {
66+
width: parent.width
6667
text: 'Reset'
6768
onClicked: livePlot.resetView()
6869
}
@@ -78,11 +79,10 @@ MultiPaneResponsiveLayout {
7879
font.pointSize: 10
7980
}
8081

81-
DoubleSpinBox {
82+
SpinBox {
8283
id: rangeSpin
8384
from: 0
8485
to: 1000
85-
stepSize: 1
8686
value: 10
8787
}
8888
}

xbot2_gui/LivePlot/Plotter.qml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ import QtQuick
22
import QtCharts
33
import QtQuick.Controls
44
import QtQuick.Layouts
5+
56
import Common
67

78
Item {
89

10+
PlotRebuilder {
11+
id: rebuilder
12+
}
13+
914
// public
1015
property Item plotterLegend
1116

@@ -46,17 +51,22 @@ Item {
4651
}
4752

4853
function rebuild() {
54+
55+
if(_rebuilding) {
56+
return
57+
}
58+
4959
_rebuilding = true
60+
61+
62+
5063
for(let i = 0; i < chart.count; i++) {
5164

5265
// save points, type, name
5366
let series = chart.series(i)
5467
console.log(series, series.name)
5568

56-
let points = Array(series.count)
57-
for(var k = 0; k < series.count; k++) {
58-
points[k] = series.at(k)
59-
}
69+
let points = rebuilder.getPoints(series)
6070
let type = series.type
6171
let name = series.name
6272

@@ -66,15 +76,14 @@ Item {
6676
// create
6777
series = chart.createSeries(type,
6878
name);
79+
6980
series.useOpenGL = true
7081
series.antialiasing = false
7182
series.axisX = axisTime
7283
series.axisY = axisValueLeft
7384

7485
// fill with saved points
75-
for(let k = 0; k < points.length; k++) {
76-
series.append(points[k].x, points[k].y)
77-
}
86+
rebuilder.setPoints(series, points)
7887

7988
// update seriesdata
8089
currSeries[name].series = series
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "plotrebuilder.h"
2+

xbot2_gui/LivePlot/plotrebuilder.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef PLOTREBUILDER_H
2+
#define PLOTREBUILDER_H
3+
4+
#include <QtCharts/QtCharts>
5+
#include <QtCharts/QXYSeries>
6+
#include <QtQmlCore/QtQmlCore>
7+
8+
class PlotRebuilder: public QObject
9+
{
10+
Q_OBJECT
11+
12+
public:
13+
14+
QML_ELEMENT
15+
16+
Q_INVOKABLE static QList<QPointF> getPoints(const QXYSeries* s)
17+
{
18+
qInfo() << "saving" << s->points().size() << "points from" << (void*)s;
19+
return s->points();
20+
}
21+
22+
Q_INVOKABLE static void setPoints(QXYSeries* s, const QList<QPointF>& points)
23+
{
24+
qInfo() << "appending" << points.size() << "points to" << (void*)s;
25+
s->append(points);
26+
}
27+
};
28+
29+
#endif // PLOTREBUILDER_H

0 commit comments

Comments
 (0)