changeset 8075:a028a5960e18

Fix for hold with no figures/axes. Set prop/val pairs to hggroups rather than underlying objects. Fix for equality test in array_property
author David Bateman <dbateman@free.fr>
date Fri, 29 Aug 2008 15:48:44 -0400
parents 595028fcf65d
children bac1061a36bc
files scripts/ChangeLog scripts/plot/__area__.m scripts/plot/__bars__.m scripts/plot/__plt2mm__.m scripts/plot/__plt2mv__.m scripts/plot/__plt2ss__.m scripts/plot/__plt2sv__.m scripts/plot/__plt2vm__.m scripts/plot/__plt2vs__.m scripts/plot/__plt2vv__.m scripts/plot/__quiver__.m scripts/plot/__stem__.m scripts/plot/hold.m scripts/plot/plot3.m scripts/plot/stairs.m src/ChangeLog src/graphics.cc
diffstat 17 files changed, 125 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Thu Aug 28 15:31:01 2008 -0400
+++ b/scripts/ChangeLog	Fri Aug 29 15:48:44 2008 -0400
@@ -1,3 +1,18 @@
+2008-08-29  David Bateman  <dbateman@free.fr>
+
+	* plot/__plt2mm__.m, plot/__plt2mv__.m, plot/__plt2ss__.m,
+	plot/__plt2sv__.m, plot/__plt2vm__.m, plot/__plt2vs__.m,
+	plot/__plt2vv__.m, plot/plot3.m, plot/__area__.m, plot/__bars__.m,
+	plot/__quiver__.m, plot/__stem__.m, plot/stairs.m :
+	Pass additional prop/val pairs to hggroup rather than underlying
+	objects. If a baseline existings specifically associate it with
+	the parent of the created hggroup to allow things like "stem(...,
+	'parent', hg)" to work correctly.
+	* plot/hold.m: If currentaxes if figure doesn't exist, create it.
+
+	* plot/plot3.m: Pass hline to __add_line_series__.
+	* plot/__add_datasource__.m: Fix off by one error.
+
 2008-08-28  David Bateman  <dbateman@free.fr>
 
 	* plot/__add_line_series__.m, plot/ishghandle.m, plot/linkprop.m,
--- a/scripts/plot/__area__.m	Thu Aug 28 15:31:01 2008 -0400
+++ b/scripts/plot/__area__.m	Fri Aug 29 15:48:44 2008 -0400
@@ -38,11 +38,11 @@
 
     if (i == 1)
       h = patch (ax, [x1(1), x1, fliplr(x1)], [bv, y1, bv*ones(1, length(y1))],
-		 __next_line_color__ (), "parent", hg, args{:});
+		 __next_line_color__ (), "parent", hg);
     else
       y1 = y0 + y1;
       h = patch (ax, [x1(1), x1, fliplr(x1)], [y0(1), y1, fliplr(y0)],
-		 __next_line_color__ (), "parent", hg, args{:});
+		 __next_line_color__ (), "parent", hg);
     endif
 
     y0 = y1;
@@ -62,6 +62,8 @@
 
     addproperty ("areagroup", hg, "data");
     set (retval, "areagroup", retval);
+
+    set (hg, args{:});
   endfor
 
 endfunction
--- a/scripts/plot/__bars__.m	Thu Aug 28 15:31:01 2008 -0400
+++ b/scripts/plot/__bars__.m	Fri Aug 29 15:48:44 2008 -0400
@@ -39,9 +39,9 @@
 	  lev = (i - 1) * (clim(2) - clim(1)) / (ycols - 1) - clim(1);
 	endif
 	h = patch(xb(:,:,i), yb(:,:,i), "FaceColor", "flat", 
-		  "cdata", lev, "parent", hg, args{:});
+		  "cdata", lev, "parent", hg);
       else
-	h = patch(xb(:,:,i), yb(:,:,i), "parent", hg, args{:});
+	h = patch(xb(:,:,i), yb(:,:,i), "parent", hg);
       endif
     else
       if (! have_color_spec)
@@ -51,9 +51,9 @@
 	  lev = (i - 1) * (clim(2) - clim(1)) / (ycols - 1) - clim(1);
 	endif
 	h = patch(yb(:,:,i), xb(:,:,i), "FaceColor", "flat", 
-		  "cdata", lev, "parent", hg, args{:});
+		  "cdata", lev, "parent", hg);
       else
