summaryrefslogtreecommitdiffstats
path: root/stats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-11 13:29:15 +0100
committerGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-11 13:29:15 +0100
commit108f6fed2f383be32808a1eb5a6ac82d078d6330 (patch)
tree19c3d51b80763a42f2a78d1007e06ede1d3cc1b8 /stats
parentbdecd98ef500a8193b3abc5c51bf89d52271ea41 (diff)
downloadsubsurface-108f6fed2f383be32808a1eb5a6ac82d078d6330.tar.gz
statistics: print ellipsis in case of too little space
In categorical axes all labels were printed leading to a big tohu wa-bohu for two many bins. Therefore, if a label is larger than the space between two ticks, replace by an ellipsis. Adjust the size of the ellipsis (".", ".." or "...") to the available space. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'stats')
-rw-r--r--stats/statsaxis.cpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/stats/statsaxis.cpp b/stats/statsaxis.cpp
index d31b5827b..2c5a5d961 100644
--- a/stats/statsaxis.cpp
+++ b/stats/statsaxis.cpp
@@ -365,9 +365,33 @@ std::pair<QString, QString> CategoryAxis::getFirstLastLabel() const
return { QString(), QString() };
}
+// Get ellipses for a given label size
+static QString ellipsis1 = QStringLiteral("․");
+static QString ellipsis2 = QStringLiteral("‥");
+static QString ellipsis3 = QStringLiteral("…");
+static QString getEllipsis(const QFontMetrics &fm, double widthIn)
+{
+ int width = static_cast<int>(floor(widthIn));
+ if (fm.size(Qt::TextSingleLine, ellipsis3).width() < width)
+ return ellipsis3;
+ if (fm.size(Qt::TextSingleLine, ellipsis2).width() < width)
+ return ellipsis2;
+ if (fm.size(Qt::TextSingleLine, ellipsis1).width() < width)
+ return ellipsis1;
+ return QString();
+}
+
void CategoryAxis::updateLabels()
{
- // TODO: paint ellipses if space too small
+ if (labelsText.empty())
+ return;
+
+ QFontMetrics fm(labelFont);
+ double size_per_label = size / static_cast<double>(labelsText.size()) - axisTickWidth;
+ double fontHeight = fm.height();
+
+ QString ellipsis = horizontal ? getEllipsis(fm, size_per_label) : QString();
+
labels.clear();
ticks.clear();
labels.reserve(labelsText.size());
@@ -375,7 +399,13 @@ void CategoryAxis::updateLabels()
double pos = 0.0;
addTick(-0.5);
for (const QString &s: labelsText) {
- addLabel(s, pos);
+ if (horizontal) {
+ double width = static_cast<double>(fm.size(Qt::TextSingleLine, s).width());
+ addLabel(width < size_per_label ? s : ellipsis, pos);
+ } else {
+ if (fontHeight < size_per_label)
+ addLabel(s, pos);
+ }
addTick(pos + 0.5);
pos += 1.0;
}