@@ -7,7 +7,9 @@ import { pointRadial } from 'd3-shape';
7
7
import useForceUpdate from './useForceUpdate' ;
8
8
import LinkControls from './LinkControls' ;
9
9
import getLinkComponent from './getLinkComponent' ;
10
- import { onHover , onHoverExit } from '../actions/actions' ;
10
+ import { localPoint } from '@visx/event' ;
11
+ import { useTooltip , useTooltipInPortal , TooltipWithBounds } from '@visx/tooltip' ;
12
+ import { onHover , onHoverExit } from '../actions/actions' ;
11
13
import { useStoreContext } from '../store' ;
12
14
13
15
const root = hierarchy ( {
@@ -30,6 +32,7 @@ interface TreeNode {
30
32
children ?: TreeNode [ ] ;
31
33
}
32
34
35
+
33
36
type HierarchyNode = HierarchyPointNode < TreeNode > ;
34
37
35
38
const defaultMargin = { top : 30 , left : 30 , right : 55 , bottom : 70 } ;
@@ -89,6 +92,33 @@ export default function ComponentMap({
89
92
sizeHeight = innerWidth ;
90
93
}
91
94
}
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
+
109
+ //mousing controls
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
+
121
+
92
122
// controls for the map
93
123
const LinkComponent = getLinkComponent ( { layout, linkType, orientation } ) ;
94
124
return totalWidth < 10 ? null : (
@@ -104,7 +134,7 @@ export default function ComponentMap({
104
134
setStepPercent = { setStepPercent }
105
135
/>
106
136
107
- < svg width = { totalWidth } height = { totalHeight } >
137
+ < svg ref = { containerRef } width = { totalWidth } height = { totalHeight } >
108
138
< LinearGradient id = "links-gradient" from = "#fd9b93" to = "#fe6e9e" />
109
139
< rect width = { totalWidth } height = { totalHeight } rx = { 14 } fill = "#242529" />
110
140
< Group top = { margin . top } left = { margin . left } >
@@ -180,31 +210,10 @@ export default function ComponentMap({
180
210
node . data . isExpanded = ! node . data . isExpanded ;
181
211
forceUpdate ( ) ;
182
212
} }
183
- //check with recoil
184
- onMouseLeave = { ( ) => {
185
- if (
186
- Object . keys ( node . data . recoilDomNode ) . length > 0
187
- ) {
188
- dispatch (
189
- onHoverExit (
190
- node . data . recoilDomNode [ node . data . name ]
191
- )
192
- ) ;
193
- } else {
194
- dispatch ( onHoverExit ( node . data . rtid ) ) ;
195
- }
196
- } }
197
- onMouseEnter = { ( ) => {
198
- if (
199
- Object . keys ( node . data . recoilDomNode ) . length > 0
200
- ) {
201
- dispatch (
202
- onHover ( node . data . recoilDomNode [ node . data . name ] )
203
- ) ;
204
- } else {
205
- dispatch ( onHover ( node . data . rtid ) ) ;
206
- }
207
- } }
213
+ //Tooltip event handlers
214
+ //test feature
215
+ onMouseOver = { handleMouseOver }
216
+ onMouseOut = { hideTooltip }
208
217
/>
209
218
) }
210
219
{ /* Display text inside of each component node */ }
@@ -232,6 +241,16 @@ export default function ComponentMap({
232
241
</ Tree >
233
242
</ Group >
234
243
</ svg >
244
+ tooltipOpen && tooltipData && (
245
+ < TooltipInPortal
246
+ // set this to random so it correctly updates with parent bounds
247
+ key = { Math . random ( ) }
248
+ top = { tooltipTop }
249
+ left = { tooltipLeft }
250
+ >
251
+ Tooltip Data: < strong > { tooltipData } </ strong >
252
+ </ TooltipInPortal >
253
+ )
235
254
</ div >
236
255
) ;
237
256
}
0 commit comments