Mercurial > octave-nkf
comparison scripts/plot/util/private/__gnuplot_draw_figure__.m @ 20435:755ba248fb4a
build: Rename __go_draw_XXX to __gnuplot_draw_XXX for clarity.
* scripts/plot/util/private/__gnuplot_draw_axes__.m: Renamed from
__go_draw_axes__.m
* scripts/plot/util/private/__gnuplot_draw_figure__.m: Renamed from
__go_draw_figure__.m
* __scatter__.m, __gnuplot_drawnow__.m: Update scripts to use new names.
* scripts/plot/util/module.mk: Use new file names in build system.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 26 Jul 2015 18:33:57 -0700 |
parents | scripts/plot/util/private/__go_draw_figure__.m@ce027487af26 |
children | 4479d73eac72 |
comparison
equal
deleted
inserted
replaced
20434:26bd6008fc9c | 20435:755ba248fb4a |
---|---|
1 ## Copyright (C) 2005-2015 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} {} __gnuplot_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 __gnuplot_draw_figure__ (h, plot_stream, enhanced, mono) | |
27 | |
28 htype = get (h, "type"); | |
29 if (strcmp (htype, "figure")) | |
30 ## Get complete list of children. | |
31 kids = allchild (h); | |
32 nkids = length (kids); | |
33 | |
34 if (nkids > 0) | |
35 fputs (plot_stream, "\nreset;\n"); | |
36 fputs (plot_stream, "set autoscale keepfix;\n"); | |
37 fputs (plot_stream, "set origin 0, 0\n"); | |
38 fputs (plot_stream, "set size 1, 1\n"); | |
39 bg = get (h, "color"); | |
40 if (isnumeric (bg)) | |
41 fprintf (plot_stream, "set obj 1 rectangle from screen 0,0 to screen 1,1 behind fc rgb \"#%02x%02x%02x\" fs solid noborder\n", round (255 * bg)); | |
42 bg_is_set = true; | |
43 else | |
44 bg_is_set = false; | |
45 endif | |
46 fg_was_set = false; | |
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", round (255 * (1 - bg))); | |
118 endif | |
119 __gnuplot_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\" fs solid noborder\n", round (255 * fg)); | |
144 fg_is_set = true; | |
145 fg_was_set = true; | |
146 elseif (fg_was_set) | |
147 fprintf (plot_stream, "unset obj 2\n"); | |
148 fg_is_set = false; | |
149 fg_was_set = false; | |
150 else | |
151 fg_is_set = false; | |
152 endif | |
153 if (bg_is_set) | |
154 fprintf (plot_stream, "set border linecolor rgb \"#%02x%02x%02x\"\n", round (255 * (1 - bg))); | |
155 endif | |
156 ## Find if this axes has an associated legend axes and pass it | |
157 ## to __gnuplot_draw_axes__ | |
158 hlegend = []; | |
159 fkids = get (h, "children"); | |
160 for j = 1 : numel (fkids) | |
161 if (ishandle (fkids (j)) | |
162 && strcmp (get (fkids (j), "type"), "axes") | |
163 && (strcmp (get (fkids (j), "tag"), "legend"))) | |
164 udata = get (fkids (j), "userdata"); | |
165 if (isscalar (udata.handle) | |
166 && ! isempty (intersect (udata.handle, kids (i)))) | |
167 hlegend = get (fkids (j)); | |
168 break; | |
169 endif | |
170 endif | |
171 endfor | |
172 __gnuplot_draw_axes__ (kids(i), plot_stream, enhanced, mono, | |
173 bg_is_set, fg_is_set, hlegend); | |
174 unwind_protect_cleanup | |
175 ## Return axes "units" and "position" back to | |
176 ## their original values. | |
177 set (kids(i), "units", orig_axes_units); | |
178 set (kids(i), "position", orig_axes_position); | |
179 bg_is_set = false; | |
180 fg_is_set = false; | |
181 end_unwind_protect | |
182 endif | |
183 case "uimenu" | |
184 ## ignore uimenu objects | |
185 kids(i) = []; | |
186 otherwise | |
187 error ("__gnuplot_draw_figure__: unknown object class, %s", type); | |
188 endswitch | |
189 endfor | |
190 if (isempty (kids)) | |
191 fputs (plot_stream, "\nreset; clear;\n"); | |
192 fflush (plot_stream); | |
193 else | |
194 fputs (plot_stream, "\nunset multiplot;\n"); | |
195 endif | |
196 else | |
197 fputs (plot_stream, "\nreset; clear;\n"); | |
198 fflush (plot_stream); | |
199 endif | |
200 else | |
201 error ("__gnuplot_draw_figure__: expecting figure object, found '%s'", | |
202 htype); | |
203 endif | |
204 | |
205 endfunction | |
206 |