annotate scripts/plot/util/__actual_axis_position__.m @ 31212:55415fa6a20f

svgconvert: Use Lossless encoding of images when available (bug #52193) * acinclude.m4: Check that QPainter::LosslessImageRendering flag is available. * octave-svgconvert.cc (draw): Use new flag if available. * print.m (doc): Update word of caution about svgconvert and images.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Mon, 29 Aug 2022 16:36:34 +0200
parents 5d3faba0342e
children 597f3ee61a48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 2009-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27106
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
8890
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
7 ##
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
8 ## 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
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24497
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
8890
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24497
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
8890
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 ## 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
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
8890
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
19 ##
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
20 ## 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
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24497
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
8890
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
25
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
26 ## -*- texinfo -*-
30875
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
27 ## @deftypefn {} {@var{pos} =} __actual_axis_position__ (@var{h})
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
28 ## @deftypefnx {} {@var{pos} =} __actual_axis_position__ (@var{axis_struct})
8890
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
29 ## Undocumented internal function.
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
30 ## @end deftypefn
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
31
10920
91ff0d7ee94b Don't pass figure handle to __calc_dimensions__.
Ben Abbott <bpabbott@mac.com>
parents: 10917
diff changeset
32 function pos = __actual_axis_position__ (h)
91ff0d7ee94b Don't pass figure handle to __calc_dimensions__.
Ben Abbott <bpabbott@mac.com>
parents: 10917
diff changeset
33
24423
1d52db450db4 Change ishandle to return true for Java objects for Matlab compatibility.
Rik <rik@octave.org>
parents: 23220
diff changeset
34 if (ishghandle (h))
10920
91ff0d7ee94b Don't pass figure handle to __calc_dimensions__.
Ben Abbott <bpabbott@mac.com>
parents: 10917
diff changeset
35 axis_obj = get (h);
91ff0d7ee94b Don't pass figure handle to __calc_dimensions__.
Ben Abbott <bpabbott@mac.com>
parents: 10917
diff changeset
36 elseif (isstruct (h))
91ff0d7ee94b Don't pass figure handle to __calc_dimensions__.
Ben Abbott <bpabbott@mac.com>
parents: 10917
diff changeset
37 axis_obj = h;
24497
1c96b44feb7a colorbar.m: Overhaul function
Rik <rik@octave.org>
parents: 24423
diff changeset
38 h = axis_obj.__axes_handle__;
8890
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
39 endif
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
40
10931
a72d53df4fa6 Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10920
diff changeset
41 ## Get figure size in pixels
8890
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
42 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
43 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
44 unwind_protect
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
45 set (axis_obj.parent, "units", "pixels");
8890
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
46 fig_position = get (axis_obj.parent, "position");
10931
a72d53df4fa6 Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10920
diff changeset
47 unwind_protect_cleanup
27106
6bfd3a890185 Consolidate separate calls to set() in to one call for interpreter efficiency.
Rik <rik@octave.org>
parents: 26376
diff changeset
48 set (axis_obj.parent, "units", orig_fig_units,
6bfd3a890185 Consolidate separate calls to set() in to one call for interpreter efficiency.
Rik <rik@octave.org>
parents: 26376
diff changeset
49 "position", orig_fig_position);
10931
a72d53df4fa6 Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10920
diff changeset
50 end_unwind_protect
11001
2ab8cc6dcced Special treatment activepositionproperty = outerposition for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10953
diff changeset
51 ## Get axes size in pixels
11576
8ac9687dbe9f rename backend to graphics_toolkit
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
52 if (strcmp (get (axis_obj.parent, "__graphics_toolkit__"), "gnuplot")
28310
1379ebcb00c3 Replace uses of axes property "activepositionproperty" by "positionconstraint" (bug #58336).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27978
diff changeset
53 && strcmp (axis_obj.positionconstraint, "outerposition"))
11001
2ab8cc6dcced Special treatment activepositionproperty = outerposition for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10953
diff changeset
54 pos_in_pixels = axis_obj.outerposition .* fig_position([3, 4, 3, 4]);
2ab8cc6dcced Special treatment activepositionproperty = outerposition for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10953
diff changeset
55 else
2ab8cc6dcced Special treatment activepositionproperty = outerposition for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10953
diff changeset
56 pos_in_pixels = axis_obj.position .* fig_position([3, 4, 3, 4]);
2ab8cc6dcced Special treatment activepositionproperty = outerposition for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10953
diff changeset
57 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11576
diff changeset
58
10931
a72d53df4fa6 Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10920
diff changeset
59 nd = __calc_dimensions__ (h);
a72d53df4fa6 Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10920
diff changeset
60
11184
d9a8a008c116 Remove deprecated temporary calculation of plotboxaspectratio for the gnuplot backend
Konstantinos Poulios <logari81@googlemail.com>
parents: 11001
diff changeset
61 if (strcmp (axis_obj.plotboxaspectratiomode, "manual")
d9a8a008c116 Remove deprecated temporary calculation of plotboxaspectratio for the gnuplot backend
Konstantinos Poulios <logari81@googlemail.com>
parents: 11001
diff changeset
62 || strcmp (axis_obj.dataaspectratiomode, "manual"))
10931
a72d53df4fa6 Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10920
diff changeset
63 ## When using {rltb}margin, Gnuplot does not handle the specified
a72d53df4fa6 Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10920
diff changeset
64 ## aspect ratio properly, so handle it here.
a72d53df4fa6 Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10920
diff changeset
65 if (nd == 2 || all (mod (axis_obj.view, 90) == 0))
a72d53df4fa6 Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10920
diff changeset
66 aspect_ratio_2d = axis_obj.plotboxaspectratio(1:2);
a72d53df4fa6 Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10920
diff changeset
67 else
17176
abf384f5d243 maint: Remove unneeded input validation from internal fcns in private/ directories.
Rik <rik@octave.org>
parents: 17096
diff changeset
68 ## FIXME: This works for "axis square", but has not been
abf384f5d243 maint: Remove unneeded input validation from internal fcns in private/ directories.
Rik <rik@octave.org>
parents: 17096
diff changeset
69 ## thoroughly tested for other aspect ratios.
10931
a72d53df4fa6 Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10920
diff changeset
70 aspect_ratio_2d = [max(axis_obj.plotboxaspectratio(1:2)), ...
a72d53df4fa6 Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10920
diff changeset
71 axis_obj.plotboxaspectratio(3)/sqrt(2)];
a72d53df4fa6 Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10920
diff changeset
72 endif
8890
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
73 orig_aspect_ratio_2d = pos_in_pixels(3:4);
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
74 rel_aspect_ratio_2d = aspect_ratio_2d ./ orig_aspect_ratio_2d;
20231
83792dd9bcc1 Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents: 19833
diff changeset
75 rel_aspect_ratio_2d ./= max (rel_aspect_ratio_2d);
26268
6dd232798997 maint: Remove useless ';' from end of for, if, while, etc. statements.
Rik <rik@octave.org>
parents: 25054
diff changeset
76 if (rel_aspect_ratio_2d(1) < rel_aspect_ratio_2d(2))
8890
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
77 dx = (1.0 - rel_aspect_ratio_2d(1)) * pos_in_pixels(3);
20231
83792dd9bcc1 Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents: 19833
diff changeset
78 pos_in_pixels += dx*[0.5, 0.0, -1.0, 0.0];
8890
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
79 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
80 dy = (1.0 - rel_aspect_ratio_2d(2)) * pos_in_pixels(4);
20231
83792dd9bcc1 Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents: 19833
diff changeset
81 pos_in_pixels += dy*[0.0, 0.5, 0.0, -1.0];
8890
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
82 endif
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
83 pos = pos_in_pixels ./ fig_position([3, 4, 3, 4]);
11576
8ac9687dbe9f rename backend to graphics_toolkit
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
84 elseif (strcmp (get (axis_obj.parent, "__graphics_toolkit__"), "gnuplot")
28310
1379ebcb00c3 Replace uses of axes property "activepositionproperty" by "positionconstraint" (bug #58336).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27978
diff changeset
85 && strcmp (axis_obj.positionconstraint, "outerposition"))
11001
2ab8cc6dcced Special treatment activepositionproperty = outerposition for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10953
diff changeset
86 pos = axis_obj.outerposition;
10953
9c0b366583cb Revert treatment of activepositionproperty from the gnuplot backend.
Ben Abbott <bpabbott@mac.com>
parents: 10931
diff changeset
87 else
10931
a72d53df4fa6 Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10920
diff changeset
88 pos = axis_obj.position;
a72d53df4fa6 Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents: 10920
diff changeset
89 endif
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 20852
diff changeset
90
8890
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
91 endfunction
ae51d068bbd5 __actual_axis_position__.m: New function to determine position of rendered axes.
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
92
19171
702aa79dc482 Add BIST tests for various quasi-internal m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
93
702aa79dc482 Add BIST tests for various quasi-internal m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
94 ## No test coverage for internal function. It is tested through calling fcn.
702aa79dc482 Add BIST tests for various quasi-internal m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
95 %!assert (1)