# HG changeset patch
# User Ben Abbott <bpabbott@mac.com>
# Date 1284846611 14400
# Node ID 9d7c542a1a465c188b1d5ac0b093df5af878e3c2
# Parent  e81914f3921f6d8fe503be48f4f66120b59d1d14
colorbar.m: Special treatment activepositionproperty = outerposition from the gnuplot backend. This allows the gnuplot key to be placed outsize the plotbox.

diff --git a/scripts/ChangeLog b/scripts/ChangeLog
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,10 @@
+2010-09-18  Ben Abbott <bpabbott@mac.com>
+
+	* plot/colorbar.m, plot/axis.m, plot/private/__actual_axis_position__.m,
+	plot/__go_draw_axes__.m: Special treatment activepositionproperty == 
+	outerposition from the gnuplot backend. This allows the gnuplot key to
+	be placed outsize the plotbox.
+
 2010-09-18  David Bateman  <dbateman@free.fr>
 
 	* plot/__go_draw_axes__.m: Modify legend code to use data from legend
diff --git a/scripts/plot/__go_draw_axes__.m b/scripts/plot/__go_draw_axes__.m
--- a/scripts/plot/__go_draw_axes__.m
+++ b/scripts/plot/__go_draw_axes__.m
@@ -82,42 +82,53 @@
       dr = 1;
     endif
 
-    if (__gnuplot_has_feature__ ("screen_coordinates_for_{lrtb}margin"))
-      if (nd == 2 || all (mod (axis_obj.view, 90) == 0))
-        x = [1, 1];
+    if (strcmp (axis_obj.activepositionproperty, "position"))
+      if (__gnuplot_has_feature__ ("screen_coordinates_for_{lrtb}margin"))
+        if (nd == 2 || all (mod (axis_obj.view, 90) == 0))
+          x = [1, 1];
+        else
+          ## 3D plots need to be sized down to fit in the window.
+          x = 1.0 ./ sqrt([2, 2.5]);
+        endif
+        fprintf (plot_stream, "set tmargin screen %.15g;\n",
+                 pos(2)+pos(4)/2+x(2)*pos(4)/2);
+        fprintf (plot_stream, "set bmargin screen %.15g;\n",
+                 pos(2)+pos(4)/2-x(2)*pos(4)/2);
+        fprintf (plot_stream, "set lmargin screen %.15g;\n",
+                 pos(1)+pos(3)/2-x(1)*pos(3)/2);
+        fprintf (plot_stream, "set rmargin screen %.15g;\n",
+                 pos(1)+pos(3)/2+x(1)*pos(3)/2);
+        sz_str = "";
       else
-        ## 3D plots need to be sized down to fit in the window.
-        x = 1.0 ./ sqrt([2, 2.5]);
+        fprintf (plot_stream, "set tmargin 0;\n");
+        fprintf (plot_stream, "set bmargin 0;\n");
+        fprintf (plot_stream, "set lmargin 0;\n");
+        fprintf (plot_stream, "set rmargin 0;\n");
+
+        if (nd == 3 && all (axis_obj.view == [0, 90]))
+          ## FIXME -- Kludge to allow colorbar to be added to a pcolor() plot
+          pos(3:4) = pos(3:4) * 1.4;
+          pos(1:2) = pos(1:2) - pos(3:4) * 0.125;
+        endif
+  
+        fprintf (plot_stream, "set origin %.15g, %.15g;\n", pos(1), pos(2));
+  
+        if (strcmpi (axis_obj.dataaspectratiomode, "manual"))
+          sz_str = sprintf ("set size ratio %.15g", -dr);
+        else
+          sz_str = "set size noratio";
+        endif
+        sz_str = sprintf ("%s %.15g, %.15g;\n", sz_str, pos(3), pos(4));
       endif
-      fprintf (plot_stream, "set tmargin screen %.15g;\n",
-               pos(2)+pos(4)/2+x(2)*pos(4)/2);
-      fprintf (plot_stream, "set bmargin screen %.15g;\n",
-               pos(2)+pos(4)/2-x(2)*pos(4)/2);
-      fprintf (plot_stream, "set lmargin screen %.15g;\n",
-               pos(1)+pos(3)/2-x(1)*pos(3)/2);
-      fprintf (plot_stream, "set rmargin screen %.15g;\n",
-               pos(1)+pos(3)/2+x(1)*pos(3)/2);
+    else ## activepositionproperty == outerposition
+      fprintf (plot_stream, "set origin %g, %g;\n", pos(1:2))
       sz_str = "";