-	h = patch(yb(:,:,i), xb(:,:,i), "parent", hg, args{:});
+	h = patch(yb(:,:,i), xb(:,:,i), "parent", hg);
       endif
     endif
 
@@ -113,6 +113,10 @@
 
     addproperty ("bargroup", hg, "data");
     set (tmp, "bargroup", tmp);
+    set (hg, args{:});
+    if (i == 1)
+      set (h_baseline, "parent", get (hg, "parent"));
+    endif
   endfor
 
   update_xlim (ax, []);
--- a/scripts/plot/__plt2mm__.m	Thu Aug 28 15:31:01 2008 -0400
+++ b/scripts/plot/__plt2mm__.m	Fri Aug 29 15:48:44 2008 -0400
@@ -62,9 +62,10 @@
 
 	h = line (x(:,i), y(:,i), "keylabel", tkey, "color", color,
 		  "linestyle", options(i).linestyle,
-		  "marker", options(i).marker, "parent", hg, args{:});
+		  "marker", options(i).marker, "parent", hg);
 
 	__add_line_series__ (h, hg);
+	set (hg, args {:});
       endfor
     else
       error ("__plt2mm__: arguments must be a matrices");
--- a/scripts/plot/__plt2mv__.m	Thu Aug 28 15:31:01 2008 -0400
+++ b/scripts/plot/__plt2mv__.m	Fri Aug 29 15:48:44 2008 -0400
@@ -78,9 +78,10 @@
 
       h = line (x(:,i), y, "keylabel", tkey, "color", color,
 		"linestyle", options(i).linestyle,
-		"marker", options(i).marker, "parent", hg, args{:});
+		"marker", options(i).marker, "parent", hg);
    
       __add_line_series__ (h, hg);
+      set (hg, args{:});
     endfor
   else
     error ("__plt2mv__: arguments must be a matrices");
--- a/scripts/plot/__plt2ss__.m	Thu Aug 28 15:31:01 2008 -0400
+++ b/scripts/plot/__plt2ss__.m	Fri Aug 29 15:48:44 2008 -0400
@@ -59,9 +59,10 @@
 
     h = line (x, y, "keylabel", key, "color", color,
 	      "linestyle", options.linestyle,
-	      "marker", options.marker, "parent", hg, properties{:});
+	      "marker", options.marker, "parent", hg);
 
     __add_line_series__ (h, hg);
+    set (hg, properties{:});
   else
     error ("__plt2ss__: arguments must be scalars");
   endif
--- a/scripts/plot/__plt2sv__.m	Thu Aug 28 15:31:01 2008 -0400
+++ b/scripts/plot/__plt2sv__.m	Fri Aug 29 15:48:44 2008 -0400
@@ -58,9 +58,10 @@
 
       h = line (x, y(i), "keylabel", tkey, "color", color,
 		"linestyle", options(i).linestyle,
-		"marker", options(i).marker, "parent", hg, args{:});
+		"marker", options(i).marker, "parent", hg);
 
       __add_line_series__ (h, hg);
+      set (hg, args{:});
     endfor
   else
     error ("__plt2sv__: first arg must be scalar, second arg must be vector");
--- a/scripts/plot/__plt2vm__.m	Thu Aug 28 15:31:01 2008 -0400
+++ b/scripts/plot/__plt2vm__.m	Fri Aug 29 15:48:44 2008 -0400
@@ -78,10 +78,10 @@
 
       h = line (x, y(:,i), "keylabel", tkey, "color", color,
 		"linestyle", options(i).linestyle,
-		"marker", options(i).marker, "parent", hg, args{:});
+		"marker", options(i).marker, "parent", hg);
 
       __add_line_series__ (h, hg);
-
+      set (hg, args{:});
     endfor
   else
     error ("__plt2vm__: arguments must be a matrices");
--- a/scripts/plot/__plt2vs__.m	Thu Aug 28 15:31:01 2008 -0400
+++ b/scripts/plot/__plt2vs__.m	Fri Aug 29 15:48:44 2008 -0400
@@ -58,9 +58,10 @@
 
       h = line (x(i), y, "keylabel", tkey, "color", color,
 		"linestyle", options(i).linestyle,
-		"marker", options(i).marker, "parent", hg, args{:});
+		"marker", options(i).marker, "parent", hg);
 
       __add_line_series__ (h, hg);
