Skip to content

Commit 0e939e7

Browse files
authored
Merge pull request #6 from C-STYR/onhover
Hover feature reformatted
2 parents a905498 + 61e6783 commit 0e939e7

File tree

1 file changed

+45
-15
lines changed

1 file changed

+45
-15
lines changed

src/app/components/ComponentMap.tsx

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import useForceUpdate from './useForceUpdate';
88
import LinkControls from './LinkControls';
99
import getLinkComponent from './getLinkComponent';
1010
import { localPoint } from '@visx/event';
11-
import { useTooltip, useTooltipInPortal, TooltipWithBounds } from '@visx/tooltip';
11+
import { useTooltip, useTooltipInPortal, TooltipWithBounds, defaultStyles } from '@visx/tooltip';
1212
import { onHover, onHoverExit } from '../actions/actions';
1313
import { useStoreContext } from '../store';
1414

@@ -104,18 +104,24 @@ export default function ComponentMap({
104104
hideTooltip,
105105
} = useTooltip();
106106

107-
const { containerRef, TooltipInPortal } = useTooltipInPortal();
107+
const { containerRef, TooltipInPortal } = useTooltipInPortal({
108+
detectBounds: true,
109+
scroll: true,
110+
});
108111

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-
});
112+
const tooltipStyles = {
113+
...defaultStyles,
114+
minWidth: 60,
115+
backgroundColor: 'rgba(0,0,0,0.9)',
116+
color: 'white',
117+
fontSize: '14px',
118+
lineHeight: '18px',
119+
fontFamily: 'Roboto',
120+
};
121+
122+
const formatRenderTime = (time) => {
123+
time = time.toFixed(3);
124+
return `${time} ms `;
119125
}
120126

121127

@@ -166,6 +172,8 @@ export default function ComponentMap({
166172
const width = widthFunc(node.data.name);
167173
const height = 25;
168174

175+
176+
169177
let top: number;
170178
let left: number;
171179
if (layout === 'polar') {
@@ -180,6 +188,21 @@ export default function ComponentMap({
180188
left = node.y;
181189
}
182190

191+
//mousing controls
192+
const handleMouseOver = (event) => {
193+
() => dispatch(onHover(node.data.rtid));
194+
const coords = localPoint(event.target.ownerSVGElement, event);
195+
const tooltipObj = Object.assign({}, node.data);
196+
if (typeof tooltipObj.state === 'object') tooltipObj.state = 'stateful';
197+
console.log("tooltipObj", tooltipObj)
198+
showTooltip({
199+
tooltipLeft: coords.x,
200+
tooltipTop: coords.y,
201+
tooltipData: tooltipObj
202+
});
203+
}
204+
205+
183206
return (
184207
<Group top={top} left={left} key={key}>
185208
{node.depth === 0 && (
@@ -241,16 +264,23 @@ export default function ComponentMap({
241264
</Tree>
242265
</Group>
243266
</svg>
244-
tooltipOpen && tooltipData && (
267+
{tooltipOpen && tooltipData && (
245268
<TooltipInPortal
246269
// set this to random so it correctly updates with parent bounds
247270
key={Math.random()}
248271
top={tooltipTop}
249272
left={tooltipLeft}
273+
style={tooltipStyles}
250274
>
251-
Tooltip Data: <strong>{tooltipData}</strong>
275+
<div style={{ }}>
276+
{' '}
277+
<strong>{tooltipData.name}</strong>{' '}
278+
</div>
279+
<div>State: {tooltipData.state}</div>
280+
<div> Render time: {formatRenderTime(tooltipData.componentData.actualDuration)} </div>
281+
252282
</TooltipInPortal>
253-
)
283+
)}
254284
</div>
255285
);
256286
}

0 commit comments

Comments
 (0)