11import React from 'react' ;
2- // import CustomNode from '../styles/CustomNode';
32// will create a build func and then call the helper funcs to return an object
43// make a new instance of this class in flow, call the build method, and pass this as state
5- // const nodeTypes = {
6- // custom: CustomNode,
7- // };
84
95class FlowBuilder {
106 constructor ( data ) {
117 this . parsedData = [ data ] ;
128 this . id = 0 ;
9+ this . x = 0 ;
10+ this . y = 0 ;
1311 this . initialNodes = [ ] ;
1412 this . viewData ;
1513 this . edgeId = 0 ;
1614 this . initialEdges = [ ] ;
1715 }
1816
19- buildNodesArray ( parsedData ) {
17+ buildNodesArray ( parsedData , x = this . x , y = this . y ) {
2018 if ( ! parsedData ) return ;
2119
2220 parsedData . forEach ( ( item ) => {
@@ -34,15 +32,15 @@ class FlowBuilder {
3432 // type: item.depth === 0 ? 'input' : '',
3533 // type: item.isClientComponent ? 'input' : 'output',
3634 type : 'default' ,
37- position : { x : 0 , y : 0 } ,
35+ position : { x : x += 40 , y : y += 30 } ,
3836 style : {
3937 border : 'none' ,
4038 borderRadius : "6px"
4139 }
4240 } ;
4341 this . initialNodes . push ( node ) ;
4442 if ( item . children ) {
45- this . buildNodesArray ( item . children ) ;
43+ this . buildNodesArray ( item . children , this . x += 40 , this . y += 30 ) ;
4644 }
4745 } ) ;
4846 } ;
@@ -98,7 +96,7 @@ class FlowBuilder {
9896 } ) ;
9997 }
10098 traverse ( treeParsed ) ;
101- // Update the vewData state
99+ // Update the viewData state
102100 this . viewData = ( [ treeParsed ] ) ;
103101 console . log ( 'viewData:' , this . viewData ) ;
104102 this . buildNodesArray ( this . viewData ) ;
0 commit comments