Mercurial > octave
changeset 32103:32313c5e1bfc
Don't use 2-digit exponent format for ticklabels when unnecessary.
* graphics.cc (calc_ticklabels): New boolean variable is_2digit_exp.
Cycle through ticklabel values using log10 to determine if maximum
exponent is greater than or equal to 10. As soon as this condition
is found set is_2digit_exp to true and break out of loop.
Within ticklabel formatting loop, only print leading '0' if is_2digit_exp
is true and the current exponent to be printed is less than 10.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 31 May 2023 10:44:35 -0700 |
parents | 8b795293c050 |
children | edbe81ee00c5 |
files | libinterp/corefcn/graphics.cc |
diffstat | 1 files changed, 9 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc Wed May 31 10:12:26 2023 -0700 +++ b/libinterp/corefcn/graphics.cc Wed May 31 10:44:35 2023 -0700 @@ -7943,14 +7943,16 @@ { double significand; double exponent; - double exp_max = 0.0; - double exp_min = 0.0; + bool is_2digit_exp = false; for (int i = 0; i < values.numel (); i++) { - double exp = std::log10 (values(i)); - exp_min = std::min (exp_min, exp); - exp_max = std::max (exp_max, exp); + double exp = std::abs (std::log10 (values(i))); + if (exp >= 10.0) + { + is_2digit_exp = true; + break; + } } for (int i = 0; i < values.numel (); i++) @@ -7969,7 +7971,7 @@ exponent = std::floor (std::log10 (-values(i))); else exponent = std::floor (std::log10 (values(i))); - significand = values(i) * std::pow (10., -exponent); + significand = values(i) * std::pow (10.0, -exponent); os.precision (5); os.str (""); @@ -7986,7 +7988,7 @@ os << '-'; exponent = -exponent; } - if (exponent < 10. && (exp_max > 9 || exp_min < -9)) + if (exponent < 10.0 && is_2digit_exp) os << '0'; os << exponent << '}';