+      set (hg, args{:});
     endfor
   else
     error ("__plt2vs__: first arg must be vector, second arg must be scalar");
--- a/scripts/plot/__plt2vv__.m	Thu Aug 28 15:31:01 2008 -0400
+++ b/scripts/plot/__plt2vv__.m	Fri Aug 29 15:48:44 2008 -0400
@@ -73,9 +73,10 @@
 
     h = line (x, y, "keylabel", key, "color", color,
 	      "linestyle", options.linestyle,
-	      "marker", options.marker, "parent", hg, properties{:});
+	      "marker", options.marker, "parent", hg);
 
     __add_line_series__ (h, hg);
+    set (hg, properties{:});
   else
     error ("__plt2vv__: vector lengths must match");
   endif
--- a/scripts/plot/__quiver__.m	Thu Aug 28 15:31:01 2008 -0400
+++ b/scripts/plot/__quiver__.m	Fri Aug 29 15:48:44 2008 -0400
@@ -171,23 +171,23 @@
 		    [y.'; yend.'; NaN(1, length (y))](:),
 		    [z.'; zend.'; NaN(1, length (z))](:),
 		    "linestyle", linespec.linestyle, 
-		    "color", linespec.color, "parent", hg, args{:});
+		    "color", linespec.color, "parent", hg);
       else
 	h1 = plot ([x.'; xend.'; NaN(1, length (x))](:),
 		   [y.'; yend.'; NaN(1, length (y))](:),
 		   "linestyle", linespec.linestyle, 
-		    "color", linespec.color, "parent", hg, args{:});
+		    "color", linespec.color, "parent", hg);
       endif
     else
       if (is3d)
 	h1 = plot3 ([x.'; xend.'; NaN(1, length (x))](:),
 		    [y.'; yend.'; NaN(1, length (y))](:),
 		    [z.'; zend.'; NaN(1, length (z))](:),
-		    "parent", hg, args{:});
+		    "parent", hg);
       else
 	h1 = plot ([x.'; xend.'; NaN(1, length (x))](:),
 		   [y.'; yend.'; NaN(1, length (y))](:),
-		   "parent", hg, args{:});
+		   "parent", hg);
       endif
     endif
 
@@ -295,6 +295,7 @@
     addlistener (hg, "markerfacecolor", @update_props); 
     addlistener (hg, "markersize", @update_props);
 
+    set (hg, args{:});
   unwind_protect_cleanup
     set (h, "nextplot", hstate);
   end_unwind_protect
--- a/scripts/plot/__stem__.m	Thu Aug 28 15:31:01 2008 -0400
+++ b/scripts/plot/__stem__.m	Fri Aug 29 15:48:44 2008 -0400
@@ -59,7 +59,7 @@
 
       hg  = hggroup ();
       h = [h; hg];
-      __add_datasource__ (caller, hg, {"x", "y", "z"}, varargin{:});
+      args = __add_datasource__ (caller, hg, {"x", "y", "z"}, varargin{:});
       
       if (i == 1)
 	set (ax, "nextplot", "add");
@@ -142,6 +142,11 @@
       addlistener (hg, "xdata", @update_data);
       addlistener (hg, "ydata", @update_data);
       addlistener (hg, "zdata", @update_data);
+
+      set (hg, args{:});
+      if (i == 1 && !isempty(h_baseline))
+	set (h_baseline, "parent", get (hg, "parent"));
+      endif
     endfor
 
   unwind_protect_cleanup
--- a/scripts/plot/hold.m	Thu Aug 28 15:31:01 2008 -0400
+++ b/scripts/plot/hold.m	Fri Aug 29 15:48:44 2008 -0400
@@ -75,6 +75,9 @@
   endif
 
   if (isfigure (h))
+    if (isempty (get (h, "currentaxes")))
+      set (h, "currentaxes", __go_axes__ (h))
+    endif
     axes_objs = findobj (h, "type", "axes");
     h = [h; axes_objs];
   endif
--- a/scripts/plot/plot3.m	Thu Aug 28 15:31:01 2008 -0400
+++ b/scripts/plot/plot3.m	Fri Aug 29 15:48:44 2008 -0400
@@ -180,9 +180,17 @@
 	color = __next_line_color__ ();
       endif
 
