From 0d2cd901506df89c9073ac1d2ea4a24a458d2641 Mon Sep 17 00:00:00 2001 From: Leon Sorokin Date: Tue, 3 Aug 2021 08:18:05 -0500 Subject: [PATCH] GraphNG: fix y axis autosizing (#37464) --- .../src/components/uPlot/config/UPlotAxisBuilder.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/grafana-ui/src/components/uPlot/config/UPlotAxisBuilder.ts b/packages/grafana-ui/src/components/uPlot/config/UPlotAxisBuilder.ts index ebd8dc911d6..29c7dc8b42f 100644 --- a/packages/grafana-ui/src/components/uPlot/config/UPlotAxisBuilder.ts +++ b/packages/grafana-ui/src/components/uPlot/config/UPlotAxisBuilder.ts @@ -71,7 +71,6 @@ export class UPlotAxisBuilder extends PlotConfigBuilder { size: this.props.size ?? calculateAxisSize, gap, - // @ts-ignore (TODO: remove once uPlot adds this in 1.6.15) labelGap: 0, grid: { @@ -94,7 +93,6 @@ export class UPlotAxisBuilder extends PlotConfigBuilder { config.label = label; config.labelSize = fontSize + labelPad; config.labelFont = font; - // @ts-ignore (TODO: remove once uPlot adds this in 1.6.15) config.labelGap = labelPad; } @@ -146,8 +144,7 @@ function calculateAxisSize(self: uPlot, values: string[], axisIdx: number) { axisSize += axis!.gap! + fontSize; } else if (values?.length) { let longestValue = values.reduce((acc, value) => (value.length > acc.length ? value : acc), ''); - // @ts-ignore (TODO: remove axis!.labelGap! once uPlot adds this in 1.6.15) - axisSize += axis!.gap! + axis!.labelGap! + measureText(longestValue, fontSize).width; + axisSize += axis!.gap! + axis!.labelGap! + measureText('0'.repeat(longestValue.length), fontSize).width; } return Math.ceil(axisSize);