diff --git a/packages/grafana-ui/src/components/uPlot/config/UPlotScaleBuilder.ts b/packages/grafana-ui/src/components/uPlot/config/UPlotScaleBuilder.ts index 30a91c20b07..45313d9e3e5 100644 --- a/packages/grafana-ui/src/components/uPlot/config/UPlotScaleBuilder.ts +++ b/packages/grafana-ui/src/components/uPlot/config/UPlotScaleBuilder.ts @@ -157,7 +157,7 @@ export class UPlotScaleBuilder extends PlotConfigBuilder { let minMax: uPlot.Range.MinMax = [dataMin, dataMax]; // don't pad numeric x scales - if (scaleKey === 'x' && !isTime) { + if (scaleKey === 'x' && !isTime && distr === ScaleDistribution.Linear) { return minMax; } diff --git a/public/app/plugins/panel/xychart/scatter.ts b/public/app/plugins/panel/xychart/scatter.ts index aad9fe1d599..d4c9896d94d 100644 --- a/public/app/plugins/panel/xychart/scatter.ts +++ b/public/app/plugins/panel/xychart/scatter.ts @@ -601,22 +601,33 @@ const prepConfig = ( const frames = getData(); let xField = scatterSeries[0].x(scatterSeries[0].frame(frames)); + let config = xField.config; + let customConfig = config.custom; + let scaleDistr = customConfig?.scaleDistribution; + builder.addScale({ scaleKey: 'x', isTime: false, orientation: ScaleOrientation.Horizontal, direction: ScaleDirection.Right, - range: (u, dataMin, dataMax) => [xField.config.min ?? dataMin, xField.config.max ?? dataMax], + distribution: scaleDistr?.type, + log: scaleDistr?.log, + linearThreshold: scaleDistr?.linearThreshold, + min: config.min, + max: config.max, + softMin: customConfig?.axisSoftMin, + softMax: customConfig?.axisSoftMax, + centeredZero: customConfig?.axisCenteredZero, + decimals: config.decimals, }); // why does this fall back to '' instead of null or undef? - let xAxisLabel = xField.config.custom.axisLabel; + let xAxisLabel = customConfig.axisLabel; builder.addAxis({ scaleKey: 'x', - placement: - xField.config.custom?.axisPlacement !== AxisPlacement.Hidden ? AxisPlacement.Bottom : AxisPlacement.Hidden, - show: xField.config.custom?.axisPlacement !== AxisPlacement.Hidden, + placement: customConfig?.axisPlacement !== AxisPlacement.Hidden ? AxisPlacement.Bottom : AxisPlacement.Hidden, + show: customConfig?.axisPlacement !== AxisPlacement.Hidden, theme, label: xAxisLabel == null || xAxisLabel === '' @@ -635,23 +646,33 @@ const prepConfig = ( //const lineWidth = s.lineWidth; let scaleKey = field.config.unit ?? 'y'; + let config = field.config; + let customConfig = config.custom; + let scaleDistr = customConfig?.scaleDistribution; builder.addScale({ scaleKey, orientation: ScaleOrientation.Vertical, direction: ScaleDirection.Up, - max: field.config.max, - min: field.config.min, + distribution: scaleDistr?.type, + log: scaleDistr?.log, + linearThreshold: scaleDistr?.linearThreshold, + min: config.min, + max: config.max, + softMin: customConfig?.axisSoftMin, + softMax: customConfig?.axisSoftMax, + centeredZero: customConfig?.axisCenteredZero, + decimals: config.decimals, }); - if (field.config.custom?.axisPlacement !== AxisPlacement.Hidden) { + if (customConfig?.axisPlacement !== AxisPlacement.Hidden) { // why does this fall back to '' instead of null or undef? - let yAxisLabel = field.config.custom?.axisLabel; + let yAxisLabel = customConfig?.axisLabel; builder.addAxis({ scaleKey, theme, - placement: field.config.custom?.axisPlacement, + placement: customConfig?.axisPlacement, label: yAxisLabel == null || yAxisLabel === '' ? getFieldDisplayName(field, scatterSeries[si].frame(frames), frames) @@ -676,7 +697,7 @@ const prepConfig = ( scaleKey: '', // facets' scales used (above) lineColor: lineColor as string, fillColor: alpha(pointColor, 0.5), - show: !field.config.custom.hideFrom?.viz, + show: !customConfig.hideFrom?.viz, }); });