1 ## Copyright (C) 2009-2012 Ben Abbott
3 ## This file is part of Octave.
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.
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.
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/>.
20 ## @deftypefn {Function File} {} __actual_axis_position__ (@var{h})
21 ## @deftypefnx {Function File} {} __actual_axis_position__ (@var{axis_struct})
22 ## Undocumented internal function.
27 function pos = __actual_axis_position__ (h)
33 h = axis_obj.__my_handle__;
36 ## Get figure size in pixels
37 orig_fig_units = get (axis_obj.parent, "units");
38 orig_fig_position = get (axis_obj.parent, "position");
40 set (axis_obj.parent, "units", "pixels");
41 fig_position = get (axis_obj.parent, "position");
42 unwind_protect_cleanup
43 set (axis_obj.parent, "units", orig_fig_units);
44 set (axis_obj.parent, "position", orig_fig_position);
46 ## Get axes size in pixels
47 if (strcmp (get (axis_obj.parent, "__graphics_toolkit__"), "gnuplot")
48 && strcmp (axis_obj.activepositionproperty, "outerposition"))
49 pos_in_pixels = axis_obj.outerposition .* fig_position([3, 4, 3, 4]);
51 pos_in_pixels = axis_obj.position .* fig_position([3, 4, 3, 4]);
54 nd = __calc_dimensions__ (h);
56 if (strcmp (axis_obj.plotboxaspectratiomode, "manual")
57 || strcmp (axis_obj.dataaspectratiomode, "manual"))
58 ## When using {rltb}margin, Gnuplot does not handle the specified
59 ## aspect ratio properly, so handle it here.
60 if (nd == 2 || all (mod (axis_obj.view, 90) == 0))
61 aspect_ratio_2d = axis_obj.plotboxaspectratio(1:2);
63 ## FIXME -- this works for "axis square", but has not been
64 ## thoroughly tested for other aspect ratios.
65 aspect_ratio_2d = [max(axis_obj.plotboxaspectratio(1:2)), ...
66 axis_obj.plotboxaspectratio(3)/sqrt(2)];
68 orig_aspect_ratio_2d = pos_in_pixels(3:4);
69 rel_aspect_ratio_2d = aspect_ratio_2d ./ orig_aspect_ratio_2d;
70 rel_aspect_ratio_2d = rel_aspect_ratio_2d ./ max (rel_aspect_ratio_2d);
71 if (rel_aspect_ratio_2d(1) < rel_aspect_ratio_2d(2));
72 dx = (1.0 - rel_aspect_ratio_2d(1)) * pos_in_pixels(3);
73 pos_in_pixels = pos_in_pixels + dx*[0.5, 0.0, -1.0, 0.0];
74 elseif (rel_aspect_ratio_2d(1) > rel_aspect_ratio_2d(2))
75 dy = (1.0 - rel_aspect_ratio_2d(2)) * pos_in_pixels(4);
76 pos_in_pixels = pos_in_pixels + dy*[0.0, 0.5, 0.0, -1.0];
78 pos = pos_in_pixels ./ fig_position([3, 4, 3, 4]);
79 elseif (strcmp (get (axis_obj.parent, "__graphics_toolkit__"), "gnuplot")
80 && strcmp (axis_obj.activepositionproperty, "outerposition"))
81 pos = axis_obj.outerposition;
83 pos = axis_obj.position;