11import { stratify , tree as Tree } from "d3" ;
2- import { channel , isObject , range , valueof } from "../options.js" ;
2+ import { channel , isObject , one , range , valueof } from "../options.js" ;
33
44export function treeNode ( {
55 path, // the delimited path
66 delimiter, // how the path is separated
77 frameAnchor = "left" , // TODO different orientations
88 tree = Tree , // TODO tree sort, tree separation
99 treeSort,
10+ treeSeparation,
1011 ...options
1112} = { } ) {
1213 const normalize = normalizer ( delimiter ) ;
@@ -21,8 +22,10 @@ export function treeNode({
2122 transform ( data , facets ) {
2223 const P = normalize ( valueof ( data , path ) ) ;
2324 const root = stratify ( ) . path ( ( i ) => P [ i ] ) ( range ( data ) ) ;
25+ const layout = tree ( ) . nodeSize ( [ 1 , 1 ] ) ;
2426 if ( treeSort != null ) root . sort ( treeSort ) ;
25- tree ( ) . nodeSize ( [ 1 , 1 ] ) ( root ) ;
27+ if ( treeSeparation !== undefined ) layout . separation ( treeSeparation ?? one ) ;
28+ layout ( root ) ;
2629 const X = setX ( [ ] ) ;
2730 const Y = setY ( [ ] ) ;
2831 for ( const o of outputs ) o [ output_values ] = o [ output_setValues ] ( [ ] ) ;
@@ -45,6 +48,7 @@ export function treeLink({
4548 curve = "bump-x" , // TODO depends on orientation
4649 tree = Tree , // TODO tree sort, tree separation
4750 treeSort,
51+ treeSeparation,
4852 ...options
4953} = { } ) {
5054 const { stroke = "#555" , strokeWidth = 1.5 , strokeOpacity = 0.4 } = options ;
@@ -67,8 +71,10 @@ export function treeLink({
6771 transform ( data , facets ) {
6872 const P = normalize ( valueof ( data , path ) ) ;
6973 const root = stratify ( ) . path ( i => P [ i ] ) ( range ( data ) ) ;
74+ const layout = tree ( ) . nodeSize ( [ 1 , 1 ] ) ;
7075 if ( treeSort != null ) root . sort ( treeSort ) ;
71- tree ( ) . nodeSize ( [ 1 , 1 ] ) ( root ) ;
76+ if ( treeSeparation !== undefined ) layout . separation ( treeSeparation ?? one ) ;
77+ layout ( root ) ;
7278 const X1 = setX1 ( [ ] ) ;
7379 const X2 = setX2 ( [ ] ) ;
7480 const Y1 = setY1 ( [ ] ) ;
0 commit comments