diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-01-01 22:30:30 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-01-02 11:04:03 -0800 |
commit | cccc0abc0c8ddf791d09fe514375230a5609e7c7 (patch) | |
tree | 117cec72d466dd14fe8d3798f6e3b2f3d24f97f7 /stats/scatterseries.h | |
parent | ad7872424b77398840352f663583be60a97892f8 (diff) | |
download | subsurface-cccc0abc0c8ddf791d09fe514375230a5609e7c7.tar.gz |
statistics: implement scatter series
Implement a simple scatter series for plotting two numerical variables
agains each other. Since the scatter symbols may overlap, on hover
multiple dives are shown in the information box. If the box
would become too large, only the first few dives are shown followed
by "and X more".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats/scatterseries.h')
-rw-r--r-- | stats/scatterseries.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/stats/scatterseries.h b/stats/scatterseries.h new file mode 100644 index 000000000..335fb828c --- /dev/null +++ b/stats/scatterseries.h @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +// A small custom scatter series, where every item represents a dive +// The original QScatterSeries was buggy and distinctly slower +#ifndef SCATTER_SERIES_H +#define SCATTER_SERIES_H + +#include "statsseries.h" + +#include <memory> +#include <vector> +#include <QGraphicsRectItem> + +class QGraphicsPixmapItem; +class InformationBox; +struct StatsVariable; +struct dive; + +class ScatterSeries : public StatsSeries { +public: + ScatterSeries(QtCharts::QChart *chart, StatsAxis *xAxis, StatsAxis *yAxis, + const StatsVariable &varX, const StatsVariable &varY); + ~ScatterSeries(); + + void updatePositions() override; + bool hover(QPointF pos) override; + void unhighlight() override; + + // Note: this expects that all items are added with increasing pos! + void append(dive *d, double pos, double value); + +private: + // Get items under mouse. + // Super weird: this function can't be const, because QChart::mapToValue takes + // a non-const reference!? + std::vector<int> getItemsUnderMouse(const QPointF &f); + + struct Item { + std::unique_ptr<QGraphicsPixmapItem> item; + dive *d; + double pos, value; + Item(QtCharts::QChart *chart, ScatterSeries *series, dive *d, double pos, double value); + void updatePosition(QtCharts::QChart *chart, ScatterSeries *series); + void highlight(bool highlight); + }; + + std::unique_ptr<InformationBox> information; + std::vector<Item> items; + std::vector<int> highlighted; + const StatsVariable &varX; + const StatsVariable &varY; +}; + +#endif |