module.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { FieldColorModeId, FieldConfigProperty, PanelPlugin } from '@grafana/data';
  2. import { LegendDisplayMode } from '@grafana/schema';
  3. import { commonOptionsBuilder } from '@grafana/ui';
  4. import { addStandardDataReduceOptions } from '../stat/types';
  5. import { PieChartPanel } from './PieChartPanel';
  6. import { PieChartPanelChangedHandler } from './migrations';
  7. import { PieChartSuggestionsSupplier } from './suggestions';
  8. import { PieChartOptions, PieChartType, PieChartLabels, PieChartLegendValues } from './types';
  9. export const plugin = new PanelPlugin<PieChartOptions>(PieChartPanel)
  10. .setPanelChangeHandler(PieChartPanelChangedHandler)
  11. .useFieldConfig({
  12. disableStandardOptions: [FieldConfigProperty.Thresholds],
  13. standardOptions: {
  14. [FieldConfigProperty.Color]: {
  15. settings: {
  16. byValueSupport: false,
  17. bySeriesSupport: true,
  18. preferThresholdsMode: false,
  19. },
  20. defaultValue: {
  21. mode: FieldColorModeId.PaletteClassic,
  22. },
  23. },
  24. },
  25. useCustomConfig: (builder) => {
  26. commonOptionsBuilder.addHideFrom(builder);
  27. },
  28. })
  29. .setPanelOptions((builder) => {
  30. addStandardDataReduceOptions(builder);
  31. builder
  32. .addRadio({
  33. name: 'Piechart type',
  34. description: 'How the piechart should be rendered',
  35. path: 'pieType',
  36. settings: {
  37. options: [
  38. { value: PieChartType.Pie, label: 'Pie' },
  39. { value: PieChartType.Donut, label: 'Donut' },
  40. ],
  41. },
  42. defaultValue: PieChartType.Pie,
  43. })
  44. .addMultiSelect({
  45. name: 'Labels',
  46. path: 'displayLabels',
  47. description: 'Select the labels to be displayed in the pie chart',
  48. settings: {
  49. options: [
  50. { value: PieChartLabels.Percent, label: 'Percent' },
  51. { value: PieChartLabels.Name, label: 'Name' },
  52. { value: PieChartLabels.Value, label: 'Value' },
  53. ],
  54. },
  55. });
  56. commonOptionsBuilder.addTooltipOptions(builder);
  57. commonOptionsBuilder.addLegendOptions(builder, false);
  58. builder.addMultiSelect({
  59. name: 'Legend values',
  60. path: 'legend.values',
  61. category: ['Legend'],
  62. settings: {
  63. options: [
  64. { value: PieChartLegendValues.Percent, label: 'Percent' },
  65. { value: PieChartLegendValues.Value, label: 'Value' },
  66. ],
  67. },
  68. showIf: (c) => c.legend.displayMode !== LegendDisplayMode.Hidden,
  69. });
  70. })
  71. .setSuggestionsSupplier(new PieChartSuggestionsSupplier());