diff --git a/types/chart.js/chart.js-tests.ts b/types/chart.js/chart.js-tests.ts index e60486cee0..a055dcac09 100644 --- a/types/chart.js/chart.js-tests.ts +++ b/types/chart.js/chart.js-tests.ts @@ -279,3 +279,17 @@ const linearScaleChart: Chart = new Chart(ctx, { } } }); + +// custom tooltips +const customTooltipsPieChart = new Chart(ctx, { + type: 'pie', + data: {}, + options: { + tooltips: { + enabled: false, + custom: (tooltipModel) => { + // do whatever + }, + }, + }, +}); diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index 3c49e97e13..fbc29a95c7 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -302,7 +302,7 @@ declare namespace Chart { interface ChartTooltipOptions { enabled?: boolean; - custom?(a: any): void; + custom?: (tooltipModel: ChartTooltipModel) => void; mode?: InteractionMode; intersect?: boolean; backgroundColor?: ChartColor; @@ -341,6 +341,47 @@ declare namespace Chart { borderWidth?: number; } + interface ChartTooltipModel { + backgroundColor: string; + bodyFontColor: string; + bodyFontSize: number; + bodySpacing: number; + borderColor: string; + borderWidth: number; + caretSize: number; + caretX: number; + caretY: number; + cornerRadius: number; + displayColors: boolean; + footerFontColor: string; + footerFontSize: number; + footerMarginTop: number; + footerSpacing: number; + height: number; + legendColorBackground: string; + opacity: number; + titleFontColor: string; + titleFontSize: number; + titleMarginBottom: number; + titleSpacing: number; + width: number; + x: number; + xAlign: string; + xPadding: number; + y: number; + yAlign: string; + yPadding: number; + _bodyAlign: string; + _bodyFontFamily: string; + _bodyFontStyle: string; + _footerAlign: string; + _footerFontFamily: string; + _footerFontStyle: string; + _titleAlign: string; + _titleFontFamily: string; + _titleFontStyle: string; + } + // NOTE: declare plugin options as interface instead of inline '{ [plugin: string]: any }' // to allow module augmentation in case some plugins want to strictly type their options. interface ChartPluginsOptions {