@@ -8,7 +8,8 @@ import useForceUpdate from './useForceUpdate';
8
8
import LinkControls from './LinkControls' ;
9
9
import getLinkComponent from './getLinkComponent' ;
10
10
import { localPoint } from '@visx/event' ;
11
- import { onHover , onHoverExit } from '../actions/actions' ;
11
+ import { useTooltip , useTooltipInPortal , TooltipWithBounds } from '@visx/tooltip' ;
12
+ import { onHover , onHoverExit } from '../actions/actions' ;
12
13
import { useStoreContext } from '../store' ;
13
14
14
15
const root = hierarchy ( {
@@ -31,6 +32,7 @@ interface TreeNode {
31
32
children ?: TreeNode [ ] ;
32
33
}
33
34
35
+
34
36
type HierarchyNode = HierarchyPointNode < TreeNode > ;
35
37
36
38
const defaultMargin = { top : 30 , left : 30 , right : 55 , bottom : 70 } ;
@@ -91,8 +93,31 @@ export default function ComponentMap({
91
93
}
92
94
}
93
95
96
+
97
+ //Tooltip stuff:
98
+ const {
99
+ tooltipData,
100
+ tooltipLeft,
101
+ tooltipTop,
102
+ tooltipOpen,
103
+ showTooltip,
104
+ hideTooltip,
105
+ } = useTooltip ( ) ;
106
+
107
+ const { containerRef, TooltipInPortal } = useTooltipInPortal ( ) ;
108
+
94
109
//mousing controls
95
- const handleMouseOver = ( ) => console . log ( "mouse entered" ) ;
110
+ const handleMouseOver = ( event ) => {
111
+ console . log ( "mouse entered" ) ;
112
+ const coords = localPoint ( event . target . ownerSVGElement , event ) ;
113
+ console . log ( "I'm coords" , coords ) ;
114
+ showTooltip ( {
115
+ tooltipLeft : coords . x ,
116
+ tooltipTop : coords . y ,
117
+ tooltipData : "test"
118
+ } ) ;
119
+ }
120
+
96
121
97
122
// controls for the map
98
123
const LinkComponent = getLinkComponent ( { layout, linkType, orientation } ) ;
@@ -109,7 +134,7 @@ export default function ComponentMap({
109
134
setStepPercent = { setStepPercent }
110
135
/>
111
136
112
- < svg width = { totalWidth } height = { totalHeight } >
137
+ < svg ref = { containerRef } width = { totalWidth } height = { totalHeight } >
113
138
< LinearGradient id = "links-gradient" from = "#fd9b93" to = "#fe6e9e" />
114
139
< rect width = { totalWidth } height = { totalHeight } rx = { 14 } fill = "#242529" />
115
140
< Group top = { margin . top } left = { margin . left } >
@@ -185,7 +210,7 @@ export default function ComponentMap({
185
210
node . data . isExpanded = ! node . data . isExpanded ;
186
211
forceUpdate ( ) ;
187
212
} }
188
- //check with recoil
213
+ //Tooltip event handlers
189
214
onMouseOver = { handleMouseOver }
190
215
onMouseOut = { hideTooltip }
191
216
/>
@@ -215,6 +240,16 @@ export default function ComponentMap({
215
240
</ Tree >
216
241
</ Group >
217
242
</ svg >
243
+ tooltipOpen && tooltipData && (
244
+ < TooltipInPortal
245
+ // set this to random so it correctly updates with parent bounds
246
+ key = { Math . random ( ) }
247
+ top = { tooltipTop }
248
+ left = { tooltipLeft }
249
+ >
250
+ Tooltip Data: < strong > { tooltipData } </ strong >
251
+ </ TooltipInPortal >
252
+ )
218
253
</ div >
219
254
) ;
220
255
}
0 commit comments