]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/private/__actual_axis_position__.m
update packages
[CreaPhase.git] / octave_packages / m / plot / private / __actual_axis_position__.m
1 ## Copyright (C) 2009-2012 Ben Abbott
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} {} __actual_axis_position__ (@var{h})
21 ## @deftypefnx {Function File} {} __actual_axis_position__ (@var{axis_struct})
22 ## Undocumented internal function.
23 ## @end deftypefn
24
25 ## Author: Ben Abbott
26
27 function pos = __actual_axis_position__ (h)
28
29   if (ishandle (h))
30     axis_obj = get (h);
31   elseif (isstruct (h))
32     axis_obj = h;
33     h = axis_obj.__my_handle__;
34   endif
35
36   ## Get figure size in pixels
37   orig_fig_units = get (axis_obj.parent, "units");
38   orig_fig_position = get (axis_obj.parent, "position");
39   unwind_protect
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);
45   end_unwind_protect
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]);
50   else
51     pos_in_pixels = axis_obj.position .* fig_position([3, 4, 3, 4]);
52   endif
53
54   nd = __calc_dimensions__ (h);
55
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);
62     else
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)];
67     endif
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];
77     endif
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;
82   else
83     pos = axis_obj.position;
84   endif
85 endfunction
86