comparison scripts/plot/private/__go_draw_figure__.m @ 12793:6f91ca83d2be

codesprint : Make many plot helper functions private. * plot/module.mk : Update where to find files for Automake *__fltk_ginput__.m, __fltk_print__.m, __gnuplot_drawnow__.m, __gnuplot_get_var__.m, __gnuplot_ginput__.m, __gnuplot_has_feature__.m, __gnuplot_open_stream__.m, __gnuplot_print__.m, __gnuplot_version__.m, __go_draw_axes__.m, __go_draw_figure__.m, __marching_cube__.m, __next_line_color__.m, __next_line_style__.m, __print_parse_opts__.m: Move helper functions into plot/private/ directory.
author Rik <octave@nomad.inbox5.com>
date Sat, 16 Jul 2011 09:28:26 -0700
parents scripts/plot/__go_draw_figure__.m@c792872f8942
children 72c96de7a403
comparison
equal deleted inserted replaced
12792:dc29b64668fa 12793:6f91ca83d2be
1 ## Copyright (C) 2005-2011 John W. Eaton
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} __go_draw_figure__ (@var{h}, @var{plot_stream}, @var{enhanced}, @var{mono})
21 ## Undocumented internal function.
22 ## @end deftypefn
23
24 ## Author: jwe
25
26 function __go_draw_figure__ (h, plot_stream, enhanced, mono)
27
28 if (nargin == 4)
29 htype = get (h, "type");
30 if (strcmp (htype, "figure"))
31 ## Get complete list of children.
32 kids = allchild (h);
33 nkids = length (kids);
34
35 if (nkids > 0)
36 fputs (plot_stream, "\nreset;\n");
37 fputs (plot_stream, "set autoscale keepfix;\n");
38 fputs (plot_stream, "set origin 0, 0\n");
39 fputs (plot_stream, "set size 1, 1\n");
40 bg = get (h, "color");
41 if (isnumeric (bg))
42 fprintf (plot_stream, "set obj 1 rectangle from screen 0,0 to screen 1,1 behind fc rgb \"#%02x%02x%02x\"\n", 255 * bg);
43 bg_is_set = true;
44 else
45 bg_is_set = false;
46 endif
47
48 for i = nkids:-1:1
49 type = get (kids(i), "type");
50 switch (type)
51 case "axes"
52 if (strcmpi (get (kids (i), "tag"), "legend"))
53 ## This is so ugly. If there was a way of getting
54 ## gnuplot to give us the text extents of strings
55 ## then we could get rid of this mess.
56 lh = getfield (get (kids(i), "userdata"), "handle");
57 if (isscalar (lh))
58 ## We have a legend with a single parent. It'll be handled
59 ## below as a gnuplot key to the axis it corresponds to
60 continue;
61 else
62 ca = lh(1);
63 ## Rely upon listener to convert axes position
64 ## to "normalized" units.
65 legend_axes_units = get (kids(i), "units");
66 legend_axes_position = get (kids(i), "position");
67 legend_axes_outerposition = get (kids(i), "outerposition");
68 legend_axes_box = get (kids(i), "box");
69 legend_axes_ylim = get (kids(i), "ylim");
70 orig_axes_units = get (ca, "units");
71 hlgnd = get (kids(i));
72
73 unwind_protect
74 set (ca, "units", "normalized");
75 set (kids(i), "units", "normalized", "box", "off",
76 "ylim", [-2, -1], "position", get (ca(1), "position"),
77 "outerposition", get (ca(1), "outerposition"));
78
79 ## Create a new set of lines with the appropriate
80 ## displaynames, etc
81 toberm = [];
82 hobj = get (kids(i), "children");
83 for j = numel (hobj) : -1 : 1
84 if (! strcmp (get (hobj(j), "type"), "text"))
85 continue;
86 endif
87 displayname = get (hobj(j), "string");
88 ll = [];
89 lm = [];
90 for k = numel (hobj) : -1 : 1
91 if (! strcmp (get (hobj(k), "type"), "line"))
92 continue;
93 endif
94 if (get (hobj(j), "userdata")
95 != get (hobj(k), "userdata"))
96 continue;
97 endif
98 if (! strcmp (get (hobj(k), "linestyle"), "none"))
99 ll = hobj(k);
100 endif
101 if (! strcmp (get (hobj(k), "marker"), "none"))
102 lm = hobj(k);
103 endif
104 endfor
105
106 if (! isempty (ll))
107 if (!isempty (lm))
108 toberm = [toberm, line("xdata",[0,0],"ydata",[0,0], "color", get(lm,"color"), "linestyle", get(ll,"linestyle"), "marker", get(lm,"marker"), "markeredgecolor", get(lm,"markeredgecolor"), "markerfacecolor", get(lm,"markerfacecolor"), "markersize", get (lm, "markersize"), "displayname", displayname, "parent", kids(i))];
109 else
110 toberm = [toberm, line("xdata",[0,0],"ydata",[0,0], "color", get(ll,"color"), "linestyle", get(ll,"linestyle"), "marker", "none", "displayname", displayname, "parent", kids(i))];
111 endif
112 elseif (! isempty (lm))
113 toberm = [toberm, line("xdata",[0,0],"ydata",[0,0], "color", get(lm,"color"), "linestyle", "none", "marker", get(lm,"marker"), "markeredgecolor", get(lm,"markeredgecolor"), "markerfacecolor", get(lm,"markerfacecolor"), "markersize", get (lm, "markersize"), "displayname", displayname, "parent", kids(i))];
114 endif
115 endfor
116 if (bg_is_set)
117 fprintf (plot_stream, "set border linecolor rgb \"#%02x%02x%02x\"\n", 255 * (1 - bg));
118 endif
119 __go_draw_axes__ (kids(i), plot_stream, enhanced, mono,
120 bg_is_set, false, hlgnd);
121 unwind_protect_cleanup
122 ## Return axes "units" and "position" back to
123 ## their original values.
124 set (ca, "units", orig_axes_units);
125 set (kids(i), "units", legend_axes_units,
126 "box", legend_axes_box,
127 "ylim", legend_axes_ylim,
128 "position", legend_axes_position,
129 "outerposition", legend_axes_outerposition);
130 delete (toberm);
131 bg_is_set = false;
132 end_unwind_protect
133 endif
134 else
135 ## Rely upon listener to convert axes position
136 ## to "normalized" units.
137 orig_axes_units = get (kids(i), "units");
138 orig_axes_position = get (kids(i), "position");
139 unwind_protect
140 set (kids(i), "units", "normalized");
141 fg = get (kids(i), "color");
142 if (isnumeric (fg) && strcmp (get (kids(i), "visible"), "on"))
143 fprintf (plot_stream, "set obj 2 rectangle from graph 0,0 to graph 1,1 behind fc rgb \"#%02x%02x%02x\"\n", 255 * fg);
144 fg_is_set = true;
145 else
146 fg_is_set = false;
147 endif
148 if (bg_is_set)
149 fprintf (plot_stream, "set border linecolor rgb \"#%02x%02x%02x\"\n", 255 * (1 - bg));
150 endif
151 ## Find if this axes has an associated legend axes and pass it
152 ## to __go_draw_axes__
153 hlegend = [];
154 fkids = get (h, "children");
155 for j = 1 : numel(fkids)
156 if (ishandle (fkids (j))
157 && strcmp (get (fkids (j), "type"), "axes")
158 && (strcmp (get (fkids (j), "tag"), "legend")))
159 udata = get (fkids (j), "userdata");
160 if (isscalar(udata.handle)
161 && ! isempty (intersect (udata.handle, kids (i))))
162 hlegend = get (fkids (j));
163 break;
164 endif
165 endif
166 endfor
167 __go_draw_axes__ (kids(i), plot_stream, enhanced, mono,
168 bg_is_set, fg_is_set, hlegend);
169 unwind_protect_cleanup
170 ## Return axes "units" and "position" back to
171 ## their original values.
172 set (kids(i), "units", orig_axes_units);
173 set (kids(i), "position", orig_axes_position);
174 bg_is_set = false;
175 fg_is_set = false;
176 end_unwind_protect
177 endif
178 case "uimenu"
179 ## ignore uimenu objects
180 otherwise
181 error ("__go_draw_figure__: unknown object class, %s", type);
182 endswitch
183 endfor
184 fputs (plot_stream, "\nunset multiplot;\n");
185 else
186 fputs (plot_stream, "\nreset; clear;\n");
187 fflush (plot_stream);
188 endif
189 else
190 error ("__go_draw_figure__: expecting figure object, found `%s'",
191 htype);
192 endif
193 else
194 print_usage ();
195 endif
196
197 endfunction
198