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
|
|
|
|
2021-08-29 22:54:21 +03:00
|
|
|
export const pointerOnHover = ({ native }: ChartEvent, [ firstElement ]: ActiveElement[]) => {
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2021-08-29 23:04:04 +03:00
|
|
|
export const renderChartLabel = ({ dataset, formattedValue }: TooltipItem<ChartType>) =>
|
|
|
|
`${dataset.label}: ${prettify(formattedValue)}`;
|
|
|
|
|
|
|
|
export const renderPieChartLabel = ({ label, formattedValue }: TooltipItem<ChartType>) =>
|
|
|
|
`${label}: ${prettify(formattedValue)}`;
|