PieChart: Display "No data" when there is no data (#38808)

PieChart: Display "No data" when there is no data
This commit is contained in:
Oscar Kilhed 2021-09-08 09:07:09 +02:00 committed by GitHub
parent 40643ee023
commit ecf40f0331
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -66,10 +66,6 @@ export const PieChart: FC<PieChartProps> = ({
return !dv.field.custom.hideFrom.viz;
});
if (filteredFieldDisplayValues.length < 0) {
return <div>No data</div>;
}
const getValue = (d: FieldDisplay) => d.display.numeric;
const getGradientId = (color: string) => `${componentInstanceId}-${tinycolor(color).toHex()}`;
const getGradientColor = (color: string) => {

View File

@ -49,6 +49,14 @@ export function PieChartPanel(props: Props) {
timeZone,
});
if (!hasFrames(fieldDisplayValues)) {
return (
<div className="panel-empty">
<p>No data</p>
</div>
);
}
return (
<VizLayout width={width} height={height} legend={getLegend(props, fieldDisplayValues)}>
{(vizWidth: number, vizHeight: number) => {
@ -127,6 +135,10 @@ function getLegend(props: Props, displayValues: FieldDisplay[]) {
);
}
function hasFrames(fieldDisplayValues: FieldDisplay[]) {
return fieldDisplayValues.some((fd) => fd.view?.dataFrame.length);
}
function useSliceHighlightState() {
const [highlightedTitle, setHighlightedTitle] = useState<string>();
const { eventBus } = usePanelContext();