module.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {
  2. FieldColorModeId,
  3. FieldConfigProperty,
  4. FieldType,
  5. identityOverrideProcessor,
  6. PanelPlugin,
  7. } from '@grafana/data';
  8. import { VisibilityMode } from '@grafana/schema';
  9. import { commonOptionsBuilder } from '@grafana/ui';
  10. import { SpanNullsEditor } from '../timeseries/SpanNullsEditor';
  11. import { StateTimelinePanel } from './StateTimelinePanel';
  12. import { timelinePanelChangedHandler } from './migrations';
  13. import { StatTimelineSuggestionsSupplier } from './suggestions';
  14. import { TimelineOptions, TimelineFieldConfig, defaultPanelOptions, defaultTimelineFieldConfig } from './types';
  15. export const plugin = new PanelPlugin<TimelineOptions, TimelineFieldConfig>(StateTimelinePanel)
  16. .setPanelChangeHandler(timelinePanelChangedHandler)
  17. .useFieldConfig({
  18. standardOptions: {
  19. [FieldConfigProperty.Color]: {
  20. settings: {
  21. byValueSupport: true,
  22. },
  23. defaultValue: {
  24. mode: FieldColorModeId.ContinuousGrYlRd,
  25. },
  26. },
  27. },
  28. useCustomConfig: (builder) => {
  29. builder
  30. .addSliderInput({
  31. path: 'lineWidth',
  32. name: 'Line width',
  33. defaultValue: defaultTimelineFieldConfig.lineWidth,
  34. settings: {
  35. min: 0,
  36. max: 10,
  37. step: 1,
  38. },
  39. })
  40. .addSliderInput({
  41. path: 'fillOpacity',
  42. name: 'Fill opacity',
  43. defaultValue: defaultTimelineFieldConfig.fillOpacity,
  44. settings: {
  45. min: 0,
  46. max: 100,
  47. step: 1,
  48. },
  49. })
  50. .addCustomEditor<void, boolean>({
  51. id: 'spanNulls',
  52. path: 'spanNulls',
  53. name: 'Connect null values',
  54. defaultValue: false,
  55. editor: SpanNullsEditor,
  56. override: SpanNullsEditor,
  57. shouldApply: (f) => f.type !== FieldType.time,
  58. process: identityOverrideProcessor,
  59. });
  60. },
  61. })
  62. .setPanelOptions((builder) => {
  63. builder
  64. .addBooleanSwitch({
  65. path: 'mergeValues',
  66. name: 'Merge equal consecutive values',
  67. defaultValue: defaultPanelOptions.mergeValues,
  68. })
  69. .addRadio({
  70. path: 'showValue',
  71. name: 'Show values',
  72. settings: {
  73. options: [
  74. { value: VisibilityMode.Auto, label: 'Auto' },
  75. { value: VisibilityMode.Always, label: 'Always' },
  76. { value: VisibilityMode.Never, label: 'Never' },
  77. ],
  78. },
  79. defaultValue: defaultPanelOptions.showValue,
  80. })
  81. .addRadio({
  82. path: 'alignValue',
  83. name: 'Align values',
  84. settings: {
  85. options: [
  86. { value: 'left', label: 'Left' },
  87. { value: 'center', label: 'Center' },
  88. { value: 'right', label: 'Right' },
  89. ],
  90. },
  91. defaultValue: defaultPanelOptions.alignValue,
  92. })
  93. .addSliderInput({
  94. path: 'rowHeight',
  95. name: 'Row height',
  96. settings: {
  97. min: 0,
  98. max: 1,
  99. step: 0.01,
  100. },
  101. defaultValue: defaultPanelOptions.rowHeight,
  102. });
  103. commonOptionsBuilder.addLegendOptions(builder, false);
  104. commonOptionsBuilder.addTooltipOptions(builder, true);
  105. })
  106. .setSuggestionsSupplier(new StatTimelineSuggestionsSupplier());