Skip to content

Commit a905498

Browse files
authored
Merge pull request #4 from C-STYR/onhover
Onhover
2 parents 0f97009 + 15e59d2 commit a905498

File tree

1 file changed

+46
-27
lines changed

1 file changed

+46
-27
lines changed

src/app/components/ComponentMap.tsx

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { pointRadial } from 'd3-shape';
77
import useForceUpdate from './useForceUpdate';
88
import LinkControls from './LinkControls';
99
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';
1113
import { useStoreContext } from '../store';
1214

1315
const root = hierarchy({
@@ -30,6 +32,7 @@ interface TreeNode {
3032
children?: TreeNode[];
3133
}
3234

35+
3336
type HierarchyNode = HierarchyPointNode<TreeNode>;
3437

3538
const defaultMargin = { top: 30, left: 30, right: 55, bottom: 70 };
@@ -89,6 +92,33 @@ export default function ComponentMap({
8992
sizeHeight = innerWidth;
9093
}
9194
}
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+
92122
// controls for the map
93123
const LinkComponent = getLinkComponent({ layout, linkType, orientation });
94124
return totalWidth < 10 ? null : (
@@ -104,7 +134,7 @@ export default function ComponentMap({
104134
setStepPercent={setStepPercent}
105135
/>
106136

107-
<svg width={totalWidth} height={totalHeight}>
137+
<svg ref={containerRef} width={totalWidth} height={totalHeight}>
108138
<LinearGradient id="links-gradient" from="#fd9b93" to="#fe6e9e" />
109139
<rect width={totalWidth} height={totalHeight} rx={14} fill="#242529" />
110140
<Group top={margin.top} left={margin.left}>
@@ -180,31 +210,10 @@ export default function ComponentMap({
180210
node.data.isExpanded = !node.data.isExpanded;
181211
forceUpdate();
182212
}}
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}
208217
/>
209218
)}
210219
{/* Display text inside of each component node */}
@@ -232,6 +241,16 @@ export default function ComponentMap({
232241
</Tree>
233242
</Group>
234243
</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+
)
235254
</div>
236255
);
237256
}

0 commit comments

Comments
 (0)