1import { 2 FieldColorModeId, 3 FieldConfigProperty, 4 FieldType, 5 identityOverrideProcessor, 6 SetFieldConfigOptionsArgs, 7} from '@grafana/data'; 8import { LineStyle, VisibilityMode } from '@grafana/schema'; 9 10import { commonOptionsBuilder, graphFieldOptions } from '@grafana/ui'; 11import { LineStyleEditor } from '../timeseries/LineStyleEditor'; 12import { ScatterFieldConfig, ScatterLineMode } from './models.gen'; 13 14const categoryStyles = undefined; // ['Scatter styles']; 15 16export function getScatterFieldConfig(cfg: ScatterFieldConfig): SetFieldConfigOptionsArgs<ScatterFieldConfig> { 17 return { 18 standardOptions: { 19 [FieldConfigProperty.Color]: { 20 settings: { 21 byValueSupport: true, 22 bySeriesSupport: true, 23 preferThresholdsMode: false, 24 }, 25 defaultValue: { 26 mode: FieldColorModeId.PaletteClassic, 27 }, 28 }, 29 }, 30 31 useCustomConfig: (builder) => { 32 builder 33 .addRadio({ 34 path: 'point', 35 name: 'Points', 36 category: categoryStyles, 37 defaultValue: cfg.point, 38 settings: { 39 options: graphFieldOptions.showPoints, 40 }, 41 }) 42 .addSliderInput({ 43 path: 'pointSize.fixed', 44 name: 'Point size', 45 category: categoryStyles, 46 defaultValue: cfg.pointSize?.fixed, 47 settings: { 48 min: 1, 49 max: 100, 50 step: 1, 51 }, 52 showIf: (c) => c.point !== VisibilityMode.Never, 53 }) 54 .addRadio({ 55 path: 'line', 56 name: 'Lines', 57 category: categoryStyles, 58 defaultValue: cfg.line, 59 settings: { 60 options: [ 61 { label: 'None', value: ScatterLineMode.None }, 62 { label: 'Linear', value: ScatterLineMode.Linear }, 63 ], 64 }, 65 }) 66 .addCustomEditor<void, LineStyle>({ 67 id: 'lineStyle', 68 path: 'lineStyle', 69 name: 'Line style', 70 category: categoryStyles, 71 showIf: (c) => c.line !== ScatterLineMode.None, 72 editor: LineStyleEditor, 73 override: LineStyleEditor, 74 process: identityOverrideProcessor, 75 shouldApply: (f) => f.type === FieldType.number, 76 }) 77 .addSliderInput({ 78 path: 'lineWidth', 79 name: 'Line width', 80 category: categoryStyles, 81 defaultValue: cfg.lineWidth, 82 settings: { 83 min: 0, 84 max: 10, 85 step: 1, 86 }, 87 showIf: (c) => c.line !== ScatterLineMode.None, 88 }); 89 90 commonOptionsBuilder.addAxisConfig(builder, cfg); 91 commonOptionsBuilder.addHideFrom(builder); 92 }, 93 }; 94} 95