123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- import {
- FieldColorModeId,
- FieldConfigProperty,
- FieldType,
- identityOverrideProcessor,
- SetFieldConfigOptionsArgs,
- stringOverrideProcessor,
- } from '@grafana/data';
- import {
- BarAlignment,
- GraphDrawStyle,
- GraphFieldConfig,
- GraphGradientMode,
- LineInterpolation,
- LineStyle,
- VisibilityMode,
- StackingMode,
- GraphTresholdsStyleMode,
- GraphTransform,
- } from '@grafana/schema';
- import { graphFieldOptions, commonOptionsBuilder } from '@grafana/ui';
- import { FillBellowToEditor } from './FillBelowToEditor';
- import { LineStyleEditor } from './LineStyleEditor';
- import { SpanNullsEditor } from './SpanNullsEditor';
- import { ThresholdsStyleEditor } from './ThresholdsStyleEditor';
- export const defaultGraphConfig: GraphFieldConfig = {
- drawStyle: GraphDrawStyle.Line,
- lineInterpolation: LineInterpolation.Linear,
- lineWidth: 1,
- fillOpacity: 0,
- gradientMode: GraphGradientMode.None,
- barAlignment: BarAlignment.Center,
- stacking: {
- mode: StackingMode.None,
- group: 'A',
- },
- axisGridShow: true,
- };
- const categoryStyles = ['Graph styles'];
- export function getGraphFieldConfig(cfg: GraphFieldConfig): SetFieldConfigOptionsArgs<GraphFieldConfig> {
- return {
- standardOptions: {
- [FieldConfigProperty.Color]: {
- settings: {
- byValueSupport: true,
- bySeriesSupport: true,
- preferThresholdsMode: false,
- },
- defaultValue: {
- mode: FieldColorModeId.PaletteClassic,
- },
- },
- },
- useCustomConfig: (builder) => {
- builder
- .addRadio({
- path: 'drawStyle',
- name: 'Style',
- category: categoryStyles,
- defaultValue: cfg.drawStyle,
- settings: {
- options: graphFieldOptions.drawStyle,
- },
- })
- .addRadio({
- path: 'lineInterpolation',
- name: 'Line interpolation',
- category: categoryStyles,
- defaultValue: cfg.lineInterpolation,
- settings: {
- options: graphFieldOptions.lineInterpolation,
- },
- showIf: (c) => c.drawStyle === GraphDrawStyle.Line,
- })
- .addRadio({
- path: 'barAlignment',
- name: 'Bar alignment',
- category: categoryStyles,
- defaultValue: cfg.barAlignment,
- settings: {
- options: graphFieldOptions.barAlignment,
- },
- showIf: (c) => c.drawStyle === GraphDrawStyle.Bars,
- })
- .addSliderInput({
- path: 'lineWidth',
- name: 'Line width',
- category: categoryStyles,
- defaultValue: cfg.lineWidth,
- settings: {
- min: 0,
- max: 10,
- step: 1,
- ariaLabelForHandle: 'Line width',
- },
- showIf: (c) => c.drawStyle !== GraphDrawStyle.Points,
- })
- .addSliderInput({
- path: 'fillOpacity',
- name: 'Fill opacity',
- category: categoryStyles,
- defaultValue: cfg.fillOpacity,
- settings: {
- min: 0,
- max: 100,
- step: 1,
- ariaLabelForHandle: 'Fill opacity',
- },
- showIf: (c) => c.drawStyle !== GraphDrawStyle.Points,
- })
- .addRadio({
- path: 'gradientMode',
- name: 'Gradient mode',
- category: categoryStyles,
- defaultValue: graphFieldOptions.fillGradient[0].value,
- settings: {
- options: graphFieldOptions.fillGradient,
- },
- showIf: (c) => c.drawStyle !== GraphDrawStyle.Points,
- })
- .addCustomEditor({
- id: 'fillBelowTo',
- path: 'fillBelowTo',
- name: 'Fill below to',
- category: categoryStyles,
- editor: FillBellowToEditor,
- override: FillBellowToEditor,
- process: stringOverrideProcessor,
- hideFromDefaults: true,
- shouldApply: (f) => true,
- })
- .addCustomEditor<void, LineStyle>({
- id: 'lineStyle',
- path: 'lineStyle',
- name: 'Line style',
- category: categoryStyles,
- showIf: (c) => c.drawStyle === GraphDrawStyle.Line,
- editor: LineStyleEditor,
- override: LineStyleEditor,
- process: identityOverrideProcessor,
- shouldApply: (f) => f.type === FieldType.number,
- })
- .addCustomEditor<void, boolean>({
- id: 'spanNulls',
- path: 'spanNulls',
- name: 'Connect null values',
- category: categoryStyles,
- defaultValue: false,
- editor: SpanNullsEditor,
- override: SpanNullsEditor,
- showIf: (c) => c.drawStyle === GraphDrawStyle.Line,
- shouldApply: (f) => f.type !== FieldType.time,
- process: identityOverrideProcessor,
- })
- .addRadio({
- path: 'showPoints',
- name: 'Show points',
- category: categoryStyles,
- defaultValue: graphFieldOptions.showPoints[0].value,
- settings: {
- options: graphFieldOptions.showPoints,
- },
- showIf: (c) => c.drawStyle !== GraphDrawStyle.Points,
- })
- .addSliderInput({
- path: 'pointSize',
- name: 'Point size',
- category: categoryStyles,
- defaultValue: 5,
- settings: {
- min: 1,
- max: 40,
- step: 1,
- ariaLabelForHandle: 'Point size',
- },
- showIf: (c) => c.showPoints !== VisibilityMode.Never || c.drawStyle === GraphDrawStyle.Points,
- });
- 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,
- },
- hideFromDefaults: true,
- });
- commonOptionsBuilder.addAxisConfig(builder, cfg);
- commonOptionsBuilder.addHideFrom(builder);
- builder.addCustomEditor({
- id: 'thresholdsStyle',
- path: 'thresholdsStyle',
- name: 'Show thresholds',
- category: ['Thresholds'],
- defaultValue: { mode: GraphTresholdsStyleMode.Off },
- settings: {
- options: graphFieldOptions.thresholdsDisplayModes,
- },
- editor: ThresholdsStyleEditor,
- override: ThresholdsStyleEditor,
- process: identityOverrideProcessor,
- shouldApply: () => true,
- });
- },
- };
- }
|