diff scripts/plot/__go_draw_axes__.m @ 10995:e81914f3921f

Update legend code to support fltk (fixes #29348 and partially fixes #30461)
author David Bateman <dbateman@free.fr>
date Sat, 18 Sep 2010 22:30:41 +0200
parents 88687577519f
children 65c14c052fe3
line wrap: on
line diff
--- a/scripts/plot/__go_draw_axes__.m	Sat Sep 18 16:19:31 2010 -0400
+++ b/scripts/plot/__go_draw_axes__.m	Sat Sep 18 22:30:41 2010 +0200
@@ -23,7 +23,7 @@
 
 ## Author: jwe
 
-function __go_draw_axes__ (h, plot_stream, enhanced, mono, bg_is_set)
+function __go_draw_axes__ (h, plot_stream, enhanced, mono, bg_is_set, hlegend)
 
   if (nargin >= 4 && nargin <= 6)
 
@@ -31,6 +31,11 @@
     unwind_protect
       set (0, "showhiddenhandles", "on");
       axis_obj = __get__ (h);
+      if (isempty (hlegend))
+        hlgnd = [];
+      else
+        hlgnd = __get__ (hlegend);
+      endif
     unwind_protect_cleanup
       set (0, "showhiddenhandles", showhiddenhandles);
     end_unwind_protect
@@ -486,11 +491,10 @@
           parametric(data_idx) = true;
           have_cdata(data_idx) = false;
           have_3d_patch(data_idx) = false;
-
-          if (isempty (obj.keylabel))
+          if (isempty (obj.displayname))
             titlespec{data_idx} = "title \"\"";
           else
-            tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "keylabel"));
+            tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "displayname"));
             titlespec{data_idx} = cstrcat ("title \"", tmp, "\"");
           endif
           usingclause{data_idx} = sprintf ("record=%d", numel (obj.xdata));
@@ -606,10 +610,10 @@
                  have_3d_patch(data_idx) = false;
                endif
 
-               if (i > 1 || isempty (obj.keylabel))
+               if (i > 1 || isempty (obj.displayname))
                  titlespec{local_idx} = "title \"\"";
                else
-                 tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "keylabel"));
+                 tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "displayname"));
                  titlespec{local_idx} = cstrcat ("title \"", tmp, "\"");
                endif
                if (isfield (obj, "facecolor"))
@@ -1028,10 +1032,11 @@
             style = do_linestyle_command (obj, obj.edgecolor,
                                           data_idx, mono, 
                                           plot_stream);
-            if (isempty (obj.keylabel))
+
+            if (isempty (obj.displayname))
               titlespec{data_idx} = "title \"\"";
             else
-              tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "keylabel"));
+              tmp = undo_string_escapes (__maybe_munge_text__ (enhanced, obj, "displayname"));
               titlespec{data_idx} = cstrcat ("title \"", tmp, "\"");
             endif
             withclause{data_idx} = sprintf ("with pm3d linestyle %d",
@@ -1351,7 +1356,7 @@
     else
       if (nd == 3)
         fputs (plot_stream, "set border 895;\n");
-      else
+      elseif (! isempty (axis_obj.ytick))
         if (strcmpi (axis_obj.yaxislocation, "right"))
           fprintf (plot_stream, "unset ytics; set y2tics %s nomirror\n",
                    axis_obj.tickdir);
@@ -1386,19 +1391,30 @@
       fprintf (plot_stream, "set border lw %f;\n", axis_obj.linewidth);
     endif
 
-    if (strcmpi (axis_obj.key, "on"))
-      if (strcmpi (axis_obj.keybox, "on"))
+    if (! isempty (hlgnd) 
+        && any (strcmpi (get (get (hlegend, "children"), "visible"), "on")))
+      hlgnd.box
+      hlgnd.orientation
+      hlgnd.textposition
+      hlgnd.location
+
+      if (strcmpi (hlgnd.box, "on"))
         box = "box";
       else
         box = "nobox";
       endif
-      if (strcmpi (axis_obj.keyreverse, "on"))
+      if (strcmpi (hlgnd.orientation, "vertical"))
+        horzvert = "vertical";
+      else
+        horzvert = "horizontal";
+      endif
+      if (strcmpi (hlgnd.textposition, "right"))
         reverse = "reverse";
       else
         reverse = "noreverse";
       endif
       inout = "inside";
-      keypos = axis_obj.keypos;
+      keypos = hlgnd.location;
       if (ischar (keypos))
         keypos = lower (keypos);
         keyout = findstr (keypos, "outside");
@@ -1408,17 +1424,6 @@
         endif
       endif
       switch (keypos)
-        case -1
-          pos = "right top";
-          inout = "outside";
-        case 1
-          pos = "right top";
-        case 2
-          pos = "left top";
-        case 3
-          pos = "left bottom";
-        case {4, 0}
-          pos = "right bottom";
         case "north"
           pos = "center top";
         case "south"
@@ -1444,16 +1449,15 @@
           pos = "";
       endswitch
       if (__gnuplot_has_feature__ ("key_has_font_properties"))
-        fontspec = create_fontspec (axis_obj.fontname, axis_obj.fontsize, gnuplot_term);
+        fontspec = create_fontspec (hlgnd.fontname, hlgnd.fontsize, gnuplot_term);
       else
         fontspec = "";
       endif
-      fprintf (plot_stream, "set key %s %s %s %s %s;\n", inout, pos, box,
-               reverse, fontspec);
+      fprintf (plot_stream, "set key %s %s;\nset key %s %s %s %s;\n", 
+               inout, pos, box, reverse, horzvert, fontspec);
     else
       fputs (plot_stream, "unset key;\n");
     endif
-
     fputs (plot_stream, "set style data lines;\n");
 
     if (! use_gnuplot_for_images)