summaryrefslogtreecommitdiffstats
path: root/stats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-14 09:48:44 +0100
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2021-01-20 08:47:18 +0100
commit218c844ad4fa3f562c375b97694025f6cdaa3ca1 (patch)
treea09ddbcc1c09d04d89691a1ce0980d99950d6675 /stats
parent790d2b2ddb36fd39fe8f002290288603ba1f0065 (diff)
downloadsubsurface-218c844ad4fa3f562c375b97694025f6cdaa3ca1.tar.gz
statistics: convert HistogramMarkers to QSGNodes
This is in analogy to the quartile markers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats')
-rw-r--r--stats/CMakeLists.txt3
-rw-r--r--stats/histogrammarker.cpp29
-rw-r--r--stats/histogrammarker.h21
-rw-r--r--stats/statsview.cpp41
-rw-r--r--stats/statsview.h15
5 files changed, 63 insertions, 46 deletions
diff --git a/stats/CMakeLists.txt b/stats/CMakeLists.txt
index 105096436..9048acf97 100644
--- a/stats/CMakeLists.txt
+++ b/stats/CMakeLists.txt
@@ -13,6 +13,9 @@ set(SUBSURFACE_STATS_SRCS
chartitem.cpp
chartlistmodel.h
chartlistmodel.cpp
+ histogrammarker.h
+ histogrammarker.cpp
+ chartlistmodel.cpp
informationbox.h
informationbox.cpp
legend.h
diff --git a/stats/histogrammarker.cpp b/stats/histogrammarker.cpp
new file mode 100644
index 000000000..e7b2512e3
--- /dev/null
+++ b/stats/histogrammarker.cpp
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "histogrammarker.h"
+#include "statsaxis.h"
+#include "zvalues.h"
+
+static const double histogramMarkerWidth = 2.0;
+
+HistogramMarker::HistogramMarker(StatsView &view, double val, bool horizontal,
+ QColor color, StatsAxis *xAxis, StatsAxis *yAxis) :
+ ChartLineItem(view, ChartZValue::ChartFeatures, color, histogramMarkerWidth),
+ xAxis(xAxis), yAxis(yAxis),
+ val(val), horizontal(horizontal)
+{
+}
+
+void HistogramMarker::updatePosition()
+{
+ if (!xAxis || !yAxis)
+ return;
+ if (horizontal) {
+ double y = yAxis->toScreen(val);
+ auto [x1, x2] = xAxis->minMaxScreen();
+ setLine(QPointF(x1, y), QPointF(x2, y));
+ } else {
+ double x = xAxis->toScreen(val);
+ auto [y1, y2] = yAxis->minMaxScreen();
+ setLine(QPointF(x, y1), QPointF(x, y2));
+ }
+}
diff --git a/stats/histogrammarker.h b/stats/histogrammarker.h
new file mode 100644
index 000000000..14d6410bd
--- /dev/null
+++ b/stats/histogrammarker.h
@@ -0,0 +1,21 @@
+// A line to show median an mean in histograms
+#ifndef HISTOGRAM_MARKER_H
+#define HISTOGRAM_MARKER_H
+
+#include "chartitem.h"
+
+class StatsAxis;
+class StatsView;
+
+// A line marking median or mean in histograms
+class HistogramMarker : public ChartLineItem {
+public:
+ HistogramMarker(StatsView &view, double val, bool horizontal, QColor color, StatsAxis *xAxis, StatsAxis *yAxis);
+ void updatePosition();
+private:
+ StatsAxis *xAxis, *yAxis;
+ double val;
+ bool horizontal;
+};
+
+#endif
diff --git a/stats/statsview.cpp b/stats/statsview.cpp
index b4b82ccfa..1e09a8cc5 100644
--- a/stats/statsview.cpp
+++ b/stats/statsview.cpp
@@ -2,6 +2,7 @@
#include "statsview.h"
#include "barseries.h"
#include "boxseries.h"
+#include "histogrammarker.h"
#include "legend.h"
#include "pieseries.h"
#include "quartilemarker.h"
@@ -214,8 +215,8 @@ void StatsView::plotAreaChanged(const QSizeF &s)
marker->updatePosition();
for (RegressionLine &line: regressionLines)
line.updatePosition();
- for (HistogramMarker &marker: histogramMarkers)
- marker.updatePosition();
+ for (auto &marker: histogramMarkers)
+ marker->updatePosition();
if (legend)
legend->resize();
updateTitlePos();
@@ -849,33 +850,9 @@ void StatsView::RegressionLine::updatePosition()
central->setPolygon(line.intersected(box));
}
-StatsView::HistogramMarker::HistogramMarker(double val, bool horizontal, QPen pen, QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis) :
- item(createItemPtr<QGraphicsLineItem>(scene)),
- xAxis(xAxis), yAxis(yAxis),
- val(val), horizontal(horizontal)
-{
- item->setZValue(ZValues::chartFeatures);
- item->setPen(pen);
-}
-
-void StatsView::HistogramMarker::updatePosition()
-{
- if (!xAxis || !yAxis)
- return;
- if (horizontal) {
- double y = yAxis->toScreen(val);
- auto [x1, x2] = xAxis->minMaxScreen();
- item->setLine(x1, y, x2, y);
- } else {
- double x = xAxis->toScreen(val);
- auto [y1, y2] = yAxis->minMaxScreen();
- item->setLine(x, y1, x, y2);
- }
-}
-
-void StatsView::addHistogramMarker(double pos, const QPen &pen, bool isHorizontal, StatsAxis *xAxis, StatsAxis *yAxis)
+void StatsView::addHistogramMarker(double pos, QColor color, bool isHorizontal, StatsAxis *xAxis, StatsAxis *yAxis)
{
- histogramMarkers.emplace_back(pos, isHorizontal, pen, &scene, xAxis, yAxis);
+ histogramMarkers.push_back(createChartItem<HistogramMarker>(pos, isHorizontal, color, xAxis, yAxis));
}
void StatsView::addLinearRegression(const struct regression_data reg, StatsAxis *xAxis, StatsAxis *yAxis)
@@ -959,17 +936,13 @@ void StatsView::plotHistogramCountChart(const std::vector<dive *> &dives,
if (categoryVariable->type() == StatsVariable::Type::Numeric) {
if (showMean) {
double mean = categoryVariable->mean(dives);
- QPen meanPen(Qt::green);
- meanPen.setWidth(2);
if (!std::isnan(mean))
- addHistogramMarker(mean, meanPen, isHorizontal, xAxis, yAxis);
+ addHistogramMarker(mean, Qt::green, isHorizontal, xAxis, yAxis);
}
if (showMedian) {
double median = categoryVariable->quartiles(dives).q2;
- QPen medianPen(Qt::red);
- medianPen.setWidth(2);
if (!std::isnan(median))
- addHistogramMarker(median, medianPen, isHorizontal, xAxis, yAxis);
+ addHistogramMarker(median, Qt::red, isHorizontal, xAxis, yAxis);
}
}
}
diff --git a/stats/statsview.h b/stats/statsview.h
index 073a200fd..aad9ec977 100644
--- a/stats/statsview.h
+++ b/stats/statsview.h
@@ -24,6 +24,7 @@ class CategoryAxis;
class ChartItem;
class CountAxis;
class HistogramAxis;
+class HistogramMarker;
class QuartileMarker;
class StatsAxis;
class StatsGrid;
@@ -136,18 +137,8 @@ private:
RegressionLine(const struct regression_data reg, QBrush brush, QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis);
};
- // A line marking median or mean in histograms
- struct HistogramMarker {
- std::unique_ptr<QGraphicsLineItem> item;
- StatsAxis *xAxis, *yAxis;
- double val;
- bool horizontal;
- void updatePosition();
- HistogramMarker(double val, bool horizontal, QPen pen, QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis);
- };
-
void addLinearRegression(const struct regression_data reg, StatsAxis *xAxis, StatsAxis *yAxis);
- void addHistogramMarker(double pos, const QPen &pen, bool isHorizontal, StatsAxis *xAxis, StatsAxis *yAxis);
+ void addHistogramMarker(double pos, QColor color, bool isHorizontal, StatsAxis *xAxis, StatsAxis *yAxis);
StatsState state;
QFont titleFont;
@@ -157,7 +148,7 @@ private:
std::unique_ptr<Legend> legend;
std::vector<std::unique_ptr<QuartileMarker>> quartileMarkers;
std::vector<RegressionLine> regressionLines;
- std::vector<HistogramMarker> histogramMarkers;
+ std::vector<std::unique_ptr<HistogramMarker>> histogramMarkers;
std::unique_ptr<QGraphicsSimpleTextItem> title;
StatsSeries *highlightedSeries;
StatsAxis *xAxis, *yAxis;