mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Cleanup tooltip generation in <PieChart>
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
a9f4bcecb2
commit
d7019d1426
@ -68,18 +68,11 @@ const NonInjectedPieChart = observer(({
|
|||||||
const total = datasetData.reduce((acc, cur) => acc + cur, 0);
|
const total = datasetData.reduce((acc, cur) => acc + cur, 0);
|
||||||
const percent = Math.round((datasetData[tooltipItem.index] as number / total) * 100);
|
const percent = Math.round((datasetData[tooltipItem.index] as number / total) * 100);
|
||||||
const percentLabel = isNaN(percent) ? "N/A" : `${percent}%`;
|
const percentLabel = isNaN(percent) ? "N/A" : `${percent}%`;
|
||||||
const tooltipLabel = dataset.tooltipLabels?.[tooltipItem.index];
|
const computeTooltipLabel = dataset.tooltipLabels?.[tooltipItem.index];
|
||||||
let tooltip = `${dataset.label}: ${percentLabel}`;
|
|
||||||
|
|
||||||
if (tooltipLabel) {
|
return computeTooltipLabel
|
||||||
if (typeof tooltipLabel === "function") {
|
? computeTooltipLabel(percentLabel)
|
||||||
tooltip = tooltipLabel(percentLabel);
|
: `${dataset.label}: ${percentLabel}`;
|
||||||
} else {
|
|
||||||
tooltip = tooltipLabel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return tooltip;
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
filter: ({ datasetIndex, index }, { datasets = [] }) => {
|
filter: ({ datasetIndex, index }, { datasets = [] }) => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user