Mercurial > octave
annotate scripts/plot/draw/private/__quiver__.m @ 27043:7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
* __quiver__.m: Verify that sizes of position matrices (x,y,z) match
those of the vector field (u,v,w).
author | Rik <rik@octave.org> |
---|---|
date | Thu, 11 Apr 2019 10:43:33 -0700 |
parents | 677764865056 |
children | 6bfd3a890185 |
rev | line source |
---|---|
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1 ## Copyright (C) 2007-2019 David Bateman |
7189 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24383
diff
changeset
|
5 ## Octave is free software: you can redistribute it and/or modify it |
7189 | 6 ## 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:
24383
diff
changeset
|
7 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22488
diff
changeset
|
8 ## (at your option) any later version. |
7189 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22488
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22488
diff
changeset
|
13 ## GNU General Public License for more details. |
7189 | 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 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24383
diff
changeset
|
17 ## <https://www.gnu.org/licenses/>. |
7189 | 18 |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8532
diff
changeset
|
19 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
20 ## @deftypefn {} {@var{hg} =} __quiver__ (@dots{}) |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8532
diff
changeset
|
21 ## Undocumented internal function. |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8532
diff
changeset
|
22 ## @end deftypefn |
7189 | 23 |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
24 function hg = __quiver__ (varargin) |
7191 | 25 |
22366
837df5db5710
Make graphic functions visually compatible w/Matlab.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
26 hax = varargin{1}; |
7191 | 27 is3d = varargin{2}; |
7189 | 28 |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
29 autoscale = 0.9; |
17671 | 30 ## Matlab uses 0.2, but Octave's algorithm produces equivalent visual |
31 ## results if arrowsize=0.33. Since this is just a non-dimensional | |
32 ## scaling factor we scale the arrowsize property value by 0.33/0.20 | |
33 ## in order to get equivalent visual results while keeping equivalent | |
34 ## property values. | |
35 arrowsize = 0.20; | |
7189 | 36 |
17671 | 37 firstnonnumeric = find (! cellfun ("isnumeric", varargin(3:nargin)), 1); |
38 if (isempty (firstnonnumeric)) | |
39 firstnonnumeric = Inf; | |
40 else | |
41 firstnonnumeric += 2; | |
42 endif | |
7189 | 43 |
44 ioff = 3; | |
45 if (nargin < (6 + is3d) || firstnonnumeric < (6 + is3d)) | |
26831
677764865056
Accept 4-input form for quiver3 (bug #55570).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
46 if (is3d) |
677764865056
Accept 4-input form for quiver3 (bug #55570).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
47 z = varargin{ioff++}; |
677764865056
Accept 4-input form for quiver3 (bug #55570).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
48 endif |
7189 | 49 u = varargin{ioff++}; |
50 v = varargin{ioff++}; | |
51 if (is3d) | |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
52 w = varargin{ioff++}; |
7189 | 53 endif |
27043
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
54 if (is3d) |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
55 if (! size_equal (z, u, v, w)) |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
56 error ("quiver3: Z, U, V, and W must be the same size"); |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
57 endif |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
58 else |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
59 if (! size_equal (u, v)) |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
60 error ("quiver: U and V must be the same size"); |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
61 endif |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
62 endif |
26831
677764865056
Accept 4-input form for quiver3 (bug #55570).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
63 [x, y] = meshgrid (1:columns (u), 1:rows (u)); |
27043
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
64 |
7191 | 65 if (nargin >= ioff && isnumeric (varargin{ioff}) |
10549 | 66 && isscalar (varargin{ioff})) |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
67 autoscale = varargin{ioff++}; |
7189 | 68 endif |
69 else | |
70 x = varargin{ioff++}; | |
71 y = varargin{ioff++}; | |
72 if (is3d) | |
73 z = varargin{ioff++}; | |
74 endif | |
75 u = varargin{ioff++}; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
76 v = varargin{ioff++}; |
7189 | 77 if (is3d) |
78 w = varargin{ioff++}; | |
7191 | 79 if (isvector (x) && isvector (y) && isvector (z) |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
80 && (! isvector (u) || ! isvector (v) || ! isvector (w))) |
10549 | 81 [x, y, z] = meshgrid (x, y, z); |
7189 | 82 endif |
83 else | |
7191 | 84 if (isvector (x) && isvector (y) && (! isvector (u) || ! isvector (v))) |
10549 | 85 [x, y] = meshgrid (x, y); |
7189 | 86 endif |
87 endif | |
27043
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
88 if (is3d) |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
89 if (! size_equal (x, y, z, u, v, w)) |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
90 error ("quiver3: X, Y, Z, U, V, and W must be the same size"); |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
91 endif |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
92 else |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
93 if (! size_equal (x, y, u, v)) |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
94 error ("quiver: X, Y, U, and V must be the same size"); |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
95 endif |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
96 endif |
7f605f88d1e3
Improve input validation for quiver, quiver3 (bug #56120).
Rik <rik@octave.org>
parents:
26831
diff
changeset
|
97 |
7191 | 98 if (nargin >= ioff && isnumeric (varargin{ioff}) |
10549 | 99 && isscalar (varargin{ioff})) |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
100 autoscale = varargin{ioff++}; |
7189 | 101 endif |
102 endif | |
103 | |
104 have_filled = false; | |
105 have_line_spec = false; | |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
8056
diff
changeset
|
106 args = {}; |
7189 | 107 while (ioff <= nargin) |
7191 | 108 arg = varargin{ioff++}; |
17405
3f0ed69d21c6
Replace unnecessary instances of strncmp with strcmp.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
109 if (ischar (arg) && strcmpi (arg, "filled")) |
7189 | 110 have_filled = true; |
17462
177147bf7b55
Overhaul use of __pltopt__.m to correctly check for cellstr, not just cell.
Rik <rik@octave.org>
parents:
17405
diff
changeset
|
111 elseif ((ischar (arg) || iscellstr (arg)) |
10549 | 112 && ! have_line_spec) |
7189 | 113 [linespec, valid] = __pltopt__ ("quiver", arg, false); |
114 if (valid) | |
10549 | 115 have_line_spec = true; |
17671 | 116 if (isempty (linespec.linestyle) || strcmp (linespec.linestyle, "none")) |
10549 | 117 linespec.linestyle = "-"; |
118 endif | |
7189 | 119 else |
17671 | 120 args{end+1} = arg; |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
8056
diff
changeset
|
121 if (ioff <= nargin) |
17671 | 122 args{end+1} = varargin{ioff++}; |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
8056
diff
changeset
|
123 endif |
7189 | 124 endif |
125 else | |
17671 | 126 args{end+1} = arg; |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
8056
diff
changeset
|
127 if (ioff <= nargin) |
17671 | 128 args{end+1} = varargin{ioff++}; |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
8056
diff
changeset
|
129 endif |
7189 | 130 endif |
131 endwhile | |
132 | |
17671 | 133 ## Normalize 0.20 to 1/3 for plotting |
134 arrowsize /= 0.20 * 3; | |
135 | |
19371
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
136 ## Scale the arrows to fit in the grid |
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
137 uu = u; |
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
138 vv = v; |
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
139 if (is3d) |
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
140 ww = w; |
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
141 len = max (sqrt (u(:).^2 + v(:).^2 + w(:).^2)); |
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
142 else |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19371
diff
changeset
|
143 len = max (sqrt (u(:).^2 + v(:).^2)); |
19371
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
144 endif |
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
145 if (len > 0 && autoscale && numel (u) > 1) |
12554
4040a95a586d
Revamp quiver autoscaling algorithm (bug #32836).
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
146 if (isvector (x)) |
17671 | 147 nx = ny = sqrt (length (x)); |
12554
4040a95a586d
Revamp quiver autoscaling algorithm (bug #32836).
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
148 else |
17671 | 149 [ny, nx] = size (x); # assume meshgrid fmt, x in columns, y in rows |
12554
4040a95a586d
Revamp quiver autoscaling algorithm (bug #32836).
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
150 endif |
17671 | 151 dx = (max (x(:)) - min (x(:))) / nx; |
152 dy = (max (y(:)) - min (y(:))) / ny; | |
7189 | 153 if (is3d) |
17671 | 154 dz = (max (z(:)) - min (z(:))) / max (nx, ny); |
7189 | 155 else |
156 dz = 0; | |
157 endif | |
19371
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
158 sd = sqrt (dx.^2 + dy.^2 + dz.^2) / len; |
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
159 if (sd != 0) |
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
160 s = autoscale * sd; |
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
161 else # special case of identical points with multiple vectors |
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
162 s = autoscale; |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
163 endif |
19371
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
164 uu = s * u; |
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
165 vv = s * v; |
8315
e9687c313d5f
Fix callbacks in stem and quiver for change in order of children. Fix for scaling in quiver for single arrow
David Bateman <dbateman@free.fr>
parents:
8190
diff
changeset
|
166 if (is3d) |
19371
009191dbc76d
quiver: fix initialization error when called with zeros (bug #43686)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17744
diff
changeset
|
167 ww = s * w; |
8315
e9687c313d5f
Fix callbacks in stem and quiver for change in order of children. Fix for scaling in quiver for single arrow
David Bateman <dbateman@free.fr>
parents:
8190
diff
changeset
|
168 endif |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
169 endif |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
170 |
22366
837df5db5710
Make graphic functions visually compatible w/Matlab.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
171 hstate = get (hax, "nextplot"); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
172 unwind_protect |
17671 | 173 if (have_line_spec) |
174 ls = linespec.linestyle; | |
175 lc = linespec.color; | |
24382
b71ba49473f4
Fix incorrect color of markers in quiver plots when linestyle given.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
176 if (isempty (lc)) |
b71ba49473f4
Fix incorrect color of markers in quiver plots when linestyle given.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
177 lc = __next_line_color__ (); |
b71ba49473f4
Fix incorrect color of markers in quiver plots when linestyle given.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
178 endif |
17671 | 179 else |
180 ls = "-"; | |
181 lc = __next_line_color__ (); | |
182 endif | |
183 | |
184 ## Must occur after __next_line_color__ in order to work correctly. | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
185 hg = hggroup (); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
8056
diff
changeset
|
186 if (is3d) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
187 args = __add_datasource__ ("quiver3", hg, |
10549 | 188 {"x", "y", "z", "u", "v", "w"}, args{:}); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
8056
diff
changeset
|
189 else |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
190 args = __add_datasource__ ("quiver", hg, |
10549 | 191 {"x", "y", "z", "u", "v", "w"}, args{:}); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
8056
diff
changeset
|
192 endif |
22366
837df5db5710
Make graphic functions visually compatible w/Matlab.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
193 |
837df5db5710
Make graphic functions visually compatible w/Matlab.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
194 hold (hax, "on"); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
195 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
196 addproperty ("xdata", hg, "data", x); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
197 addproperty ("ydata", hg, "data", y); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
198 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
199 addproperty ("udata", hg, "data", u); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
200 addproperty ("vdata", hg, "data", v); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
201 if (is3d) |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
202 addproperty ("zdata", hg, "data", z); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
203 addproperty ("wdata", hg, "data", w); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
204 else |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
205 addproperty ("zdata", hg, "data", []); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
206 addproperty ("wdata", hg, "data", []); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
207 endif |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
208 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
209 addlistener (hg, "xdata", @update_data); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
210 addlistener (hg, "ydata", @update_data); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
211 addlistener (hg, "zdata", @update_data); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
212 addlistener (hg, "udata", @update_data); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
213 addlistener (hg, "vdata", @update_data); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
214 addlistener (hg, "wdata", @update_data); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
215 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
216 x = x(:); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
217 y = y(:); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
218 xend = x + uu(:); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
219 yend = y + vv(:); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
220 if (is3d) |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
221 z = z(:); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
222 zend = z + ww(:); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
223 endif |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
224 |
17671 | 225 ## Draw arrow shaft as one line object |
226 if (is3d) | |
227 h1 = plot3 ([x.'; xend.'; NaN(1, length (x))](:), | |
228 [y.'; yend.'; NaN(1, length (y))](:), | |
229 [z.'; zend.'; NaN(1, length (z))](:), | |
230 "linestyle", ls, "color", lc, "parent", hg); | |
231 else | |
232 h1 = plot ([x.'; xend.'; NaN(1, length (x))](:), | |
233 [y.'; yend.'; NaN(1, length (y))](:), | |
234 "linestyle", ls, "color", lc, "parent", hg); | |
235 endif | |
236 | |
237 xtmp = x + uu(:) * (1 - arrowsize); | |
238 ytmp = y + vv(:) * (1 - arrowsize); | |
239 | |
240 if (is3d) | |
241 xydist = sqrt (uu(:).^2 + vv(:).^2 + ww(:).^2) ./ ... | |
242 (sqrt (uu(:).^2 + vv(:).^2) + eps); | |
243 xarrw1 = xtmp + vv(:) .* xydist * arrowsize / 4; | |
244 xarrw2 = xtmp - vv(:) .* xydist * arrowsize / 4; | |
245 yarrw1 = ytmp - uu(:) .* xydist * arrowsize / 4; | |
246 yarrw2 = ytmp + uu(:) .* xydist * arrowsize / 4; | |
247 zarrw1 = zarrw2 = zend - ww(:) * arrowsize; | |
248 else | |
249 xarrw1 = xtmp + vv(:) * arrowsize / 3; | |
250 xarrw2 = xtmp - vv(:) * arrowsize / 3; | |
251 yarrw1 = ytmp - uu(:) * arrowsize / 3; | |
252 yarrw2 = ytmp + uu(:) * arrowsize / 3; | |
253 endif | |
254 | |
255 ## Draw arrowhead as one line object | |
24382
b71ba49473f4
Fix incorrect color of markers in quiver plots when linestyle given.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
256 |
b71ba49473f4
Fix incorrect color of markers in quiver plots when linestyle given.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
257 ## Arrowhead is constructed, but NOT displayed, when marker is present. |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
258 if (have_line_spec) |
17671 | 259 if (! isempty (linespec.marker) && ! strcmp (linespec.marker, "none")) |
24382
b71ba49473f4
Fix incorrect color of markers in quiver plots when linestyle given.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
260 ls = "none"; |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
261 endif |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
262 endif |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
263 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
264 if (is3d) |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
265 h2 = plot3 ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), |
10549 | 266 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), |
267 [zarrw1.'; zend.'; zarrw2.'; NaN(1, length (z))](:), | |
17671 | 268 "linestyle", ls, "color", lc, "parent", hg); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
269 else |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
270 h2 = plot ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), |
10549 | 271 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), |
17671 | 272 "linestyle", ls, "color", lc, "parent", hg); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
273 endif |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
274 |
17671 | 275 ## Draw arrow base marker as a third line object |
276 if (! have_line_spec || isempty (linespec.marker)) | |
277 mk = "none"; | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
278 else |
17671 | 279 mk = linespec.marker; |
280 endif | |
281 if (is3d) | |
24382
b71ba49473f4
Fix incorrect color of markers in quiver plots when linestyle given.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
282 h3 = plot3 (x, y, z, "linestyle", "none", "color", lc, "marker", mk, |
b71ba49473f4
Fix incorrect color of markers in quiver plots when linestyle given.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
283 "parent", hg); |
17671 | 284 else |
24382
b71ba49473f4
Fix incorrect color of markers in quiver plots when linestyle given.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
285 h3 = plot (x, y, "linestyle", "none", "color", lc, "marker", mk, |
b71ba49473f4
Fix incorrect color of markers in quiver plots when linestyle given.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
286 "parent", hg); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
287 endif |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
288 if (have_filled) |
24382
b71ba49473f4
Fix incorrect color of markers in quiver plots when linestyle given.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
289 set (h3, "markerfacecolor", lc); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
290 endif |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
291 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
292 ## Set up the hggroup properties and listeners |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
293 if (autoscale) |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
294 addproperty ("autoscale", hg, "radio", "{on}|off", "on"); |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
295 addproperty ("autoscalefactor", hg, "data", autoscale); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
296 else |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
297 addproperty ("autoscale", hg, "radio", "{on}|off", "off"); |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
298 addproperty ("autoscalefactor", hg, "data", 1.0); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
299 endif |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
300 addlistener (hg, "autoscale", @update_data); |
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
301 addlistener (hg, "autoscalefactor", @update_data); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
302 |
17671 | 303 addproperty ("maxheadsize", hg, "data", arrowsize * .20*3); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
304 addlistener (hg, "maxheadsize", @update_data); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
305 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
306 addproperty ("showarrowhead", hg, "radio", "{on}|off", "on"); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
307 addlistener (hg, "showarrowhead", @update_props); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
308 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
309 addproperty ("color", hg, "linecolor", get (h1, "color")); |
17671 | 310 addproperty ("linestyle", hg, "linelinestyle", get (h1, "linestyle")); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
311 addproperty ("linewidth", hg, "linelinewidth", get (h1, "linewidth")); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
312 addproperty ("marker", hg, "linemarker", get (h3, "marker")); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
313 addproperty ("markerfacecolor", hg, "linemarkerfacecolor", |
10549 | 314 get (h3, "markerfacecolor")); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
315 addproperty ("markersize", hg, "linemarkersize", get (h3, "markersize")); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
316 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
317 addlistener (hg, "color", @update_props); |
17671 | 318 addlistener (hg, "linestyle", @update_props); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
319 addlistener (hg, "linewidth", @update_props); |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
320 addlistener (hg, "marker", @update_props); |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
321 addlistener (hg, "markerfacecolor", @update_props); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
322 addlistener (hg, "markersize", @update_props); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
323 |
17527
76614e624818
Add "HitTestArea" property to certain hggroups for Matlab compatibility
Rik <rik@octave.org>
parents:
17462
diff
changeset
|
324 ## Matlab property, although Octave does not implement it. |
76614e624818
Add "HitTestArea" property to certain hggroups for Matlab compatibility
Rik <rik@octave.org>
parents:
17462
diff
changeset
|
325 addproperty ("hittestarea", hg, "radio", "on|{off}", "off"); |
76614e624818
Add "HitTestArea" property to certain hggroups for Matlab compatibility
Rik <rik@octave.org>
parents:
17462
diff
changeset
|
326 |
8079
082fa7859574
Additional do not call set with empty arguments fixes
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
327 if (! isempty (args)) |
082fa7859574
Additional do not call set with empty arguments fixes
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
328 set (hg, args{:}); |
082fa7859574
Additional do not call set with empty arguments fixes
David Bateman <dbateman@free.fr>
parents:
8075
diff
changeset
|
329 endif |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
330 unwind_protect_cleanup |
22366
837df5db5710
Make graphic functions visually compatible w/Matlab.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
331 set (hax, "nextplot", hstate); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
332 end_unwind_protect |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
333 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
334 endfunction |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
335 |
17671 | 336 function update_data (h, ~) |
337 | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
338 x = get (h, "xdata"); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
339 y = get (h, "ydata"); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
340 z = get (h, "zdata"); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
341 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
342 u = get (h, "udata"); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
343 v = get (h, "vdata"); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
344 w = get (h, "wdata"); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
345 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
346 s = get (h, "autoscalefactor"); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
347 arrowsize = get (h, "maxheadsize"); |
17671 | 348 arrowsize /= 0.20 * 3; |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
349 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
350 kids = get (h, "children"); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
351 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
352 if (isempty (z) || isempty (w)) |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
353 is3d = false; |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
354 else |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
355 is3d = true; |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
356 endif |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
357 |
17671 | 358 if (strcmp (get (h, "autoscale"), "on") && s != 0) |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
359 ## Scale the arrows to fit in the grid |
12554
4040a95a586d
Revamp quiver autoscaling algorithm (bug #32836).
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
360 if (isvector (x)) |
17671 | 361 nx = ny = sqrt (length (x)); |
12554
4040a95a586d
Revamp quiver autoscaling algorithm (bug #32836).
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
362 else |
17671 | 363 [ny, nx] = size (x); |
12554
4040a95a586d
Revamp quiver autoscaling algorithm (bug #32836).
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
364 endif |
17671 | 365 dx = (max (x(:)) - min (x(:))) / nx; |
366 dy = (max (y(:)) - min (y(:))) / ny; | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
367 if (is3d) |
17671 | 368 dz = (max (z(:)) - min (z(:))) / max (nx, ny); |
12554
4040a95a586d
Revamp quiver autoscaling algorithm (bug #32836).
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
369 len = max (sqrt (u(:).^2 + v(:).^2 + w(:).^2)); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
370 else |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
371 dz = 0; |
12554
4040a95a586d
Revamp quiver autoscaling algorithm (bug #32836).
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
372 len = max (sqrt (u(:).^2 + v(:).^2)); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
373 endif |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
374 if (len > 0) |
12554
4040a95a586d
Revamp quiver autoscaling algorithm (bug #32836).
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
375 sd = sqrt (dx.^2 + dy.^2 + dz.^2) / len; |
4040a95a586d
Revamp quiver autoscaling algorithm (bug #32836).
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
376 if (sd != 0) |
17671 | 377 s *= sd; |
12554
4040a95a586d
Revamp quiver autoscaling algorithm (bug #32836).
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
378 endif |
7189 | 379 u = s * u; |
380 v = s * v; | |
381 if (is3d) | |
17671 | 382 w = s * w; |
7189 | 383 endif |
384 endif | |
385 endif | |
386 | |
387 x = x(:); | |
388 y = y(:); | |
389 xend = x + u(:); | |
390 yend = y + v(:); | |
391 if (is3d) | |
392 z = z(:); | |
393 zend = z + w(:); | |
394 endif | |
395 | |
17671 | 396 set (kids(3), "xdata", [x.'; xend.'; NaN(1, length (x))](:)); |
397 set (kids(3), "ydata", [y.'; yend.'; NaN(1, length (y))](:)); | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
398 if (is3d) |
17671 | 399 set (kids(3), "zdata", [z.'; zend.'; NaN(1, length (z))](:)); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
400 endif |
7189 | 401 |
17671 | 402 xtmp = x + u(:) * (1 - arrowsize); |
403 ytmp = y + v(:) * (1 - arrowsize); | |
404 | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
405 if (is3d) |
17671 | 406 xydist = sqrt (u(:).^2 + v(:).^2 + w(:).^2) ./ ... |
407 (sqrt (u(:).^2 + v(:).^2) + eps); | |
408 xarrw1 = xtmp + v(:) .* xydist * arrowsize / 4; | |
409 xarrw2 = xtmp - v(:) .* xydist * arrowsize / 4; | |
410 yarrw1 = ytmp - u(:) .* xydist * arrowsize / 4; | |
411 yarrw2 = ytmp + u(:) .* xydist * arrowsize / 4; | |
412 zarrw1 = zarrw2 = zend - w(:) * arrowsize; | |
413 else | |
414 xarrw1 = xtmp + v(:) * arrowsize / 3; | |
415 xarrw2 = xtmp - v(:) * arrowsize / 3; | |
416 yarrw1 = ytmp - u(:) * arrowsize / 3; | |
417 yarrw2 = ytmp + u(:) * arrowsize / 3; | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
418 endif |
7189 | 419 |
17671 | 420 set (kids(2), "xdata", [x.'; xend.'; NaN(1, length (x))](:)); |
421 set (kids(2), "ydata", [y.'; yend.'; NaN(1, length (y))](:)); | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
422 if (is3d) |
17671 | 423 set (kids(2), "zdata", [z.'; zend.'; NaN(1, length (z))](:)); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
424 endif |
7189 | 425 |
17671 | 426 set (kids(2), "xdata", [xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:)); |
427 set (kids(2), "ydata", [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:)); | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
428 if (is3d) |
17671 | 429 set (kids(2), "zdata", [zarrw1.'; zend.'; zarrw2.'; NaN(1, length (z))](:)); |
430 endif | |
431 | |
432 set (kids(1), "xdata", x); | |
433 set (kids(1), "ydata", y); | |
434 if (is3d) | |
435 set (kids(1), "zdata", z); | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
436 endif |
7189 | 437 |
438 endfunction | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
439 |
17671 | 440 function update_props (h, ~) |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
441 |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
442 kids = get (h, "children"); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
443 |
17671 | 444 set (kids([3 2]), {"color", "linestyle", "linewidth"}, |
445 get (h, {"color", "linestyle", "linewidth"})); | |
446 set (kids(2), "visible", get (h, "showarrowhead")); | |
447 set (kids(1), {"color", "marker", "markerfacecolor", "markersize"}, | |
448 get (h, {"color", "marker", "markerfacecolor", "markersize"})); | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
449 |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
450 endfunction |