statistics: fix zero-range on value axis

The code that calculates the bounds of the value axis was broken
when all items had the same value. In that case, increase the shown
range explicitly. It doesn't really matter how much the range
is increased, because all items will be at the center of the graph.

Also, don't overwrite the "decimal" value of the class. That was
just weird.

Fixes #3544.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-11-16 17:24:06 +01:00 committed by Dirk Hohndel
parent cf70a25be4
commit 5bd5ff2c2d
2 changed files with 10 additions and 6 deletions

View file

@ -1,3 +1,4 @@
statistics: fix value axis for degenerate value ranges
profile: Show correct gas density when in CCR mode profile: Show correct gas density when in CCR mode
statistics: show correct color of selected scatter items when switching to unbinned mode statistics: show correct color of selected scatter items when switching to unbinned mode
statistics: fix display of month number in continuous date axis statistics: fix display of month number in continuous date axis

View file

@ -284,7 +284,7 @@ void ValueAxis::updateLabels()
// Use full decimal increments // Use full decimal increments
double height = max - min; double height = max - min;
double inc = height / numTicks; double inc = height / numTicks;
double digits = floor(log10(inc)); double digits = std::max(floor(log10(inc)), static_cast<double>(-decimals));
int digits_int = lrint(digits); int digits_int = lrint(digits);
double digits_factor = pow(10.0, digits); double digits_factor = pow(10.0, digits);
int inc_int = std::max((int)ceil(inc / digits_factor), 1); int inc_int = std::max((int)ceil(inc / digits_factor), 1);
@ -294,11 +294,14 @@ void ValueAxis::updateLabels()
if (inc_int == 3) if (inc_int == 3)
inc_int = 4; inc_int = 4;
inc = inc_int * digits_factor; inc = inc_int * digits_factor;
if (-digits_int > decimals) int show_decimals = std::max(-digits_int, decimals);
decimals = -digits_int;
double actMin = floor(min / inc) * inc; double actMin = floor(min / inc) * inc;
double actMax = ceil(max / inc) * inc; double actMax = ceil(max / inc) * inc;
if (actMax - actMin < inc) {
actMax += inc;
actMin -= inc;
}
int num = lrint((actMax - actMin) / inc); int num = lrint((actMax - actMin) / inc);
setRange(actMin, actMax); setRange(actMin, actMax);
@ -308,7 +311,7 @@ void ValueAxis::updateLabels()
ticks.reserve(num + 1); ticks.reserve(num + 1);
QFontMetrics fm(theme.axisLabelFont); QFontMetrics fm(theme.axisLabelFont);
for (int i = 0; i <= num; ++i) { for (int i = 0; i <= num; ++i) {
addLabel(fm, loc.toString(act, 'f', decimals), act); addLabel(fm, loc.toString(act, 'f', show_decimals), act);
addTick(act); addTick(act);
act += actStep; act += actStep;
} }