fix: flip slope tooltip below dot when near chart top edge

This commit is contained in:
Davide Scaini
2026-05-23 22:06:02 +02:00
parent e5c5383471
commit 40aa51be4d
+6 -2
View File
@@ -355,11 +355,15 @@
);
if (isSlope) {
const nearTop = (d: any) => {
const range = lineDomainMax - lineDomainMin;
return range > 0 && (d[yKey] - lineDomainMin) / range > 0.85;
};
marks.push(
Plot.text(lineData, Plot.pointerX({
x, y: yKey,
text: (d: any) => d.slope != null ? `${d.slope > 0.05 ? '+' : ''}${(+d.slope).toFixed(1)}%` : '',
dy: -22,
dy: (d: any) => nearTop(d) ? 22 : -22,
fill: (d: any) => slopeColor(d.slope ?? 0),
stroke: tc.tooltipBg, strokeWidth: 3,
fontSize: 11, fontWeight: '700',
@@ -367,7 +371,7 @@
Plot.text(lineData, Plot.pointerX({
x, y: yKey,
text: (d: any) => d[yKey] != null ? `${Math.round(d[yKey])}m` : '',
dy: -10,
dy: (d: any) => nearTop(d) ? 10 : -10,
fill: tc.axis, stroke: tc.tooltipBg, strokeWidth: 3,
fontSize: 10,
})),