changeset 16855:359ac80ecb30

Trim ticklabel strings and repeat them as necessary to fill tick marks (bug #39344) * libinterp/interp-core/gl-render.cc(render_ticktexts): Trim spaces from labels. Use % operator to repeat labels as necessary to fill number of ticks. * libinterp/interpfcn/graphics.cc(get_ticklabel_extents): Trim spaces from labels before calculating extent of text.
author Rik <rik@octave.org>
date Wed, 26 Jun 2013 15:49:57 -0700
parents 563f8f0a7e29
children 787de2f144d9
files libinterp/interp-core/gl-render.cc libinterp/interpfcn/graphics.cc
diffstat 2 files changed, 22 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/interp-core/gl-render.cc
+++ b/libinterp/interp-core/gl-render.cc
@@ -754,28 +754,37 @@
                                    int xyz, int ha, int va,
                                    int& wmax, int& hmax)
 {
-  int n = std::min (ticklabels.numel (), ticks.numel ());
-
-  for (int i = 0; i < n; i++)
+  int nticks  = ticks.numel ();
+  int nlabels = ticklabels.numel ();
+
+  if (nlabels == 0)
+    return;
+
+  for (int i = 0; i < nticks; i++)
     {
       double val = ticks(i);
 
       if (lim1 <= val && val <= lim2)
         {
           Matrix b;
-          // FIXME: as tick text is transparent, shouldn't be
+
+          std::string label (ticklabels(i % nlabels));
+          label.erase (0, label.find_first_not_of (" "));
+          label = label.substr (0, label.find_last_not_of (" ")+1);
+
+          // FIXME: as tick text is transparent, shouldn't it be
           //        drawn after axes object, for correct rendering?
           if (xyz == 0) // X
             {
-              b = render_text (ticklabels(i), val, p1, p2, ha, va);
+              b = render_text (label, val, p1, p2, ha, va);
             }
           else if (xyz == 1) // Y
             {
-              b = render_text (ticklabels(i), p1, val, p2, ha, va);
+              b = render_text (label, p1, val, p2, ha, va);
             }
           else if (xyz == 2) // Z
             {
-              b = render_text (ticklabels(i), p1, p2, val, ha, va);
+              b = render_text (label, p1, p2, val, ha, va);
             }
 
           wmax = std::max (wmax, static_cast<int> (b(2)));
--- a/libinterp/interpfcn/graphics.cc
+++ b/libinterp/interpfcn/graphics.cc
@@ -6348,13 +6348,16 @@
       double val = ticks(i);
       if (limits(0) <= val && val <= limits(1))
         {
+          std::string label (ticklabels(i));
+          label.erase (0, label.find_first_not_of (" "));
+          label = label.substr (0, label.find_last_not_of (" ")+1);
 #ifdef HAVE_FREETYPE
-          ext = text_renderer.get_extent (ticklabels(i));
+          ext = text_renderer.get_extent (label);
           wmax = std::max (wmax, ext(0));
           hmax = std::max (hmax, ext(1));
 #else
-          //FIXME: find a better approximation
-          int len = ticklabels(i).length ();
+          // FIXME: find a better approximation
+          int len = label.length ();
           wmax = std::max (wmax, 0.5*fontsize*len);
           hmax = fontsize;
 #endif