You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/marks/tree.md
+15-4Lines changed: 15 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ function indent() {
32
32
33
33
# Tree mark
34
34
35
-
The **tree mark** produces tree diagrams using the [tree transform](../transforms/tree.md). It is a [composite mark](../features/marks.md#marks-marks), consisting of a [link](./link.md) to render links from parent to child, an optional [dot](./dot.md) for nodes, and a[text](./text.md) for node labels. The link mark uses the [treeLink transform](../transforms/tree.md#treelink-options), while the dot and text marks use the [treeNode transform](../transforms/tree.md#treenode-options).
35
+
The **tree mark** produces tree diagrams using the [tree transform](../transforms/tree.md). It is a [composite mark](../features/marks.md#marks-marks), consisting of a [link](./link.md) to render links from parent to child, an optional [dot](./dot.md) for nodes, and one or two[text](./text.md) for node labels. The link mark uses the [treeLink transform](../transforms/tree.md#treelink-options), while the dot and text marks use the [treeNode transform](../transforms/tree.md#treenode-options).
36
36
37
37
For example, here is a little family tree of Greek gods.
38
38
@@ -41,7 +41,8 @@ For example, here is a little family tree of Greek gods.
41
41
Plot.plot({
42
42
axis:null,
43
43
height:100,
44
-
margin:20,
44
+
margin:10,
45
+
marginLeft:35,
45
46
marginRight:120,
46
47
marks: [
47
48
Plot.tree(gods, {textStroke:"var(--vp-c-bg)"})
@@ -63,6 +64,7 @@ As a more complete example, here is a visualization of a software package hierar
63
64
Plot.plot({
64
65
axis:null,
65
66
margin:10,
67
+
marginLeft:30,
66
68
marginRight:160,
67
69
width:688,
68
70
height:1800,
@@ -80,6 +82,7 @@ The **treeLayout** option specifies the layout algorithm. The tree mark uses the
80
82
Plot.plot({
81
83
axis:null,
82
84
margin:10,
85
+
marginLeft:30,
83
86
marginRight:160,
84
87
width:688,
85
88
height:2400,
@@ -148,11 +151,19 @@ The following options are supported:
148
151
***title** - the text and dot title; defaults to *node:path*
149
152
***text** - the text label; defaults to *node:name*
150
153
***textStroke** - the text stroke; defaults to *white*
151
-
***dx** - the text horizontal offset; defaults to 6 if left-anchored, or -6 if right-anchored
154
+
***textLayout** - the text anchoring layout
155
+
***dx** - the text horizontal offset; defaults to 6
152
156
***dy** - the text vertical offset; defaults to 0
153
157
154
158
Any additional *options* are passed through to the constituent link, dot, and text marks and their corresponding treeLink or treeNode transform.
155
159
160
+
The **textLayout** option controls how text labels are anchored to the node. Two layouts are supported:
161
+
162
+
**mirrored* - leaf-node labels are left-anchored, and non-leaf nodes right-anchored
163
+
**normal* - all labels are left-anchored
164
+
165
+
If the **treeLayout** is d3.tree or d3.cluster, the **textLayout** defaults to *mirrored*; otherwise it defaults to *normal*.
166
+
156
167
## tree(*data*, *options*)
157
168
158
169
```js
@@ -167,4 +178,4 @@ Returns a new tree mark with the given *data* and *options*.
167
178
Plot.cluster(flare, {path:"name", delimiter:"."})
168
179
```
169
180
170
-
Like [tree](#tree-data-options), except sets the **treeLayout** option to [d3.cluster](https://github.com/d3/d3-hierarchy/blob/main/README.md#cluster), aligning leaf nodes.
181
+
Like [tree](#tree-data-options), except sets the **treeLayout** option to [d3.cluster](https://github.com/d3/d3-hierarchy/blob/main/README.md#cluster), aligning leaf nodes, and defaults the **textLayout** option to *mirrored*.
0 commit comments