-    else
-      fprintf (plot_stream, "set tmargin 0;\n");
-      fprintf (plot_stream, "set bmargin 0;\n");
-      fprintf (plot_stream, "set lmargin 0;\n");
-      fprintf (plot_stream, "set rmargin 0;\n");
-
-      if (nd == 3 && all (axis_obj.view == [0, 90]))
-        ## FIXME -- Kludge to allow colorbar to be added to a pcolor() plot
-        pos(3:4) = pos(3:4) * 1.4;
-        pos(1:2) = pos(1:2) - pos(3:4) * 0.125;
+      if (strcmpi (axis_obj.dataaspectratiomode, "manual"))
+        sz_str = sprintf ("ratio %g", -dr);
+      else
+        sz_str = "noratio";
       endif
-
-      fprintf (plot_stream, "set origin %.15g, %.15g;\n", pos(1), pos(2));
-
-      if (strcmpi (axis_obj.dataaspectratiomode, "manual"))
-        sz_str = sprintf ("set size ratio %.15g", -dr);
-      else
-        sz_str = "set size noratio";
-      endif
-      sz_str = sprintf ("%s %.15g, %.15g;\n", sz_str, pos(3), pos(4));
+      sz_str = sprintf ("set size %s %g, %g;\n", sz_str, pos(3:4));
     endif
     if (! isempty (sz_str))
       fputs (plot_stream, sz_str);
@@ -610,7 +621,7 @@
                  have_3d_patch(data_idx) = false;
                endif
 
-               if (i > 1 || isempty (obj.displayname))
+               if (i > 1 || ! isfield (obj, "displayname") || isempty (obj.displayname))
                  titlespec{local_idx} = "title \"\"";
                else
                  tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "displayname"));
diff --git a/scripts/plot/axis.m b/scripts/plot/axis.m
--- a/scripts/plot/axis.m
+++ b/scripts/plot/axis.m
@@ -184,6 +184,10 @@
     elseif  (strcmp (ax, "equal"))
       x = xlim;
       y = ylim;
+      if (strcmp (get (get (ca, "parent"), "__backend__"), "gnuplot"))
+        ## FIXME - gnuplot applies the aspect ratio activepostionproperty.
+        set (ca, "activepositionproperty", "position");
+      endif
       set (ca, "plotboxaspectratio", [(x(2)-x(1)), (y(2)-y(1)), 1]);
     elseif (strcmpi (ax, "normal"))
       set (ca, "plotboxaspectratio", [1, 1, 1])
diff --git a/scripts/plot/colorbar.m b/scripts/plot/colorbar.m
--- a/scripts/plot/colorbar.m
+++ b/scripts/plot/colorbar.m
@@ -271,8 +271,14 @@
     else
       scale = [scale, 1];
     endif
-    obj.position = obj.position .* [1, 1, scale];
-    off = 0.5 * (obj.position (3:4) - __actual_axis_position__ (obj)(3:4));
+    if (strcmp (get (cf, "__backend__"), "gnuplot")
+        && strcmp (obj.activepositionproperty, "outerposition"))
+      obj.outerposition = obj.outerposition .* [1, 1, scale];
+      off = 0.5 * (obj.outerposition (3:4) - __actual_axis_position__ (obj)(3:4));
+    else
+      obj.position = obj.position .* [1, 1, scale];
+      off = 0.5 * (obj.position (3:4) - __actual_axis_position__ (obj)(3:4));
+    endif
   else
     off = 0.0;
   endif
@@ -587,6 +593,7 @@
 %! shading ("interp")
 %! axis ("tight", "square")
 %! colorbar ()
+#%! axes('color','none','box','on','activepositionproperty','position')
 
 %!demo
 %! clf
diff --git a/scripts/plot/private/__actual_axis_position__.m b/scripts/plot/private/__actual_axis_position__.m
--- a/scripts/plot/private/__actual_axis_position__.m
+++ b/scripts/plot/private/__actual_axis_position__.m
@@ -43,8 +43,13 @@
     set (axis_obj.parent, "units", orig_fig_units)
     set (axis_obj.parent, "position", orig_fig_position)
   end_unwind_protect
-  ## Get axis plot-box size in pixels
-  pos_in_pixels = axis_obj.position .* fig_position([3, 4, 3, 4]);
+  ## Get axes size in pixels
+  if (strcmp (get (axis_obj.parent, "__backend__"), "gnuplot")
+      && strcmp (axis_obj.activepositionproperty, "outerposition"))
+    pos_in_pixels = axis_obj.outerposition .* fig_position([3, 4, 3, 4]);
+  else
+    pos_in_pixels = axis_obj.position .* fig_position([3, 4, 3, 4]);
+  endif
     
   nd = __calc_dimensions__ (h);
 
@@ -82,6 +87,9 @@
       pos_in_pixels = pos_in_pixels + dy*[0.0, 0.5, 0.0, -1.0];
     endif
     pos = pos_in_pixels ./ fig_position([3, 4, 3, 4]);
+  elseif (strcmp (get (axis_obj.parent, "__backend__"), "gnuplot")
+          && strcmp (axis_obj.activepositionproperty, "outerposition"))
+    pos = axis_obj.outerposition;
   else
     pos = axis_obj.position;
   endif
