@@ -29,15 +29,13 @@ const defaultMargin: DefaultMargin = {
29
29
bottom : 70 ,
30
30
} ;
31
31
32
-
33
32
export default function ComponentMap ( {
34
33
// imported props to be used to display the dendrogram
35
34
width : totalWidth ,
36
35
height : totalHeight ,
37
36
margin = defaultMargin ,
38
37
currentSnapshot, // from 'tabs[currentTab].stateSnapshot object in 'MainContainer'
39
38
} : LinkTypesProps ) : JSX . Element {
40
-
41
39
const [ layout , setLayout ] = useState ( 'cartesian' ) ; // We create a local state "layout" and set it to a string 'cartesian'
42
40
const [ orientation , setOrientation ] = useState ( 'vertical' ) ; // We create a local state "orientation" and set it to a string 'vertical'.
43
41
const [ linkType , setLinkType ] = useState ( 'diagonal' ) ; // We create a local state "linkType" and set it to a string 'diagonal'.
@@ -86,9 +84,15 @@ export default function ComponentMap({
86
84
}
87
85
}
88
86
89
- // Tooltip stuff:
90
- const { tooltipData, tooltipLeft, tooltipTop, tooltipOpen, showTooltip, hideTooltip } =
91
- useTooltip ( ) ;
87
+ // Tooltip stuff that was destructured from the returned object from 'useTooltip()'
88
+ const {
89
+ tooltipData, // value/data that tooltip may need to render
90
+ tooltipLeft, // number used for tooltip positioning
91
+ tooltipTop, // number used for tooltip positioning
92
+ tooltipOpen, // boolean whether the tooltip state is open or closed
93
+ showTooltip, // function to set tooltip state
94
+ hideTooltip // function to close a tooltip
95
+ } = useTooltip ( ) ; // returns an object with several properties that you can use to manage the tooltip state of your component
92
96
93
97
const { containerRef, TooltipInPortal } = useTooltipInPortal ( {
94
98
detectBounds : true ,
@@ -122,8 +126,7 @@ export default function ComponentMap({
122
126
return `${ renderTime } ms ` ;
123
127
} ;
124
128
125
- // places all nodes into a flat array
126
- const nodeList : [ ] = [ ] ;
129
+ const nodeList : [ ] = [ ] ; // create a nodeList array to store our nodes as a flat array
127
130
128
131
const collectNodes : void = ( node ) => {
129
132
nodeList . splice ( 0 , nodeList . length ) ;
@@ -137,31 +140,34 @@ export default function ComponentMap({
137
140
}
138
141
}
139
142
} ;
143
+
140
144
collectNodes ( currentSnapshot ) ;
141
145
// @ts
142
146
// find the node that has been selected and use it as the root
143
147
let startNode = null ;
144
148
let rootNode ;
145
- const findSelectedNode = ( ) => {
149
+
150
+ const findSelectedNode = ( ) => { // iterates through each node of nodeList and sets the rootNode and startNode to a node with the name root
146
151
for ( const node of nodeList ) {
147
152
if ( node . name === 'root' ) rootNode = node ;
148
- if ( node . name === selectedNode ) startNode = node ;
153
+ if ( node . name === selectedNode ) startNode = node ; // selectedNode label initialized as 'root'
149
154
}
150
155
if ( startNode === null ) startNode = rootNode ;
151
156
} ;
157
+
152
158
findSelectedNode ( ) ;
153
159
154
160
// controls for the map
155
161
const LinkComponent : React . ComponentType < unknown > = getLinkComponent ( { layout, linkType, orientation } ) ;
156
162
return totalWidth < 10 ? null : (
157
163
< div >
158
164
< LinkControls
159
- layout = { layout }
160
- orientation = { orientation }
161
- linkType = { linkType }
162
- stepPercent = { stepPercent }
165
+ layout = { layout }
166
+ orientation = { orientation }
167
+ linkType = { linkType }
168
+ stepPercent = { stepPercent }
163
169
snapShots = { currentSnapshot }
164
- selectedNode = { selectedNode }
170
+ selectedNode = { selectedNode }
165
171
setLayout = { setLayout }
166
172
setOrientation = { setOrientation }
167
173
setLinkType = { setLinkType }
@@ -200,25 +206,28 @@ export default function ComponentMap({
200
206
) ) }
201
207
202
208
{ tree . descendants ( ) . map ( ( node , key ) => {
203
- const widthFunc :number = ( name ) => {
204
- // is this the name of the component - so if it's longer it will make the box wider?
209
+ const widthFunc :number = ( name ) => { // function that takes in a node's name and returns a number that is related to the length of the name.
205
210
const nodeLength = name . length ;
206
- if ( nodeLength < 5 ) return nodeLength + 80 ; // change from 40 to 80, to see what's affected
207
- if ( nodeLength < 10 ) return nodeLength + 120 ; // change from 60 to 120 to see what's affected
208
- return nodeLength + 140 ; // change from 70 to 140 to see what happens
211
+ if ( nodeLength <= 5 ) return nodeLength + 80 ; // returns a number between 80-85
212
+ if ( nodeLength <= 10 ) return nodeLength + 120 ; // returns a number between 125-130
213
+ return nodeLength + 140 ; // returns a number greater than 150
209
214
} ;
210
- const width :number = widthFunc ( node . data . name ) ;
211
- const height :number = 25 ;
212
215
216
+ const width :number = widthFunc ( node . data . name ) ; // the width is determined by the length of the node.name
217
+ const height :number = 25 ;
213
218
let top : number ;
214
219
let left : number ;
220
+
221
+
215
222
if ( layout === 'polar' ) {
216
223
const [ radialX , radialY ] = pointRadial ( node . x , node . y ) ;
217
224
top = radialY ;
218
225
left = radialX ;
226
+
219
227
} else if ( orientation === 'vertical' ) {
220
228
top = node . y ;
221
229
left = node . x ;
230
+
222
231
} else {
223
232
top = node . x ;
224
233
left = node . y ;
0 commit comments