annotate scripts/plot/__go_draw_figure__.m @ 10473:169be980faf9

__go_draw_figure__.m: Untabify.
author Ben Abbott <bpabbott@mac.com>
date Sat, 27 Mar 2010 19:56:08 -0400
parents 9f0e7bfe63e5
children 424795ef82b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8889
diff changeset
1 ## Copyright (C) 2005, 2007, 2008, 2009 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"))
9393
d6c99b2ee941 print.m: reimplement options -landscape and -portrait.
Ben Abbott <bpabbott@mac.com>
parents: 9281
diff changeset
39 ## When printing, set paperunits to inches and rely on a listener to convert
d6c99b2ee941 print.m: reimplement options -landscape and -portrait.
Ben Abbott <bpabbott@mac.com>
parents: 9281
diff changeset
40 ## the values for papersize and paperposition.
8889
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
41 if (output_to_paper)
10473
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
42 orig_paper_units = get (h, "paperunits");
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
43 gpval_term = __gnuplot_get_var__ (h, "GPVAL_TERM");
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
44 gpval_termoptions = __gnuplot_get_var__ (h, "GPVAL_TERMOPTIONS");
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
45 unwind_protect
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
46 set (h, "paperunits", "inches");
8889
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]);
10473
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
50 implicit_margin = implicit_margin ./ paper_size;
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
51 unwind_protect_cleanup
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
52 set (h, "paperunits", orig_paper_units);
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
53 end_unwind_protect
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
54 if (strcmp (gpval_term, "postscript")
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
55 && ! isempty (strfind (gpval_termoptions, "landscape")))
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
56 ## This needed to obtain the expected result.
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
57 implicit_margin(2) = -implicit_margin(2);
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
58 endif
8889
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
59 else
10473
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
60 implicit_margin = implicit_margin * [1 1];
8889
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
61 endif
665b264b6a50 Compatible support of figure paper properties and resolution for the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 8812
diff changeset
62
9098
5ecdb3d3568f Allow fontsize to be specified for all objects with fontname == "*".
Ben Abbott <bpabbott@mac.com>
parents: 9062
diff changeset
63 ## Get complete list of children.
5ecdb3d3568f Allow fontsize to be specified for all objects with fontname == "*".
Ben Abbott <bpabbott@mac.com>
parents: 9062
diff changeset
64 kids = allchild (h);
5ecdb3d3568f Allow fontsize to be specified for all objects with fontname == "*".
Ben Abbott <bpabbott@mac.com>
parents: 9062
diff changeset
65 nkids = length (kids);
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
66
9098
5ecdb3d3568f Allow fontsize to be specified for all objects with fontname == "*".
Ben Abbott <bpabbott@mac.com>
parents: 9062
diff changeset
67 if (nkids > 0)
10473
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
68 fputs (plot_stream, "\nreset;\n");
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
69 fputs (plot_stream, "set autoscale keepfix;\n");
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
70 fputs (plot_stream, "set origin 0, 0\n");
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
71 fputs (plot_stream, "set size 1, 1\n");
10119
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
72 bg = get (h, "color");
10136
ee18258bc002 Also treat white figure and axes color properties
David Bateman <dbateman@free.fr>
parents: 10120
diff changeset
73 if (isnumeric (bg))
10119
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
74 fprintf (plot_stream, "set obj 1 rectangle from screen 0,0 to screen 1,1 behind fc rgb \"#%02x%02x%02x\"\n", 255 * bg);
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
75 bg_is_set = true;
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
76 else
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
77 bg_is_set = false;
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
78 endif
10473
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
79 for i = nkids:-1:1
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
80 type = get (kids(i), "type");
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
81 switch (type)
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
82 case "axes"
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
83 ## Rely upon listener to convert axes position to "normalized" units.
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
84 orig_axes_units = get (kids(i), "units");
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
85 orig_axes_position = get (kids(i), "position");
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
86 unwind_protect
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
87 set (kids(i), "units", "normalized");
10119
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
88 fg = get (kids(i), "color");
10136
ee18258bc002 Also treat white figure and axes color properties
David Bateman <dbateman@free.fr>
parents: 10120
diff changeset
89 if (isnumeric (fg))
10119
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
90 fprintf (plot_stream, "set obj 2 rectangle from graph 0,0 to graph 1,1 behind fc rgb \"#%02x%02x%02x\"\n", 255 * fg);
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
91 fg_is_set = true;
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
92 else
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
93 fg_is_set = false;
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
94 endif
10473
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
95 if (output_to_paper)
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
96 axes_position_on_page = orig_axes_position .* paper_position([3, 4, 3 ,4]);
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
97 axes_position_on_page(1:2) = axes_position_on_page(1:2) + paper_position(1:2);
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
98 set (kids(i), "position", axes_position_on_page);
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
99 __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin);
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
100 else
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
101 ## Return axes "units" and "position" back to their original values.
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
102 __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin);
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
103 endif
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
104 unwind_protect_cleanup
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
105 set (kids(i), "units", orig_axes_units);
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
106 set (kids(i), "position", orig_axes_position);
10119
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
107 if (fg_is_set)
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
108 fputs (plot_stream, "unset obj 2\n");
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
109 endif
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
110 if (bg_is_set)
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
111 fputs (plot_stream, "unset obj 1\n");
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
112 bg_is_set = false;
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
113 endif
10473
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
114 end_unwind_protect
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
115 otherwise
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
116 error ("__go_draw_figure__: unknown object class, %s", type);
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
117 endswitch
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
118 endfor
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
119 fputs (plot_stream, "\nunset multiplot;\n");
9098
5ecdb3d3568f Allow fontsize to be specified for all objects with fontname == "*".
Ben Abbott <bpabbott@mac.com>
parents: 9062
diff changeset
120 else
10473
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
121 fputs (plot_stream, "\nreset; clear;\n");
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
122 fflush (plot_stream);
9098
5ecdb3d3568f Allow fontsize to be specified for all objects with fontname == "*".
Ben Abbott <bpabbott@mac.com>
parents: 9062
diff changeset
123 endif
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
124 else
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
125 error ("__go_draw_figure__: expecting figure object, found `%s'",
10473
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
126 htype);
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
127 endif
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
128 else
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
129 print_usage ();
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
130 endif
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
131
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
132 endfunction
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
133