mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* 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
47 lines
1.2 KiB
TypeScript
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}
|
|
/>
|
|
);
|
|
};
|