annotate scripts/sparse/treeplot.m @ 11589:b0084095098e

missing semicolons in script files
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jan 2011 18:26:09 -0500
parents c792872f8942
children bac54daffde2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11469
diff changeset
1 ## Copyright (C) 2005-2011 Ivana Varekova
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
2 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
3 ## This file is part of Octave.
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
4 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
6 ## under the terms of the GNU General Public License as published by
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
8 ## your option) any later version.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
9 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
13 ## General Public License for more details.
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
14 ##
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
18
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
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} {} treeplot (@var{tree})
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
21 ## @deftypefnx {Function File} {} treeplot (@var{tree}, @var{node_style}, @var{edge_style})
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
22 ## Produces a graph of tree or forest. The first argument is vector of
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
23 ## predecessors, optional parameters @var{node_style} and @var{edge_style}
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
24 ## define the output style. The complexity of the algorithm is O(n) in
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
25 ## terms of is time and memory requirements.
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5578
diff changeset
26 ## @seealso{etreeplot, gplot}
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
27 ## @end deftypefn
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
28
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
29 function treeplot (tree, node_s, edge_s)
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
30
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
31 if (nargin < 1 || nargin > 3 || nargout > 0)
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 6339
diff changeset
32 print_usage ();
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
33 else
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
34 if (! ismatrix (tree) || rows (tree) != 1 || ! isnumeric (tree)
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
35 || ! isvector (tree) || any (tree > length (tree)))
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
36 error ("treeplot: the first input argument must be a vector of predecessors");
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 6339
diff changeset
37 else
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
38 ## The initialization of node end edge style.
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
39 node_style = "k*";
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
40 edge_style = "r";
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
41 if (nargin > 2)
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
42 edge_style = edge_s;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
43 if (nargin > 1)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
44 if (length (findstr (node_s, "*")) == 0
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
45 && length (findstr (node_s, "+")) == 0
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
46 && length (findstr (node_s, "x")) == 0)
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
47 node_style = [node_s, "o"];
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
48 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
49 node_style = node_s;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
50 endif
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
51 endif
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
52 endif
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 6339
diff changeset
53
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
54 ## Make it a row vector.
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
55 tree = tree(:)';
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
56
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
57 ## The count of nodes of the graph.
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
58 num_nodes = length (tree);
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
59
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
60 ## The number of children.
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
61 num_children = zeros (1, num_nodes+1);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
62
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
63 for i = 1:num_nodes
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
64 ## VEC_OF_CHILD is helping vector which is used to speed up the
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
65 ## choose of descendant nodes.
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
66
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
67 num_children(tree(i)+1) = num_children(tree(i)+1) + 1;
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
68 endfor
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
69 pos = 1;
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
70 start = zeros (1, num_nodes+1);
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
71 xhelp = zeros (1, num_nodes+1);
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
72 stop = zeros (1, num_nodes+1);
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
73 for i = 1:num_nodes+1
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
74 start(i) = pos;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
75 xhelp(i) = pos;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
76 pos += num_children(i);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
77 stop(i) = pos;
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
78 endfor
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
79 for i = 1:num_nodes
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
80 vec_of_child(xhelp(tree(i)+1)) = i;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
81 xhelp(tree(i)+1) = xhelp(tree(i)+1)+1;
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 6339
diff changeset
82 endfor
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 6339
diff changeset
83
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
84 ## The number of "parent" (actual) node (it's descendants will be
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
85 ## browse in the next iteration).
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
86 par_number = 0;
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 6339
diff changeset
87
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
88 ## The x-coordinate of the left most descendant of "parent node"
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
89 ## this value is increased in each leaf.
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
90 left_most = 0;
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 6339
diff changeset
91
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
92 ## The level of "parent" node (root level is num_nodes).
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
93 level = num_nodes;
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 6339
diff changeset
94
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
95 ## Num_nodes - max_ht is the height of this graph.
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
96 max_ht = num_nodes;
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 6339
diff changeset
97
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
98 ## Main stack - each item consists of two numbers - the number of
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 6339
diff changeset
99 ## node and the number it's of parent node on the top of stack
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
100 ## there is "parent node".
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
101 stk = [-1, 0];
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 6339
diff changeset
102
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
103 ## Stack which is use to draw the graph edge (it have to be
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
104 ## uninterupted line).
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
105 skelet = 0;
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 6339
diff changeset
106
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
107 ## The top of the stack.
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
108 while (par_number != -1)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
109 if (start(par_number+1) < stop(par_number+1))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
110 idx = vec_of_child(start(par_number+1):stop(par_number+1)-1);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
111 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
112 idx = zeros (1, 0);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
113 endif
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
114 ## Add to idx the vector of parent descendants.
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
115 stk = [stk; [idx', ones(fliplr(size(idx)))*par_number]];
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
116 ## Add to stack the records relevant to parent descandant s.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
117 if (par_number != 0)
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
118 skelet = [skelet; ([ones(size(idx))*par_number; idx])(:)];
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
119 endif
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 6339
diff changeset
120
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
121 ## If there is not any descendant of "parent node":
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
122 if (stk(end,2) != par_number)
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
123 left_most++;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
124 x_coordinate_r(par_number) = left_most;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
125 max_ht = min (max_ht, level);
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
126 if (length(stk) > 1 && find ((shift(stk,1)-stk) == 0) > 1
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
127 && stk(end,2) != stk(end-1,2))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
128 ## Return to the nearest branching the position to return
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
129 ## position is the position on the stack, where should be
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
130 ## started further search (there are two nodes which has the
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
131 ## same parent node).
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
132 position = (find ((shift(stk(:,2),1)-stk(:,2)) == 0))(end) + 1;
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
133 par_number_vec = stk(position:end,2);
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
134 ## The vector of removed nodes (the content of stack form
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
135 ## position to end).
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
136 skelet = [skelet; flipud(par_number_vec)];
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
137 level += length (par_number_vec);
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
138 ## The level have to be decreased.
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
139 x_coordinate_r(par_number_vec) = left_most;
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
140 stk(position:end,:) = [];
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
141 endif
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
142 ## Remove the next node from "searched branch".
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
143 stk(end,:) = [];
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
144 ## Choose new "parent node".
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
145 par_number = stk(end,1);
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
146 ## If there is another branch start to search it.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
147 if (par_number != -1)
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
148 skelet = [skelet; stk(end,2); par_number];
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
149 y_coordinate(par_number) = level;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
150 x_coordinate_l(par_number) = left_most + 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
151 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
152 else
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
153 ## There were descendants of "parent nod" choose the last of
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
154 ## them and go on through it.
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
155 level--;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
156 par_number = stk(end,1);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
157 y_coordinate(par_number) = level;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
158 x_coordinate_l(par_number) = left_most + 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
159 endif
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
160 endwhile
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
161
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
162 ## Calculate the x coordinates (the known values are the position
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
163 ## of most left and most right descendants).
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
164 x_coordinate = (x_coordinate_l + x_coordinate_r) / 2;
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
165
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
166 ## FIXME -- we should probably stuff all the arguments into a cell
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
167 ## array and make a single call to plot here so we can avoid
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
168 ## setting the hold state...
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
169
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
170 hold_is_on = ishold ();
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
171 unwind_protect
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
172 hold ("on");
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
173
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
174 ## Plot grah nodes.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
175 plot (x_coordinate, y_coordinate, node_style);
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
176
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
177 ## Helping command - usable for plotting edges
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
178 skelet = [skelet; 0];
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
179
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
180 ## Draw graph edges.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
181 idx = find (skelet == 0);
6498
2c85044aa63f [project @ 2007-04-05 17:59:47 by jwe]
jwe
parents: 6339
diff changeset
182
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
183 ## Plot each tree component in one loop.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
184 for i = 2:length(idx)
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
185 ## Tree component start.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
186 istart = idx(i-1) + 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
187 ## Tree component end.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
188 istop = idx(i) - 1;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
189 if (istop - istart < 1)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
190 continue;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
191 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
192 plot (x_coordinate(skelet(istart:istop)),
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
193 y_coordinate(skelet(istart:istop)), edge_style);
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
194 endfor
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
195
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
196 ## Set axis and graph size.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
197 axis ([0.5, left_most+0.5, max_ht-0.5, num_nodes-0.5], "nolabel");
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
198
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
199 unwind_protect_cleanup
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
200 if (! hold_is_on)
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
201 hold ("off");
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
202 endif
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
203 end_unwind_protect
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
204
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
205 endif
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
206 endif
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
207 endfunction
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
208
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
209 %!demo
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
210 %! % Plot a simple tree plot
5576
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
211 %! treeplot([2 4 2 0 6 4 6])
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
212
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
213 %!demo
7e008607a86e [project @ 2005-12-13 19:05:54 by jwe]
jwe
parents:
diff changeset
214 %! % Plot a simple tree plot defining the edge and node styles
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
215 %! treeplot([2 4 2 0 6 4 6], "b+", "g")