1- import { cluster as Cluster } from "d3" ;
1+ import { cluster as Cluster , tree as Tree } from "d3" ;
22import { marks } from "../mark.js" ;
33import { isNoneish } from "../options.js" ;
44import { 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
8890export function cluster ( data , options ) {
89- return tree ( data , { textLayout : "mirrored" , ...options , treeLayout : Cluster } ) ;
91+ return tree ( data , { ...options , treeLayout : Cluster } ) ;
9092}
0 commit comments