Mercurial > hg > octave-nkf
comparison scripts/plot/gnuplot_drawnow.m @ 8638:20e93feaa7f8
gnuplot_drawnow.m: gnuplot_drawnow.m: respect x11 figure position property
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Fri, 30 Jan 2009 11:06:44 -0500 |
parents | ff7d90d92db8 |
children | 2476ce55d4b5 |
comparison
equal
deleted
inserted
replaced
8637:4385bb503467 | 8638:20e93feaa7f8 |
---|---|
139 | 139 |
140 if (isempty (strfind (opts_str, " size "))) | 140 if (isempty (strfind (opts_str, " size "))) |
141 ## Convert position to units used by gnuplot. | 141 ## Convert position to units used by gnuplot. |
142 if (isbackend (term)) | 142 if (isbackend (term)) |
143 ## Get figure size in pixels. | 143 ## Get figure size in pixels. |
144 gnuplot_size = get_figsize (h); | 144 [gnuplot_size, gnuplot_pos] = get_figsize (h); |
145 else | 145 else |
146 ## Get size of the printed plot in inches. | 146 ## Get size of the printed plot in inches. |
147 gnuplot_size = get_canvassize (h); | 147 gnuplot_size = get_canvassize (h); |
148 ## If the output is a bitmap, convert to pixels. | 148 ## If the output is a bitmap, convert to pixels. |
149 if (isbitmap (term) || strcmpi (term, "svg")) | 149 if (isbitmap (term) || strcmpi (term, "svg")) |
153 if (all (gnuplot_size > 0)) | 153 if (all (gnuplot_size > 0)) |
154 ## Set terminal size. | 154 ## Set terminal size. |
155 terminals_with_size = {"emf", "gif", "jpeg", "latex", "pbm", ... | 155 terminals_with_size = {"emf", "gif", "jpeg", "latex", "pbm", ... |
156 "pdf", "png", "postscript", "svg", "wxt", ... | 156 "pdf", "png", "postscript", "svg", "wxt", ... |
157 "epslatex", "pstex", "pslatex"}; | 157 "epslatex", "pstex", "pslatex"}; |
158 if (__gnuplot_has_feature__("x11_figure_position")) | |
159 terminals_with_size{end+1} = "x11"; | |
160 endif | |
158 if (any (strncmpi (term, terminals_with_size, 3))) | 161 if (any (strncmpi (term, terminals_with_size, 3))) |
159 size_str = sprintf ("size %d,%d", gnuplot_size(1), gnuplot_size(2)); | 162 size_str = sprintf ("size %d,%d", gnuplot_size(1), gnuplot_size(2)); |
163 if (strncmpi (term, "X11", 3)) | |
164 screen_size = get (0, "screensize")(3:4); | |
165 if (all (screen_size > 0)) | |
166 ## For X11, set the figure positon as well as the size | |
167 ## gnuplot position is UL, Octave's is LL (same for screen/window) | |
168 gnuplot_pos(2) = screen_size(2) - gnuplot_pos(2) - gnuplot_size(2); | |
169 gnuplot_pos = max (gnuplot_pos, 1); | |
170 size_str = sprintf ("%s position %d,%d", size_str, | |
171 gnuplot_pos(1), gnuplot_pos(2)); | |
172 endif | |
173 endif | |
160 elseif (any (strncmpi (term, {"aqua", "fig"}, 3))) | 174 elseif (any (strncmpi (term, {"aqua", "fig"}, 3))) |
161 ## Aqua and Fig also have size, but the format is different. | 175 ## Aqua and Fig also have size, but the format is different. |
162 size_str = sprintf ("size %d %d", gnuplot_size(1), gnuplot_size(2)); | 176 size_str = sprintf ("size %d %d", gnuplot_size(1), gnuplot_size(2)); |
163 elseif (any (strncmpi (term, {"corel", "hpgl"}, 3))) | 177 elseif (any (strncmpi (term, {"corel", "hpgl"}, 3))) |
164 ## The size for corel and hpgl are goes at the end (implicit). | 178 ## The size for corel and hpgl are goes at the end (implicit). |
188 endif | 202 endif |
189 | 203 |
190 ## Set the gnuplot terminal (type, enhanced?, title, & size). | 204 ## Set the gnuplot terminal (type, enhanced?, title, & size). |
191 if (! isempty (term)) | 205 if (! isempty (term)) |
192 term_str = sprintf ("set terminal %s", term); | 206 term_str = sprintf ("set terminal %s", term); |
207 if (any (strncmpi (term, {"x11", "wxt"}, 3)) | |
208 && __gnuplot_has_feature__ ("x11_figure_position")) | |
209 ## The "close" is added to allow the figure position property | |
210 ## to remain active. | |
211 term_str = sprintf ("%s close", term_str); | |
212 endif | |
193 if (! isempty (enh_str)) | 213 if (! isempty (enh_str)) |
194 term_str = sprintf ("%s %s", term_str, enh_str); | 214 term_str = sprintf ("%s %s", term_str, enh_str); |
195 endif | 215 endif |
196 if (! isempty (title_str)) | 216 if (! isempty (title_str)) |
197 term_str = sprintf ("%s %s", term_str, title_str); | 217 term_str = sprintf ("%s %s", term_str, title_str); |
281 term = gnuplot_term (); | 301 term = gnuplot_term (); |
282 endif | 302 endif |
283 ret = any (strcmpi ({"png", "jpeg", "gif", "pbm"}, term)); | 303 ret = any (strcmpi ({"png", "jpeg", "gif", "pbm"}, term)); |
284 endfunction | 304 endfunction |
285 | 305 |
286 function fig_size = get_figsize (h) | 306 function [fig_size, fig_pos] = get_figsize (h) |
287 ## Determine the size of the figure in pixels | 307 ## Determine the size of the figure in pixels. |
288 possize = get (h, "position")(3:4); | 308 position = get (h, "position"); |
289 units = get (h, "units"); | 309 units = get (h, "units"); |
290 t.inches = 1; | 310 t.inches = 1; |
291 t.centimeters = 2.54; | 311 t.centimeters = 2.54; |
292 t.pixels = get (0, "screenpixelsperinch"); | 312 t.pixels = get (0, "screenpixelsperinch"); |
293 ## gnuplot treats pixels/points the same | 313 ## gnuplot treats pixels/points for the screen the same (?). |
294 t.points = t.pixels; | 314 t.points = t.pixels; |
295 t.normalized = get (0, "screensize")(3:4) / t.pixels; | 315 screensize = get (0, "screensize")(3:4); |
296 fig_size = possize * (t.pixels / t.(units)); | 316 t.normalized = screensize / t.pixels; |
297 if (prod (fig_size) > 1e8) | 317 fig_size = position(3:4) * (t.pixels / t.(units)); |
298 warning ("gnuplot_drawnow: figure size is excessive. Reducing to 1024x768.") | 318 fig_pos = position(1:2) * (t.pixels / t.(units)); |
299 fig_size = [1024, 768]; | 319 fig_pos(1) = max (min (fig_pos(1), screensize(1)), 10); |
300 position = get (h, "position"); | 320 fig_pos(2) = max (min (fig_pos(2), screensize(2)), 10); |
301 set (h, "position", [position(1:2), fig_size], "units", "pixels"); | 321 fig_size(1) = max (min (fig_size(1), screensize(1)), 10-fig_pos(1)); |
302 endif | 322 fig_size(2) = max (min (fig_size(2), screensize(2)), 10-fig_pos(2)); |
303 endfunction | 323 endfunction |
304 | 324 |
305 function plotsize = get_canvassize (h) | 325 function plotsize = get_canvassize (h) |
306 ## Returns the intended size of the plot on the page in inches. | 326 ## Returns the intended size of the plot on the page in inches. |
307 ## "canvas size" is a gnuplot term. Gnuplot doesn't explicity plot to | 327 ## "canvas size" is a gnuplot term. Gnuplot doesn't explicity plot to |