# HG changeset patch
# User Daniel J Sebald <daniel.sebald@ieee.org>
# Date 1434394186 18000
# Node ID b738e79ce8a3cb94e3b42dc9b5f1ddd1b02fba40
# Parent  530803d4f65fccafa3f3059e5757ec4f54b56f50
Fix gnuplot toolkit face/edgecolor and linestyle/width for surf() (bug #34523)

* __gnuplot_has_feature__.m (__gnuplot_has_feature__): Add "dashtype" to list
of 'features' string cell array, "5.0" to 'versions' string cell array, and
">=" to 'operators' string cell array.

* __go_draw_axes__.m (__go_draw_axes__): Move linestyle property translation to
its own function gnuplot_linetype() and call that function.  For a surface,
move the flat_interp_face, flat_interp_edge and facecolor_none_or_white
definitions to sooner point in flow.  If the surface has a face color, set the
fourth data column to the same 24-bit RGB face color value.  Consolidate 'unset
pm3d' at one location prior to conditional tests.  If surface has face color,
use pm3d with the RGB variable mode option in gnuplot splot command and
construct 'set pm3d' options for border, line/dash type, line color and line
width.  Place a newline character at the end of the data sent to gnuplot.
(gnuplot_linetype): New function containing switch statements for translating
linestyle to a gnuplot command option, either dashtype or linetype depending
upon whether gnuplot has the recent dashtype feature.

diff --git a/scripts/plot/util/private/__gnuplot_has_feature__.m b/scripts/plot/util/private/__gnuplot_has_feature__.m
--- a/scripts/plot/util/private/__gnuplot_has_feature__.m
+++ b/scripts/plot/util/private/__gnuplot_has_feature__.m
@@ -35,7 +35,8 @@ function res = __gnuplot_has_feature__ (
                          "variable_GPVAL_TERMINALS",
                          "key_has_font_properties",
                          "windows_figure_position",
-                         "has_termoption_dashed"};
+                         "has_termoption_dashed",
+                         "dashtype"};
   persistent has_features;
 
   if (isempty (has_features))
