summaryrefslogtreecommitdiffstats
path: root/stats/boxseries.h
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-01 22:23:29 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-01-02 11:04:03 -0800
commitb0bdef469ee142f09b3994eddc8dba0d5c6f79c3 (patch)
tree6bf21021c8556b57091d4d92fdda6b8e34f3ef53 /stats/boxseries.h
parentca572acb0d23aef77fda896d08f2b1af360c5e99 (diff)
downloadsubsurface-b0bdef469ee142f09b3994eddc8dba0d5c6f79c3.tar.gz
statistics: implement a box-and-whisker series
Implements a simple box-and-whisker series to display quartile based data. When hovering over a box-and-whiskers item the precise data of the quartiles is shown. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats/boxseries.h')
-rw-r--r--stats/boxseries.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/stats/boxseries.h b/stats/boxseries.h
new file mode 100644
index 000000000..964e3aec1
--- /dev/null
+++ b/stats/boxseries.h
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0
+// A small custom box plot series, which displays quartiles.
+// The QtCharts bar series were too inflexible with respect
+// to placement of the bars.
+#ifndef BOX_SERIES_H
+#define BOX_SERIES_H
+
+#include "statsseries.h"
+#include "statsvariables.h" // for StatsQuartiles
+
+#include <memory>
+#include <vector>
+#include <QGraphicsLineItem>
+#include <QGraphicsRectItem>
+
+class InformationBox;
+
+class BoxSeries : public StatsSeries {
+public:
+ BoxSeries(QtCharts::QChart *chart, StatsAxis *xAxis, StatsAxis *yAxis,
+ const QString &variable, const QString &unit, int decimals);
+ ~BoxSeries();
+
+ void updatePositions() override;
+ bool hover(QPointF pos) override;
+ void unhighlight() override;
+
+ // Note: this expects that all items are added with increasing pos
+ // and that no bar is inside another bar, i.e. lowerBound and upperBound
+ // are ordered identically.
+ void append(double lowerBound, double upperBound, const StatsQuartiles &q, const QString &binName);
+
+private:
+ // Get item under mouse pointer, or -1 if none
+ int getItemUnderMouse(const QPointF &f);
+
+ struct Item {
+ QGraphicsRectItem box;
+ QGraphicsLineItem topWhisker, bottomWhisker;
+ QGraphicsLineItem topBar, bottomBar;
+ QGraphicsLineItem center;
+ QRectF bounding; // bounding box in screen coordinates
+ ~Item();
+ double lowerBound, upperBound;
+ StatsQuartiles q;
+ QString binName;
+ Item(QtCharts::QChart *chart, BoxSeries *series, double lowerBound, double upperBound, const StatsQuartiles &q, const QString &binName);
+ void updatePosition(QtCharts::QChart *chart, BoxSeries *series);
+ void highlight(bool highlight);
+ };
+
+ QString variable, unit;
+ int decimals;
+
+ std::vector<QString> formatInformation(const Item &item) const;
+ std::unique_ptr<InformationBox> information;
+ std::vector<std::unique_ptr<Item>> items;
+ int highlighted; // -1: no item highlighted
+};
+
+#endif