mirror of
https://github.com/grafana/grafana.git
synced 2026-08-18 00:54:58 -05:00
grafana/u: Move stacking config to common options builder (#34106)
* Move stacking config to options builder * Extract stacking interface
This commit is contained in:
@@ -193,6 +193,13 @@ export interface StackingConfig {
|
|||||||
group?: string;
|
group?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @alpha
|
||||||
|
*/
|
||||||
|
export interface StackableFieldConfig {
|
||||||
|
stacking?: StackingConfig;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @alpha
|
* @alpha
|
||||||
*/
|
*/
|
||||||
@@ -220,10 +227,10 @@ export interface GraphFieldConfig
|
|||||||
PointsConfig,
|
PointsConfig,
|
||||||
AxisConfig,
|
AxisConfig,
|
||||||
BarConfig,
|
BarConfig,
|
||||||
|
StackableFieldConfig,
|
||||||
HideableFieldConfig {
|
HideableFieldConfig {
|
||||||
drawStyle?: DrawStyle;
|
drawStyle?: DrawStyle;
|
||||||
gradientMode?: GraphGradientMode;
|
gradientMode?: GraphGradientMode;
|
||||||
stacking?: StackingConfig;
|
|
||||||
thresholdsStyle?: GraphThresholdsStyleConfig;
|
thresholdsStyle?: GraphThresholdsStyleConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ export * from './axis';
|
|||||||
export * from './hideSeries';
|
export * from './hideSeries';
|
||||||
export * from './legend';
|
export * from './legend';
|
||||||
export * from './tooltip';
|
export * from './tooltip';
|
||||||
|
export * from './stacking';
|
||||||
|
|||||||
+30
-3
@@ -1,6 +1,12 @@
|
|||||||
import React from 'react';
|
|
||||||
import { FieldOverrideEditorProps } from '@grafana/data';
|
|
||||||
import {
|
import {
|
||||||
|
FieldConfigEditorBuilder,
|
||||||
|
FieldOverrideEditorProps,
|
||||||
|
FieldType,
|
||||||
|
identityOverrideProcessor,
|
||||||
|
} from '@grafana/data';
|
||||||
|
import React from 'react';
|
||||||
|
import {
|
||||||
|
graphFieldOptions,
|
||||||
HorizontalGroup,
|
HorizontalGroup,
|
||||||
IconButton,
|
IconButton,
|
||||||
Input,
|
Input,
|
||||||
@@ -8,7 +14,7 @@ import {
|
|||||||
StackingConfig,
|
StackingConfig,
|
||||||
StackingMode,
|
StackingMode,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
} from '@grafana/ui';
|
} from '../..';
|
||||||
|
|
||||||
export const StackingEditor: React.FC<FieldOverrideEditorProps<StackingConfig, any>> = ({
|
export const StackingEditor: React.FC<FieldOverrideEditorProps<StackingConfig, any>> = ({
|
||||||
value,
|
value,
|
||||||
@@ -49,3 +55,24 @@ export const StackingEditor: React.FC<FieldOverrideEditorProps<StackingConfig, a
|
|||||||
</HorizontalGroup>
|
</HorizontalGroup>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function addStackingConfig(
|
||||||
|
builder: FieldConfigEditorBuilder<{ stacking: StackingConfig }>,
|
||||||
|
defaultConfig?: StackingConfig,
|
||||||
|
category = ['Graph styles']
|
||||||
|
) {
|
||||||
|
builder.addCustomEditor({
|
||||||
|
id: 'stacking',
|
||||||
|
path: 'stacking',
|
||||||
|
name: 'Stack series',
|
||||||
|
category: category,
|
||||||
|
defaultValue: defaultConfig,
|
||||||
|
editor: StackingEditor,
|
||||||
|
override: StackingEditor,
|
||||||
|
settings: {
|
||||||
|
options: graphFieldOptions.stacking,
|
||||||
|
},
|
||||||
|
process: identityOverrideProcessor,
|
||||||
|
shouldApply: (f) => f.type === FieldType.number,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
FieldColorModeId,
|
FieldColorModeId,
|
||||||
FieldConfigEditorBuilder,
|
|
||||||
FieldConfigProperty,
|
FieldConfigProperty,
|
||||||
FieldType,
|
FieldType,
|
||||||
identityOverrideProcessor,
|
identityOverrideProcessor,
|
||||||
@@ -16,14 +15,12 @@ import {
|
|||||||
LineInterpolation,
|
LineInterpolation,
|
||||||
LineStyle,
|
LineStyle,
|
||||||
PointVisibility,
|
PointVisibility,
|
||||||
StackingConfig,
|
|
||||||
StackingMode,
|
StackingMode,
|
||||||
commonOptionsBuilder,
|
commonOptionsBuilder,
|
||||||
} from '@grafana/ui';
|
} from '@grafana/ui';
|
||||||
import { LineStyleEditor } from './LineStyleEditor';
|
import { LineStyleEditor } from './LineStyleEditor';
|
||||||
import { FillBellowToEditor } from './FillBelowToEditor';
|
import { FillBellowToEditor } from './FillBelowToEditor';
|
||||||
import { SpanNullsEditor } from './SpanNullsEditor';
|
import { SpanNullsEditor } from './SpanNullsEditor';
|
||||||
import { StackingEditor } from './StackingEditor';
|
|
||||||
|
|
||||||
export const defaultGraphConfig: GraphFieldConfig = {
|
export const defaultGraphConfig: GraphFieldConfig = {
|
||||||
drawStyle: DrawStyle.Line,
|
drawStyle: DrawStyle.Line,
|
||||||
@@ -176,7 +173,7 @@ export function getGraphFieldConfig(cfg: GraphFieldConfig): SetFieldConfigOption
|
|||||||
showIf: (c) => c.showPoints !== PointVisibility.Never || c.drawStyle === DrawStyle.Points,
|
showIf: (c) => c.showPoints !== PointVisibility.Never || c.drawStyle === DrawStyle.Points,
|
||||||
});
|
});
|
||||||
|
|
||||||
addStackingConfig(builder, cfg.stacking);
|
commonOptionsBuilder.addStackingConfig(builder, cfg.stacking, categoryStyles);
|
||||||
commonOptionsBuilder.addAxisConfig(builder, cfg);
|
commonOptionsBuilder.addAxisConfig(builder, cfg);
|
||||||
commonOptionsBuilder.addHideFrom(builder);
|
commonOptionsBuilder.addHideFrom(builder);
|
||||||
|
|
||||||
@@ -192,23 +189,3 @@ export function getGraphFieldConfig(cfg: GraphFieldConfig): SetFieldConfigOption
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addStackingConfig(
|
|
||||||
builder: FieldConfigEditorBuilder<{ stacking: StackingConfig }>,
|
|
||||||
defaultConfig?: StackingConfig
|
|
||||||
) {
|
|
||||||
builder.addCustomEditor({
|
|
||||||
id: 'stacking',
|
|
||||||
path: 'stacking',
|
|
||||||
name: 'Stack series',
|
|
||||||
category: categoryStyles,
|
|
||||||
defaultValue: defaultConfig,
|
|
||||||
editor: StackingEditor,
|
|
||||||
override: StackingEditor,
|
|
||||||
settings: {
|
|
||||||
options: graphFieldOptions.stacking,
|
|
||||||
},
|
|
||||||
process: identityOverrideProcessor,
|
|
||||||
shouldApply: (f) => f.type === FieldType.number,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user