2021-08-29 22:54:21 +03:00
|
|
|
import { ActiveElement, ChartEvent, ChartType, TooltipItem } from 'chart.js';
|
2020-09-20 12:46:07 +03:00
|
|
|
import { prettify } from './numbers';
|
2020-09-20 12:43:24 +03:00
|
|
|
|
2022-03-26 14:17:42 +03:00
|
|
|
export const pointerOnHover = ({ native }: ChartEvent, [firstElement]: ActiveElement[]) => {
|
2021-08-29 22:54:21 +03:00
|
|
|
if (!native?.target) {
|
|
|
|
return;
|
|
|
|
}
|
2020-09-20 12:46:07 +03:00
|
|
|
|
2021-08-29 23:04:04 +03:00
|
|
|
const canvas = native.target as HTMLCanvasElement;
|
|
|
|
|
|
|
|
canvas.style.cursor = firstElement ? 'pointer' : 'default';
|
2020-09-20 12:46:07 +03:00
|
|
|
};
|
|
|
|
|
2022-05-25 21:26:34 +03:00
|
|
|
export const renderChartLabel = ({ dataset, raw }: TooltipItem<ChartType>) => `${dataset.label}: ${prettify(`${raw}`)}`;
|
2021-08-29 23:04:04 +03:00
|
|
|
|
2022-05-25 21:26:34 +03:00
|
|
|
export const renderPieChartLabel = ({ label, raw }: TooltipItem<ChartType>) => `${label}: ${prettify(`${raw}`)}`;
|