|
jwe@8920
|
1 |
## Copyright (C) 2005, 2007, 2008, 2009 John W. Eaton
|
|
jwe@6405
|
2 |
##
|
|
jwe@6405
|
3 |
## This file is part of Octave.
|
|
jwe@6405
|
4 |
##
|
|
jwe@6405
|
5 |
## Octave is free software; you can redistribute it and/or modify it
|
|
jwe@6405
|
6 |
## under the terms of the GNU General Public License as published by
|
|
jwe@7016
|
7 |
## the Free Software Foundation; either version 3 of the License, or (at
|
|
jwe@7016
|
8 |
## your option) any later version.
|
|
jwe@6405
|
9 |
##
|
|
jwe@6405
|
10 |
## Octave is distributed in the hope that it will be useful, but
|
|
jwe@6405
|
11 |
## WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
jwe@6405
|
12 |
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
jwe@6405
|
13 |
## General Public License for more details.
|
|
jwe@6405
|
14 |
##
|
|
jwe@6405
|
15 |
## You should have received a copy of the GNU General Public License
|
|
jwe@7016
|
16 |
## along with Octave; see the file COPYING. If not, see
|
|
jwe@7016
|
17 |
## <http://www.gnu.org/licenses/>.
|
|
jwe@6405
|
18 |
|
|
jwe@8812
|
19 |
## -*- texinfo -*-
|
|
jwe@8812
|
20 |
## @deftypefn {Function File} {} __go_draw_figure__ (@var{h}, @var{plot_stream}, @var{enhanced}, @var{mono})
|
|
jwe@6895
|
21 |
## Undocumented internal function.
|
|
jwe@8812
|
22 |
## @end deftypefn
|
|
jwe@6405
|
23 |
|
|
jwe@6405
|
24 |
## Author: jwe
|
|
jwe@6405
|
25 |
|
|
bpabbott@8889
|
26 |
function __go_draw_figure__ (h, plot_stream, enhanced, mono, output_to_paper, implicit_margin)
|
|
jwe@6405
|
27 |
|
|
bpabbott@8889
|
28 |
if (nargin < 5)
|
|
bpabbott@8889
|
29 |
output_to_paper = false;
|
|
bpabbott@8889
|
30 |
elseif (nargin < 6)
|
|
bpabbott@8889
|
31 |
## Gnuplot has implicit margins for some output. For example, for postscript
|
|
bpabbott@8889
|
32 |
## the margin is 50pts. If not specified asssume 0.
|
|
bpabbott@8889
|
33 |
implicit_margin = 0;
|
|
bpabbott@8889
|
34 |
endif
|
|
bpabbott@8889
|
35 |
|
|
bpabbott@8889
|
36 |
if (nargin >= 4 && nargin <= 6)
|
|
jwe@8249
|
37 |
htype = get (h, "type");
|
|
jwe@8249
|
38 |
if (strcmp (htype, "figure"))
|
|
bpabbott@9366
|
39 |
## When printing, set paperunits to inches and rely on a listener to convert
|
|
bpabbott@9366
|
40 |
## the values for papersize and paperposition.
|
|
bpabbott@8889
|
41 |
if (output_to_paper)
|
|
bpabbott@8889
|
42 |
orig_paper_units = get (h, "paperunits");
|
|
bpabbott@9366
|
43 |
gpval_term = __gnuplot_get_var__ (h, "GPVAL_TERM");
|
|
bpabbott@9366
|
44 |
gpval_termoptions = __gnuplot_get_var__ (h, "GPVAL_TERMOPTIONS");
|
|
bpabbott@8889
|
45 |
unwind_protect
|
|
bpabbott@8889
|
46 |
set (h, "paperunits", "inches");
|
|
bpabbott@8889
|
47 |
paper_size = get (h, "papersize");
|
|
bpabbott@8889
|
48 |
paper_position = get (h, "paperposition");
|
|
bpabbott@8889
|
49 |
paper_position = paper_position ./ paper_size([1, 2, 1, 2]);
|
|
bpabbott@9366
|
50 |
implicit_margin = implicit_margin ./ paper_size;
|
|
bpabbott@8889
|
51 |
unwind_protect_cleanup
|
|
bpabbott@8889
|
52 |
set (h, "paperunits", orig_paper_units);
|
|
bpabbott@8889
|
53 |
end_unwind_protect
|
|
bpabbott@9366
|
54 |
if (strcmp (gpval_term, "postscript")
|
|
bpabbott@9366
|
55 |
&& ! isempty (strfind (gpval_termoptions, "landscape")))
|
|
bpabbott@9366
|
56 |
## This needed to obtain the expected result.
|
|
bpabbott@9366
|
57 |
implicit_margin(2) = -implicit_margin(2);
|
|
bpabbott@9366
|
58 |
endif
|
|
bpabbott@8889
|
59 |
else
|
|
bpabbott@8889
|
60 |
implicit_margin = implicit_margin * [1 1];
|
|
bpabbott@8889
|
61 |
endif
|
|
bpabbott@8889
|
62 |
|
|
bpabbott@9098
|
63 |
## Get complete list of children.
|
|
bpabbott@9098
|
64 |
kids = allchild (h);
|
|
bpabbott@9098
|
65 |
nkids = length (kids);
|
|
jwe@6405
|
66 |
|
|
bpabbott@9098
|
67 |
if (nkids > 0)
|
|
bpabbott@9098
|
68 |
fputs (plot_stream, "\nreset;\n");
|
|
bpabbott@9281
|
69 |
fputs (plot_stream, "set autoscale keepfix;\n");
|
|
bpabbott@9098
|
70 |
fputs (plot_stream, "set origin 0, 0\n");
|
|
bpabbott@9098
|
71 |
fputs (plot_stream, "set size 1, 1\n");
|
|
bpabbott@9098
|
72 |
for i = 1:nkids
|
|
bpabbott@9098
|
73 |
type = get (kids(i), "type");
|
|
bpabbott@9098
|
74 |
switch (type)
|
|
bpabbott@9098
|
75 |
case "axes"
|
|
bpabbott@9098
|
76 |
## Rely upon listener to convert axes position to "normalized" units.
|
|
bpabbott@9098
|
77 |
orig_axes_units = get (kids(i), "units");
|
|
bpabbott@9098
|
78 |
orig_axes_position = get (kids(i), "position");
|
|
bpabbott@9098
|
79 |
unwind_protect
|
|
bpabbott@9098
|
80 |
set (kids(i), "units", "normalized");
|
|
bpabbott@9098
|
81 |
if (output_to_paper)
|
|
bpabbott@9098
|
82 |
axes_position_on_page = orig_axes_position .* paper_position([3, 4, 3 ,4]);
|
|
bpabbott@9098
|
83 |
axes_position_on_page(1:2) = axes_position_on_page(1:2) + paper_position(1:2);
|
|
bpabbott@9098
|
84 |
set (kids(i), "position", axes_position_on_page);
|
|
bpabbott@9098
|
85 |
__go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin);
|
|
bpabbott@9098
|
86 |
else
|
|
bpabbott@9098
|
87 |
## Return axes "units" and "position" back to their original values.
|
|
bpabbott@9098
|
88 |
__go_draw_axes__ (kids(i), plot_stream, enhanced, mono, implicit_margin);
|
|
bpabbott@9098
|
89 |
endif
|
|
bpabbott@9098
|
90 |
unwind_protect_cleanup
|
|
bpabbott@9098
|
91 |
set (kids(i), "units", orig_axes_units);
|
|
bpabbott@9098
|
92 |
set (kids(i), "position", orig_axes_position);
|
|
bpabbott@9098
|
93 |
end_unwind_protect
|
|
bpabbott@9098
|
94 |
otherwise
|
|
bpabbott@9098
|
95 |
error ("__go_draw_figure__: unknown object class, %s", type);
|
|
bpabbott@9098
|
96 |
endswitch
|
|
bpabbott@9098
|
97 |
endfor
|
|
bpabbott@9098
|
98 |
else
|
|
bpabbott@9098
|
99 |
fputs (plot_stream, "\nreset; clear;\n");
|
|
bpabbott@9098
|
100 |
fflush (plot_stream);
|
|
bpabbott@9098
|
101 |
endif
|
|
jwe@6405
|
102 |
else
|
|
jwe@6405
|
103 |
error ("__go_draw_figure__: expecting figure object, found `%s'",
|
|
jwe@8249
|
104 |
htype);
|
|
jwe@6405
|
105 |
endif
|
|
jwe@6405
|
106 |
else
|
|
jwe@6405
|
107 |
print_usage ();
|
|
jwe@6405
|
108 |
endif
|
|
jwe@6405
|
109 |
|
|
jwe@6405
|
110 |
endfunction
|
|
jwe@6405
|
111 |
|