changeset 11423:00b0aa8d539e

__go_draw_axes__.m: Enable vertical alignment of text objects for gnuplot.
author Ben Abbott <bpabbott@mac.com>
date Wed, 29 Dec 2010 17:26:21 -0500
parents 3cae59b4c0f7
children bc509d5f763f
files scripts/ChangeLog scripts/plot/__go_draw_axes__.m
diffstat 2 files changed, 28 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Tue Dec 28 17:43:43 2010 -0800
+++ b/scripts/ChangeLog	Wed Dec 29 17:26:21 2010 -0500
@@ -1,3 +1,8 @@
+2010-12-29  Ben Abbott  <bpabbott@mac.com>
+
+	* plot/__go_draw_axes__.m: Enable vertical alignment of text objects for
+	gnuplot.
+
 2010-12-28  Ben Abbott <bpabbott@mac.com>
 
 	* plot/private/__plt__.m: Fix to allow inline legend keys. Bug 31991.
--- a/scripts/plot/__go_draw_axes__.m	Tue Dec 28 17:43:43 2010 -0800
+++ b/scripts/plot/__go_draw_axes__.m	Wed Dec 29 17:26:21 2010 -0500
@@ -1233,6 +1233,7 @@
           fontspec = create_fontspec (f, s, gnuplot_term);
           lpos = obj.position;
           halign = obj.horizontalalignment;
+          valign = obj.verticalalignment;
           angle = obj.rotation;
           units = obj.units;
           color = obj.color;
@@ -1249,17 +1250,35 @@
             colorspec = get_text_colorspec (color, mono);
           endif
 
+          switch valign
+            ## Text offset in characters. This relies on gnuplot for font metrics.
+            case "top"
+              dy = -0.5;
+            case "cap"
+              dy = -0.5;
+            case "middle"
+              dy = 0;
+            case "baseline"
+              dy = 0.5;
+            case "bottom"
+              dy = 0.5;
+          endswitch
+          ## Gnuplot's Character units are different for x/y and vary with fontsize. The aspect ratio
+          ## of 1:2.5 was determined by experiment.
+          dx_and_dy = [(-dy * sind (angle)), (dy * cosd(angle))] .* [2.5 1];
+
           if (nd == 3)
+            ## This produces the desired vertical alignment in 3D.
             fprintf (plot_stream,
-                     "set label \"%s\" at %s %.15g,%.15g,%.15g %s rotate by %f %s %s front %s;\n",
+                     "set label \"%s\" at %s %.15g,%.15g,%.15g %s rotate by %f offset character %f,%f %s %s front %s;\n",
                      undo_string_escapes (label), units, lpos(1),
-                     lpos(2), lpos(3), halign, angle, fontspec,
+                     lpos(2), lpos(3), halign, angle, dx_and_dy, fontspec,
                      __do_enhanced_option__ (enhanced, obj), colorspec);
           else
             fprintf (plot_stream,
-                     "set label \"%s\" at %s %.15g,%.15g %s rotate by %f %s %s front %s;\n",
+                     "set label \"%s\" at %s %.15g,%.15g %s rotate by %f offset character %f,%f %s %s front %s;\n",
                      undo_string_escapes (label), units,
-                     lpos(1), lpos(2), halign, angle, fontspec,
+                     lpos(1), lpos(2), halign, angle, dx_and_dy, fontspec,
                      __do_enhanced_option__ (enhanced, obj), colorspec);
           endif