Skip to content

Commit dbe9608

Browse files
committed
added a way to update data dynamically
Also removed unwanted code
1 parent 4c7c5bc commit dbe9608

File tree

2 files changed

+31
-42
lines changed

2 files changed

+31
-42
lines changed

chart.cpp

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,73 +19,59 @@ Chart::Chart(QObject *parent) : QObject(parent) {
1919
void Chart::startUpdating(const QList<QLineSeries *> &seriesList, const QVector<qreal> &values, qreal windowWidth,
2020
qreal frequency) {
2121

22+
c_seriesList = seriesList;
23+
c_windowWidth = windowWidth;
24+
2225
// this will wait to get the frequency first
2326
if (frequency == 0) {
2427
return;
2528
}
2629

2730
auto valuesVector = std::vector<qreal>(values.begin(), values.end());
2831
RowVectorXd vector = Map<RowVectorXd, Unaligned>(valuesVector.data(), (long) valuesVector.size());
29-
// cout << vector << endl;
3032

31-
c_seriesList = seriesList;
3233
matrix->row(valueCounter) = vector;
33-
// cout << matrix->row(0) << endl;
34-
// cout << "hello" << endl;
3534

36-
// qreal xAdjustment = 20.0 / (10 * values.length());
37-
// qreal yMultiplier = 3.0 / qreal(values.length());
35+
xAdjustment = 20.0 / (10 * values.length());
36+
yMultiplier = 3.0 / qreal(values.length());
37+
3838
valueCounter += 1;
39-
// qInfo() << windowWidth;
40-
41-
// for (int i = 0; i < values.length(); i++) {
42-
// QVector<QPointF> data;
43-
// for (int j = 0; j < seriesList.length(); ++j) {
44-
// data.append(QPointF(valueCounter, values[i]));
45-
// }
46-
// m_data.append(data);
47-
// }
48-
// qInfo() << m_data;
49-
50-
// tempData.append(values);
51-
52-
// for (int i = 0; i < values.length(); ++i) {
53-
//// seriesList[i]->clear();
54-
//// seriesList[i].remo
55-
////
56-
//// seriesList[i]->append(QPointF(2.5, QRandomGenerator::global()->bounded(5) - 2.5));
57-
//// qInfo() << seriesList[i]->points().length();
58-
//
59-
//// qInfo() << valueCounter;
60-
// m_data.append(QPointF(valueCounter, values[i]));
61-
// }
62-
// qInfo() << m_data.length() << valueCounter;
63-
// if (valueCounter > windowWidth) {
64-
// m_data.removeFirst();
65-
// valueCounter = 0;
66-
// }
6739

6840
if (valueCounter == frequency) {
6941
dataUpdater.start();
70-
// qInfo() << tempData;
7142
valueCounter = 0;
7243
}
7344
}
7445

7546
void Chart::updateAllSeries() {
76-
pointCounter += 1;
7747

7848
qInfo() << "updates called";
7949
qInfo() << tempData.length();
8050

81-
// tempData.clear();
8251
removeZeroRows(*matrix);
83-
cout << matrix->colwise().mean() << endl;
84-
// exit(0);
52+
RowVectorXd meanData = matrix->colwise().mean().normalized();
53+
54+
for (int i = 0; i < meanData.size(); i++) {
55+
QVector<QPointF> data;
56+
for (int j = 0; j < c_seriesList.length(); ++j) {
57+
data.append(QPointF(pointCounter / 2, meanData[i]));
58+
}
59+
m_data.append(data);
60+
}
61+
62+
qInfo() << m_data.size() << c_windowWidth << pointCounter/2;
63+
64+
for (auto &i : c_seriesList) {
65+
i->replace(m_data);
66+
}
67+
68+
pointCounter += 1;
69+
70+
if (pointCounter/2 > 10) {
71+
m_data.clear();
72+
pointCounter = 0;
73+
}
8574

86-
// for (int i = 0; i < c_seriesList.length(); ++i) {
87-
// c_seriesList[i]->replace(m_data);
88-
// }
8975
delete matrix;
9076
matrix = nullptr;
9177
matrix = new MatrixXd(250, 24);

chart.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ private slots:
4747
QVector<QVector<qreal>> tempData;
4848
qreal pointCounter = 0;
4949
MatrixXd *matrix = nullptr;
50+
qreal xAdjustment = 0;
51+
qreal yMultiplier = 0;
52+
qreal c_windowWidth;
5053

5154
private:
5255
/**

0 commit comments

Comments
 (0)