Mercurial > hg > octave-lyh
annotate scripts/plot/private/__actual_axis_position__.m @ 10920:91ff0d7ee94b
Don't pass figure handle to __calc_dimensions__.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Fri, 27 Aug 2010 21:06:04 -0400 |
parents | 888c75785221 |
children | a72d53df4fa6 |
rev | line source |
---|---|
8890
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
1 ## Copyright (C) 2009 Ben Abbott |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
2 ## |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
3 ## This file is part of Octave. |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
4 ## |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
8 ## your option) any later version. |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
9 ## |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
13 ## General Public License for more details. |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
14 ## |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
18 |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {} __actual_axis_position__ (@var{h}) |
8890
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
21 ## @deftypefnx {Function File} {} __actual_axis_position__ (@var{axis_struct}) |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
22 ## Undocumented internal function. |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
23 ## @end deftypefn |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
24 |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
25 ## Author: Ben Abbott |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
26 |
10920
91ff0d7ee94b
Don't pass figure handle to __calc_dimensions__.
Ben Abbott <bpabbott@mac.com>
parents:
10917
diff
changeset
|
27 function pos = __actual_axis_position__ (h) |
91ff0d7ee94b
Don't pass figure handle to __calc_dimensions__.
Ben Abbott <bpabbott@mac.com>
parents:
10917
diff
changeset
|
28 |
91ff0d7ee94b
Don't pass figure handle to __calc_dimensions__.
Ben Abbott <bpabbott@mac.com>
parents:
10917
diff
changeset
|
29 if (ishandle (h)) |
91ff0d7ee94b
Don't pass figure handle to __calc_dimensions__.
Ben Abbott <bpabbott@mac.com>
parents:
10917
diff
changeset
|
30 axis_obj = get (h); |
91ff0d7ee94b
Don't pass figure handle to __calc_dimensions__.
Ben Abbott <bpabbott@mac.com>
parents:
10917
diff
changeset
|
31 elseif (isstruct (h)) |
91ff0d7ee94b
Don't pass figure handle to __calc_dimensions__.
Ben Abbott <bpabbott@mac.com>
parents:
10917
diff
changeset
|
32 axis_obj = h; |
91ff0d7ee94b
Don't pass figure handle to __calc_dimensions__.
Ben Abbott <bpabbott@mac.com>
parents:
10917
diff
changeset
|
33 h = axis_obj.__my_handle__; |
8890
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
34 endif |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
35 |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
36 ## When using {rltb}margin, Gnuplot does not handle the specified |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
37 ## aspect ratio properly, so handle it here. |
10920
91ff0d7ee94b
Don't pass figure handle to __calc_dimensions__.
Ben Abbott <bpabbott@mac.com>
parents:
10917
diff
changeset
|
38 if (__calc_dimensions__ (h) == 2 |
10917
888c75785221
Improvements to FLTK backend rotation
Jordi Guti?rrez Hermoso <jordigh@gmail.com>
parents:
10910
diff
changeset
|
39 || all (mod (axis_obj.view, 90) == 0)) |
10910
40cf7cc4ea62
Properly interpret plotboxaspectratio when 3D objects are viewed as 2D.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
40 aspect_ratio_2d = axis_obj.plotboxaspectratio(1:2); |
40cf7cc4ea62
Properly interpret plotboxaspectratio when 3D objects are viewed as 2D.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
41 else |
8890
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
42 ## FIXME -- this works for "axis square", but has not been |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
43 ## thoroughly tested for other aspect ratios. |
10226
2884758e265b
Replace dataaspectratio props with plotboxaspectratio props.
Ben Abbott <bpabbott@mac.com>
parents:
9896
diff
changeset
|
44 aspect_ratio_2d = [max(axis_obj.plotboxaspectratio(1:2)), ... |
10549 | 45 axis_obj.plotboxaspectratio(3)/sqrt(2)]; |
8890
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
46 endif |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
47 orig_fig_units = get (axis_obj.parent, "units"); |
10530
114376c7cba5
__actual_axis_position__.m: Fix bug when restoring figure position property to its original value.
Ben Abbott <bpabbott@mac.com>
parents:
10226
diff
changeset
|
48 orig_fig_position = get (axis_obj.parent, "position"); |
8890
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
49 unwind_protect |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
50 set (axis_obj.parent, "units", "pixels") |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
51 fig_position = get (axis_obj.parent, "position"); |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
52 pos_in_pixels = axis_obj.position .* fig_position([3, 4, 3, 4]); |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
53 orig_aspect_ratio_2d = pos_in_pixels(3:4); |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
54 rel_aspect_ratio_2d = aspect_ratio_2d ./ orig_aspect_ratio_2d; |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
55 rel_aspect_ratio_2d = rel_aspect_ratio_2d ./ max (rel_aspect_ratio_2d); |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
56 if (rel_aspect_ratio_2d(1) < rel_aspect_ratio_2d(2)); |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
57 dx = (1.0 - rel_aspect_ratio_2d(1)) * pos_in_pixels(3); |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
58 pos_in_pixels = pos_in_pixels + dx*[0.5, 0.0, -1.0, 0.0]; |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
59 elseif (rel_aspect_ratio_2d(1) > rel_aspect_ratio_2d(2)) |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
60 dy = (1.0 - rel_aspect_ratio_2d(2)) * pos_in_pixels(4); |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
61 pos_in_pixels = pos_in_pixels + dy*[0.0, 0.5, 0.0, -1.0]; |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
62 endif |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
63 pos = pos_in_pixels ./ fig_position([3, 4, 3, 4]); |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
64 unwind_protect_cleanup |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
65 set (axis_obj.parent, "units", orig_fig_units) |
10530
114376c7cba5
__actual_axis_position__.m: Fix bug when restoring figure position property to its original value.
Ben Abbott <bpabbott@mac.com>
parents:
10226
diff
changeset
|
66 set (axis_obj.parent, "position", orig_fig_position) |
8890
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
67 end_unwind_protect |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
68 |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
69 endfunction |
ae51d068bbd5
__actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
70 |