changeset 24145:196ea1ee99b8

Revamp input validation for bar functions (bug #52135). * __bar__.m: Validate that first input is numeric. Treat a second numeric scalar input as width, rather than Y. If Y is a vector, try both row and column orientations to attempt to match X length. Check that any X values are unique, but don't require that they be in ascending order. Remove old code which had been commented out.
author Rik <rik@octave.org>
date Fri, 29 Sep 2017 08:45:51 -0700
parents 8e034cb195f1
children d72ba9191352
files scripts/plot/draw/private/__bar__.m
diffstat 1 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/draw/private/__bar__.m	Fri Oct 13 13:30:20 2017 -0700
+++ b/scripts/plot/draw/private/__bar__.m	Fri Sep 29 08:45:51 2017 -0700
@@ -27,6 +27,10 @@
 
   [hax, varargin, nargin] = __plt_get_axis_arg__ (func, varargin{:});
 
+  if (! isnumeric (varargin{1}))
+    error ("%s: Y must be numeric", func);
+  endif
+
   width = 0.8;
   group = true;
   histc = NA;
@@ -46,16 +50,16 @@
     if (isvector (y))
       y = y(:);
     endif
-    if (rows (x) != rows (y))
-      y = varargin{1};
-      if (isvector (y))
-        y = y(:);
-      endif
+    if (isscalar (y) && ! isscalar (x))
+      ## "y" is actually "width" argument
+      y = x;
       x = [1:rows(y)]';
       idx = 2;
     else
       if (! isvector (x))
         error ("%s: X must be a vector", func);
+      elseif (numel (unique (x)) != numel (x))
+        error ("%s: X vector values must be unique", func);
       endif
       idx = 3;
     endif
@@ -115,12 +119,13 @@
   endwhile
 
   ngrp = rows (x);
+
+  if (isvector (y) && ngrp != rows (y))
+    y = y.';
+  endif
   if (ngrp != rows (y))
     error ("%s: length of X and Y must be equal", func);
   endif
-  if (any (x(2:end) < x(1:end-1)))
-    error ("%s: X vector values must be in ascending order", func);
-  endif
 
   nbars = columns (y);
 
@@ -372,7 +377,6 @@
       set (hg, "basevalue", 1);
     endif
   else
-#    warning ("off", "Octave:negative-data-log-axis", "local");
     if (get (hg, "basevalue") == 1)
       set (hg, "basevalue", 0);
     endif