From 5bd5ff2c2d0c4cef8a6895f07508e6706f66ce45 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 16 Nov 2022 17:24:06 +0100 Subject: [PATCH] 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 --- CHANGELOG.md | 1 + stats/statsaxis.cpp | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7959f812c..261578741 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +statistics: fix value axis for degenerate value ranges profile: Show correct gas density when in CCR mode statistics: show correct color of selected scatter items when switching to unbinned mode statistics: fix display of month number in continuous date axis diff --git a/stats/statsaxis.cpp b/stats/statsaxis.cpp index 8e35d96ba..c4cc76ddb 100644 --- a/stats/statsaxis.cpp +++ b/stats/statsaxis.cpp @@ -284,7 +284,7 @@ void ValueAxis::updateLabels() // Use full decimal increments double height = max - min; double inc = height / numTicks; - double digits = floor(log10(inc)); + double digits = std::max(floor(log10(inc)), static_cast(-decimals)); int digits_int = lrint(digits); double digits_factor = pow(10.0, digits); int inc_int = std::max((int)ceil(inc / digits_factor), 1); @@ -294,11 +294,14 @@ void ValueAxis::updateLabels() if (inc_int == 3) inc_int = 4; inc = inc_int * digits_factor; - if (-digits_int > decimals) - decimals = -digits_int; + int show_decimals = std::max(-digits_int, decimals); - double actMin = floor(min / inc) * inc; - double actMax = ceil(max / inc) * inc; + double actMin = floor(min / inc) * inc; + double actMax = ceil(max / inc) * inc; + if (actMax - actMin < inc) { + actMax += inc; + actMin -= inc; + } int num = lrint((actMax - actMin) / inc); setRange(actMin, actMax); @@ -308,7 +311,7 @@ void ValueAxis::updateLabels() ticks.reserve(num + 1); QFontMetrics fm(theme.axisLabelFont); 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); act += actStep; }