@@ -6,6 +6,7 @@ import { pointRadial } from 'd3-shape';
6
6
import useForceUpdate from './useForceUpdate' ;
7
7
import LinkControls from './LinkControls' ;
8
8
import getLinkComponent from './getLinkComponent' ;
9
+ import { node } from 'prop-types' ;
9
10
10
11
interface TreeNode {
11
12
name : string ;
@@ -69,7 +70,18 @@ export default function Example({
69
70
margin = defaultMargin ,
70
71
snapshots : snapshots ,
71
72
} : LinkTypesProps ) {
72
- console . log ( 'snapshots passed in' , snapshots ) ;
73
+ //-------------------------------------------------------------------
74
+ let obj = { name : 'root' , children : snapshots } ;
75
+ console . log ( 'obj' , obj ) ;
76
+
77
+ const nodeCreator = ( node ) => {
78
+ const lastNode = node . length - 1 ;
79
+ return node [ lastNode ] ;
80
+ } ;
81
+ const finalObj = nodeCreator ( snapshots ) ;
82
+ //-------------------------------------------------------------------
83
+
84
+ // console.log('snapshots children', snapshots.children);
73
85
const [ layout , setLayout ] = useState < string > ( 'cartesian' ) ;
74
86
const [ orientation , setOrientation ] = useState < string > ( 'horizontal' ) ;
75
87
const [ linkType , setLinkType ] = useState < string > ( 'diagonal' ) ;
@@ -102,7 +114,7 @@ export default function Example({
102
114
}
103
115
104
116
const LinkComponent = getLinkComponent ( { layout, linkType, orientation } ) ;
105
-
117
+ console . log ( data ) ;
106
118
return totalWidth < 10 ? null : (
107
119
< div >
108
120
< LinkControls
@@ -116,11 +128,13 @@ export default function Example({
116
128
setStepPercent = { setStepPercent }
117
129
/>
118
130
< svg width = { totalWidth } height = { totalHeight } >
119
- < LinearGradient id = " links-gradient" from = " #fd9b93" to = " #fe6e9e" />
120
- < rect width = { totalWidth } height = { totalHeight } rx = { 14 } fill = " #242529" />
131
+ < LinearGradient id = ' links-gradient' from = ' #fd9b93' to = ' #fe6e9e' />
132
+ < rect width = { totalWidth } height = { totalHeight } rx = { 14 } fill = ' #242529' />
121
133
< Group top = { margin . top } left = { margin . left } >
122
134
< Tree
123
- root = { hierarchy ( data , ( d ) => ( d . isExpanded ? null : d . children ) ) }
135
+ root = { hierarchy ( finalObj , ( d ) =>
136
+ d . isExpanded ? null : d . children ,
137
+ ) }
124
138
size = { [ sizeWidth , sizeHeight ] }
125
139
separation = { ( a , b ) => ( a . parent === b . parent ? 1 : 0.5 ) / a . depth }
126
140
>
@@ -131,9 +145,9 @@ export default function Example({
131
145
key = { i }
132
146
data = { link }
133
147
percent = { stepPercent }
134
- stroke = " rgb(254,110,158,0.6)"
135
- strokeWidth = "1"
136
- fill = " none"
148
+ stroke = ' rgb(254,110,158,0.6)'
149
+ strokeWidth = '1'
150
+ fill = ' none'
137
151
/>
138
152
) ) }
139
153
@@ -174,7 +188,7 @@ export default function Example({
174
188
width = { width }
175
189
y = { - height / 2 }
176
190
x = { - width / 2 }
177
- fill = " #272b4d"
191
+ fill = ' #272b4d'
178
192
stroke = { node . data . children ? '#03c0dc' : '#26deb0' }
179
193
strokeWidth = { 1 }
180
194
strokeDasharray = { node . data . children ? '0' : '2,2' }
@@ -188,10 +202,10 @@ export default function Example({
188
202
/>
189
203
) }
190
204
< text
191
- dy = " .33em"
205
+ dy = ' .33em'
192
206
fontSize = { 9 }
193
- fontFamily = " Arial"
194
- textAnchor = " middle"
207
+ fontFamily = ' Arial'
208
+ textAnchor = ' middle'
195
209
style = { { pointerEvents : 'none' } }
196
210
fill = {
197
211
node . depth === 0
0 commit comments