config.ts 2.7 KB

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