diff --git a/public/app/core/components/GraphNG/GraphNG.tsx b/public/app/core/components/GraphNG/GraphNG.tsx index 56677ba33ce..88b4b5048bf 100644 --- a/public/app/core/components/GraphNG/GraphNG.tsx +++ b/public/app/core/components/GraphNG/GraphNG.tsx @@ -33,6 +33,7 @@ export type PropDiffFn = {}> = (prev: T, next: export interface GraphNGProps extends Themeable2 { frames: DataFrame[]; structureRev?: number; // a number that will change when the frames[] structure changes + hideFromVizStates?: string; width: number; height: number; timeRange: TimeRange; @@ -175,7 +176,9 @@ export class GraphNG extends Component { }; } - const nonHiddenFields = alignedFrameFinal.fields.filter((field) => field.config.custom?.hideFrom?.viz !== true); + const nonHiddenFields = alignedFrameFinal.fields.filter( + (field, i) => i === 0 || field.config.custom?.hideFrom?.viz !== true + ); alignedFrameFinal = { ...alignedFrameFinal, fields: nonHiddenFields, @@ -201,9 +204,10 @@ export class GraphNG extends Component { } componentDidUpdate(prevProps: GraphNGProps) { - const { frames, structureRev, timeZone, cursorSync, propsToDiff } = this.props; + const { frames, structureRev, timeZone, cursorSync, propsToDiff, hideFromVizStates } = this.props; - const propsChanged = !sameProps(prevProps, this.props, propsToDiff); + const propsChanged = + !sameProps(prevProps, this.props, propsToDiff) || hideFromVizStates !== prevProps.hideFromVizStates; if ( frames !== prevProps.frames || diff --git a/public/app/core/components/TimeSeries/utils.ts b/public/app/core/components/TimeSeries/utils.ts index 8774299b1ed..32aaa61ea9e 100644 --- a/public/app/core/components/TimeSeries/utils.ts +++ b/public/app/core/components/TimeSeries/utils.ts @@ -497,7 +497,7 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn = ({ barMaxWidth: customConfig.barMaxWidth, pointSize: customConfig.pointSize, spanNulls: customConfig.spanNulls || false, - show: !customConfig.hideFrom?.viz, + show: !customConfig.hideFrom?.viz && !field.state?.hideFrom?.viz, gradientMode: customConfig.gradientMode, thresholds: config.thresholds, hardMin: field.config.min, diff --git a/public/app/plugins/panel/candlestick/CandlestickPanel.tsx b/public/app/plugins/panel/candlestick/CandlestickPanel.tsx index acddd0a5727..d97d8e97fc4 100644 --- a/public/app/plugins/panel/candlestick/CandlestickPanel.tsx +++ b/public/app/plugins/panel/candlestick/CandlestickPanel.tsx @@ -59,8 +59,8 @@ export const CandlestickPanel = ({ const theme = useTheme2(); const info = useMemo(() => { - return prepareCandlestickFields(data.series, options, theme, timeRange); - }, [data.series, options, theme, timeRange]); + return prepareCandlestickFields(data.series, fieldConfig, options, theme, timeRange); + }, [data.series, fieldConfig, options, theme, timeRange]); // temp range set for adding new annotation set by TooltipPlugin2, consumed by AnnotationPlugin2 const [newAnnotationRange, setNewAnnotationRange] = useState(null); diff --git a/public/app/plugins/panel/candlestick/fields.ts b/public/app/plugins/panel/candlestick/fields.ts index c370b953a72..b8884b40ac7 100644 --- a/public/app/plugins/panel/candlestick/fields.ts +++ b/public/app/plugins/panel/candlestick/fields.ts @@ -1,6 +1,7 @@ import { DataFrame, Field, + FieldConfigSource, FieldType, getFieldDisplayName, GrafanaTheme2, @@ -96,6 +97,7 @@ function findFieldOrAuto(frame: DataFrame, info: FieldPickerInfo, options: Candl export function prepareCandlestickFields( series: DataFrame[] | undefined, + fieldConfig: FieldConfigSource, options: Partial, theme: GrafanaTheme2, timeRange?: TimeRange @@ -120,7 +122,7 @@ export function prepareCandlestickFields( const data: CandlestickData = { aligned, frame: aligned, names: {} }; // Apply same filter as everything else in timeseries - const timeSeriesFrames = prepareGraphableFields([aligned], theme, timeRange); + const timeSeriesFrames = prepareGraphableFields([aligned], fieldConfig, theme, timeRange); if (!timeSeriesFrames) { return null; } diff --git a/public/app/plugins/panel/timeseries/TimeSeriesPanel.tsx b/public/app/plugins/panel/timeseries/TimeSeriesPanel.tsx index fb9076f8a01..1854542fd59 100644 --- a/public/app/plugins/panel/timeseries/TimeSeriesPanel.tsx +++ b/public/app/plugins/panel/timeseries/TimeSeriesPanel.tsx @@ -44,7 +44,14 @@ export const TimeSeriesPanel = ({ // Vertical orientation is not available for users through config. // It is simplified version of horizontal time series panel and it does not support all plugins. const isVerticallyOriented = options.orientation === VizOrientation.Vertical; - const frames = useMemo(() => prepareGraphableFields(data.series, config.theme2, timeRange), [data.series, timeRange]); + const { frames, hideFromVizStates } = useMemo(() => { + let frames = prepareGraphableFields(data.series, fieldConfig, config.theme2, timeRange); + return { + frames, + hideFromVizStates: frames?.flatMap((fr) => fr.fields.flatMap((f) => Boolean(f.state?.hideFrom?.viz))).join(), + }; + }, [data.series, fieldConfig, timeRange]); + const timezones = useMemo(() => getTimezones(options.timezone, timeZone), [options.timezone, timeZone]); const suggestions = useMemo(() => { if (frames?.length && frames.every((df) => df.meta?.type === DataFrameType.TimeSeriesLong)) { @@ -79,6 +86,7 @@ export const TimeSeriesPanel = ({