Skip to content

Commit 8cb8b43

Browse files
committed
tweak textLayout default
1 parent c601427 commit 8cb8b43

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

docs/marks/tree.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ Any additional *options* are passed through to the constituent link, dot, and te
159159

160160
The **textLayout** option controls how text labels are anchored to the node. Two layouts are supported:
161161

162-
* *mirrored* - leaf-node labels are left-anchored, and non-leaf nodes right-anchored (with a -dx offset); default unless a **treeLayout** is specified
163-
* *normal* - all labels are left-anchored; default if a **treeLayout** is specified
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*.
164166

165167
## tree(*data*, *options*)
166168

src/marks/tree.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {cluster as Cluster} from "d3";
1+
import {cluster as Cluster, tree as Tree} from "d3";
22
import {marks} from "../mark.js";
33
import {isNoneish} from "../options.js";
44
import {maybeTreeAnchor, treeLink, treeNode} from "../transforms/tree.js";
@@ -29,21 +29,20 @@ export function tree(
2929
dx,
3030
dy,
3131
textAnchor,
32-
textLayout,
32+
treeLayout = Tree,
33+
textLayout = treeLayout === Tree || treeLayout === Cluster ? "mirrored" : "normal",
3334
...options
3435
} = {}
3536
) {
3637
if (dx === undefined) dx = maybeTreeAnchor(options.treeAnchor).dx;
3738
if (textAnchor !== undefined) throw new Error("textAnchor is not a configurable tree option");
38-
textLayout = keyword(
39-
textLayout === undefined ? (options.treeLayout === undefined ? "mirrored" : "normal") : textLayout,
40-
"textLayout",
41-
["mirrored", "normal"]
42-
);
39+
textLayout = keyword(textLayout, "textLayout", ["mirrored", "normal"]);
40+
4341
function treeText(textOptions) {
4442
return text(
4543
data,
4644
treeNode({
45+
treeLayout,
4746
text: textText,
4847
fill: fill === undefined ? "currentColor" : fill,
4948
stroke: textStroke,
@@ -60,6 +59,7 @@ export function tree(
6059
link(
6160
data,
6261
treeLink({
62+
treeLayout,
6363
markerStart,
6464
markerEnd,
6565
stroke: stroke !== undefined ? stroke : fill === undefined ? "node:internal" : fill,
@@ -73,7 +73,9 @@ export function tree(
7373
...options
7474
})
7575
),
76-
dotDot ? dot(data, treeNode({fill: fill === undefined ? "node:internal" : fill, title, ...options})) : null,
76+
dotDot
77+
? dot(data, treeNode({treeLayout, fill: fill === undefined ? "node:internal" : fill, title, ...options}))
78+
: null,
7779
textText != null
7880
? textLayout === "mirrored"
7981
? [
@@ -86,5 +88,5 @@ export function tree(
8688
}
8789

8890
export function cluster(data, options) {
89-
return tree(data, {textLayout: "mirrored", ...options, treeLayout: Cluster});
91+
return tree(data, {...options, treeLayout: Cluster});
9092
}

0 commit comments

Comments
 (0)