]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/private/__line__.m
update packages
[CreaPhase.git] / octave_packages / m / plot / private / __line__.m
1 ## Copyright (C) 2005-2012 John W. Eaton
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} {@var{h} =} __line__ (@var{p}, @dots{})
21 ## Undocumented internal function.
22 ## @end deftypefn
23
24 ## __line__ (p, x, y, z)
25 ## Create line object from x, y, and z with parent p.
26 ## Return handle to line object.
27
28 ## Author: jwe
29
30 function h = __line__ (p, varargin)
31
32   if (nargin < 1)
33     print_usage ();
34   endif
35
36   nvargs = numel (varargin);
37
38   if (nvargs > 1 && isnumeric (varargin{1}) && isnumeric (varargin{2}))
39     if (nvargs > 2 && isnumeric (varargin{3}))
40       num_data_args = 3;
41     else
42       num_data_args = 2;
43     endif
44   else
45     num_data_args = 0;
46   endif
47
48   if (num_data_args > 0 && ! size_equal (varargin{1:num_data_args}))
49     error ("line: number of X, Y, and Z points must be equal");
50   endif
51
52   if (rem (nvargs - num_data_args, 2) != 0)
53     error ("line: invalid number of PROPERTY / VALUE pairs");
54   endif
55
56   other_args = {};
57   if (nvargs > num_data_args)
58     other_args = varargin(num_data_args+1:end);
59   endif
60
61   nlines = 0;
62   nvecpts = 0;
63   ismat = false (1, 3);
64   for i = 1:num_data_args
65     tmp = varargin{i}(:,:);
66     if (isvector (tmp))
67       nlines = max (1, nlines);
68       if (! isscalar (tmp))
69         if (nvecpts == 0)
70           nvecpts = numel (tmp);
71         elseif (nvecpts != numel (tmp))
72           error ("line: data size mismatch");
73         endif
74       endif
75     else
76       ismat(i) = true;
77       nlines = max (columns (tmp), nlines);
78     endif
79     varargin{i} = tmp;
80   endfor
81
82   if (num_data_args == 0)
83     varargin = {[0, 1], [0, 1]};
84     num_data_args = 2;
85     nlines = 1;
86   endif
87
88   handles = zeros (nlines, 1);
89
90   data = cell (1, 3);
91
92   if (num_data_args > 1)
93     data(1) = varargin{1};
94     data(2) = varargin{2};
95     if (num_data_args == 3)
96       data(3) = varargin{3};
97     endif
98   endif
99
100   data_args = reshape ({"xdata", "ydata", "zdata"; data{:}}, [1, 6]);
101   mask = reshape ([false(1,3); ismat], [1, 6]);
102
103   for i = 1:nlines
104     tmp = data(ismat);
105     if (! size_equal (tmp)
106         || (nvecpts != 0 && any (nvecpts != cellfun ("size", tmp, 1))))
107       error ("line: data size_mismatch");
108     endif
109
110     data_args(mask) = cellfun (@(x) x(:,i), data(ismat),
111                                "uniformoutput", false);
112
113     handles(i) = __go_line__ (p, data_args{:}, other_args{:});
114
115   endfor
116
117   if (nargout > 0)
118     h = handles;
119   endif
120
121 endfunction