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