mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
statistics: convert HistogramMarkers to QSGNodes
This is in analogy to the quartile markers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
790d2b2ddb
commit
218c844ad4
6 changed files with 65 additions and 46 deletions
|
@ -133,6 +133,7 @@ SOURCES += subsurface-mobile-main.cpp \
|
||||||
stats/boxseries.cpp \
|
stats/boxseries.cpp \
|
||||||
stats/chartitem.cpp \
|
stats/chartitem.cpp \
|
||||||
stats/chartlistmodel.cpp \
|
stats/chartlistmodel.cpp \
|
||||||
|
stats/histogrammarker.cpp \
|
||||||
stats/informationbox.cpp \
|
stats/informationbox.cpp \
|
||||||
stats/legend.cpp \
|
stats/legend.cpp \
|
||||||
stats/pieseries.cpp \
|
stats/pieseries.cpp \
|
||||||
|
@ -283,6 +284,7 @@ HEADERS += \
|
||||||
stats/boxseries.h \
|
stats/boxseries.h \
|
||||||
stats/chartitem.h \
|
stats/chartitem.h \
|
||||||
stats/chartlistmodel.h \
|
stats/chartlistmodel.h \
|
||||||
|
stats/histogrammarker.h \
|
||||||
stats/informationbox.h \
|
stats/informationbox.h \
|
||||||
stats/legend.h \
|
stats/legend.h \
|
||||||
stats/pieseries.h \
|
stats/pieseries.h \
|
||||||
|
|
|
@ -13,6 +13,9 @@ set(SUBSURFACE_STATS_SRCS
|
||||||
chartitem.cpp
|
chartitem.cpp
|
||||||
chartlistmodel.h
|
chartlistmodel.h
|
||||||
chartlistmodel.cpp
|
chartlistmodel.cpp
|
||||||
|
histogrammarker.h
|
||||||
|
histogrammarker.cpp
|
||||||
|
chartlistmodel.cpp
|
||||||
informationbox.h
|
informationbox.h
|
||||||
informationbox.cpp
|
informationbox.cpp
|
||||||
legend.h
|
legend.h
|
||||||
|
|
29
stats/histogrammarker.cpp
Normal file
29
stats/histogrammarker.cpp
Normal file
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
21
stats/histogrammarker.h
Normal file
21
stats/histogrammarker.h
Normal file
|
@ -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
|
|
@ -2,6 +2,7 @@
|
||||||
#include "statsview.h"
|
#include "statsview.h"
|
||||||
#include "barseries.h"
|
#include "barseries.h"
|
||||||
#include "boxseries.h"
|
#include "boxseries.h"
|
||||||
|
#include "histogrammarker.h"
|
||||||
#include "legend.h"
|
#include "legend.h"
|
||||||
#include "pieseries.h"
|
#include "pieseries.h"
|
||||||
#include "quartilemarker.h"
|
#include "quartilemarker.h"
|
||||||
|
@ -214,8 +215,8 @@ void StatsView::plotAreaChanged(const QSizeF &s)
|
||||||
marker->updatePosition();
|
marker->updatePosition();
|
||||||
for (RegressionLine &line: regressionLines)
|
for (RegressionLine &line: regressionLines)
|
||||||
line.updatePosition();
|
line.updatePosition();
|
||||||
for (HistogramMarker &marker: histogramMarkers)
|
for (auto &marker: histogramMarkers)
|
||||||
marker.updatePosition();
|
marker->updatePosition();
|
||||||
if (legend)
|
if (legend)
|
||||||
legend->resize();
|
legend->resize();
|
||||||
updateTitlePos();
|
updateTitlePos();
|
||||||
|
@ -849,33 +850,9 @@ void StatsView::RegressionLine::updatePosition()
|
||||||
central->setPolygon(line.intersected(box));
|
central->setPolygon(line.intersected(box));
|
||||||
}
|
}
|
||||||
|
|
||||||
StatsView::HistogramMarker::HistogramMarker(double val, bool horizontal, QPen pen, QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis) :
|
void StatsView::addHistogramMarker(double pos, QColor color, bool isHorizontal, StatsAxis *xAxis, StatsAxis *yAxis)
|
||||||
item(createItemPtr<QGraphicsLineItem>(scene)),
|
|
||||||
xAxis(xAxis), yAxis(yAxis),
|
|
||||||
val(val), horizontal(horizontal)
|
|
||||||
{
|
{
|
||||||
item->setZValue(ZValues::chartFeatures);
|
histogramMarkers.push_back(createChartItem<HistogramMarker>(pos, isHorizontal, color, xAxis, yAxis));
|
||||||
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)
|
|
||||||
{
|
|
||||||
histogramMarkers.emplace_back(pos, isHorizontal, pen, &scene, xAxis, yAxis);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatsView::addLinearRegression(const struct regression_data reg, StatsAxis *xAxis, StatsAxis *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 (categoryVariable->type() == StatsVariable::Type::Numeric) {
|
||||||
if (showMean) {
|
if (showMean) {
|
||||||
double mean = categoryVariable->mean(dives);
|
double mean = categoryVariable->mean(dives);
|
||||||
QPen meanPen(Qt::green);
|
|
||||||
meanPen.setWidth(2);
|
|
||||||
if (!std::isnan(mean))
|
if (!std::isnan(mean))
|
||||||
addHistogramMarker(mean, meanPen, isHorizontal, xAxis, yAxis);
|
addHistogramMarker(mean, Qt::green, isHorizontal, xAxis, yAxis);
|
||||||
}
|
}
|
||||||
if (showMedian) {
|
if (showMedian) {
|
||||||
double median = categoryVariable->quartiles(dives).q2;
|
double median = categoryVariable->quartiles(dives).q2;
|
||||||
QPen medianPen(Qt::red);
|
|
||||||
medianPen.setWidth(2);
|
|
||||||
if (!std::isnan(median))
|
if (!std::isnan(median))
|
||||||
addHistogramMarker(median, medianPen, isHorizontal, xAxis, yAxis);
|
addHistogramMarker(median, Qt::red, isHorizontal, xAxis, yAxis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ class CategoryAxis;
|
||||||
class ChartItem;
|
class ChartItem;
|
||||||
class CountAxis;
|
class CountAxis;
|
||||||
class HistogramAxis;
|
class HistogramAxis;
|
||||||
|
class HistogramMarker;
|
||||||
class QuartileMarker;
|
class QuartileMarker;
|
||||||
class StatsAxis;
|
class StatsAxis;
|
||||||
class StatsGrid;
|
class StatsGrid;
|
||||||
|
@ -136,18 +137,8 @@ private:
|
||||||
RegressionLine(const struct regression_data reg, QBrush brush, QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis);
|
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 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;
|
StatsState state;
|
||||||
QFont titleFont;
|
QFont titleFont;
|
||||||
|
@ -157,7 +148,7 @@ private:
|
||||||
std::unique_ptr<Legend> legend;
|
std::unique_ptr<Legend> legend;
|
||||||
std::vector<std::unique_ptr<QuartileMarker>> quartileMarkers;
|
std::vector<std::unique_ptr<QuartileMarker>> quartileMarkers;
|
||||||
std::vector<RegressionLine> regressionLines;
|
std::vector<RegressionLine> regressionLines;
|
||||||
std::vector<HistogramMarker> histogramMarkers;
|
std::vector<std::unique_ptr<HistogramMarker>> histogramMarkers;
|
||||||
std::unique_ptr<QGraphicsSimpleTextItem> title;
|
std::unique_ptr<QGraphicsSimpleTextItem> title;
|
||||||
StatsSeries *highlightedSeries;
|
StatsSeries *highlightedSeries;
|
||||||
StatsAxis *xAxis, *yAxis;
|
StatsAxis *xAxis, *yAxis;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue