2021-01-01 21:23:29 +00:00
|
|
|
// 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
|
|
|
|
|
2021-01-17 20:07:57 +00:00
|
|
|
#include "chartitem.h"
|
2021-01-01 21:23:29 +00:00
|
|
|
#include "statsseries.h"
|
|
|
|
#include "statsvariables.h" // for StatsQuartiles
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-01-11 12:22:39 +00:00
|
|
|
struct InformationBox;
|
2021-01-01 21:23:29 +00:00
|
|
|
|
|
|
|
class BoxSeries : public StatsSeries {
|
|
|
|
public:
|
2021-01-18 11:35:22 +00:00
|
|
|
BoxSeries(StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
|
2021-01-01 21:23:29 +00:00
|
|
|
const QString &variable, const QString &unit, int decimals);
|
|
|
|
~BoxSeries();
|
|
|
|
|
|
|
|
void updatePositions() override;
|
|
|
|
bool hover(QPointF pos) override;
|
|
|
|
void unhighlight() override;
|
2021-01-17 12:34:18 +00:00
|
|
|
void selectItemsUnderMouse(const QPointF &point) override;
|
2021-01-01 21:23:29 +00:00
|
|
|
|
|
|
|
// 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 {
|
2021-01-18 21:29:34 +00:00
|
|
|
ChartItemPtr<ChartBoxItem> item;
|
2021-01-01 21:23:29 +00:00
|
|
|
double lowerBound, upperBound;
|
|
|
|
StatsQuartiles q;
|
|
|
|
QString binName;
|
2021-01-17 20:07:57 +00:00
|
|
|
Item(StatsView &view, BoxSeries *series, double lowerBound, double upperBound, const StatsQuartiles &q, const QString &binName);
|
|
|
|
~Item();
|
2021-01-05 11:11:46 +00:00
|
|
|
void updatePosition(BoxSeries *series);
|
2021-01-01 21:23:29 +00:00
|
|
|
void highlight(bool highlight);
|
|
|
|
};
|
|
|
|
|
|
|
|
QString variable, unit;
|
|
|
|
int decimals;
|
|
|
|
|
|
|
|
std::vector<QString> formatInformation(const Item &item) const;
|
2021-01-18 21:29:34 +00:00
|
|
|
ChartItemPtr<InformationBox> information;
|
2021-01-01 21:23:29 +00:00
|
|
|
std::vector<std::unique_ptr<Item>> items;
|
|
|
|
int highlighted; // -1: no item highlighted
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|