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
// Clear plot
plot->removeData();
QVector<double> xValues;
QMap<QString, QVector<double>* > xValues;
QMap<QString, QVector<double>* > yValues;
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;
// Clear UI elements
......@@ -408,6 +423,7 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil
if (curveName != xAxisFilter) {
if ((yAxisFilter == "") || yAxisFilter.contains(curveName)) {
yValues.insert(curveName, new QVector<double>());
xValues.insert(curveName, new QVector<double>());
// Add separator starting with second item
if (curveNameIndex > 0 && curveNameIndex < curveNames.count()) {
ui->yAxis->setText(ui->yAxis->text()+"|");
......@@ -425,29 +441,58 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil
double x,y;
while (!in.atEnd()) {
while (!in.atEnd())
{
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);
bool headerfound = false;
foreach(curveName, curveNames) {
bool okx;
if (curveName == xAxisFilter) {
// First get header - ORDER MATTERS HERE!
foreach(curveName, curveNames)
{
if (curveName == xAxisFilter)
{
// X AXIS HANDLING
// Take this value as x if it is selected
x = values.at(curveNames.indexOf(curveName)).toDouble(&okx);
xValues.append(x);// - 1270125570000ULL);
} else {
// Y AXIS HANDLING
QString text = values.at(curveNames.indexOf(curveName));
text = text.trimmed();
if (text.length() > 0 && text != " " && text != "\n" && text != "\r" && text != "\t")
{
bool okx = true;
x = text.toDouble(&okx);
if (okx && !isnan(x) && !isinf(x))
{
headerfound = true;
}
}
}
}
if(yAxisFilter == "" || yAxisFilter.contains(curveName)) {
// Only append y values where a valid x value is present
if (yValues.value(curveName)->count() == xValues.count() - 1) {
bool oky;
int curveNameIndex = curveNames.indexOf(curveName);
if (values.count() > curveNameIndex) {
y = values.at(curveNameIndex).toDouble(&oky);
if (headerfound)
{
// Search again from start for values - ORDER MATTERS HERE!
foreach(curveName, curveNames)
{
// Y AXIS HANDLING
if(curveName != xAxisFilter && (yAxisFilter == "" || yAxisFilter.contains(curveName)))
{
bool oky;
int curveNameIndex = curveNames.indexOf(curveName);
if (values.count() > curveNameIndex)
{
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);
}
}
......@@ -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)
// Iterates through all x-y curve combinations
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());
}
......
......@@ -259,9 +259,9 @@ void IncrementalPlot::resetScaling()
void IncrementalPlot::updateScale()
{
const double margin = 0.05;
double xMinRange = xmin+(xmin*margin);
double xMinRange = xmin-(xmin*margin);
double xMaxRange = xmax+(xmax*margin);
double yMinRange = ymin+(ymin*margin);
double yMinRange = ymin-(ymin*margin);
double yMaxRange = ymax+(ymax*margin);
if (symmetric) {
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