aboutsummaryrefslogtreecommitdiffstats
path: root/doc/user/dia_tree
blob: d16f2bcabaa6059e92ee9eff18e53df5139a779e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
@Section
    @Tag { dia_tree }
    @Title { Trees }
@Begin
@PP
@@Diag offers some symbols for producing tree diagrams, using the
tree. @Index { @Code "@Tree" symbol in @@Diag }
@Code "@Tree" symbol, which may appear anywhere within the nodes part:
@ID @OneRow @Code {
"@Diag {"
"    ..."
"    @Tree { ... }"
"    ..."
"}"
}
Within this symbol, new symbols {@Code "@LeftSub"}, {@Code "@RightSub"},
{@Code "@FirstSub"}, {@Code "@NextSub"}, and {@Code "@StubSub"} become
available.  The first two are used to get a (non-empty) binary tree:
@ID @OneRow {
@Code {
"@Tree {"
"    @Circle A"
"    @LeftSub {"
"        @Circle B"
"        @LeftSub @Square C"
"        @RightSub @Square D"
"    }"
"    @RightSub @Circle E"
"}"
}
||7ct
@Diag {
@Tree {
    @Circle A
    @LeftSub {
        @Circle B
        @LeftSub @Square C
        @RightSub @Square D
    }
    @RightSub @Circle E
}
}
}
The root of the tree, which must be a single node but may have any
outline, comes first.  After that comes the @Code "@LeftSub" symbol
followed by the left subtree, which must be enclosed in braces unless
it consists of a single node.  After that comes the @Code "@RightSub"
symbol followed by the right subtree, again enclosed in braces unless it
consists of a single node.  These rules apply recursively and will
produce a binary tree of arbitrary size and depth.  If a node has no
left or right subtree, leave out the corresponding @Code "@LeftSub" or
@Code "@RightSub" symbol.
@PP
A similar system using @Code "@FirstSub" and @Code "@NextSub" produces
trees in which each node may have arbitrarily many children:
@ID @OneRow {
@Code {
"@Tree {"
"    @Circle A"
"    @FirstSub {"
"        @Circle B"
"        @FirstSub @Square C"
"        @NextSub @Square D"
"    }"
"    @NextSub @Circle E"
"    @NextSub @Circle F"
"}"
}
||7ct
@Diag {
@Tree {
    @Circle A
    @FirstSub {
        @Circle B
        @FirstSub @Square C
        @NextSub @Square D
    }
    @NextSub @Circle E
    @NextSub @Circle F
}
}
}
The first subtree is preceded by {@Code "@FirstSub"}, and subsequent
trees are preceded by {@Code "@NextSub"}.  The subtrees are spaced
at equal separations from each other, with the root centred over
them, in contrast to the binary tree arrangement in which the two
subtrees are positioned to the left and right of the root, never
intruding into the space beneath it.
@PP
Although each subtree must contain a node for its root, it is not hard
to get around this:
@ID @OneRow {
@Code {
"@Tree"
"{"
"@Circle"
"@FirstSub @Circle"
"@NextSub pathstyle { noline }"
"    @Circle outlinestyle { noline }"
"       ..."
"@NextSub @Circle"
"}"
}
||7ct
@Diag {
@Tree
{
@Circle
@FirstSub @Circle
@NextSub pathstyle { noline }
    @Circle outlinestyle { noline }
       ...
@NextSub @Circle
}
}
}
Clumsy as this is, it often assists in placing the unenclosed object
in a way consistent with the surrounding nodes, and offers margins
and so forth which help with fine-tuning its position.
@PP
The fifth subtree symbol, {@Code "@StubSub"}, produces a stub subtree:
@ID @OneRow {
@Code {
"@Tree {"
"@Circle @Eq { a }"
"@StubSub @Eq { T tsub a }"
"}"
}
||7ct
@Diag {
@Tree {
@Circle @Eq { a }
@StubSub @Eq { T tsub a }
}
}
}
Unlike the other subtree symbols, {@Code "@StubSub"} is not followed
by a subtree with a node for its root; rather, it is followed by an
arbitrary object, and the path is drawn around this stub object, which
is placed directly underneath the parent node with zero vertical
separation.  In practice, it is usually necessary to attach margins to
the following object; the easiest way to do that is to enclose it in
{@Code "@Box outlinestyle { noline }"}.  An example appears below.
@PP
It is possible to mix the three subtree types, by having binary tree
symbols following some nodes, non-binary tree symbols following
others, and a single {@Code "@StubSub"} following others.  However,
at any one node the subtrees must be all either binary, non-binary,
or stub.
@PP
The subtree symbols have all of the options of {@Code "@Link"}, and
these apply to the link drawn from the parent of the root of the subtree
to the root of the subtree (or anticlockwise around the stub object):
@ID @OneRow {
@Code {
"@Tree {"
"    @Circle A"
"    @LeftSub"
"        arrow { yes }"
"        xlabel { 1 }"
"    @Circle B"
"    @RightSub"
"        arrow { yes }"
"        xlabel { 2 }"
"    @Circle C"
"}"
}
||7ct
@Diag {
@Tree {
    @Circle A
    @LeftSub
        arrow { yes }
        xlabel { 1 }
    @Circle B
    @RightSub
        arrow { yes }
        xlabel { 2 }
    @Circle C
}
}
}
To get reverse arrows use @Code "arrow { back }" as usual.
@PP
The subtree symbols do not need @Code from and @Code to options,
because they already know which nodes they are linking together.  However,
you may use @Code from or @Code to to give a tag specifying a particular
point within the node:
@ID @OneRow {
@Code {
"@Tree {"
"@Circle"
"@LeftSub from { S } to { N }"
"    @Isosceles vsize { 2f }"
"@RightSub from { S } to { N }"
"    @Isosceles vsize { 2f }"
"}"
}
||7ct
@Diag
{
@Tree {
@Circle
@LeftSub from { S } to { N }
    @Isosceles vsize { 2f }
@RightSub from { S } to { N }
    @Isosceles vsize { 2f }
}
}
}
In this example both links go from the @Code S tag of the parent node to the
@Code N tag of the child node (at the apex of the iscosceles triangle).  These
options also work for {@Code "@StubSub"}, where they refer to the start and
end of the stub path:
@ID @OneRow {
@Code {
"@Tree {"
"@Circle @Eq { a }"
"@StubSub"
"    from { SW }"
"    to { SE }"
"@Box outlinestyle { noline }"
"    @Eq { T tsub a }"
"}"
}
||7ct
@Diag {
@Tree {
@Circle @Eq { a }
@StubSub
    from { SW }
    to { SE }
@Box outlinestyle { noline }
    @Eq { T tsub a }
}
}
}
and so the tags both refer to points in the parent node in this case.
@PP
The @Code "@LeftSub" and @Code "@RightSub" symbols have variants called
@Code "@ZeroWidthLeftSub" and @Code "@ZeroWidthRightSub" which are the
same except that the resulting subtrees consume no width:
@ID @OneRow {
@Code {
"@Tree {"
"@Circle"
"@LeftSub {"
"    @Circle"
"    @LeftSub @Square"
"    @RightSub @Square"
"}"
"@RightSub {"
"    @Circle"
"    @LeftSub {"
"        @Circle"
"        @ZeroWidthLeftSub @Square"
"        @ZeroWidthRightSub @Square"
"    }"
"    @RightSub @Square"
"} }"
}
||7ct
@Diag {
@Tree
{
@Circle
@LeftSub {
    @Circle
    @LeftSub @Square
    @RightSub @Square
}
@RightSub {
    @Circle
    @LeftSub {
        @Circle
        @ZeroWidthLeftSub @Square
        @ZeroWidthRightSub @Square
    }
    @RightSub @Square
}
}
}
}
There is nothing analogous for the other subtree symbols.
@PP
The @Code "@Diag" symbol has a few options for adjusting the appearance
of the tree.  The @Code "treehsep" option determines the horizontal space left
between a root and its left subtree, between a root and its right subtree,
and between one subtree and the next when @Code "@NextSub" is used.  The
@Code "treevsep" option determines the vertical space left between a root
and its subtrees:
@ID @OneRow {
@Code {
"@Diag"
"    treehsep { 0c }"
"    treevsep { 0c }"
"{"
"@Tree"
"{"
"    @Circle A"
"    @LeftSub @Square B"
"    @RightSub @Square C"
"}"
"}"
}
||7ct
@Diag
    treehsep { 0c }
    treevsep { 0c }
{
@Tree
{
    @Circle A
    @LeftSub @Square B
    @RightSub @Square C
}
}
}
These options may also be given to individual subtree symbols, although
@Code "treevsep" works as expected only with @Code "@LeftSub" and
{@Code "@FirstSub"}, since these determine the vertical separation of
all children of their parent.
@PP
The @Code "treehindent" option determines where the root of a non-binary
tree is positioned over its subtrees; the value may be @Code "left"
for at left, @Code "ctr" for centred over them (the default),
@Code "right" for at the right, or any length, meaning that far from
the left.  Owing to problems behind the scenes, this option may not be
given to individual subtree symbols; so as a consolation, it is permitted
as an option to the @Code "@Tree" symbol.
@PP
It is not possible to attach tags to nodes within a tree, because
tags are attached automatically by the tree symbols and any extra
tags would disrupt the linking.  However, you can use @Code "@ShowTags"
to find out what these automatic tags are, and use them in a subsequent
links part.  For example, the tag attached to the right child of the left
child of the root of a binary tree is {@Code "L@R@T"}, and in general the
tag records the path from the root to the node, with @Code "T" added to
the end.  The root always has tag {@Code "T"}.  The tree as a whole may
be retagged in the usual way.
@PP
There is an @Code "@HTree" symbol which is the same as
htree. @Index { @Code "@HTree" symbol in @@Diag }
@Code "@Tree" except that the tree grows horizontally (from left to
right) instead of vertically.  The same symbols are available within
@Code "@HTree" as within {@Code "@Tree"}; @Code "@LeftSub" and
@Code "@FirstSub" produce what might be called the top subtree, and
@Code "@RightSub" and @Code "@NextSub" produce lower trees.  @Code "@HTree"
has no @Code "treehindent" option; instead, it has an exactly analogous
@Code "treevindent" option.
@PP
@Code "@HTree" may be used to get horizontal lists:
@ID @OneRow {
@Code {
"@I @Diag"
"    arrow { yes } treehsep { 1c } {"
"@HTree {"
"    @Node A"
"    @FirstSub {"
"        @Node B"
"        @FirstSub @Node C"
"    }"
"}"
"}"
}
||7ct
@I @Diag arrow { yes } treehsep { 1c } {
@HTree {
@Node A
@FirstSub {
    @Node B
    @FirstSub @Node C 
}
}
}
}
The braces are clumsy but necessary.  The first node has tag {@Code "T"}, the
second has tag {@Code "S@T"}, the third has tag {@Code "S@S@T"}, and so on.
@End @Section