From 37cd94e4e4fe1462272cef4610e3929774c172af Mon Sep 17 00:00:00 2001 From: Uwe Date: Mon, 30 May 2022 02:57:29 +0200 Subject: [PATCH] [Gui] fix default color gradient numbering as reported here: https://forum.freecadweb.org/viewtopic.php?p=598390#p598390 we must assure the user sees not by default get several gradient labels showing the same and labels showing 0.000 --- src/Gui/SoFCColorGradient.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Gui/SoFCColorGradient.cpp b/src/Gui/SoFCColorGradient.cpp index 987111fbf5..b68db9d5a8 100644 --- a/src/Gui/SoFCColorGradient.cpp +++ b/src/Gui/SoFCColorGradient.cpp @@ -156,16 +156,20 @@ void SoFCColorGradient::setRange(float fMin, float fMax, int prec) { _cColGrad.setRange(fMin, fMax); - // format the label the following way: - // if fMin is smaller than 1e- or fMax greater than 1e+4, output in scientific notation - // otherwise output "normal" (fixed notation) - SoMFString label; float eps = std::pow(10.0f, static_cast(-prec)); float value_min = std::min(fabs(fMin), fabs(fMax)); float value_max = std::max(fabs(fMin), fabs(fMax)); - bool scientific = (value_min < eps && value_min > 0.0f) || value_max > 1e4; + // format the label the following way: + // if Min is smaller than 1e-, + // or Max greater than 1e+4, + // or (Max - Min) < 1e- * number of labels - 1 (assures every label shows different number) + // -> output in scientific notation + // otherwise output "normal" (fixed notation) + bool scientific = (value_min < eps && value_min > 0.0f) + || (value_max - value_min) < eps * (_cColGrad.getCountColors() - 1) + || value_max > 1e4; std::ios::fmtflags flags = scientific ? (std::ios::scientific | std::ios::showpoint | std::ios::showpos) : (std::ios::fixed | std::ios::showpoint | std::ios::showpos);