From 3884cfe270314b37082f20f5d03328ec80c7aa14 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Mon, 31 May 2021 04:29:57 -0400 Subject: [PATCH] GraphNG: Remove fieldName and hideInLegend properties from UPlotSeriesBuilder (#34901) (#34965) * Remove fieldName and hideInLegend properties from UPlotSeriesBuilder * Fix test (cherry picked from commit 573d7b8893876dff712c2cb038b2b300e03d369b) Co-authored-by: Dominik Prokop --- .../grafana-ui/src/components/Sparkline/Sparkline.tsx | 2 -- packages/grafana-ui/src/components/TimeSeries/utils.ts | 3 --- packages/grafana-ui/src/components/uPlot/PlotLegend.tsx | 7 +++---- .../components/uPlot/config/UPlotConfigBuilder.test.ts | 8 -------- .../src/components/uPlot/config/UPlotSeriesBuilder.ts | 2 -- public/app/plugins/panel/barchart/utils.ts | 3 --- public/app/plugins/panel/histogram/Histogram.tsx | 3 --- public/app/plugins/panel/state-timeline/utils.ts | 3 --- 8 files changed, 3 insertions(+), 28 deletions(-) diff --git a/packages/grafana-ui/src/components/Sparkline/Sparkline.tsx b/packages/grafana-ui/src/components/Sparkline/Sparkline.tsx index 9e91b949630..476f58acfee 100755 --- a/packages/grafana-ui/src/components/Sparkline/Sparkline.tsx +++ b/packages/grafana-ui/src/components/Sparkline/Sparkline.tsx @@ -7,7 +7,6 @@ import { FieldSparkline, FieldType, getFieldColorModeForField, - getFieldDisplayName, } from '@grafana/data'; import { AxisPlacement, @@ -158,7 +157,6 @@ export class Sparkline extends PureComponent { builder.addSeries({ scaleKey, theme, - fieldName: getFieldDisplayName(field, data), drawStyle: customConfig.drawStyle!, lineColor: customConfig.lineColor ?? seriesColor, lineWidth: customConfig.lineWidth, diff --git a/packages/grafana-ui/src/components/TimeSeries/utils.ts b/packages/grafana-ui/src/components/TimeSeries/utils.ts index f23a57b6efb..19e70a33f9f 100644 --- a/packages/grafana-ui/src/components/TimeSeries/utils.ts +++ b/packages/grafana-ui/src/components/TimeSeries/utils.ts @@ -185,11 +185,8 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{ sync: DashboardCursor show: !customConfig.hideFrom?.viz, gradientMode: customConfig.gradientMode, thresholds: config.thresholds, - // The following properties are not used in the uPlot config, but are utilized as transport for legend config dataFrameFieldIndex: field.state?.origin, - fieldName: getFieldDisplayName(field, frame), - hideInLegend: customConfig.hideFrom?.legend, }); // Render thresholds in graph diff --git a/packages/grafana-ui/src/components/uPlot/PlotLegend.tsx b/packages/grafana-ui/src/components/uPlot/PlotLegend.tsx index 42c2cae8011..e952349056e 100644 --- a/packages/grafana-ui/src/components/uPlot/PlotLegend.tsx +++ b/packages/grafana-ui/src/components/uPlot/PlotLegend.tsx @@ -29,18 +29,17 @@ export const PlotLegend: React.FC = ({ const fieldIndex = seriesConfig.dataFrameFieldIndex; const axisPlacement = config.getAxisPlacement(s.props.scaleKey); - if (seriesConfig.hideInLegend || !fieldIndex) { + if (!fieldIndex) { return undefined; } const field = data[fieldIndex.frameIndex]?.fields[fieldIndex.fieldIndex]; - if (!field) { + if (!field || field.config.custom.hideFrom?.legend) { return undefined; } - const label = getFieldDisplayName(field, data[fieldIndex.frameIndex]!); - + const label = getFieldDisplayName(field, data[fieldIndex.frameIndex]!, data); return { disabled: !seriesConfig.show ?? false, fieldIndex, diff --git a/packages/grafana-ui/src/components/uPlot/config/UPlotConfigBuilder.test.ts b/packages/grafana-ui/src/components/uPlot/config/UPlotConfigBuilder.test.ts index 213e3f59452..3281b7e26ed 100644 --- a/packages/grafana-ui/src/components/uPlot/config/UPlotConfigBuilder.test.ts +++ b/packages/grafana-ui/src/components/uPlot/config/UPlotConfigBuilder.test.ts @@ -405,7 +405,6 @@ describe('UPlotConfigBuilder', () => { builder.addSeries({ drawStyle: DrawStyle.Line, scaleKey: 'scale-x', - fieldName: 'A-series', lineColor: '#0000ff', theme: darkTheme, }); @@ -418,7 +417,6 @@ describe('UPlotConfigBuilder', () => { builder.addSeries({ drawStyle: DrawStyle.Line, scaleKey: 'scale-x', - fieldName: 'A-series', lineColor: '#FFAABB', fillOpacity: 50, theme: darkTheme, @@ -432,7 +430,6 @@ describe('UPlotConfigBuilder', () => { builder.addSeries({ drawStyle: DrawStyle.Line, scaleKey: 'scale-x', - fieldName: 'A-series', lineColor: '#FFAABB', fillOpacity: 50, fillColor: '#FF0000', @@ -447,7 +444,6 @@ describe('UPlotConfigBuilder', () => { builder.addSeries({ drawStyle: DrawStyle.Line, scaleKey: 'scale-x', - fieldName: 'A-series', lineColor: '#FFAABB', fillOpacity: 50, gradientMode: GraphGradientMode.Opacity, @@ -462,7 +458,6 @@ describe('UPlotConfigBuilder', () => { builder.addSeries({ drawStyle: DrawStyle.Line, scaleKey: 'scale-x', - fieldName: 'A-series', fillOpacity: 50, gradientMode: GraphGradientMode.Opacity, showPoints: PointVisibility.Auto, @@ -524,7 +519,6 @@ describe('UPlotConfigBuilder', () => { builder.addSeries({ drawStyle: DrawStyle.Line, scaleKey: 'scale-x', - fieldName: 'A-series', fillOpacity: 50, gradientMode: GraphGradientMode.Opacity, showPoints: PointVisibility.Auto, @@ -536,7 +530,6 @@ describe('UPlotConfigBuilder', () => { builder.addSeries({ drawStyle: DrawStyle.Line, scaleKey: 'scale-x', - fieldName: 'B-series', fillOpacity: 50, gradientMode: GraphGradientMode.Opacity, showPoints: PointVisibility.Auto, @@ -550,7 +543,6 @@ describe('UPlotConfigBuilder', () => { builder.addSeries({ drawStyle: DrawStyle.Line, scaleKey: 'scale-x', - fieldName: 'C-series', fillOpacity: 50, gradientMode: GraphGradientMode.Opacity, showPoints: PointVisibility.Auto, diff --git a/packages/grafana-ui/src/components/uPlot/config/UPlotSeriesBuilder.ts b/packages/grafana-ui/src/components/uPlot/config/UPlotSeriesBuilder.ts index b827a848be2..d6369fc03fb 100755 --- a/packages/grafana-ui/src/components/uPlot/config/UPlotSeriesBuilder.ts +++ b/packages/grafana-ui/src/components/uPlot/config/UPlotSeriesBuilder.ts @@ -23,13 +23,11 @@ export interface SeriesProps extends LineConfig, BarConfig, FillConfig, PointsCo thresholds?: ThresholdsConfig; /** Used when gradientMode is set to Scheme */ colorMode?: FieldColorMode; - fieldName: string; drawStyle?: DrawStyle; pathBuilder?: Series.PathBuilder; pointsBuilder?: Series.Points.Show; show?: boolean; dataFrameFieldIndex?: DataFrameFieldIndex; - hideInLegend?: boolean; theme: GrafanaTheme2; } diff --git a/public/app/plugins/panel/barchart/utils.ts b/public/app/plugins/panel/barchart/utils.ts index 12d080ee83b..56faf9e093a 100644 --- a/public/app/plugins/panel/barchart/utils.ts +++ b/public/app/plugins/panel/barchart/utils.ts @@ -3,7 +3,6 @@ import { FieldType, formattedValueToString, getFieldColorModeForField, - getFieldDisplayName, getFieldSeriesColor, MutableDataFrame, VizOrientation, @@ -134,8 +133,6 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn = ({ fieldIndex: i, frameIndex: 0, }, - fieldName: getFieldDisplayName(field, frame), - hideInLegend: customConfig.hideFrom?.legend, }); // The builder will manage unique scaleKeys and combine where appropriate diff --git a/public/app/plugins/panel/histogram/Histogram.tsx b/public/app/plugins/panel/histogram/Histogram.tsx index f8dfe3776d6..d3bfffb1a67 100644 --- a/public/app/plugins/panel/histogram/Histogram.tsx +++ b/public/app/plugins/panel/histogram/Histogram.tsx @@ -4,7 +4,6 @@ import { DataFrame, formattedValueToString, getFieldColorModeForField, - getFieldDisplayName, getFieldSeriesColor, GrafanaTheme2, } from '@grafana/data'; @@ -152,8 +151,6 @@ const prepConfig = (frame: DataFrame, theme: GrafanaTheme2) => { fieldIndex: i, frameIndex: 0, }, - fieldName: getFieldDisplayName(field, frame), - hideInLegend: customConfig.hideFrom?.legend, }); } diff --git a/public/app/plugins/panel/state-timeline/utils.ts b/public/app/plugins/panel/state-timeline/utils.ts index ca58344d077..a261bbd4e88 100644 --- a/public/app/plugins/panel/state-timeline/utils.ts +++ b/public/app/plugins/panel/state-timeline/utils.ts @@ -178,11 +178,8 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn = ({ theme, show: !customConfig.hideFrom?.viz, thresholds: config.thresholds, - // The following properties are not used in the uPlot config, but are utilized as transport for legend config dataFrameFieldIndex: field.state?.origin, - fieldName: getFieldDisplayName(field, frame), - hideInLegend: customConfig.hideFrom?.legend, }); }