Skip to content

Commit bf9dfff

Browse files
committed
Adjust tooltip structure and position
1 parent a9ac963 commit bf9dfff

1 file changed

Lines changed: 24 additions & 20 deletions

File tree

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ export const MainGraph = ({
349349
/>
350350
{selectedIndex !== null && remappedData[selectedIndex] && (
351351
<GraphTooltip
352-
width={width}
352+
maxX={width}
353353
showZoomToPeriod={showZoomToPeriod}
354354
shouldShowYear={hasMultipleYears}
355355
period={period}
@@ -371,7 +371,7 @@ const GraphTooltip = ({
371371
interval,
372372
period,
373373
shouldShowYear,
374-
width,
374+
maxX,
375375
x,
376376
y,
377377
datum,
@@ -389,22 +389,26 @@ const GraphTooltip = ({
389389
showZoomToPeriod?: boolean
390390
bucketIndex: number
391391
totalBuckets: number
392-
width: number
392+
maxX: number
393393
}) => {
394394
const formatter = MetricFormatterShort[metric]
395-
const isLeftOfCursor = width - x < 200
395+
const tooltipWidth = 200
396+
const tooltipWidthClass = 'w-[200px]'
397+
const buffer = 16
398+
const position = maxX - x < tooltipWidth - buffer ? 'left' : 'right'
396399
return (
397400
<div
398401
style={{
399402
left: x,
400403
top: y
401404
}}
402405
className={classNames(
403-
'absolute bg-gray-800 py-3 px-4 rounded-md z-[100] min-w-[180px] pointer-events-none shadow shadow-gray-200 dark:shadow-gray-850',
406+
tooltipWidthClass,
407+
'absolute bg-gray-800 dark:bg-gray-950 py-3 px-4 rounded-md z-[100] pointer-events-none shadow shadow-gray-200 dark:shadow-gray-850',
404408
'-translate-y-full',
405409
{
406-
'translate-x-2': !isLeftOfCursor,
407-
'-translate-x-full': isLeftOfCursor
410+
'translate-x-0': position === 'right',
411+
'-translate-x-full': position === 'left'
408412
}
409413
)}
410414
>
@@ -427,9 +431,9 @@ const GraphTooltip = ({
427431
<div className="flex flex-col">
428432
{typeof datum.timeLabel === 'string' && (
429433
<div className="flex flex-row justify-between items-center">
430-
<span className="flex items-center mr-4">
431-
<div className="size-2 mr-2 rounded-full bg-indigo-400"></div>
432-
<span>
434+
<div className="flex items-center mr-4">
435+
<div className="size-2 flex-none mr-2 rounded-full bg-indigo-400" />
436+
<div>
433437
{getFullBucketLabel(datum.timeLabel, {
434438
period,
435439
interval,
@@ -438,17 +442,17 @@ const GraphTooltip = ({
438442
totalBuckets,
439443
isPartial: datum.isPartial!
440444
})}
441-
</span>
442-
</span>
443-
<span className="font-bold">{formatter(datum.value)}</span>
445+
</div>
446+
</div>
447+
<div className="font-bold">{formatter(datum.value)}</div>
444448
</div>
445449
)}
446450

447451
{typeof datum.comparisonTimeLabel === 'string' && (
448452
<div className="flex flex-row justify-between items-center">
449-
<span className="flex items-center mr-4">
450-
<div className="size-2 mr-2 rounded-full bg-gray-500"></div>
451-
<span>
453+
<div className="flex items-center mr-4">
454+
<div className="size-2 flex-none mr-2 rounded-full bg-gray-500"></div>
455+
<div>
452456
{getFullBucketLabel(datum.comparisonTimeLabel, {
453457
period,
454458
interval,
@@ -457,11 +461,11 @@ const GraphTooltip = ({
457461
totalBuckets,
458462
isPartial: false
459463
})}
460-
</span>
461-
</span>
462-
<span className="font-bold">
464+
</div>
465+
</div>
466+
<div className="font-bold">
463467
{formatter(datum.comparisonValue)}
464-
</span>
468+
</div>
465469
</div>
466470
)}
467471
</div>

0 commit comments

Comments
 (0)