changeset 32102:8b795293c050

Display 5 digits when setting "xtick", "xticklabel" graphics properties (bug #64625) * graphics.cc (calc_ticklabels): Set precision of ostringstream to either 5 or 4 digits depending on data to be displayed. Add FIXME note that this kluge should be fixed more permanently by using display routines from Octave itself, rather than C++ standard library workarounds. * graphics.cc (convert_ticklabel_string): Set precision of ostringstream to either 5 or 4 digits depending on data to be displayed.
author Rik <rik@octave.org>
date Wed, 31 May 2023 10:12:26 -0700
parents aaaee134c8df
children 32313c5e1bfc
files libinterp/corefcn/graphics.cc
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc	Tue May 30 20:52:07 2023 -0700
+++ b/libinterp/corefcn/graphics.cc	Wed May 31 10:12:26 2023 -0700
@@ -6789,6 +6789,13 @@
           for (octave_idx_type i = 0; i < val.numel (); i++)
             {
               oss.str ("");
+              // FIXME: Code should probably call out to display routines
+              // within Octave, rather than hack things up with C++ library.
+              // See FIXME in calc_ticklabels().
+              if (std::abs (data(i)) < 1.0)
+                oss.precision (4);
+              else
+                oss.precision (5);
               oss << data(i);
               sv.append (oss.str ());
             }
@@ -7964,6 +7971,7 @@
             exponent = std::floor (std::log10 (values(i)));
           significand = values(i) * std::pow (10., -exponent);
 
+          os.precision (5);
           os.str ("");
           if ((std::abs (significand) - 1) >
               10*std::numeric_limits<double>::epsilon())
@@ -8001,6 +8009,15 @@
           else
             {
               os.str ("");
+              // FIXME: Code should probably call out to display routines
+              // within Octave, rather than hack things up with C++ library.
+              // In particular, this fails for values much less than 1 where
+              // 4 significant digits will be preceded by zeros making the
+              // overall field length large.  For example, pi/1000.
+              if (std::abs (values(i)) < 1.0)
+                os.precision (4);
+              else
+                os.precision (5);
               os << values(i);
               c(i) = os.str ();
             }