module.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { FieldColorModeId, FieldConfigProperty, PanelPlugin } from '@grafana/data';
  2. import { histogramFieldInfo } from '@grafana/data/src/transformations/transformers/histogram';
  3. import { commonOptionsBuilder, graphFieldOptions } from '@grafana/ui';
  4. import { HistogramPanel } from './HistogramPanel';
  5. import { PanelFieldConfig, PanelOptions, defaultPanelFieldConfig, defaultPanelOptions } from './models.gen';
  6. import { originalDataHasHistogram } from './utils';
  7. export const plugin = new PanelPlugin<PanelOptions, PanelFieldConfig>(HistogramPanel)
  8. .setPanelOptions((builder) => {
  9. builder
  10. .addCustomEditor({
  11. id: '__calc__',
  12. path: '__calc__',
  13. name: 'Values',
  14. description: 'Showing frequencies that are calculated in the query',
  15. editor: () => null, // empty editor
  16. showIf: (opts, data) => originalDataHasHistogram(data),
  17. })
  18. .addNumberInput({
  19. path: 'bucketSize',
  20. name: histogramFieldInfo.bucketSize.name,
  21. description: histogramFieldInfo.bucketSize.description,
  22. settings: {
  23. placeholder: 'Auto',
  24. min: 0,
  25. },
  26. defaultValue: defaultPanelOptions.bucketSize,
  27. showIf: (opts, data) => !originalDataHasHistogram(data),
  28. })
  29. .addNumberInput({
  30. path: 'bucketOffset',
  31. name: histogramFieldInfo.bucketOffset.name,
  32. description: histogramFieldInfo.bucketOffset.description,
  33. settings: {
  34. placeholder: '0',
  35. min: 0,
  36. },
  37. defaultValue: defaultPanelOptions.bucketOffset,
  38. showIf: (opts, data) => !originalDataHasHistogram(data),
  39. })
  40. .addBooleanSwitch({
  41. path: 'combine',
  42. name: histogramFieldInfo.combine.name,
  43. description: histogramFieldInfo.combine.description,
  44. defaultValue: defaultPanelOptions.combine,
  45. showIf: (opts, data) => !originalDataHasHistogram(data),
  46. });
  47. // commonOptionsBuilder.addTooltipOptions(builder);
  48. commonOptionsBuilder.addLegendOptions(builder);
  49. })
  50. .useFieldConfig({
  51. standardOptions: {
  52. [FieldConfigProperty.Color]: {
  53. settings: {
  54. byValueSupport: true,
  55. },
  56. defaultValue: {
  57. mode: FieldColorModeId.PaletteClassic,
  58. },
  59. },
  60. },
  61. useCustomConfig: (builder) => {
  62. const cfg = defaultPanelFieldConfig;
  63. builder
  64. .addSliderInput({
  65. path: 'lineWidth',
  66. name: 'Line width',
  67. defaultValue: cfg.lineWidth,
  68. settings: {
  69. min: 0,
  70. max: 10,
  71. step: 1,
  72. },
  73. })
  74. .addSliderInput({
  75. path: 'fillOpacity',
  76. name: 'Fill opacity',
  77. defaultValue: cfg.fillOpacity,
  78. settings: {
  79. min: 0,
  80. max: 100,
  81. step: 1,
  82. },
  83. })
  84. .addRadio({
  85. path: 'gradientMode',
  86. name: 'Gradient mode',
  87. defaultValue: graphFieldOptions.fillGradient[0].value,
  88. settings: {
  89. options: graphFieldOptions.fillGradient,
  90. },
  91. });
  92. commonOptionsBuilder.addHideFrom(builder);
  93. },
  94. });