@@ -45,8 +46,8 @@ function res = __gnuplot_has_feature__ (
       ## Don't throw an error if gnuplot isn't installed
       gnuplot_version = "0.0.0";
     end_try_catch
-    versions = {"4.2.5", "4.4", "4.4", "4.4", "4.2", "4.2", "4.4", "4.4", "4.4", "4.4", "4.3"};
-    operators = {">=", ">=", ">=", ">=", ">=", ">=", ">=", ">=", ">=", ">=", ">="};
+    versions = {"4.2.5", "4.4", "4.4", "4.4", "4.2", "4.2", "4.4", "4.4", "4.4", "4.4", "4.3", "5.0"};
+    operators = {">=", ">=", ">=", ">=", ">=", ">=", ">=", ">=", ">=", ">=", ">=", ">="};
     have_features = false (size (features));
     for n = 1 : numel (have_features)
       has_features(n) = compare_versions (gnuplot_version, versions{n}, operators{n});
diff --git a/scripts/plot/util/private/__go_draw_axes__.m b/scripts/plot/util/private/__go_draw_axes__.m
--- a/scripts/plot/util/private/__go_draw_axes__.m
+++ b/scripts/plot/util/private/__go_draw_axes__.m
@@ -884,24 +884,7 @@ function __go_draw_axes__ (h, plot_strea
              color = [0, 0, 0];
            endif
 
-           if (isfield (obj, "linestyle"))
-             switch (obj.linestyle)
-               case "-"
-                 lt = "lt 1";
-               case "--"
-                 lt = "lt 2";
-               case ":"
-                 lt = "lt 3";
-               case "-."
-                 lt = "lt 6";
-               case "none"
-                 lt = "";
-               otherwise
-                 lt = "";
-             endswitch
-           else
-             lt = "";
-           endif
+           lt = gnuplot_linetype (obj);
 
            if (isfield (obj, "linewidth"))
              lw = sprintf ("linewidth %f", obj.linewidth);
@@ -1145,6 +1128,14 @@ function __go_draw_axes__ (h, plot_strea
           withpm3d = true;
           pm3didx = data_idx;
 
+          flat_interp_face = (strcmp (obj.facecolor, "flat")
+                              || strcmp (obj.facecolor, "interp"));
+          flat_interp_edge = (strcmp (obj.edgecolor, "flat")
+                              || strcmp (obj.edgecolor, "interp"));
+
+          facecolor_none_or_white = (strcmp (obj.facecolor, "none")
+                                     || (isnumeric (obj.facecolor)
+                                         && all (obj.facecolor == 1)));
           xdat = obj.xdata;
           ydat = obj.ydata;
           zdat = obj.zdata;
@@ -1182,7 +1173,13 @@ function __go_draw_axes__ (h, plot_strea
               zz(:,kk)   = xdat(:,k);
               zz(:,kk+1) = ydat(:,k);
               zz(:,kk+2) = zdat(:,k);
-              zz(:,kk+3) = cdat(:,k);
+              if (facecolor_none_or_white)
+                zz(:,kk+3) = cdat(:,k);
+              else
+                ## Convert color to 24-bit RGB
+                zz(:,kk+3) = hex2dec (sprintf ("%02x%02x%02x",
+                                               round (255*obj.facecolor)));
+              endif
               k++;
             endfor
             data{data_idx} = zz.';
@@ -1196,20 +1193,12 @@ function __go_draw_axes__ (h, plot_strea
           endif
           usingclause{data_idx} = sprintf ("record=%dx%d using ($1):($2):($3):($4)", ylen, xlen);
 
-          flat_interp_face = (strcmp (obj.facecolor, "flat")
-                              || strcmp (obj.facecolor, "interp"));
-          flat_interp_edge = (strcmp (obj.edgecolor, "flat")
-                              || strcmp (obj.edgecolor, "interp"));
-
-          facecolor_none_or_white = (strcmp (obj.facecolor, "none")
-                                     || (isnumeric (obj.facecolor)
-                                         && all (obj.facecolor == 1)));
           hidden_removal = false;
+          fputs (plot_stream, "unset pm3d\n");
           fputs (plot_stream, "set style increment default;\n");
           if (flat_interp_edge && facecolor_none_or_white)
             withpm3d = false;
             withclause{data_idx} = sprintf ("with %s palette", style{1});
-            fputs (plot_stream, "unset pm3d\n");
             if (all (obj.facecolor == 1))
               hidden_removal = true;
             endif
@@ -1217,12 +1206,14 @@ function __go_draw_axes__ (h, plot_strea
             if (all (obj.facecolor == 1))
               hidden_removal = true;
             endif
-            fputs (plot_stream,"unset pm3d;\n");
             fputs (plot_stream,"set style increment user;\n");
             withpm3d = false;
             withclause{data_idx} = sprintf ("with %s linestyle %d",
                                             style{1}, data_idx);
-            fputs (plot_stream, "unset pm3d\n");
+          else
+            ## gnuplot hidden line removal doesn't support pm3d
+            hidden_removal = false;
+            withclause{data_idx} = sprintf ("with pm3d linecolor rgb variable");
           endif
 
           if (doing_interp_color)
@@ -1248,10 +1239,22 @@ function __go_draw_axes__ (h, plot_strea
                        "set pm3d explicit at s %s corners2color c3;\n",
                        interp_str, dord);
             else
+              lt = gnuplot_linetype (obj);
+              lc = sprintf ("linecolor rgb \"#%02x%02x%02x\"",
+                            round (255*obj.edgecolor));
+              if (isfield (obj, "linewidth"))
+                lw = sprintf ("linewidth %f", obj.linewidth);
+              else
+                lw = "";
+              endif
+              if (__gnuplot_has_feature__ ("dashtype"))
+                bopt = "border";
+              else
+                bopt = "";
+              endif
               fprintf (plot_stream,
-                       "set pm3d explicit at s hidden3d %d %s %s corners2color c3;\n",
-                       data_idx, interp_str, dord);
-
+                       "set pm3d explicit at s hidden3d %s %s %s %s %s %s corners2color c3;\n",
+                       bopt, lt, lc, lw, interp_str, dord);
               if (__gnuplot_has_feature__ ("transparent_surface")
                   && isscalar (obj.facealpha))
                 fprintf (plot_stream,
@@ -1403,7 +1406,7 @@ function __go_draw_axes__ (h, plot_strea
 
   endwhile
 
-  ## This is need to prevent warnings for rotations in 3D plots, while
+  ## This is needed to prevent warnings for rotations in 3D plots, while
   ## allowing colorbars with contours.
   if (nd == 2 || (data_idx > 1 && ! view_map))
     fputs (plot_stream, "set pm3d implicit;\n");
@@ -1748,6 +1751,7 @@ function __go_draw_axes__ (h, plot_strea
                                 have_cdata(i));
       endif
     endfor
+    fputs (plot_stream, "\n");
   else
     fputs (plot_stream, "plot \"-\";\nInf Inf\ne\n");
   endif
@@ -1817,28 +1821,9 @@ function style = do_linestyle_command (o
     color = [0, 0, 0];
   endif
 
-  if (isfield (obj, "linestyle"))
-    switch (obj.linestyle)
-      case "-"
-        lt = "1";
-      case "--"
-        lt = "2";
-      case ":"
-        lt = "3";
-      case "-."
-        lt = "6";
-      case "none"
-        lt = "";
-      otherwise
-        lt = "";
-    endswitch
-
-    if (! isempty (lt))
-      fprintf (plot_stream, " linetype %s", lt);
-    endif
-
-  else
-    lt = "";
+  lt = gnuplot_linetype (obj);
+  if (! isempty (lt))
+    fprintf (plot_stream, " %s", lt);
   endif
   if (! isempty (errbars))
     found_style = true;
@@ -1965,6 +1950,49 @@ function style = do_linestyle_command (o
 
 endfunction
 
+function [lt] = gnuplot_linetype (obj)
+  if (isfield (obj, "linestyle"))
+    if (__gnuplot_has_feature__ ("dashtype"))
+      opt = "dashtype";
+      switch (obj.linestyle)
+        case "-"
+          lt = "1";
+        case "--"
+          lt = "2";
+        case ":"
+          lt = "3";
+        case "-."
+          lt = "4";
+        case "none"
+          lt = "";
+        otherwise
+          lt = "";
+      endswitch
+    else
+      opt = "linetype";
+      switch (obj.linestyle)
+        case "-"
+          lt = "1";
+        case "--"
+          lt = "2";
+        case ":"
+          lt = "3";
+        case "-."
+          lt = "6";
+        case "none"
+          lt = "";
+        otherwise
+          lt = "";
+      endswitch
+    endif
+    if (! isempty (lt))
+      lt = sprintf ("%s %s", opt, lt);
+    endif
+  else
+    lt = "";
+  endif
+endfunction
+
 function [pt, pt2, obj] = gnuplot_pointtype (obj)
   if (isfield (obj, "marker"))
     switch (obj.marker)
exporting patch:
<fdopen>
