mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-27 20:58:47 +00:00
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:
parent
cf70a25be4
commit
5bd5ff2c2d
2 changed files with 10 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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<double>(-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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue