changeset 20302:ce8fda51d236

Set correct number of axis tickmarks when axis limits are manually configured (bug #45356). * graphics.cc (axes::properties::calc_ticks_and_lims): When axis limits are "manual", make sure that ticks are within the manual limits. Add BIST test for correct behavior.
author Rik <rik@octave.org>
date Sat, 20 Jun 2015 16:00:50 -0700
parents f357e076776f
children 062422f2e399
files libinterp/corefcn/graphics.cc
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc	Wed Jun 17 16:52:09 2015 +0200
+++ b/libinterp/corefcn/graphics.cc	Sat Jun 20 16:00:50 2015 -0700
@@ -7087,6 +7087,14 @@
         }
       lims = tmp_lims;
     }
+  else
+    {
+      // adjust min and max tics to be within limits
+      if (i1*tick_sep < lo)
+        i1++;
+      if (i2*tick_sep > hi)
+        i2--;
+    }
 
   Matrix tmp_ticks (1, i2-i1+1);
   for (int i = 0; i <= i2-i1; i++)
@@ -7119,6 +7127,19 @@
   mticks = tmp_mticks;
 }
 
+/*
+%!test  # Bug #45356
+%! hf = figure ("visible", "off");
+%! unwind_protect
+%!   plot (1:10);
+%!   xlim ([4.75, 8.5]);
+%!   tics = get (gca, "xtick");
+%!   assert (tics, [5 6 7 8]);
+%! unwind_protect_cleanup
+%!   close (hf);
+%! end_unwind_protect
+*/
+
 void
 axes::properties::calc_ticklabels (const array_property& ticks,
                                    any_property& labels, bool logscale)