Skip to content

Commit 40b7ee1

Browse files
committed
Adjust tooltip position
1 parent ec8b3e6 commit 40b7ee1

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

assets/js/dashboard/components/graph-tooltip.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ export const GraphTooltipWrapper = ({
2121
isTouchDevice?: boolean
2222
}) => {
2323
const ref = useRef<HTMLDivElement>(null)
24-
// distance from cursor to tooltip edge
25-
const offsetFromCursor = 32
24+
// bigger on mobile to have room between thumb and tooltip
25+
const xOffsetFromCursor = isTouchDevice ? 24 : 12
26+
const yOffsetFromCursor = isTouchDevice ? 48 : 24
2627
const [measuredWidth, setMeasuredWidth] = useState(minWidth)
2728
// center tooltip above the cursor, clamped to prevent left/right overflow
28-
const rawLeft = x - measuredWidth / 2
29+
const rawLeft = x + xOffsetFromCursor
2930
const tooltipLeft = Math.max(0, Math.min(rawLeft, maxX - measuredWidth))
3031

3132
useLayoutEffect(() => {
@@ -54,7 +55,7 @@ export const GraphTooltipWrapper = ({
5455
minWidth,
5556
left: tooltipLeft,
5657
top: y,
57-
transform: `translateY(-100%) translateY(-${offsetFromCursor}px)`
58+
transform: `translateY(-100%) translateY(-${yOffsetFromCursor}px)`
5859
}}
5960
>
6061
{children}

assets/js/dashboard/components/graph.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ function InnerGraph<T extends ReadonlyArray<number | null>>({
266266
xPointer >= xLeftEdge - hoverBuffer &&
267267
xPointer <= xRightEdge + hoverBuffer &&
268268
yPointer >= yTopEdge - hoverBuffer &&
269-
yPointer <= yBottomEdge + hoverBuffer
269+
// chart is interactive even over x-axis labels
270+
yPointer <= height
270271
return { xPointer, yPointer, inHoverableArea }
271272
}
272273
const getClosestIndexToPointer = (xPointer: number): number =>

assets/js/dashboard/stats/graph/main-graph.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ const MainGraphTooltip = ({
321321
maxX={maxX}
322322
isTouchDevice={isTouchDevice}
323323
className={
324-
'absolute select-none pointer-events-none bg-gray-800 dark:bg-gray-950 py-3 px-4 rounded-md z-[100] shadow shadow-gray-200 dark:shadow-gray-850'
324+
'absolute z-10 select-none pointer-events-none bg-gray-800 dark:bg-gray-950 py-3 px-4 rounded-md shadow shadow-gray-200 dark:shadow-gray-850'
325325
}
326326
>
327327
<aside className="text-sm font-normal text-gray-100 flex flex-col gap-1.5">
@@ -407,7 +407,7 @@ export const MainGraphContainer = React.forwardRef<
407407
{ children: ReactNode }
408408
>((props, ref) => {
409409
return (
410-
<div className="relative my-4 h-92 w-full z-0" ref={ref}>
410+
<div className="relative my-4 h-92 w-full" ref={ref}>
411411
{props.children}
412412
</div>
413413
)

0 commit comments

Comments
 (0)