annotate scripts/plot/__go_draw_figure__.m @ 8889:665b264b6a50

Compatible support of figure paper properties and resolution for the gnuplot backend.
author Ben Abbott <bpabbott@mac.com>
date Sat, 28 Feb 2009 19:36:09 -0500
parents 7d48766c21a5
children eb63fbe60fab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
1 ## Copyright (C) 2005, 2007 John W. Eaton
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
2 ##
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
4 ##
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
8 ## your option) any later version.
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
9 ##
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
14 ##
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
17 ## <http://www.gnu.org/licenses/>.
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
18
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8249
diff changeset
19 ## -*- texinfo -*-
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8249
diff changeset
20 ## @deftypefn {Function File} {} __go_draw_figure__ (@var{h}, @var{plot_stream}, @var{enhanced}, @var{mono})
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6619
diff changeset
21 ## Undocumented internal function.
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8249
diff changeset
22 ## @end deftypefn
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
23
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
24 ## Author: jwe
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
25
8889
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
26 function __go_draw_figure__ (h, plot_stream, enhanced, mono, output_to_paper, implicit_margin)
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
27
8889
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
28 if (nargin < 5)
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
29 output_to_paper = false;
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
30 elseif (nargin < 6)
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
31 ## Gnuplot has implicit margins for some output. For example, for postscript
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
32 ## the margin is 50pts. If not specified asssume 0.
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
33 implicit_margin = 0;
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
34 endif
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
35
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
36 if (nargin >= 4 && nargin <= 6)
8249
1f429086565c [mq]: hidden-children
John W. Eaton <jwe@octave.org>
parents: 8224
diff changeset
37 htype = get (h, "type");
1f429086565c [mq]: hidden-children
John W. Eaton <jwe@octave.org>
parents: 8224
diff changeset
38 if (strcmp (htype, "figure"))
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
39
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
40 ## Set figure properties here?
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
41
8889
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
42 ## For output, determine the normalized paperposition.
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
43 if (output_to_paper)
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
44 orig_paper_units = get (h, "paperunits");
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
45 unwind_protect
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
46 set (h, "paperunits", "inches");
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
47 paper_size = get (h, "papersize");
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
48 paper_position = get (h, "paperposition");
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
49 paper_position = paper_position ./ paper_size([1, 2, 1, 2]);
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
50 implicit_margin = implicit_margin ./ paper_size([1, 2]);
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
51 unwind_protect_cleanup
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
52 set (h, "paperunits", orig_paper_units);
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
53 end_unwind_protect
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
54 else
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
55 implicit_margin = implicit_margin * [1 1];
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
56 endif
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
57
8249
1f429086565c [mq]: hidden-children
John W. Eaton <jwe@octave.org>
parents: 8224
diff changeset
58 ## Get complete list of children.
1f429086565c [mq]: hidden-children
John W. Eaton <jwe@octave.org>
parents: 8224
diff changeset
59 kids = allchild (h);
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
60 nkids = length (kids);
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
61
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
62 if (nkids > 0)
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
63
6619
b2b3b0509586 [project @ 2007-05-14 16:32:54 by jwe]
jwe
parents: 6438
diff changeset
64 fputs (plot_stream, "\nreset;\n");
7271
c18512d0ddb6 [project @ 2007-12-10 06:52:51 by jwe]
jwe
parents: 7269
diff changeset
65 fputs (plot_stream, "set autoscale fix;\n");
8224
62d90e049d4f Always use multiplot with gnuplot to ensure correct postscript bounding box
David Bateman <dbateman@free.fr>
parents: 8208
diff changeset
66 fputs (plot_stream, "set multiplot;\n");
62d90e049d4f Always use multiplot with gnuplot to ensure correct postscript bounding box
David Bateman <dbateman@free.fr>
parents: 8208
diff changeset
67 fputs (plot_stream, "set origin 0, 0\n");
62d90e049d4f Always use multiplot with gnuplot to ensure correct postscript bounding box
David Bateman <dbateman@free.fr>
parents: 8208
diff changeset
68 fputs (plot_stream, "set size 1, 1\n");
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
69
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
70 for i = 1:nkids
8889
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
71 type = get (kids(i), "type");
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
72 switch (type)
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
73 case "axes"
8889
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
74 ## Rely upon listener to convert axes position to "normalized" units.
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
75 orig_axes_units = get (kids(i), "units");
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
76 orig_axes_position = get (kids(i), "position");
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
77 unwind_protect
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
78 set (kids(i), "units", "normalized");
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
79 if (output_to_paper)
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
80 axes_position_on_page = orig_axes_position .* paper_position([3, 4, 3 ,4]);
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
81 axes_position_on_page(1:2) = axes_position_on_page(1:2) + paper_position(1:2);
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
82 set (kids(i), "position", axes_position_on_page);
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
83 __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin);
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
84 else
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
85 ## Return axes "units" and "position" back to their original values.
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
86 __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin);
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
87 endif
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
88 unwind_protect_cleanup
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
89 set (kids(i), "units", orig_axes_units);
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
90 set (kids(i), "position", orig_axes_position);
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
91 end_unwind_protect
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
92 otherwise
8889
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
93 error ("__go_draw_figure__: unknown object class, %s", type);
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
94 endswitch
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
95 endfor
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
96
8224
62d90e049d4f Always use multiplot with gnuplot to ensure correct postscript bounding box
David Bateman <dbateman@free.fr>
parents: 8208
diff changeset
97 fputs (plot_stream, "unset multiplot;\n");
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
98 else
6619
b2b3b0509586 [project @ 2007-05-14 16:32:54 by jwe]
jwe
parents: 6438
diff changeset
99 fputs (plot_stream, "\nreset; clear;\n");
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
100 fflush (plot_stream);
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
101 endif
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
102 else
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
103 error ("__go_draw_figure__: expecting figure object, found `%s'",
8249
1f429086565c [mq]: hidden-children
John W. Eaton <jwe@octave.org>
parents: 8224
diff changeset
104 htype);
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
105 endif
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
106 else
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
107 print_usage ();
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
108 endif
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
109
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
110 endfunction
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
111