summaryrefslogtreecommitdiffstats
path: root/stats/statsview.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-11 12:59:17 +0100
committerGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-11 12:59:17 +0100
commitbdecd98ef500a8193b3abc5c51bf89d52271ea41 (patch)
tree6f76c1996fea522af1868e3a6296b27f5f091743 /stats/statsview.cpp
parent0ff1145fd822fec21d301c221744073733f012ed (diff)
downloadsubsurface-bdecd98ef500a8193b3abc5c51bf89d52271ea41.tar.gz
statistics: consider overhang of horizontal axes
The old code didn't consider that labels can peak out of horizontal axes if labels are under ticks. This commit takes this into account. However, it must be noted that this is only heuristics: Before setting the size of the axes, the actual minimum and maximum label are not known, because we round to "nice" numbers. But the size of the axis can only be set after knowing the overhang, leading to a circular dependency. Therefore, the code currently simply uses the minimum and maximum value of the data, hoping that the "nice" values will not format to something significantly larger. We could do a multi-pass scheme, but let's not for now. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats/statsview.cpp')
-rw-r--r--stats/statsview.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/stats/statsview.cpp b/stats/statsview.cpp
index 1533583ba..5583643d7 100644
--- a/stats/statsview.cpp
+++ b/stats/statsview.cpp
@@ -97,15 +97,21 @@ void StatsView::plotAreaChanged(const QSizeF &s)
if (title)
top += title->boundingRect().height() + titleBorder;
// Currently, we only have either none, or an x- and a y-axis
- if (xAxis)
+ std::pair<double,double> horizontalSpace{ 0.0, 0.0 };
+ if (xAxis) {
bottom -= xAxis->height();
+ horizontalSpace = xAxis->horizontalOverhang();
+ }
if (bottom - top < minSize)
return;
if (yAxis) {
yAxis->setSize(bottom - top);
- left += yAxis->width();
- yAxis->setPos(QPointF(left, bottom));
+ horizontalSpace.first = std::max(horizontalSpace.first, yAxis->width());
}
+ left += horizontalSpace.first;
+ right -= horizontalSpace.second;
+ if (yAxis)
+ yAxis->setPos(QPointF(left, bottom));
if (right - left < minSize)
return;
if (xAxis) {