From fc413c9c7fd6d7718ff25ef1ba9b213e8654c73c Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Thu, 21 Oct 2021 13:48:50 -0700 Subject: [PATCH] add negative y config --- .../src/field/overrides/processors.ts | 2 ++ packages/grafana-schema/src/schema/graph.cue | 2 ++ .../grafana-schema/src/schema/graph.gen.ts | 6 +++++ .../src/components/OptionsUI/select.tsx | 3 ++- public/app/plugins/panel/timeseries/config.ts | 23 +++++++++++++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/grafana-data/src/field/overrides/processors.ts b/packages/grafana-data/src/field/overrides/processors.ts index 4d12da0b87d..55d16aa4b6d 100644 --- a/packages/grafana-data/src/field/overrides/processors.ts +++ b/packages/grafana-data/src/field/overrides/processors.ts @@ -65,6 +65,8 @@ export const valueMappingsOverrideProcessor = ( export interface SelectFieldConfigSettings { allowCustomValue?: boolean; + isClearable?: boolean; + /** The default options */ options: Array>; diff --git a/packages/grafana-schema/src/schema/graph.cue b/packages/grafana-schema/src/schema/graph.cue index 0af58f7c5b1..cc1abcf37b9 100644 --- a/packages/grafana-schema/src/schema/graph.cue +++ b/packages/grafana-schema/src/schema/graph.cue @@ -7,6 +7,7 @@ LineInterpolation: "linear" | "smooth" | "stepBefore" | "stepAfter" @cue ScaleDistribution: "linear" | "log" | "ordinal" @cuetsy(kind="enum") GraphGradientMode: "none" | "opacity" | "hue" | "scheme" @cuetsy(kind="enum") StackingMode: "none" | "normal" | "percent" @cuetsy(kind="enum") +GraphTransform: "constant" | "negative-Y" @cuetsy(kind="enum") BarAlignment: -1 | 0 | 1 @cuetsy(kind="enum",memberNames="Before|Center|After") ScaleOrientation: 0 | 1 @cuetsy(kind="enum",memberNames="Horizontal|Vertical") ScaleDirection: 1 | 1 | -1 | -1 @cuetsy(kind="enum",memberNames="Up|Right|Down|Left") @@ -84,4 +85,5 @@ GraphFieldConfig: { drawStyle?: GraphDrawStyle gradientMode?: GraphGradientMode thresholdsStyle?: GraphThresholdsStyleConfig + transform?: GraphTransform } @cuetsy(kind="interface") diff --git a/packages/grafana-schema/src/schema/graph.gen.ts b/packages/grafana-schema/src/schema/graph.gen.ts index 5d9004906c0..3878bbcb69d 100644 --- a/packages/grafana-schema/src/schema/graph.gen.ts +++ b/packages/grafana-schema/src/schema/graph.gen.ts @@ -24,6 +24,11 @@ export enum GraphDrawStyle { Points = 'points', } +export enum GraphTransform { + Constant = 'constant', + NegativeY = 'negative-Y', +} + export enum LineInterpolation { Linear = 'linear', Smooth = 'smooth', @@ -250,6 +255,7 @@ export interface GraphFieldConfig drawStyle?: GraphDrawStyle; gradientMode?: GraphGradientMode; thresholdsStyle?: GraphThresholdsStyleConfig; + transform?: GraphTransform; } export interface VizLegendOptions { diff --git a/packages/grafana-ui/src/components/OptionsUI/select.tsx b/packages/grafana-ui/src/components/OptionsUI/select.tsx index ac45c393c91..2c3405bbcc0 100644 --- a/packages/grafana-ui/src/components/OptionsUI/select.tsx +++ b/packages/grafana-ui/src/components/OptionsUI/select.tsx @@ -67,7 +67,8 @@ export class SelectValueEditor extends React.PureComponent, State value={current} defaultValue={value} allowCustomValue={settings?.allowCustomValue} - onChange={(e) => onChange(e.value)} + isClearable={settings?.isClearable} + onChange={(e) => onChange(e?.value)} options={options} /> ); diff --git a/public/app/plugins/panel/timeseries/config.ts b/public/app/plugins/panel/timeseries/config.ts index 073784bf461..6e7667d60d1 100644 --- a/public/app/plugins/panel/timeseries/config.ts +++ b/public/app/plugins/panel/timeseries/config.ts @@ -16,6 +16,7 @@ import { VisibilityMode, StackingMode, GraphTresholdsStyleMode, + GraphTransform, } from '@grafana/schema'; import { graphFieldOptions, commonOptionsBuilder } from '@grafana/ui'; @@ -181,6 +182,28 @@ export function getGraphFieldConfig(cfg: GraphFieldConfig): SetFieldConfigOption }); commonOptionsBuilder.addStackingConfig(builder, cfg.stacking, categoryStyles); + + builder.addSelect({ + category: categoryStyles, + name: 'Transform', + path: 'transform', + settings: { + options: [ + { + label: 'Constant', + value: GraphTransform.Constant, + description: 'The first value will be shown as a constant line', + }, + { + label: 'Negative Y', + value: GraphTransform.NegativeY, + description: 'Flip the results to negative values on the y axis', + }, + ], + isClearable: true, + }, + }); + commonOptionsBuilder.addAxisConfig(builder, cfg); commonOptionsBuilder.addHideFrom(builder);