From 1c4b20b2686b38dfa2312dd0c36ec7fce777f493 Mon Sep 17 00:00:00 2001 From: Leon Sorokin Date: Mon, 28 Feb 2022 15:21:09 -0600 Subject: [PATCH] BarChart: fix single group rendering (#45953) --- public/app/plugins/panel/barchart/bars.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/public/app/plugins/panel/barchart/bars.ts b/public/app/plugins/panel/barchart/bars.ts index a8e79ca1942..098160b6e73 100644 --- a/public/app/plugins/panel/barchart/bars.ts +++ b/public/app/plugins/panel/barchart/bars.ts @@ -189,7 +189,7 @@ export function getConfig(opts: BarsOptions, theme: GrafanaTheme2) { // this expands the distr: 2 scale so that the indicies of each data[0] land at the proper justified positions const xRange: Scale.Range = (u, min, max) => { min = 0; - max = u.data[0].length - 1; + max = Math.max(1, u.data[0].length - 1); let pctOffset = 0; @@ -199,13 +199,17 @@ export function getConfig(opts: BarsOptions, theme: GrafanaTheme2) { }); // expand scale range by equal amounts on both ends - let rn = max - min; // TODO: clamp to 1? + let rn = max - min; - let upScale = 1 / (1 - pctOffset * 2); - let offset = (upScale * rn - rn) / 2; + if (pctOffset === 0.5) { + min -= rn; + } else { + let upScale = 1 / (1 - pctOffset * 2); + let offset = (upScale * rn - rn) / 2; - min -= offset; - max += offset; + min -= offset; + max += offset; + } return [min, max]; };