mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
bdecd98ef5
commit
108f6fed2f
1 changed files with 32 additions and 2 deletions
|
@ -365,9 +365,33 @@ std::pair<QString, QString> CategoryAxis::getFirstLastLabel() const
|
||||||
return { QString(), QString() };
|
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()
|
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();
|
labels.clear();
|
||||||
ticks.clear();
|
ticks.clear();
|
||||||
labels.reserve(labelsText.size());
|
labels.reserve(labelsText.size());
|
||||||
|
@ -375,7 +399,13 @@ void CategoryAxis::updateLabels()
|
||||||
double pos = 0.0;
|
double pos = 0.0;
|
||||||
addTick(-0.5);
|
addTick(-0.5);
|
||||||
for (const QString &s: labelsText) {
|
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);
|
addTick(pos + 0.5);
|
||||||
pos += 1.0;
|
pos += 1.0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue