Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for using a second Y axis when plotting #382

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 76 additions & 8 deletions pages/pageloganalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
#include <QStandardPaths>
#include <QScrollBar>

const int dataTableColName = 0;
const int dataTableColValue = 1;
const int dataTableColPlot = 2;
const int dataTableColAltAxis = 3;
const int dataTableColScale = 4;

PageLogAnalysis::PageLogAnalysis(QWidget *parent) :
QWidget(parent),
ui(new Ui::PageLogAnalysis)
Expand Down Expand Up @@ -70,12 +76,20 @@ PageLogAnalysis::PageLogAnalysis(QWidget *parent) :
ui->plot->axisRect()->setRangeZoom(Qt::Orientations());
ui->plot->axisRect()->setRangeDrag(Qt::Orientations());

ui->dataTable->setColumnWidth(0, 140);
ui->dataTable->setColumnWidth(1, 120);
ui->statTable->setColumnWidth(0, 140);
ui->logTable->setColumnWidth(0, 250);
ui->vescLogTable->setColumnWidth(0, 250);

ui->dataTable->horizontalHeader()->setSectionResizeMode(dataTableColName, QHeaderView::Interactive);
ui->dataTable->horizontalHeader()->setSectionResizeMode(dataTableColValue, QHeaderView::Stretch);
ui->dataTable->horizontalHeader()->setSectionResizeMode(dataTableColScale, QHeaderView::Fixed);
ui->dataTable->horizontalHeader()->setSectionResizeMode(dataTableColAltAxis, QHeaderView::Fixed);
ui->dataTable->horizontalHeader()->setSectionResizeMode(dataTableColPlot, QHeaderView::Fixed);

ui->dataTable->setColumnWidth(dataTableColAltAxis, 30);
ui->dataTable->setColumnWidth(dataTableColPlot, 45);
ui->dataTable->setColumnWidth(dataTableColScale, 60);

m3dView = new Vesc3DView(this);
m3dView->setMinimumWidth(200);
m3dView->setRollPitchYaw(20, 20, 0);
Expand Down Expand Up @@ -739,7 +753,21 @@ void PageLogAnalysis::truncateDataAndPlot(bool zoomGraph)

void PageLogAnalysis::updateGraphs()
{
auto rows = ui->dataTable->selectionModel()->selectedRows();
QSet<QModelIndex> uniqueRows;

auto selectedRows = ui->dataTable->selectionModel()->selectedRows();
for (const QModelIndex &index : selectedRows) {
uniqueRows.insert(index);
}

for (int row = 0; row < ui->dataTable->rowCount(); ++row) {
QTableWidgetItem *item = ui->dataTable->item(row, dataTableColPlot);
if (item && item->checkState() == Qt::Checked) {
uniqueRows.insert(ui->dataTable->model()->index(row, 0));
}
}

auto rows = uniqueRows.values();

QVector<double> xAxis;
QVector<QVector<double> > yAxes;
Expand Down Expand Up @@ -789,6 +817,7 @@ void PageLogAnalysis::updateGraphs()
}

ui->plot->clearGraphs();
ui->plot->yAxis2->setVisible(false);

for (int i = 0;i < yAxes.size();i++) {
QPen pen = QPen(Utility::getAppQColor("plot_graph1"));
Expand All @@ -805,9 +834,26 @@ void PageLogAnalysis::updateGraphs()
pen = QPen(Utility::getAppQColor("plot_graph4"));
}

ui->plot->addGraph();
auto row = rows.at(i).row();

bool altAxis = false;

if(QTableWidgetItem *aaWidget = ui->dataTable->item(row, dataTableColAltAxis)) {
altAxis = (aaWidget->checkState() == Qt::Checked);
}

if (altAxis){
ui->plot->addGraph(ui->plot->xAxis, ui->plot->yAxis2);
ui->plot->yAxis2->setVisible(true);
}
else{
ui->plot->addGraph();
}


ui->plot->graph(i)->setPen(pen);
ui->plot->graph(i)->setName(names.at(i));

ui->plot->graph(i)->setData(xAxis, yAxes.at(i));
}

