grafana/public/app/plugins/panel/xychart/config.ts
Oscar Kilhed f3aa058886
XY Panel: Add and use schema for XY Panel configuration (#62148)
* Add schema for XYChart

* Minor cleanup

* remove unessecary fields from ScatterFieldConfigVeneer, and cleaning up more

* Fix counts

Co-authored-by: sam boyer <sdboyer@grafana.com>
2023-01-25 22:29:07 +00:00

82 lines
2.2 KiB
TypeScript

import {
FieldColorModeId,
FieldConfigProperty,
FieldType,
identityOverrideProcessor,
SetFieldConfigOptionsArgs,
} from '@grafana/data';
import { LineStyle } from '@grafana/schema';
import { commonOptionsBuilder } from '@grafana/ui';
import { LineStyleEditor } from '../timeseries/LineStyleEditor';
import { ScatterFieldConfig, ScatterShow } from './types';
export function getScatterFieldConfig(cfg: ScatterFieldConfig): SetFieldConfigOptionsArgs<ScatterFieldConfig> {
return {
standardOptions: {
[FieldConfigProperty.Color]: {
settings: {
byValueSupport: true,
bySeriesSupport: true,
preferThresholdsMode: false,
},
defaultValue: {
mode: FieldColorModeId.PaletteClassic,
},
},
},
useCustomConfig: (builder) => {
builder
.addRadio({
path: 'show',
name: 'Show',
defaultValue: cfg.show,
settings: {
options: [
{ label: 'Points', value: ScatterShow.Points },
{ label: 'Lines', value: ScatterShow.Lines },
{ label: 'Both', value: ScatterShow.PointsAndLines },
],
},
})
.addSliderInput({
path: 'pointSize.fixed',
name: 'Point size',
defaultValue: cfg.pointSize?.fixed,
settings: {
min: 1,
max: 100,
step: 1,
},
showIf: (c) => c.show !== ScatterShow.Lines,
})
.addCustomEditor<void, LineStyle>({
id: 'lineStyle',
path: 'lineStyle',
name: 'Line style',
showIf: (c) => c.show !== ScatterShow.Points,
editor: LineStyleEditor,
override: LineStyleEditor,
process: identityOverrideProcessor,
shouldApply: (f) => f.type === FieldType.number,
})
.addSliderInput({
path: 'lineWidth',
name: 'Line width',
defaultValue: cfg.lineWidth,
settings: {
min: 0,
max: 10,
step: 1,
},
showIf: (c) => c.show !== ScatterShow.Points,
});
commonOptionsBuilder.addAxisConfig(builder, cfg);
commonOptionsBuilder.addHideFrom(builder);
},
};
}