Little clean up

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev committed 2022-04-11 07:41:24 +03:00
1 parent e22f8216e8
commit 39786e7911
1 file changed
+3 -4
+3 -4
View File
@@ -23,7 +23,6 @@ export interface PieChartData extends ChartJS.ChartData {
export type DatasetTooltipLabel = (percent: string) => string | string; export type DatasetTooltipLabel = (percent: string) => string | string;
interface PieChartDataSets extends ChartJS.ChartDataSets { interface PieChartDataSets extends ChartJS.ChartDataSets {
id?: string;
tooltipLabels?: DatasetTooltipLabel[]; tooltipLabels?: DatasetTooltipLabel[];
} }
@@ -43,10 +42,10 @@ export class PieChart extends React.Component<PieChartProps> {
const dataset = data.datasets[tooltipItem.datasetIndex]; const dataset = data.datasets[tooltipItem.datasetIndex];
const datasetData = dataset.data as number[]; const datasetData = dataset.data as number[];
const total = datasetData.reduce((acc, cur) => acc + cur, 0); const total = datasetData.reduce((acc, cur) => acc + cur, 0);
const percent = Math.round((dataset.data[tooltipItem["index"]] as number / total) * 100); const percent = Math.round((dataset.data[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 tooltipLabel = dataset.tooltipLabels?.[tooltipItem.index];
let tooltip = `${dataset["label"]}: ${percentLabel}`; let tooltip = `${dataset.label}: ${percentLabel}`;
if (tooltipLabel) { if (tooltipLabel) {
if (typeof tooltipLabel === "function") { if (typeof tooltipLabel === "function") {