changeset 6790:f1157da78825

[project @ 2007-07-24 19:02:27 by jwe]
author jwe
date Tue, 24 Jul 2007 19:02:27 +0000
parents 166f388b5173
children be31a048c449
files scripts/ChangeLog scripts/plot/__go_draw_axes__.m src/ChangeLog src/graphics.cc src/graphics.h
diffstat 5 files changed, 146 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Tue Jul 24 16:38:46 2007 +0000
+++ b/scripts/ChangeLog	Tue Jul 24 19:02:27 2007 +0000
@@ -1,3 +1,7 @@
+2007-07-24  Kai Habel  <kai.habel@gmx.de>
+
+	* plot/__go_draw_axes__.m: Handle patch.
+
 2007-07-23  David Bateman  <dbateman@free.fr>
 
 	* general/rat.m: New function for ration approximation imported
--- a/scripts/plot/__go_draw_axes__.m	Tue Jul 24 16:38:46 2007 +0000
+++ b/scripts/plot/__go_draw_axes__.m	Tue Jul 24 19:02:27 2007 +0000
@@ -408,6 +408,84 @@
 	    endif
 	  endif
 
+       case "patch"
+         if (! have_newer_gnuplot)
+           warning ("patch objects require gnuplot v4.2 or later!, sorry")
+         else
+	   if (! isempty (obj.zdata))
+             warning ("gnuplot (as of v4.2) supports only 2D patches, ignoring z values")
+	   endif
+	   nd = 2;
+           cmap = parent_figure_obj.colormap;
+           clim = axis_obj.clim;
+	   data_idx++;
+	   is_image_data(data_idx) = false;
+           titlespec{data_idx} = "title \"\"";
+	   usingclause{data_idx} = "";
+           if (isfield (obj, "facecolor") && isfield (obj, "cdata"))
+             if (strncmp (obj.facecolor, "none", 4))
+	       color = [1, 1, 1];
+             elseif (strncmp (obj.facecolor, "flat", 4))
+               r = 1 + round ((size (cmap, 1) - 1) * (obj.cdata - clim(1))/(clim(2) - clim(1)));
+               r = max (1, min (r, size (cmap, 1)));
+	       color = cmap(r,:);
+             elseif (strncmp (obj.facecolor, "interp", 6))
+               warning ("\"interp\" not supported, using 1st entry of cdata")
+               r = 1 + round ((size (cmap, 1) - 1) * obj.cdata(1));
+               r = max (1, min (r, size (cmap, 1)));
+	       color = cmap(r,:);
+             else
+	       color = obj.facecolor;
+             endif
+           else
+             color = [1, 0, 0];
+           endif
+
+	   withclause{data_idx} = sprintf ("with filledcurve lc rgb \"#%02x%02x%02x\"",round (255*color));
+	   parametric(data_idx) = true;
+
+	   xdat = obj.xdata(:);
+	   ydat = obj.ydata(:);
+
+	   if (xautoscale)
+             [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat);
+	   endif
+	   if (yautoscale)
+	     [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ydat);
+	   endif
+	   data{data_idx} = [xdat, ydat]';
+	   usingclause{data_idx} = "using ($1):($2)";
+	 endif
+
+         ## patch outline
+         data_idx++;
+         is_image_data(data_idx) = false;
+         ## I had to use data_idx instead of i here, not sure if o.k. (Kai)
+         parametric(data_idx) = true;
+         titlespec{data_idx} = "title \"\"";
+	 usingclause{data_idx} = "";
+         if (isfield (obj, "edgecolor"))
+           if (strncmp (obj.edgecolor, "none", 4))
+             color = [1, 1, 1];
+           elseif (strncmp (obj.edgecolor, "flat", 4))
+             warning("\"flat\" for edgecolor not supported");
+             color = [0, 0, 0];
+           elseif (strncmp (obj.edgecolor, "interp", 6))
+             warning("\"interp\" for edgecolor not supported");
+             color = [0, 0, 0];
+           else
+	     color = obj.edgecolor;
+           endif
+         else
+           color = [0, 0, 0];
+         endif
+	 withclause{data_idx} = sprintf ("with lines lc rgb \"#%02x%02x%02x\"",round (255*color));
+
+         xdat = [xdat; xdat(1)];
+	 ydat = [ydat; ydat(1)];
+	 data{data_idx} = [xdat, ydat]';
+	 usingclause{data_idx} = "using ($1):($2)";
+
 	case "surface"
 	  data_idx++;
 	  is_image_data(data_idx) = false;
--- a/src/ChangeLog	Tue Jul 24 16:38:46 2007 +0000
+++ b/src/ChangeLog	Tue Jul 24 19:02:27 2007 +0000
@@ -1,3 +1,9 @@
+2007-07-24  Shai Ayal  <shaiay@users.sourceforge.net>
+
+	* graphics.cc (color_property::operator = (const octave_value&)):
+	New method.
+	* graphics.h: Provide decl.
+
 2007-07-24  Rafael Laboissiere  <rafael@debian.org>
 
 	* oct-conf.h.in (OCTAVE_CONF_RUNTEST): Delete definition.
--- a/src/graphics.cc	Tue Jul 24 16:38:46 2007 +0000
+++ b/src/graphics.cc	Tue Jul 24 19:02:27 2007 +0000
@@ -171,6 +171,61 @@
     error ("invalid color specification");
 }
 
+// We also provide this assignment operator so that assignment from an
+// octave_value object can happen without wiping out list of possible
+// radio_values set in color_property constructor.
+
+color_property&
+color_property::operator = (const octave_value& val)
+{
+  if (val.is_string ())
+    {
+      std::string s = val.string_value ();
+
+      if (! s.empty ())
+	{
+	  if (radio_val.validate (s))
+	    {
+	      current_val = s;
+	      current_type = radio_t;
+	    }
+          else
+	    {
+	      color_values col (s);
+	      if (! error_state)
+		{
+		  color_val = col;
+		  current_type = color_t;
+		}
+	      else
+		error ("invalid color specification");	  
+	    }	
+	}
+      else
+	error ("invalid color specification");	  
+    }
+  else if (val.is_real_matrix ())
+    {
+      Matrix m = val.matrix_value ();
+
+      if (m.numel () == 3)
+	{
+	  color_values col (m (0), m (1), m(2));
+	  if (! error_state)
+	    {
+	      color_val = col;
+	      current_type = color_t;
+	    }
+	}
+      else
+	error ("invalid color specification");
+    }
+  else 
+    error ("invalid color specification");
+
+  return *this;
+}
+
 
 void
 property_list::set (const property_name& name, const octave_value& val)
@@ -1564,7 +1619,7 @@
   else if (name.compare ("xudata"))
     xudata = val;
   else if (name.compare ("color"))
-    color = color_property (val);
+    color = val;
   else if (name.compare ("linestyle"))
     linestyle = val;
   else if (name.compare ("linewidth"))
--- a/src/graphics.h	Tue Jul 24 16:38:46 2007 +0000
+++ b/src/graphics.h	Tue Jul 24 19:02:27 2007 +0000
@@ -261,6 +261,8 @@
     return *this;
   }
 
+  color_property& operator = (const octave_value& newval);
+
   bool is_rgb (void) const { return (current_type == color_t); }
 
   bool is_radio (void) const { return (current_type == radio_t); }