diff --git a/public/app/plugins/panel/barchart/bars.ts b/public/app/plugins/panel/barchart/bars.ts index 392b1c0722a..3574b6d5045 100644 --- a/public/app/plugins/panel/barchart/bars.ts +++ b/public/app/plugins/panel/barchart/bars.ts @@ -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;