File tree Expand file tree Collapse file tree 2 files changed +26
-9
lines changed
Expand file tree Collapse file tree 2 files changed +26
-9
lines changed Original file line number Diff line number Diff line change @@ -2,9 +2,17 @@ import { Tree } from "./tree"
22
33
44export interface hierarchyData {
5- children ?: hierarchyData [ ] ,
6- data : Tree ,
7- depth : number ,
8- height : number ,
9- parent : hierarchyData | null
10- }
5+ id : string ,
6+ position : { x : number , y : number } ,
7+ type : string ,
8+ data : { label : string } ,
9+ style : {
10+ borderRadius : string ,
11+ borderWidth : string ,
12+ borderColor : string ,
13+ display : string ,
14+ justifyContent : string ,
15+ placeItems : string ,
16+ backgroundColor : string ,
17+ }
18+ }
Original file line number Diff line number Diff line change @@ -61,10 +61,19 @@ const OverviewFlow = () => {
6161
6262 // Create a holder for the heirarchical data (msg.value), data comes in an object of all the Trees
6363 const root : d3 . HierarchyNode < Tree > = d3 . hierarchy ( data )
64-
6564
66- //create tree layout and give nodes their positions
67- const treeLayout : d3 . TreeLayout < unknown > = d3 . tree ( ) . size ( [ 800 , 500 ] )
65+ // Dynamically adjust height and width of display depending on the amount of nodes
66+ const totalNodes : number = root . descendants ( ) . length ;
67+ const width : number = Math . max ( totalNodes * 100 , 800 ) ;
68+ const height = Math . max ( totalNodes * 20 , 500 )
69+
70+
71+ //create tree layout and give nodes their positions and
72+ const treeLayout : d3 . TreeLayout < unknown > = d3 . tree ( )
73+ . size ( [ width , height ] )
74+ . separation ( ( a : d3 . HierarchyPointNode < Node > , b : d3 . HierarchyPointNode < Node > ) => ( a . parent == b . parent ? 2 : 2.5 ) )
75+
76+
6877 treeLayout ( root ) ;
6978 // Iterate through each Tree and create a node
7079 root . each ( ( node : any ) : void => {
You can’t perform that action at this time.
0 commit comments