[v11.2.x] BarChart: Prevent label clipping at top (#92025)

BarChart: Prevent label clipping at top (#91990)

* BarChart: Prevent label clipping at top

* Fix const issue

(cherry picked from commit 3c5d799c8c)

Co-authored-by: Drew Slobodnjak <60050885+drew08t@users.noreply.github.com>
This commit is contained in:
grafana-delivery-bot[bot]
2024-08-16 09:55:25 -07:00
committed by GitHub
co-authored by Drew Slobodnjak
parent c16e4f1e86
commit f818808690
+6 -1
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;