Skip to content

Commit 0fb868e

Browse files
authored
Merge pull request #809 from SlideRuleEarth/carlos-dev4
Tooltip for photon on analysis page getting cut off
2 parents c381dad + 3776173 commit 0fb868e

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

web-client/src/utils/plotUtils.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,54 @@ export async function getScatterOptions(req_id: number): Promise<any> {
11381138
},
11391139
tooltip: {
11401140
trigger: 'item',
1141-
formatter: (params: any) => formatTooltip(params, latFieldName, lonFieldName, reqIdStr)
1141+
formatter: (params: any) => formatTooltip(params, latFieldName, lonFieldName, reqIdStr),
1142+
confine: true,
1143+
position: function (
1144+
point: number[],
1145+
_params: any,
1146+
_dom: HTMLElement,
1147+
_rect: any,
1148+
size: any
1149+
) {
1150+
// point is the mouse position [x, y]
1151+
// size contains viewSize and contentSize: {viewSize: [width, height], contentSize: [width, height]}
1152+
const tooltipWidth = size.contentSize[0]
1153+
const tooltipHeight = size.contentSize[1]
1154+
const chartWidth = size.viewSize[0]
1155+
const chartHeight = size.viewSize[1]
1156+
1157+
let x = point[0]
1158+
let y = point[1]
1159+
1160+
// Offset tooltip from cursor
1161+
const offset = 15
1162+
1163+
// Default position: right and below cursor
1164+
x = point[0] + offset
1165+
y = point[1] + offset
1166+
1167+
// If tooltip would overflow right edge, position it to the left of cursor
1168+
if (x + tooltipWidth > chartWidth) {
1169+
x = point[0] - tooltipWidth - offset
1170+
}
1171+
1172+
// If tooltip would overflow bottom edge, position it above cursor
1173+
if (y + tooltipHeight > chartHeight) {
1174+
y = point[1] - tooltipHeight - offset
1175+
}
1176+
1177+
// Ensure tooltip doesn't go off left edge
1178+
if (x < 0) {
1179+
x = offset
1180+
}
1181+
1182+
// Ensure tooltip doesn't go off top edge
1183+
if (y < 0) {
1184+
y = offset
1185+
}
1186+
1187+
return [x, y]
1188+
}
11421189
},
11431190
legend: {
11441191
data: legendNames,

0 commit comments

Comments
 (0)