grafana/public/app/plugins/panel/piechart/PieChartPanel.tsx
Oscar Kilhed e7757b0175
Add datalinks support to PieChart v2 (#31642)
* Remove default value for multiSelect

* Add data links support for PieChart v2

* Temporarily fix story

* Refactor PieSlice, deduplicate colors

* Add field config to context menu of pie chart

* Add custom key to legend

This is a bit hacky. When there are multiple DisplayValues with the same
title the react keys collide and LegendListItems are not cleared
correctly.

* Forgot to add the interface

* Fix missing tooltip in edit mode
2021-03-10 23:02:04 +01:00

47 lines
1.2 KiB
TypeScript

import React, { useCallback } from 'react';
import { PieChart, useTheme } from '@grafana/ui';
import { PieChartOptions } from './types';
import { getFieldDisplayValues, PanelProps } from '@grafana/data';
import { changeSeriesColorConfigFactory } from '../timeseries/overrides/colorSeriesConfigFactory';
interface Props extends PanelProps<PieChartOptions> {}
export const PieChartPanel: React.FC<Props> = ({
width,
height,
options,
data,
onFieldConfigChange,
replaceVariables,
fieldConfig,
timeZone,
}) => {
const onSeriesColorChange = useCallback(
(label: string, color: string) => {
onFieldConfigChange(changeSeriesColorConfigFactory(label, color, fieldConfig));
},
[fieldConfig, onFieldConfigChange]
);
const fieldDisplayValues = getFieldDisplayValues({
fieldConfig,
reduceOptions: options.reduceOptions,
data: data.series,
theme: useTheme(),
replaceVariables: replaceVariables,
timeZone,
});
return (
<PieChart
width={width}
height={height}
fieldDisplayValues={fieldDisplayValues}
onSeriesColorChange={onSeriesColorChange}
pieType={options.pieType}
displayLabels={options.displayLabels}
legendOptions={options.legend}
/>
);
};