mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Remove fieldName and hideInLegend properties from UPlotSeriesBuilder
* Fix test
(cherry picked from commit 573d7b8893
)
Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
This commit is contained in:
parent
a7a9d002cb
commit
3884cfe270
@ -7,7 +7,6 @@ import {
|
|||||||
FieldSparkline,
|
FieldSparkline,
|
||||||
FieldType,
|
FieldType,
|
||||||
getFieldColorModeForField,
|
getFieldColorModeForField,
|
||||||
getFieldDisplayName,
|
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import {
|
import {
|
||||||
AxisPlacement,
|
AxisPlacement,
|
||||||
@ -158,7 +157,6 @@ export class Sparkline extends PureComponent<SparklineProps, State> {
|
|||||||
builder.addSeries({
|
builder.addSeries({
|
||||||
scaleKey,
|
scaleKey,
|
||||||
theme,
|
theme,
|
||||||
fieldName: getFieldDisplayName(field, data),
|
|
||||||
drawStyle: customConfig.drawStyle!,
|
drawStyle: customConfig.drawStyle!,
|
||||||
lineColor: customConfig.lineColor ?? seriesColor,
|
lineColor: customConfig.lineColor ?? seriesColor,
|
||||||
lineWidth: customConfig.lineWidth,
|
lineWidth: customConfig.lineWidth,
|
||||||
|
@ -185,11 +185,8 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{ sync: DashboardCursor
|
|||||||
show: !customConfig.hideFrom?.viz,
|
show: !customConfig.hideFrom?.viz,
|
||||||
gradientMode: customConfig.gradientMode,
|
gradientMode: customConfig.gradientMode,
|
||||||
thresholds: config.thresholds,
|
thresholds: config.thresholds,
|
||||||
|
|
||||||
// The following properties are not used in the uPlot config, but are utilized as transport for legend config
|
// The following properties are not used in the uPlot config, but are utilized as transport for legend config
|
||||||
dataFrameFieldIndex: field.state?.origin,
|
dataFrameFieldIndex: field.state?.origin,
|
||||||
fieldName: getFieldDisplayName(field, frame),
|
|
||||||
hideInLegend: customConfig.hideFrom?.legend,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Render thresholds in graph
|
// Render thresholds in graph
|
||||||
|
@ -29,18 +29,17 @@ export const PlotLegend: React.FC<PlotLegendProps> = ({
|
|||||||
const fieldIndex = seriesConfig.dataFrameFieldIndex;
|
const fieldIndex = seriesConfig.dataFrameFieldIndex;
|
||||||
const axisPlacement = config.getAxisPlacement(s.props.scaleKey);
|
const axisPlacement = config.getAxisPlacement(s.props.scaleKey);
|
||||||
|
|
||||||
if (seriesConfig.hideInLegend || !fieldIndex) {
|
if (!fieldIndex) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const field = data[fieldIndex.frameIndex]?.fields[fieldIndex.fieldIndex];
|
const field = data[fieldIndex.frameIndex]?.fields[fieldIndex.fieldIndex];
|
||||||
|
|
||||||
if (!field) {
|
if (!field || field.config.custom.hideFrom?.legend) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const label = getFieldDisplayName(field, data[fieldIndex.frameIndex]!);
|
const label = getFieldDisplayName(field, data[fieldIndex.frameIndex]!, data);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
disabled: !seriesConfig.show ?? false,
|
disabled: !seriesConfig.show ?? false,
|
||||||
fieldIndex,
|
fieldIndex,
|
||||||
|
@ -405,7 +405,6 @@ describe('UPlotConfigBuilder', () => {
|
|||||||
builder.addSeries({
|
builder.addSeries({
|
||||||
drawStyle: DrawStyle.Line,
|
drawStyle: DrawStyle.Line,
|
||||||
scaleKey: 'scale-x',
|
scaleKey: 'scale-x',
|
||||||
fieldName: 'A-series',
|
|
||||||
lineColor: '#0000ff',
|
lineColor: '#0000ff',
|
||||||
theme: darkTheme,
|
theme: darkTheme,
|
||||||
});
|
});
|
||||||
@ -418,7 +417,6 @@ describe('UPlotConfigBuilder', () => {
|
|||||||
builder.addSeries({
|
builder.addSeries({
|
||||||
drawStyle: DrawStyle.Line,
|
drawStyle: DrawStyle.Line,
|
||||||
scaleKey: 'scale-x',
|
scaleKey: 'scale-x',
|
||||||
fieldName: 'A-series',
|
|
||||||
lineColor: '#FFAABB',
|
lineColor: '#FFAABB',
|
||||||
fillOpacity: 50,
|
fillOpacity: 50,
|
||||||
theme: darkTheme,
|
theme: darkTheme,
|
||||||
@ -432,7 +430,6 @@ describe('UPlotConfigBuilder', () => {
|
|||||||
builder.addSeries({
|
builder.addSeries({
|
||||||
drawStyle: DrawStyle.Line,
|
drawStyle: DrawStyle.Line,
|
||||||
scaleKey: 'scale-x',
|
scaleKey: 'scale-x',
|
||||||
fieldName: 'A-series',
|
|
||||||
lineColor: '#FFAABB',
|
lineColor: '#FFAABB',
|
||||||
fillOpacity: 50,
|
fillOpacity: 50,
|
||||||
fillColor: '#FF0000',
|
fillColor: '#FF0000',
|
||||||
@ -447,7 +444,6 @@ describe('UPlotConfigBuilder', () => {
|
|||||||
builder.addSeries({
|
builder.addSeries({
|
||||||
drawStyle: DrawStyle.Line,
|
drawStyle: DrawStyle.Line,
|
||||||
scaleKey: 'scale-x',
|
scaleKey: 'scale-x',
|
||||||
fieldName: 'A-series',
|
|
||||||
lineColor: '#FFAABB',
|
lineColor: '#FFAABB',
|
||||||
fillOpacity: 50,
|
fillOpacity: 50,
|
||||||
gradientMode: GraphGradientMode.Opacity,
|
gradientMode: GraphGradientMode.Opacity,
|
||||||
@ -462,7 +458,6 @@ describe('UPlotConfigBuilder', () => {
|
|||||||
builder.addSeries({
|
builder.addSeries({
|
||||||
drawStyle: DrawStyle.Line,
|
drawStyle: DrawStyle.Line,
|
||||||
scaleKey: 'scale-x',
|
scaleKey: 'scale-x',
|
||||||
fieldName: 'A-series',
|
|
||||||
fillOpacity: 50,
|
fillOpacity: 50,
|
||||||
gradientMode: GraphGradientMode.Opacity,
|
gradientMode: GraphGradientMode.Opacity,
|
||||||
showPoints: PointVisibility.Auto,
|
showPoints: PointVisibility.Auto,
|
||||||
@ -524,7 +519,6 @@ describe('UPlotConfigBuilder', () => {
|
|||||||
builder.addSeries({
|
builder.addSeries({
|
||||||
drawStyle: DrawStyle.Line,
|
drawStyle: DrawStyle.Line,
|
||||||
scaleKey: 'scale-x',
|
scaleKey: 'scale-x',
|
||||||
fieldName: 'A-series',
|
|
||||||
fillOpacity: 50,
|
fillOpacity: 50,
|
||||||
gradientMode: GraphGradientMode.Opacity,
|
gradientMode: GraphGradientMode.Opacity,
|
||||||
showPoints: PointVisibility.Auto,
|
showPoints: PointVisibility.Auto,
|
||||||
@ -536,7 +530,6 @@ describe('UPlotConfigBuilder', () => {
|
|||||||
builder.addSeries({
|
builder.addSeries({
|
||||||
drawStyle: DrawStyle.Line,
|
drawStyle: DrawStyle.Line,
|
||||||
scaleKey: 'scale-x',
|
scaleKey: 'scale-x',
|
||||||
fieldName: 'B-series',
|
|
||||||
fillOpacity: 50,
|
fillOpacity: 50,
|
||||||
gradientMode: GraphGradientMode.Opacity,
|
gradientMode: GraphGradientMode.Opacity,
|
||||||
showPoints: PointVisibility.Auto,
|
showPoints: PointVisibility.Auto,
|
||||||
@ -550,7 +543,6 @@ describe('UPlotConfigBuilder', () => {
|
|||||||
builder.addSeries({
|
builder.addSeries({
|
||||||
drawStyle: DrawStyle.Line,
|
drawStyle: DrawStyle.Line,
|
||||||
scaleKey: 'scale-x',
|
scaleKey: 'scale-x',
|
||||||
fieldName: 'C-series',
|
|
||||||
fillOpacity: 50,
|
fillOpacity: 50,
|
||||||
gradientMode: GraphGradientMode.Opacity,
|
gradientMode: GraphGradientMode.Opacity,
|
||||||
showPoints: PointVisibility.Auto,
|
showPoints: PointVisibility.Auto,
|
||||||
|
@ -23,13 +23,11 @@ export interface SeriesProps extends LineConfig, BarConfig, FillConfig, PointsCo
|
|||||||
thresholds?: ThresholdsConfig;
|
thresholds?: ThresholdsConfig;
|
||||||
/** Used when gradientMode is set to Scheme */
|
/** Used when gradientMode is set to Scheme */
|
||||||
colorMode?: FieldColorMode;
|
colorMode?: FieldColorMode;
|
||||||
fieldName: string;
|
|
||||||
drawStyle?: DrawStyle;
|
drawStyle?: DrawStyle;
|
||||||
pathBuilder?: Series.PathBuilder;
|
pathBuilder?: Series.PathBuilder;
|
||||||
pointsBuilder?: Series.Points.Show;
|
pointsBuilder?: Series.Points.Show;
|
||||||
show?: boolean;
|
show?: boolean;
|
||||||
dataFrameFieldIndex?: DataFrameFieldIndex;
|
dataFrameFieldIndex?: DataFrameFieldIndex;
|
||||||
hideInLegend?: boolean;
|
|
||||||
theme: GrafanaTheme2;
|
theme: GrafanaTheme2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ import {
|
|||||||
FieldType,
|
FieldType,
|
||||||
formattedValueToString,
|
formattedValueToString,
|
||||||
getFieldColorModeForField,
|
getFieldColorModeForField,
|
||||||
getFieldDisplayName,
|
|
||||||
getFieldSeriesColor,
|
getFieldSeriesColor,
|
||||||
MutableDataFrame,
|
MutableDataFrame,
|
||||||
VizOrientation,
|
VizOrientation,
|
||||||
@ -134,8 +133,6 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<BarChartOptions> = ({
|
|||||||
fieldIndex: i,
|
fieldIndex: i,
|
||||||
frameIndex: 0,
|
frameIndex: 0,
|
||||||
},
|
},
|
||||||
fieldName: getFieldDisplayName(field, frame),
|
|
||||||
hideInLegend: customConfig.hideFrom?.legend,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// The builder will manage unique scaleKeys and combine where appropriate
|
// The builder will manage unique scaleKeys and combine where appropriate
|
||||||
|
@ -4,7 +4,6 @@ import {
|
|||||||
DataFrame,
|
DataFrame,
|
||||||
formattedValueToString,
|
formattedValueToString,
|
||||||
getFieldColorModeForField,
|
getFieldColorModeForField,
|
||||||
getFieldDisplayName,
|
|
||||||
getFieldSeriesColor,
|
getFieldSeriesColor,
|
||||||
GrafanaTheme2,
|
GrafanaTheme2,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
@ -152,8 +151,6 @@ const prepConfig = (frame: DataFrame, theme: GrafanaTheme2) => {
|
|||||||
fieldIndex: i,
|
fieldIndex: i,
|
||||||
frameIndex: 0,
|
frameIndex: 0,
|
||||||
},
|
},
|
||||||
fieldName: getFieldDisplayName(field, frame),
|
|
||||||
hideInLegend: customConfig.hideFrom?.legend,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,11 +178,8 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<TimelineOptions> = ({
|
|||||||
theme,
|
theme,
|
||||||
show: !customConfig.hideFrom?.viz,
|
show: !customConfig.hideFrom?.viz,
|
||||||
thresholds: config.thresholds,
|
thresholds: config.thresholds,
|
||||||
|
|
||||||
// The following properties are not used in the uPlot config, but are utilized as transport for legend config
|
// The following properties are not used in the uPlot config, but are utilized as transport for legend config
|
||||||
dataFrameFieldIndex: field.state?.origin,
|
dataFrameFieldIndex: field.state?.origin,
|
||||||
fieldName: getFieldDisplayName(field, frame),
|
|
||||||
hideInLegend: customConfig.hideFrom?.legend,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user