mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
statistics: highlight selected boxes in box plot
In analogy to bar plots, highlight selected boxes in box plots. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
91d371374b
commit
bd252fc820
5 changed files with 37 additions and 5 deletions
|
@ -247,7 +247,7 @@ std::vector<BarSeries::SubItem> BarSeries::makeSubItems(std::vector<SubItemDesc>
|
|||
int bin_nr = 0;
|
||||
for (auto &[v, dives, label]: items) {
|
||||
if (v > 0.0) {
|
||||
bool selected = std::all_of(dives.begin(), dives.end(), [] (const dive *d) { return d->selected; });
|
||||
bool selected = allDivesSelected(dives);
|
||||
res.push_back({ view.createChartItem<ChartBarItem>(ChartZValue::Series, barBorderWidth),
|
||||
std::move(dives),
|
||||
{}, from, from + v, bin_nr, selected });
|
||||
|
@ -428,7 +428,7 @@ void BarSeries::divesSelected(const QVector<dive *> &)
|
|||
{
|
||||
for (Item &item: items) {
|
||||
for (SubItem &subitem: item.subitems) {
|
||||
bool selected = std::all_of(subitem.dives.begin(), subitem.dives.end(), [] (const dive *d) { return d->selected; });
|
||||
bool selected = allDivesSelected(subitem.dives);
|
||||
if (subitem.selected != selected) {
|
||||
subitem.selected = selected;
|
||||
|
||||
|
|
|
@ -27,9 +27,10 @@ BoxSeries::~BoxSeries()
|
|||
}
|
||||
|
||||
BoxSeries::Item::Item(StatsView &view, BoxSeries *series, double lowerBound, double upperBound,
|
||||
const StatsQuartiles &q, const QString &binName) :
|
||||
lowerBound(lowerBound), upperBound(upperBound), q(q),
|
||||
binName(binName)
|
||||
const StatsQuartiles &qIn, const QString &binName) :
|
||||
lowerBound(lowerBound), upperBound(upperBound), q(qIn),
|
||||
binName(binName),
|
||||
selected(allDivesSelected(q.dives))
|
||||
{
|
||||
item = view.createChartItem<ChartBoxItem>(ChartZValue::Series, boxBorderWidth);
|
||||
highlight(false);
|
||||
|
@ -44,6 +45,8 @@ void BoxSeries::Item::highlight(bool highlight)
|
|||
{
|
||||
if (highlight)
|
||||
item->setColor(highlightedColor, highlightedBorderColor);
|
||||
else if (selected)
|
||||
item->setColor(selectedColor, selectedBorderColor);
|
||||
else
|
||||
item->setColor(fillColor, ::borderColor);
|
||||
}
|
||||
|
@ -155,3 +158,17 @@ bool BoxSeries::selectItemsUnderMouse(const QPointF &pos, bool)
|
|||
setSelection(dives, dives.empty() ? nullptr : dives.front());
|
||||
return true;
|
||||
}
|
||||
|
||||
void BoxSeries::divesSelected(const QVector<dive *> &)
|
||||
{
|
||||
for (auto &item: items) {
|
||||
bool selected = allDivesSelected(item->q.dives);
|
||||
if (item->selected != selected) {
|
||||
item->selected = selected;
|
||||
|
||||
int idx = &item - &items[0];
|
||||
bool highlight = idx == highlighted;
|
||||
item->highlight(highlight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ private:
|
|||
double lowerBound, upperBound;
|
||||
StatsQuartiles q;
|
||||
QString binName;
|
||||
bool selected;
|
||||
Item(StatsView &view, BoxSeries *series, double lowerBound, double upperBound, const StatsQuartiles &q, const QString &binName);
|
||||
~Item();
|
||||
void updatePosition(BoxSeries *series);
|
||||
|
@ -52,6 +53,7 @@ private:
|
|||
ChartItemPtr<InformationBox> information;
|
||||
std::vector<std::unique_ptr<Item>> items;
|
||||
int highlighted; // -1: no item highlighted
|
||||
void divesSelected(const QVector<dive *> &) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
#include "statshelper.h"
|
||||
#include "core/dive.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
@ -8,3 +9,9 @@ QPointF roundPos(const QPointF &p)
|
|||
{
|
||||
return QPointF(round(p.x()), round(p.y()));
|
||||
}
|
||||
|
||||
bool allDivesSelected(const std::vector<dive *> &dives)
|
||||
{
|
||||
return std::all_of(dives.begin(), dives.end(),
|
||||
[] (const dive *d) { return d->selected; });
|
||||
}
|
||||
|
|
|
@ -5,12 +5,18 @@
|
|||
#define STATSHELPER_H
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <QPointF>
|
||||
#include <QSGNode>
|
||||
|
||||
struct dive;
|
||||
|
||||
// Round positions to integer values to avoid ugly artifacts
|
||||
QPointF roundPos(const QPointF &p);
|
||||
|
||||
// Are all dives in this vector selected?
|
||||
bool allDivesSelected(const std::vector<dive *> &dives);
|
||||
|
||||
// A stupid pointer class that initializes to null and can be copy
|
||||
// assigned. This is for historical reasons: unique_ptrs to ChartItems
|
||||
// were replaced by plain pointers. Instead of nulling the plain pointers
|
||||
|
|
Loading…
Add table
Reference in a new issue