BarChart: Prevent label clipping at top (#91990)

* BarChart: Prevent label clipping at top

* Fix const issue
This commit is contained in:
Drew Slobodnjak 2024-08-16 09:29:25 -07:00 committed by GitHub
parent 126169f3ca
commit 3c5d799c8c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -399,7 +399,7 @@ export function getConfig(opts: BarsOptions, theme: GrafanaTheme2) {
// Calculate final co-ordinates for text position
const x =
u.bbox.left + (isXHorizontal ? lft + wid / 2 : value < 0 ? lft - labelOffset : lft + wid + labelOffset);
const y =
let y =
u.bbox.top +
(isXHorizontal ? (value < 0 ? top + hgt + labelOffset : top - labelOffset) : top + hgt / 2 - middleShift);
@ -436,6 +436,11 @@ export function getConfig(opts: BarsOptions, theme: GrafanaTheme2) {
xAdjust = value < 0 ? textMetrics.width * scaleFactor : 0;
}
// Force label bounding box y position to not be negative
if (y - yAdjust < 0) {
y = yAdjust;
}
// Construct final bounding box for the label text
labels[dataIdx][seriesIdx].x = x;
labels[dataIdx][seriesIdx].y = y;