Expand Down Expand Up @@ -1105,24 +1151,46 @@ void PageLogAnalysis::addDataItem(QString name, bool hasScale, double scaleStep,
{
ui->dataTable->setRowCount(ui->dataTable->rowCount() + 1);
auto item1 = new QTableWidgetItem(name);
ui->dataTable->setItem(ui->dataTable->rowCount() - 1, 0, item1);
ui->dataTable->setItem(ui->dataTable->rowCount() - 1, 1, new QTableWidgetItem(""));
ui->dataTable->setItem(ui->dataTable->rowCount() - 1, dataTableColName, item1);
ui->dataTable->setItem(ui->dataTable->rowCount() - 1, dataTableColValue, new QTableWidgetItem(""));
if (hasScale) {
QDoubleSpinBox *sb = new QDoubleSpinBox;
sb->setSingleStep(scaleStep);
sb->setValue(1.0);
sb->setMaximum(scaleMax);
// Prevent mouse wheel focus to avoid changing the selection
sb->setFocusPolicy(Qt::StrongFocus);
ui->dataTable->setCellWidget(ui->dataTable->rowCount() - 1, 2, sb);
ui->dataTable->setCellWidget(ui->dataTable->rowCount() - 1, dataTableColScale, sb);
connect(sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
[this](double value) {
(void)value;
printf("scale changed\n");
updateGraphs();
});
} else {
ui->dataTable->setItem(ui->dataTable->rowCount() - 1, 2, new QTableWidgetItem("Not Plottable"));
ui->dataTable->setItem(ui->dataTable->rowCount() - 1, dataTableColScale, new QTableWidgetItem("N/A"));
}

// Axis
QTableWidgetItem *axisItem = new QTableWidgetItem("");
axisItem->setCheckState(Qt::Unchecked);
ui->dataTable->setItem(ui->dataTable->rowCount() - 1, dataTableColAltAxis, axisItem);

connect(ui->dataTable, &QTableWidget::itemChanged, [this, axisItem](QTableWidgetItem *item) {
if (item == axisItem){
updateGraphs();
}
});

// Plot
QTableWidgetItem *plotItem = new QTableWidgetItem("");
plotItem->setCheckState(Qt::Unchecked);
ui->dataTable->setItem(ui->dataTable->rowCount() - 1, dataTableColPlot, plotItem);
connect(ui->dataTable, &QTableWidget::itemChanged, [this, plotItem](QTableWidgetItem *item) {
if (item == plotItem){
updateGraphs();
}
});
}

void PageLogAnalysis::openLog(QByteArray data)
Expand Down
65 changes: 39 additions & 26 deletions pages/pageloganalysis.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<item>
<widget class="QSplitter" name="mapSplitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<widget class="QWidget" name="layoutWidget">
<layout class="QHBoxLayout" name="horizontalLayout_2">
Expand Down Expand Up @@ -171,7 +171,7 @@
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -218,7 +218,7 @@
</widget>
<widget class="QSplitter" name="statSplitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<widget class="QCustomPlot" name="plot" native="true">
<property name="sizePolicy">
Expand All @@ -230,13 +230,13 @@
</widget>
<widget class="QTabWidget" name="tabWidget">
<property name="tabPosition">
<enum>QTabWidget::North</enum>
<enum>QTabWidget::TabPosition::North</enum>
</property>
<property name="tabShape">
<enum>QTabWidget::Triangular</enum>
<enum>QTabWidget::TabShape::Triangular</enum>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab_4">
<attribute name="title">
Expand Down Expand Up @@ -264,10 +264,10 @@
<item>
<widget class="QTabWidget" name="browseTabWidget">
<property name="tabPosition">
<enum>QTabWidget::North</enum>
<enum>QTabWidget::TabPosition::North</enum>
</property>
<property name="tabShape">
<enum>QTabWidget::Triangular</enum>
<enum>QTabWidget::TabShape::Triangular</enum>
</property>
<property name="currentIndex">
<number>0</number>
Expand Down Expand Up @@ -295,13 +295,13 @@
<item>
<widget class="QTableWidget" name="vescLogTable">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
<set>QAbstractItemView::EditTrigger::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
<enum>QAbstractItemView::SelectionMode::ExtendedSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
<enum>QAbstractItemView::SelectionBehavior::SelectRows</enum>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
Expand Down Expand Up @@ -363,7 +363,7 @@
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -455,13 +455,13 @@
<item>
<widget class="QTableWidget" name="logTable">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
<set>QAbstractItemView::EditTrigger::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
<enum>QAbstractItemView::SelectionMode::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
<enum>QAbstractItemView::SelectionBehavior::SelectRows</enum>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
Expand All @@ -483,7 +483,7 @@
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -543,19 +543,19 @@
<item>
<widget class="QTableWidget" name="dataTable">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
<set>QAbstractItemView::EditTrigger::NoEditTriggers</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
<enum>QAbstractItemView::SelectionMode::ExtendedSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
<enum>QAbstractItemView::SelectionBehavior::SelectRows</enum>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
<bool>false</bool>
</attribute>
<column>
<property name="text">
Expand All @@ -569,7 +569,20 @@
</column>
<column>
<property name="text">
<string>Plot Scale</string>
<string>Plot</string>
</property>
</column>
<column>
<property name="text">
<string>Y2</string>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Show this data series on the second Y axis to the right&lt;/p&gt;&lt;p&gt;Y axes will be autoscaled independently&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</column>
<column>
<property name="text">
<string>Scale</string>
</property>
</column>
</widget>
Expand All @@ -596,16 +609,16 @@
<item>
<widget class="QTableWidget" name="statTable">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
<set>QAbstractItemView::EditTrigger::NoEditTriggers</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
<enum>QAbstractItemView::SelectionMode::NoSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
<enum>QAbstractItemView::SelectionBehavior::SelectRows</enum>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
Expand Down Expand Up @@ -637,7 +650,7 @@
<item>
<widget class="SuperSlider" name="spanSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -677,7 +690,7 @@
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down
Loading