aboutsummaryrefslogtreecommitdiffstats
path: root/stats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2021-01-12 21:27:16 +0100
committerGravatar Robert C. Helling <helling@atdotde.de>2021-01-14 20:51:23 +0100
commit25cfd852b910c7bbd53f0a1a5244c659761c2cc5 (patch)
tree3794f44deae82870c92ca2c8caad75685104682f /stats
parentd6712bc5ac1af3bd1bc42c62d66a0df7be56e68b (diff)
downloadsubsurface-25cfd852b910c7bbd53f0a1a5244c659761c2cc5.tar.gz
Add back central line for linear regression
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Diffstat (limited to 'stats')
-rw-r--r--stats/statsview.cpp9
-rw-r--r--stats/statsview.h1
2 files changed, 10 insertions, 0 deletions
diff --git a/stats/statsview.cpp b/stats/statsview.cpp
index 63e9183b6..e5e6b0b0d 100644
--- a/stats/statsview.cpp
+++ b/stats/statsview.cpp
@@ -725,12 +725,16 @@ void StatsView::QuartileMarker::updatePosition()
StatsView::RegressionLine::RegressionLine(const struct regression_data reg, QBrush brush, QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis) :
item(createItemPtr<QGraphicsPolygonItem>(scene)),
+ central(createItemPtr<QGraphicsPolygonItem>(scene)),
xAxis(xAxis), yAxis(yAxis),
reg(reg)
{
item->setZValue(ZValues::chartFeatures);
item->setPen(Qt::NoPen);
item->setBrush(brush);
+
+ central->setZValue(ZValues::chartFeatures+1);
+ central->setPen(QPen(Qt::red));
}
void StatsView::RegressionLine::updatePosition()
@@ -740,6 +744,10 @@ void StatsView::RegressionLine::updatePosition()
auto [minX, maxX] = xAxis->minMax();
auto [minY, maxY] = yAxis->minMax();
+ QPolygonF line;
+ line << QPoint(xAxis->toScreen(minX), yAxis->toScreen(reg.a * minX + reg.b))
+ << QPoint(xAxis->toScreen(maxX), yAxis->toScreen(reg.a * maxX + reg.b));
+
// Draw the confidence interval according to http://www2.stat.duke.edu/~tjl13/s101/slides/unit6lec3H.pdf p.5 with t*=2 for 95% confidence
QPolygonF poly;
for (double x = minX; x <= maxX + 1; x += (maxX - minX) / 100)
@@ -751,6 +759,7 @@ void StatsView::RegressionLine::updatePosition()
QRectF box(QPoint(xAxis->toScreen(minX), yAxis->toScreen(minY)), QPoint(xAxis->toScreen(maxX), yAxis->toScreen(maxY)));
item->setPolygon(poly.intersected(box));
+ central->setPolygon(line.intersected(box));
}
StatsView::HistogramMarker::HistogramMarker(double val, bool horizontal, QPen pen, QGraphicsScene *scene, StatsAxis *xAxis, StatsAxis *yAxis) :
diff --git a/stats/statsview.h b/stats/statsview.h
index b2c973856..b1e178565 100644
--- a/stats/statsview.h
+++ b/stats/statsview.h
@@ -126,6 +126,7 @@ private:
// A regression line
struct RegressionLine {
std::unique_ptr<QGraphicsPolygonItem> item;
+ std::unique_ptr<QGraphicsPolygonItem> central;
StatsAxis *xAxis, *yAxis;
const struct regression_data reg;
void updatePosition();