Cleanup tooltip generation in <PieChart>

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2022-08-18 10:38:30 -04:00
1 parent a9f4bcecb2
commit d7019d1426
1 file changed
+4 -11
+4 -11
View File
@@ -68,18 +68,11 @@ const NonInjectedPieChart = observer(({
const total = datasetData.reduce((acc, cur) => acc + cur, 0);
const percent = Math.round((datasetData[tooltipItem.index] as number / total) * 100);
const percentLabel = isNaN(percent) ? "N/A" : `${percent}%`;
const tooltipLabel = dataset.tooltipLabels?.[tooltipItem.index];
let tooltip = `${dataset.label}: ${percentLabel}`;
const computeTooltipLabel = dataset.tooltipLabels?.[tooltipItem.index];
if (tooltipLabel) {
if (typeof tooltipLabel === "function") {
tooltip = tooltipLabel(percentLabel);
} else {
tooltip = tooltipLabel;
}
}
return tooltip;
return computeTooltipLabel
? computeTooltipLabel(percentLabel)
: `${dataset.label}: ${percentLabel}`;
},
},
filter: ({ datasetIndex, index }, { datasets = [] }) => {