Commit 14c97a7e authored by LM's avatar LM

Fixed very bad plot bugs preventing correct plotting, made QGC suspectible to plot crashes

parent 24aea41f
...@@ -375,10 +375,25 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil ...@@ -375,10 +375,25 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil
// Clear plot // Clear plot
plot->removeData(); plot->removeData();
QVector<double> xValues; QMap<QString, QVector<double>* > xValues;
QMap<QString, QVector<double>* > yValues; QMap<QString, QVector<double>* > yValues;
curveNames.append(header.split(separator, QString::SkipEmptyParts)); curveNames.append(header.split(separator, QString::SkipEmptyParts));
// Eliminate any non-string curve names
for (int i = 0; i < curveNames.count(); ++i)
{
if (curveNames.at(i).length() == 0 ||
curveNames.at(i) == " " ||
curveNames.at(i) == "\n" ||
curveNames.at(i) == "\t" ||
curveNames.at(i) == "\r")
{
// Remove bogus curve name
curveNames.removeAt(i);
}
}
QString curveName; QString curveName;
// Clear UI elements // Clear UI elements
...@@ -408,6 +423,7 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil ...@@ -408,6 +423,7 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil
if (curveName != xAxisFilter) { if (curveName != xAxisFilter) {
if ((yAxisFilter == "") || yAxisFilter.contains(curveName)) { if ((yAxisFilter == "") || yAxisFilter.contains(curveName)) {
yValues.insert(curveName, new QVector<double>()); yValues.insert(curveName, new QVector<double>());
xValues.insert(curveName, new QVector<double>());
// Add separator starting with second item // Add separator starting with second item
if (curveNameIndex > 0 && curveNameIndex < curveNames.count()) { if (curveNameIndex > 0 && curveNameIndex < curveNames.count()) {
ui->yAxis->setText(ui->yAxis->text()+"|"); ui->yAxis->setText(ui->yAxis->text()+"|");
...@@ -425,29 +441,58 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil ...@@ -425,29 +441,58 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil
double x,y; double x,y;
while (!in.atEnd()) { while (!in.atEnd())
{
QString line = in.readLine(); QString line = in.readLine();
QStringList values = line.split(separator, QString::SkipEmptyParts); // Keep empty parts here - we still have to act on them
QStringList values = line.split(separator, QString::KeepEmptyParts);
foreach(curveName, curveNames) { bool headerfound = false;
bool okx;
if (curveName == xAxisFilter) { // First get header - ORDER MATTERS HERE!
foreach(curveName, curveNames)
{
if (curveName == xAxisFilter)
{
// X AXIS HANDLING // X AXIS HANDLING
// Take this value as x if it is selected // Take this value as x if it is selected
x = values.at(curveNames.indexOf(curveName)).toDouble(&okx); QString text = values.at(curveNames.indexOf(curveName));
xValues.append(x);// - 1270125570000ULL); text = text.trimmed();
} else { if (text.length() > 0 && text != " " && text != "\n" && text != "\r" && text != "\t")
// Y AXIS HANDLING {
bool okx = true;
x = text.toDouble(&okx);
if (okx && !isnan(x) && !isinf(x))
{
headerfound = true;
}
}
}
}
if(yAxisFilter == "" || yAxisFilter.contains(curveName)) { if (headerfound)
// Only append y values where a valid x value is present {
if (yValues.value(curveName)->count() == xValues.count() - 1) { // Search again from start for values - ORDER MATTERS HERE!
foreach(curveName, curveNames)
{
// Y AXIS HANDLING
if(curveName != xAxisFilter && (yAxisFilter == "" || yAxisFilter.contains(curveName)))
{
bool oky; bool oky;
int curveNameIndex = curveNames.indexOf(curveName); int curveNameIndex = curveNames.indexOf(curveName);
if (values.count() > curveNameIndex) { if (values.count() > curveNameIndex)
y = values.at(curveNameIndex).toDouble(&oky); {
QString text(values.at(curveNameIndex));
text = text.trimmed();
y = text.toDouble(&oky);
// Only INF is really an issue for the plot
// NaN is fine
if (oky && !isnan(y) && !isinf(y) && text.length() > 0 && text != " " && text != "\n" && text != "\r" && text != "\t")
{
// Only append definitely valid values
xValues.value(curveName)->append(x);
yValues.value(curveName)->append(y); yValues.value(curveName)->append(y);
} }
} }
...@@ -459,8 +504,9 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil ...@@ -459,8 +504,9 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil
// Add data array of each curve to the plot at once (fast) // Add data array of each curve to the plot at once (fast)
// Iterates through all x-y curve combinations // Iterates through all x-y curve combinations
for (int i = 0; i < yValues.count(); i++) { for (int i = 0; i < yValues.count(); i++) {
plot->appendData(yValues.keys().at(i), xValues.data(), yValues.values().at(i)->data(), xValues.count()); plot->appendData(yValues.keys().at(i), xValues.values().at(i)->data(), yValues.values().at(i)->data(), xValues.values().at(i)->count());
} }
plot->updateScale();
plot->setStyleText(ui->style->currentText()); plot->setStyleText(ui->style->currentText());
} }
......
...@@ -259,9 +259,9 @@ void IncrementalPlot::resetScaling() ...@@ -259,9 +259,9 @@ void IncrementalPlot::resetScaling()
void IncrementalPlot::updateScale() void IncrementalPlot::updateScale()
{ {
const double margin = 0.05; const double margin = 0.05;
double xMinRange = xmin+(xmin*margin); double xMinRange = xmin-(xmin*margin);
double xMaxRange = xmax+(xmax*margin); double xMaxRange = xmax+(xmax*margin);
double yMinRange = ymin+(ymin*margin); double yMinRange = ymin-(ymin*margin);
double yMaxRange = ymax+(ymax*margin); double yMaxRange = ymax+(ymax*margin);
if (symmetric) { if (symmetric) {
double xRange = xMaxRange - xMinRange; double xRange = xMaxRange - xMinRange;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment