1
- import { cluster as Cluster } from "d3" ;
1
+ import { cluster as Cluster , tree as Tree } from "d3" ;
2
2
import { marks } from "../mark.js" ;
3
3
import { isNoneish } from "../options.js" ;
4
4
import { maybeTreeAnchor , treeLink , treeNode } from "../transforms/tree.js" ;
@@ -29,21 +29,20 @@ export function tree(
29
29
dx,
30
30
dy,
31
31
textAnchor,
32
- textLayout,
32
+ treeLayout = Tree ,
33
+ textLayout = treeLayout === Tree || treeLayout === Cluster ? "mirrored" : "normal" ,
33
34
...options
34
35
} = { }
35
36
) {
36
37
if ( dx === undefined ) dx = maybeTreeAnchor ( options . treeAnchor ) . dx ;
37
38
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
+
43
41
function treeText ( textOptions ) {
44
42
return text (
45
43
data ,
46
44
treeNode ( {
45
+ treeLayout,
47
46
text : textText ,
48
47
fill : fill === undefined ? "currentColor" : fill ,
49
48
stroke : textStroke ,
@@ -60,6 +59,7 @@ export function tree(
60
59
link (
61
60
data ,
62
61
treeLink ( {
62
+ treeLayout,
63
63
markerStart,
64
64
markerEnd,
65
65
stroke : stroke !== undefined ? stroke : fill === undefined ? "node:internal" : fill ,
@@ -73,7 +73,9 @@ export function tree(
73
73
...options
74
74
} )
75
75
) ,
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 ,
77
79
textText != null
78
80
? textLayout === "mirrored"
79
81
? [
@@ -86,5 +88,5 @@ export function tree(
86
88
}
87
89
88
90
export function cluster ( data , options ) {
89
- return tree ( data , { textLayout : "mirrored" , ...options , treeLayout : Cluster } ) ;
91
+ return tree ( data , { ...options , treeLayout : Cluster } ) ;
90
92
}
0 commit comments