Skip to content

Commit bff118b

Browse files
committed
fix tooltip
1 parent 9d53540 commit bff118b

File tree

1 file changed

+43
-42
lines changed

1 file changed

+43
-42
lines changed

src/app/components/ComponentMap.tsx

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
// @ts-nocheck
2-
import React, { useState } from 'react';
3-
import { Group } from '@visx/group';
4-
import { hierarchy, Tree } from '@visx/hierarchy';
5-
import { LinearGradient } from '@visx/gradient';
6-
import { pointRadial } from 'd3-shape';
7-
import useForceUpdate from './useForceUpdate';
8-
import LinkControls from './LinkControls';
9-
import getLinkComponent from './getLinkComponent';
10-
import { localPoint } from '@visx/event';
11-
import { useTooltip, useTooltipInPortal, TooltipWithBounds } from '@visx/tooltip';
12-
import { onHover, onHoverExit } from '../actions/actions';
13-
import { useStoreContext } from '../store';
2+
import React, { useState } from "react";
3+
import { Group } from "@visx/group";
4+
import { hierarchy, Tree } from "@visx/hierarchy";
5+
import { LinearGradient } from "@visx/gradient";
6+
import { pointRadial } from "d3-shape";
7+
import useForceUpdate from "./useForceUpdate";
8+
import LinkControls from "./LinkControls";
9+
import getLinkComponent from "./getLinkComponent";
10+
import { localPoint } from "@visx/event";
11+
import {
12+
useTooltip,
13+
useTooltipInPortal,
14+
TooltipWithBounds,
15+
} from "@visx/tooltip";
16+
import { onHover, onHoverExit } from "../actions/actions";
17+
import { useStoreContext } from "../store";
1418

1519
const root = hierarchy({
16-
name: 'root',
20+
name: "root",
1721
children: [
18-
{ name: 'child #1' },
22+
{ name: "child #1" },
1923
{
20-
name: 'child #2',
24+
name: "child #2",
2125
children: [
22-
{ name: 'grandchild #1' },
23-
{ name: 'grandchild #2' },
24-
{ name: 'grandchild #3' },
26+
{ name: "grandchild #1" },
27+
{ name: "grandchild #2" },
28+
{ name: "grandchild #3" },
2529
],
2630
},
2731
],
@@ -32,7 +36,6 @@ interface TreeNode {
3236
children?: TreeNode[];
3337
}
3438

35-
3639
type HierarchyNode = HierarchyPointNode<TreeNode>;
3740

3841
const defaultMargin = { top: 30, left: 30, right: 55, bottom: 70 };
@@ -57,9 +60,9 @@ export default function ComponentMap({
5760
const data: {} = snapshots[lastNode];
5861

5962
// importing custom hooks for the selection tabs.
60-
const [layout, setLayout] = useState('cartesian');
61-
const [orientation, setOrientation] = useState('horizontal');
62-
const [linkType, setLinkType] = useState('diagonal');
63+
const [layout, setLayout] = useState("cartesian");
64+
const [orientation, setOrientation] = useState("horizontal");
65+
const [linkType, setLinkType] = useState("diagonal");
6366
const [stepPercent, setStepPercent] = useState(10);
6467

6568
// Declared this variable and assigned it to the useForceUpdate function that forces a state to change causing that component to re-render and display on the map
@@ -75,7 +78,7 @@ export default function ComponentMap({
7578

7679
// This sets the starting position for the root node on the maps display. the polar layout sets the root node to the relative center of the display box based on the size of the browser window.
7780
// the else conditional statements determines the root nodes location either in the left middle or top middle of the browser window relative to the size of the browser.
78-
if (layout === 'polar') {
81+
if (layout === "polar") {
7982
origin = {
8083
x: innerWidth / 2,
8184
y: innerHeight / 2,
@@ -84,7 +87,7 @@ export default function ComponentMap({
8487
sizeHeight = Math.min(innerWidth, innerHeight) / 2;
8588
} else {
8689
origin = { x: 0, y: 0 };
87-
if (orientation === 'vertical') {
90+
if (orientation === "vertical") {
8891
sizeWidth = innerWidth;
8992
sizeHeight = innerHeight;
9093
} else {
@@ -93,8 +96,7 @@ export default function ComponentMap({
9396
}
9497
}
9598

96-
97-
//Tooltip stuff:
99+
//Tooltip stuff:
98100
const {
99101
tooltipData,
100102
tooltipLeft,
@@ -108,16 +110,15 @@ export default function ComponentMap({
108110

109111
//mousing controls
110112
const handleMouseOver = (event) => {
111-
console.log("mouse entered");
113+
// console.log("mouse entered");
112114
const coords = localPoint(event.target.ownerSVGElement, event);
113-
console.log("I'm coords", coords);
115+
// console.log("I'm coords", coords);
114116
showTooltip({
115117
tooltipLeft: coords.x,
116118
tooltipTop: coords.y,
117-
tooltipData: "test"
119+
tooltipData: "test",
118120
});
119-
}
120-
121+
};
121122

122123
// controls for the map
123124
const LinkComponent = getLinkComponent({ layout, linkType, orientation });
@@ -168,11 +169,11 @@ export default function ComponentMap({
168169

169170
let top: number;
170171
let left: number;
171-
if (layout === 'polar') {
172+
if (layout === "polar") {
172173
const [radialX, radialY] = pointRadial(node.x, node.y);
173174
top = radialY;
174175
left = radialX;
175-
} else if (orientation === 'vertical') {
176+
} else if (orientation === "vertical") {
176177
top = node.y;
177178
left = node.x;
178179
} else {
@@ -200,10 +201,10 @@ export default function ComponentMap({
200201
width={width}
201202
y={-height / 2}
202203
x={-width / 2}
203-
fill={node.children ? '#161521' : '#62d6fb'}
204-
stroke={node.children ? '#62d6fb' : '#161521'}
204+
fill={node.children ? "#161521" : "#62d6fb"}
205+
stroke={node.children ? "#62d6fb" : "#161521"}
205206
strokeWidth={1}
206-
strokeDasharray={node.children ? '0' : '2,2'}
207+
strokeDasharray={node.children ? "0" : "2,2"}
207208
strokeOpacity="1"
208209
rx={node.children ? 4 : 10}
209210
onClick={() => {
@@ -222,13 +223,13 @@ export default function ComponentMap({
222223
fontSize={10}
223224
fontFamily="Roboto"
224225
textAnchor="middle"
225-
style={{ pointerEvents: 'none' }}
226+
style={{ pointerEvents: "none" }}
226227
fill={
227228
node.depth === 0
228-
? '#161521'
229+
? "#161521"
229230
: node.children
230-
? 'white'
231-
: '#161521'
231+
? "white"
232+
: "#161521"
232233
}
233234
>
234235
{node.data.name}
@@ -241,7 +242,7 @@ export default function ComponentMap({
241242
</Tree>
242243
</Group>
243244
</svg>
244-
tooltipOpen && tooltipData && (
245+
{tooltipOpen && tooltipData && (
245246
<TooltipInPortal
246247
// set this to random so it correctly updates with parent bounds
247248
key={Math.random()}
@@ -250,7 +251,7 @@ export default function ComponentMap({
250251
>
251252
Tooltip Data: <strong>{tooltipData}</strong>
252253
</TooltipInPortal>
253-
)
254+
)}
254255
</div>
255256
);
256257
}

0 commit comments

Comments
 (0)