2021-01-15 13:03:41 -06:00
|
|
|
import {
|
|
|
|
FieldColorModeId,
|
2021-01-29 14:52:52 -06:00
|
|
|
FieldConfigEditorBuilder,
|
2021-01-15 13:03:41 -06:00
|
|
|
FieldConfigProperty,
|
|
|
|
FieldType,
|
|
|
|
identityOverrideProcessor,
|
2021-01-22 15:25:39 -06:00
|
|
|
PanelOptionsEditorBuilder,
|
2021-01-18 12:48:45 -06:00
|
|
|
SetFieldConfigOptionsArgs,
|
2021-01-22 15:25:39 -06:00
|
|
|
standardEditorsRegistry,
|
|
|
|
StatsPickerConfigSettings,
|
2021-01-15 13:03:41 -06:00
|
|
|
stringOverrideProcessor,
|
|
|
|
} from '@grafana/data';
|
2021-01-11 00:57:48 -06:00
|
|
|
import {
|
|
|
|
AxisPlacement,
|
2021-02-01 07:54:10 -06:00
|
|
|
BarAlignment,
|
2021-01-11 00:57:48 -06:00
|
|
|
DrawStyle,
|
|
|
|
GraphFieldConfig,
|
|
|
|
graphFieldOptions,
|
|
|
|
LineInterpolation,
|
|
|
|
LineStyle,
|
|
|
|
PointVisibility,
|
|
|
|
ScaleDistribution,
|
|
|
|
ScaleDistributionConfig,
|
2021-01-18 12:48:45 -06:00
|
|
|
GraphGradientMode,
|
2021-01-22 15:25:39 -06:00
|
|
|
LegendDisplayMode,
|
2021-01-29 14:52:52 -06:00
|
|
|
AxisConfig,
|
2021-01-11 00:57:48 -06:00
|
|
|
} from '@grafana/ui';
|
|
|
|
import { SeriesConfigEditor } from './HideSeriesConfigEditor';
|
|
|
|
import { ScaleDistributionEditor } from './ScaleDistributionEditor';
|
|
|
|
import { LineStyleEditor } from './LineStyleEditor';
|
2021-01-15 13:03:41 -06:00
|
|
|
import { FillBellowToEditor } from './FillBelowToEditor';
|
2021-01-22 15:25:39 -06:00
|
|
|
import { OptionsWithLegend } from './types';
|
2021-03-24 23:32:03 -05:00
|
|
|
import { SpanNullsEditor } from './SpanNullsEditor';
|
2021-01-11 00:57:48 -06:00
|
|
|
|
|
|
|
export const defaultGraphConfig: GraphFieldConfig = {
|
|
|
|
drawStyle: DrawStyle.Line,
|
|
|
|
lineInterpolation: LineInterpolation.Linear,
|
|
|
|
lineWidth: 1,
|
|
|
|
fillOpacity: 0,
|
2021-01-18 12:48:45 -06:00
|
|
|
gradientMode: GraphGradientMode.None,
|
2021-02-01 07:54:10 -06:00
|
|
|
barAlignment: BarAlignment.Center,
|
2021-01-11 00:57:48 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
export function getGraphFieldConfig(cfg: GraphFieldConfig): SetFieldConfigOptionsArgs<GraphFieldConfig> {
|
|
|
|
return {
|
|
|
|
standardOptions: {
|
|
|
|
[FieldConfigProperty.Color]: {
|
|
|
|
settings: {
|
|
|
|
byValueSupport: false,
|
2021-01-18 12:48:45 -06:00
|
|
|
bySeriesSupport: true,
|
|
|
|
preferThresholdsMode: false,
|
2021-01-11 00:57:48 -06:00
|
|
|
},
|
|
|
|
defaultValue: {
|
|
|
|
mode: FieldColorModeId.PaletteClassic,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-01-20 00:59:48 -06:00
|
|
|
useCustomConfig: (builder) => {
|
2021-01-11 00:57:48 -06:00
|
|
|
builder
|
|
|
|
.addRadio({
|
|
|
|
path: 'drawStyle',
|
|
|
|
name: 'Style',
|
|
|
|
defaultValue: cfg.drawStyle,
|
|
|
|
settings: {
|
|
|
|
options: graphFieldOptions.drawStyle,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.addRadio({
|
|
|
|
path: 'lineInterpolation',
|
|
|
|
name: 'Line interpolation',
|
|
|
|
defaultValue: cfg.lineInterpolation,
|
|
|
|
settings: {
|
|
|
|
options: graphFieldOptions.lineInterpolation,
|
|
|
|
},
|
2021-01-20 00:59:48 -06:00
|
|
|
showIf: (c) => c.drawStyle === DrawStyle.Line,
|
2021-01-11 00:57:48 -06:00
|
|
|
})
|
2021-02-01 07:54:10 -06:00
|
|
|
.addRadio({
|
|
|
|
path: 'barAlignment',
|
|
|
|
name: 'Bar alignment',
|
|
|
|
defaultValue: cfg.barAlignment,
|
|
|
|
settings: {
|
|
|
|
options: graphFieldOptions.barAlignment,
|
|
|
|
},
|
|
|
|
showIf: (c) => c.drawStyle === DrawStyle.Bars,
|
|
|
|
})
|
2021-01-11 00:57:48 -06:00
|
|
|
.addSliderInput({
|
|
|
|
path: 'lineWidth',
|
|
|
|
name: 'Line width',
|
|
|
|
defaultValue: cfg.lineWidth,
|
|
|
|
settings: {
|
|
|
|
min: 0,
|
|
|
|
max: 10,
|
|
|
|
step: 1,
|
|
|
|
},
|
2021-01-20 00:59:48 -06:00
|
|
|
showIf: (c) => c.drawStyle !== DrawStyle.Points,
|
2021-01-11 00:57:48 -06:00
|
|
|
})
|
|
|
|
.addSliderInput({
|
|
|
|
path: 'fillOpacity',
|
|
|
|
name: 'Fill opacity',
|
|
|
|
defaultValue: cfg.fillOpacity,
|
|
|
|
settings: {
|
|
|
|
min: 0,
|
|
|
|
max: 100,
|
|
|
|
step: 1,
|
|
|
|
},
|
2021-01-20 00:59:48 -06:00
|
|
|
showIf: (c) => c.drawStyle !== DrawStyle.Points,
|
2021-01-11 00:57:48 -06:00
|
|
|
})
|
|
|
|
.addRadio({
|
2021-01-18 12:48:45 -06:00
|
|
|
path: 'gradientMode',
|
|
|
|
name: 'Gradient mode',
|
2021-01-21 05:51:12 -06:00
|
|
|
defaultValue: graphFieldOptions.fillGradient[0].value,
|
2021-01-11 00:57:48 -06:00
|
|
|
settings: {
|
|
|
|
options: graphFieldOptions.fillGradient,
|
|
|
|
},
|
2021-01-20 00:59:48 -06:00
|
|
|
showIf: (c) => c.drawStyle !== DrawStyle.Points,
|
2021-01-11 00:57:48 -06:00
|
|
|
})
|
2021-01-15 13:03:41 -06:00
|
|
|
.addCustomEditor({
|
|
|
|
id: 'fillBelowTo',
|
|
|
|
path: 'fillBelowTo',
|
|
|
|
name: 'Fill below to',
|
|
|
|
editor: FillBellowToEditor,
|
|
|
|
override: FillBellowToEditor,
|
|
|
|
process: stringOverrideProcessor,
|
|
|
|
hideFromDefaults: true,
|
2021-01-20 00:59:48 -06:00
|
|
|
shouldApply: (f) => true,
|
2021-01-15 13:03:41 -06:00
|
|
|
})
|
2021-01-11 00:57:48 -06:00
|
|
|
.addCustomEditor<void, LineStyle>({
|
|
|
|
id: 'lineStyle',
|
|
|
|
path: 'lineStyle',
|
|
|
|
name: 'Line style',
|
2021-01-20 00:59:48 -06:00
|
|
|
showIf: (c) => c.drawStyle === DrawStyle.Line,
|
2021-01-11 00:57:48 -06:00
|
|
|
editor: LineStyleEditor,
|
|
|
|
override: LineStyleEditor,
|
|
|
|
process: identityOverrideProcessor,
|
2021-01-20 00:59:48 -06:00
|
|
|
shouldApply: (f) => f.type === FieldType.number,
|
2021-01-11 00:57:48 -06:00
|
|
|
})
|
2021-03-24 23:32:03 -05:00
|
|
|
.addCustomEditor<void, boolean>({
|
|
|
|
id: 'spanNulls',
|
2021-01-11 00:57:48 -06:00
|
|
|
path: 'spanNulls',
|
2021-03-24 23:32:03 -05:00
|
|
|
name: 'Connect null values',
|
2021-01-11 00:57:48 -06:00
|
|
|
defaultValue: false,
|
2021-03-24 23:32:03 -05:00
|
|
|
editor: SpanNullsEditor,
|
|
|
|
override: SpanNullsEditor,
|
2021-01-20 00:59:48 -06:00
|
|
|
showIf: (c) => c.drawStyle === DrawStyle.Line,
|
2021-03-24 23:32:03 -05:00
|
|
|
shouldApply: (f) => f.type !== FieldType.time,
|
|
|
|
process: identityOverrideProcessor,
|
2021-01-11 00:57:48 -06:00
|
|
|
})
|
|
|
|
.addRadio({
|
|
|
|
path: 'showPoints',
|
|
|
|
name: 'Show points',
|
|
|
|
defaultValue: graphFieldOptions.showPoints[0].value,
|
|
|
|
settings: {
|
|
|
|
options: graphFieldOptions.showPoints,
|
|
|
|
},
|
2021-01-20 00:59:48 -06:00
|
|
|
showIf: (c) => c.drawStyle !== DrawStyle.Points,
|
2021-01-11 00:57:48 -06:00
|
|
|
})
|
|
|
|
.addSliderInput({
|
|
|
|
path: 'pointSize',
|
|
|
|
name: 'Point size',
|
|
|
|
defaultValue: 5,
|
|
|
|
settings: {
|
|
|
|
min: 1,
|
|
|
|
max: 40,
|
|
|
|
step: 1,
|
|
|
|
},
|
2021-01-20 00:59:48 -06:00
|
|
|
showIf: (c) => c.showPoints !== PointVisibility.Never || c.drawStyle === DrawStyle.Points,
|
2021-01-11 00:57:48 -06:00
|
|
|
});
|
2021-01-29 14:52:52 -06:00
|
|
|
|
|
|
|
addAxisConfig(builder, cfg);
|
|
|
|
addHideFrom(builder);
|
2021-01-11 00:57:48 -06:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2021-01-22 15:25:39 -06:00
|
|
|
|
2021-01-29 14:52:52 -06:00
|
|
|
export function addHideFrom(builder: FieldConfigEditorBuilder<AxisConfig>) {
|
|
|
|
builder.addCustomEditor({
|
|
|
|
id: 'hideFrom',
|
|
|
|
name: 'Hide in area',
|
|
|
|
category: ['Series'],
|
|
|
|
path: 'hideFrom',
|
|
|
|
defaultValue: {
|
|
|
|
tooltip: false,
|
|
|
|
graph: false,
|
|
|
|
legend: false,
|
|
|
|
},
|
|
|
|
editor: SeriesConfigEditor,
|
|
|
|
override: SeriesConfigEditor,
|
|
|
|
shouldApply: () => true,
|
|
|
|
hideFromDefaults: true,
|
|
|
|
hideFromOverrides: true,
|
|
|
|
process: (value) => value,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function addAxisConfig(
|
|
|
|
builder: FieldConfigEditorBuilder<AxisConfig>,
|
|
|
|
defaultConfig: AxisConfig,
|
|
|
|
hideScale?: boolean
|
|
|
|
) {
|
|
|
|
builder
|
|
|
|
.addRadio({
|
|
|
|
path: 'axisPlacement',
|
|
|
|
name: 'Placement',
|
|
|
|
category: ['Axis'],
|
|
|
|
defaultValue: graphFieldOptions.axisPlacement[0].value,
|
|
|
|
settings: {
|
|
|
|
options: graphFieldOptions.axisPlacement,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.addTextInput({
|
|
|
|
path: 'axisLabel',
|
|
|
|
name: 'Label',
|
|
|
|
category: ['Axis'],
|
|
|
|
defaultValue: '',
|
|
|
|
settings: {
|
|
|
|
placeholder: 'Optional text',
|
|
|
|
},
|
|
|
|
showIf: (c) => c.axisPlacement !== AxisPlacement.Hidden,
|
|
|
|
// no matter what the field type is
|
|
|
|
shouldApply: () => true,
|
|
|
|
})
|
|
|
|
.addNumberInput({
|
|
|
|
path: 'axisWidth',
|
|
|
|
name: 'Width',
|
|
|
|
category: ['Axis'],
|
|
|
|
settings: {
|
|
|
|
placeholder: 'Auto',
|
|
|
|
},
|
|
|
|
showIf: (c) => c.axisPlacement !== AxisPlacement.Hidden,
|
|
|
|
})
|
|
|
|
.addNumberInput({
|
|
|
|
path: 'axisSoftMin',
|
|
|
|
name: 'Soft min',
|
|
|
|
defaultValue: defaultConfig.axisSoftMin,
|
|
|
|
category: ['Axis'],
|
|
|
|
settings: {
|
|
|
|
placeholder: 'See: Standard options > Min',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.addNumberInput({
|
|
|
|
path: 'axisSoftMax',
|
|
|
|
name: 'Soft max',
|
|
|
|
defaultValue: defaultConfig.axisSoftMax,
|
|
|
|
category: ['Axis'],
|
|
|
|
settings: {
|
|
|
|
placeholder: 'See: Standard options > Max',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
if (!hideScale) {
|
|
|
|
builder.addCustomEditor<void, ScaleDistributionConfig>({
|
|
|
|
id: 'scaleDistribution',
|
|
|
|
path: 'scaleDistribution',
|
|
|
|
name: 'Scale',
|
|
|
|
category: ['Axis'],
|
|
|
|
editor: ScaleDistributionEditor,
|
|
|
|
override: ScaleDistributionEditor,
|
|
|
|
defaultValue: { type: ScaleDistribution.Linear },
|
|
|
|
shouldApply: (f) => f.type === FieldType.number,
|
|
|
|
process: identityOverrideProcessor,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-22 03:06:07 -06:00
|
|
|
export function addLegendOptions<T extends OptionsWithLegend>(builder: PanelOptionsEditorBuilder<T>) {
|
2021-01-22 15:25:39 -06:00
|
|
|
builder
|
|
|
|
.addRadio({
|
|
|
|
path: 'legend.displayMode',
|
|
|
|
name: 'Legend mode',
|
|
|
|
description: '',
|
|
|
|
defaultValue: LegendDisplayMode.List,
|
|
|
|
settings: {
|
|
|
|
options: [
|
|
|
|
{ value: LegendDisplayMode.List, label: 'List' },
|
|
|
|
{ value: LegendDisplayMode.Table, label: 'Table' },
|
|
|
|
{ value: LegendDisplayMode.Hidden, label: 'Hidden' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.addRadio({
|
|
|
|
path: 'legend.placement',
|
|
|
|
name: 'Legend placement',
|
|
|
|
description: '',
|
|
|
|
defaultValue: 'bottom',
|
|
|
|
settings: {
|
|
|
|
options: [
|
|
|
|
{ value: 'bottom', label: 'Bottom' },
|
|
|
|
{ value: 'right', label: 'Right' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
showIf: (c) => c.legend.displayMode !== LegendDisplayMode.Hidden,
|
|
|
|
})
|
|
|
|
.addCustomEditor<StatsPickerConfigSettings, string[]>({
|
|
|
|
id: 'legend.calcs',
|
|
|
|
path: 'legend.calcs',
|
|
|
|
name: 'Legend calculations',
|
|
|
|
description: 'Choose a reducer functions / calculations to include in legend',
|
|
|
|
editor: standardEditorsRegistry.get('stats-picker').editor as any,
|
|
|
|
defaultValue: [],
|
|
|
|
settings: {
|
|
|
|
allowMultiple: true,
|
|
|
|
},
|
|
|
|
showIf: (currentConfig) => currentConfig.legend.displayMode !== LegendDisplayMode.Hidden,
|
|
|
|
});
|
|
|
|
}
|