From 86de94cbfad5f726f5f3840aa4dd132d88db06db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Bedi?= Date: Thu, 18 Aug 2022 15:26:40 +0200 Subject: [PATCH] TimeSeries: Don't show y axis when visualisation is hidden (#53671) * TimeSeries: Don't show y axis when visualisation is hidden * Update snapshot * make scale ranger return nulls for minMax when no visible data exists on scale * drop unneeded change * remove explicit axis.show Co-authored-by: Leon Sorokin --- .../GraphNG/__snapshots__/utils.test.ts.snap | 18 +++++++++--------- .../grafana-ui/src/components/GraphNG/utils.ts | 4 +--- .../src/components/TimeSeries/utils.ts | 1 - .../uPlot/config/UPlotScaleBuilder.ts | 7 ++++++- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/grafana-ui/src/components/GraphNG/__snapshots__/utils.test.ts.snap b/packages/grafana-ui/src/components/GraphNG/__snapshots__/utils.test.ts.snap index 66aa3f7800b..bb9819144ef 100644 --- a/packages/grafana-ui/src/components/GraphNG/__snapshots__/utils.test.ts.snap +++ b/packages/grafana-ui/src/components/GraphNG/__snapshots__/utils.test.ts.snap @@ -41,8 +41,8 @@ Object { }, "labelGap": 0, "rotate": undefined, - "scale": "__fixed/na-na/na-na/auto/linear/na/false", - "show": false, + "scale": "__fixed/na-na/na-na/auto/linear/na", + "show": true, "side": 3, "size": [Function], "space": [Function], @@ -79,7 +79,7 @@ Object { "key": "__global_", "scales": Array [ "x", - "__fixed/na-na/na-na/auto/linear/na/false", + "__fixed/na-na/na-na/auto/linear/na", ], }, }, @@ -87,7 +87,7 @@ Object { "mode": 1, "padding": undefined, "scales": Object { - "__fixed/na-na/na-na/auto/linear/na/false": Object { + "__fixed/na-na/na-na/auto/linear/na": Object { "auto": true, "dir": 1, "distr": 1, @@ -125,7 +125,7 @@ Object { "stroke": "#ff0000", }, "pxAlign": undefined, - "scale": "__fixed/na-na/na-na/auto/linear/na/false", + "scale": "__fixed/na-na/na-na/auto/linear/na", "show": true, "spanGaps": false, "stroke": "#ff0000", @@ -148,7 +148,7 @@ Object { "stroke": "#ff0000", }, "pxAlign": undefined, - "scale": "__fixed/na-na/na-na/auto/linear/na/false", + "scale": "__fixed/na-na/na-na/auto/linear/na", "show": true, "spanGaps": false, "stroke": "#ff0000", @@ -171,7 +171,7 @@ Object { "stroke": "#ff0000", }, "pxAlign": undefined, - "scale": "__fixed/na-na/na-na/auto/linear/na/false", + "scale": "__fixed/na-na/na-na/auto/linear/na", "show": true, "spanGaps": false, "stroke": "#ff0000", @@ -194,7 +194,7 @@ Object { "stroke": "#ff0000", }, "pxAlign": undefined, - "scale": "__fixed/na-na/na-na/auto/linear/na/false", + "scale": "__fixed/na-na/na-na/auto/linear/na", "show": true, "spanGaps": false, "stroke": "#ff0000", @@ -217,7 +217,7 @@ Object { "stroke": "#ff0000", }, "pxAlign": undefined, - "scale": "__fixed/na-na/na-na/auto/linear/na/false", + "scale": "__fixed/na-na/na-na/auto/linear/na", "show": true, "spanGaps": false, "stroke": "#ff0000", diff --git a/packages/grafana-ui/src/components/GraphNG/utils.ts b/packages/grafana-ui/src/components/GraphNG/utils.ts index e5b6893485e..e5de3bd9f66 100644 --- a/packages/grafana-ui/src/components/GraphNG/utils.ts +++ b/packages/grafana-ui/src/components/GraphNG/utils.ts @@ -151,9 +151,7 @@ export function buildScaleKey(config: FieldConfig) { const scaleLabel = Boolean(config.custom?.axisLabel) ? config.custom!.axisLabel : defaultPart; - const shouldHideFromViz = Boolean(config.custom?.hideFrom?.viz); - - return `${scaleUnit}/${scaleRange}/${scaleSoftRange}/${scalePlacement}/${scaleDistribution}/${scaleLabel}/${shouldHideFromViz}`; + return `${scaleUnit}/${scaleRange}/${scaleSoftRange}/${scalePlacement}/${scaleDistribution}/${scaleLabel}`; } function getScaleDistributionPart(config: ScaleDistributionConfig) { diff --git a/packages/grafana-ui/src/components/TimeSeries/utils.ts b/packages/grafana-ui/src/components/TimeSeries/utils.ts index af621e30e6c..b077fca144a 100644 --- a/packages/grafana-ui/src/components/TimeSeries/utils.ts +++ b/packages/grafana-ui/src/components/TimeSeries/utils.ts @@ -272,7 +272,6 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{ formatValue: (v, decimals) => formattedValueToString(fmt(v, config.decimals ?? decimals)), theme, grid: { show: customConfig.axisGridShow }, - show: customConfig.hideFrom?.viz === false, ...axisColorOpts, }, field diff --git a/packages/grafana-ui/src/components/uPlot/config/UPlotScaleBuilder.ts b/packages/grafana-ui/src/components/uPlot/config/UPlotScaleBuilder.ts index ee8aee79b68..e4aa36e7904 100644 --- a/packages/grafana-ui/src/components/uPlot/config/UPlotScaleBuilder.ts +++ b/packages/grafana-ui/src/components/uPlot/config/UPlotScaleBuilder.ts @@ -74,11 +74,16 @@ export class UPlotScaleBuilder extends PlotConfigBuilder { let hardMaxOnly = softMax == null && hardMax != null; // uPlot range function - const rangeFn = (u: uPlot, dataMin: number, dataMax: number, scaleKey: string) => { + const rangeFn = (u: uPlot, dataMin: number | null, dataMax: number | null, scaleKey: string) => { const scale = u.scales[scaleKey]; let minMax: uPlot.Range.MinMax = [dataMin, dataMax]; + // happens when all series on a scale are `show: false`, re-returning nulls will auto-disable axis + if (dataMin == null || dataMax == null) { + return minMax; + } + if (scale.distr === 1 || scale.distr === 2) { if (centeredZero) { let absMin = Math.abs(dataMin);