-      tmp(++idx) = line (x(:), y(:), z(:),  "keylabel", key, "color", color,
-			 "linestyle", options.linestyle,
-			 "marker", options.marker, properties{:});
+      hg = hggroup ();
+      tmp(++idx) = hg;
+      properties = __add_datasource__ ("plot3", hg, {"x", "y", "z"}, properties{:});
+
+      hline = line (x(:), y(:), z(:),  "keylabel", key, "color", color,
+		    "linestyle", options.linestyle,
+		    "marker", options.marker, "parent", hg);
+
+      __add_line_series__ (hline, hg);
+
+      set (hg, properties{:});
 
       x_set = 0;
       y_set = 0;
@@ -231,9 +239,11 @@
 
       hline = line (x(:), y(:), z(:),  "keylabel", key, "color", color,
 		    "linestyle", options.linestyle,
-		    "marker", options.marker, "parent", hg, properties{:});
+		    "marker", options.marker, "parent", hg);
 
-      __add_line_series__ (h, hg);
+      __add_line_series__ (hline, hg);
+
+      set (hg, properties{:});
 
       x = new;
       y_set = 0;
@@ -301,9 +311,10 @@
 
     hline = line (x(:), y(:), z(:),  "keylabel", key, "color", color,
 		  "linestyle", options.linestyle,
-		  "marker", options.marker, "parent", hg, properties{:});
+		  "marker", options.marker, "parent", hg);
 
-    __add_line_series__ (h, hg);
+    __add_line_series__ (hline, hg);
+
   endif
 
   set (gca (), "view", [-37.5, 30]);
--- a/scripts/plot/stairs.m	Thu Aug 28 15:31:01 2008 -0400
+++ b/scripts/plot/stairs.m	Fri Aug 29 15:48:44 2008 -0400
@@ -146,10 +146,6 @@
 	h = [h; hg];
 	args = __add_datasource__ ("stairs", hg, {"x", "y"}, varargin{:});
 
-	if (i == 1)
-	  set (gca (), "nextplot", "add");
-	endif
-
 	addproperty ("xdata", hg, "data", x(:,i).');
 	addproperty ("ydata", hg, "data", y(:,i).');
 
@@ -157,8 +153,8 @@
 	addlistener (hg, "ydata", @update_data);
 
 	tmp = line (xs(:,i).', ys(:,i).', "color", __next_line_color__ (),
-		    "parent", hg, args{:});
-	
+		    "parent", hg);
+
         addproperty ("color", hg, "linecolor", get (tmp, "color"));
 	addproperty ("linewidth", hg, "linelinewidth", get (tmp, "linewidth"));
 	addproperty ("linestyle", hg, "linelinestyle", get (tmp, "linestyle"));
@@ -178,6 +174,8 @@
 	addlistener (hg, "markerfacecolor", @update_props); 
 	addlistener (hg, "markeredgecolor", @update_props); 
 	addlistener (hg, "markersize", @update_props); 
+
+	set (hg, args{:});
       endfor
     unwind_protect_cleanup
       set (gca (), "nextplot", hold_state);
--- a/src/ChangeLog	Thu Aug 28 15:31:01 2008 -0400
+++ b/src/ChangeLog	Fri Aug 29 15:48:44 2008 -0400
@@ -1,3 +1,11 @@
+2008-08-29  David Bateman  <dbateman@free.fr>
+
+	* src/graphics.cc: Replace int by octave_idx_type in multiple
+	places.
+	(array_property::is_equal): In macro CHECK_ARRAY_EQUAL, special
+	case scalar case and keep copy of array value to avoid early
+	destruction of converted array values.
+	
 2008-08-28  David Bateman  <dbateman@free.fr>
 
 	* graphics.h.in (root_figure::properties::showhiddenhandles):
--- a/src/graphics.cc	Thu Aug 28 15:31:01 2008 -0400
+++ b/src/graphics.cc	Fri Aug 29 15:48:44 2008 -0400
@@ -319,8 +319,8 @@
 
   NDArray a (dv);
 
-  int lda = static_cast<int> (a.numel () / 3);
-  int nc = cmap.rows ();
+  octave_idx_type lda = a.numel () / static_cast<octave_idx_type> (3);
+  octave_idx_type nc = cmap.rows ();
 
   double *av = a.fortran_vec ();
   const double *cmapv = cmap.data ();
@@ -332,7 +332,7 @@
   else
     cv = cdata.array_value ().data ();
 
-  for (int i = 0; i < lda; i++)
+  for (octave_idx_type i = 0; i < lda; i++)
     {
       double x = (cv ? cv[i] : double (icv[i]));
 
@@ -346,7 +346,7 @@
       else if (x >= nc)
 	x = (nc - 1);
 
-      int idx = static_cast<int> (x);
+      octave_idx_type idx = static_cast<octave_idx_type> (x);
 
       av[i]       = cmapv[idx];
       av[i+lda]   = cmapv[idx+nc];
@@ -362,9 +362,9 @@
 		  double& eminp)
 {
   const T *data = m.data ();
-  int n = m.numel ();
-
-  for (int i = 0; i < n; i++)
+  octave_idx_type n = m.numel ();
+
+  for (octave_idx_type i = 0; i < n; i++)
     {
       double e = double (data[i]);
 
@@ -736,40 +736,51 @@
     {
       if (data.dims () == v.dims ())
 	{
-#define CHECK_ARRAY_EQUAL(T,F) \
+
+#define CHECK_ARRAY_EQUAL(T,F,A) \
 	    { \
-	      const T* d1 = data.F ().data (); \
-	      const T* d2 = v.F ().data (); \
-	      \
-	      bool flag = true; \
-	      \
-	      for (int i = 0; flag && i < data.numel (); i++) \
-		if (d1[i] != d2[i]) \
-		  flag = false; \
-	      \
-	      return flag; \
+	      if (data.numel () == 1) \
+		return data.F ## scalar_value () == \
+		  v.F ## scalar_value (); \
+	      else  \
+		{ \
+                  /* Keep copy of array_value to allow sparse/bool arrays */ \
+		  /* that are converted, to not be deallocated early */ \
+		  const A m1 = data.F ## array_value (); \
+		  const T* d1 = m1.data (); \
+		  const A m2 = v.F ## array_value (); \
+		  const T* d2 = m2.data ();\
+		  \
+		  bool flag = true; \
+		  \
+		  for (int i = 0; flag && i < data.numel (); i++) \
+		    if (d1[i] != d2[i]) \
+		      flag = false; \
+		  \
+		  return flag; \
+		} \
 	    }
 
-	  if (data.is_double_type())
-	    CHECK_ARRAY_EQUAL (double, array_value)
+	  if (data.is_double_type() || data.is_bool_type ())
+	    CHECK_ARRAY_EQUAL (double, , NDArray)
 	  else if (data.is_single_type ())
-	    CHECK_ARRAY_EQUAL (float, float_array_value)
+	    CHECK_ARRAY_EQUAL (float, float_, FloatNDArray)
 	  else if (data.is_int8_type ())
-	    CHECK_ARRAY_EQUAL (octave_int8, int8_array_value)
+	    CHECK_ARRAY_EQUAL (octave_int8, int8_, int8NDArray)
 	  else if (data.is_int16_type ())
-	    CHECK_ARRAY_EQUAL (octave_int16, int16_array_value)
+	    CHECK_ARRAY_EQUAL (octave_int16, int16_, int16NDArray)
 	  else if (data.is_int32_type ())
-	    CHECK_ARRAY_EQUAL (octave_int32, int32_array_value)
+	    CHECK_ARRAY_EQUAL (octave_int32, int32_, int32NDArray)
 	  else if (data.is_int64_type ())
-	    CHECK_ARRAY_EQUAL (octave_int64, int64_array_value)
+	    CHECK_ARRAY_EQUAL (octave_int64, int64_, int64NDArray)
 	  else if (data.is_uint8_type ())
-	    CHECK_ARRAY_EQUAL (octave_uint8, uint8_array_value)
+	    CHECK_ARRAY_EQUAL (octave_uint8, uint8_, uint8NDArray)
 	  else if (data.is_uint16_type ())
-	    CHECK_ARRAY_EQUAL (octave_uint16, uint16_array_value)
+	    CHECK_ARRAY_EQUAL (octave_uint16, uint16_, uint16NDArray)
 	  else if (data.is_uint32_type ())
-	    CHECK_ARRAY_EQUAL (octave_uint32, uint32_array_value)
+	    CHECK_ARRAY_EQUAL (octave_uint32, uint32_, uint32NDArray)
 	  else if (data.is_uint64_type ())
-	    CHECK_ARRAY_EQUAL (octave_uint64, uint64_array_value)
+	    CHECK_ARRAY_EQUAL (octave_uint64, uint64_, uint64NDArray)
 	}
     }