diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index cad58a2aa8..ec8a7c0c03 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -24,11 +24,50 @@ declare class Chart { getElementAtEvent: (e: any) => {}; getElementsAtEvent: (e: any) => {}[]; getDatasetAtEvent: (e: any) => {}[]; + static pluginService: PluginServiceStatic; static defaults: { global: Chart.ChartOptions; } } +declare class PluginServiceStatic { + register(plugin?: PluginServiceRegistrationOptions): void; +} + +declare interface PluginServiceRegistrationOptions { + beforeInit?: (chartInstance: Chart) => void, + afterInit?: (chartInstance: Chart) => void, + + resize?: (chartInstance: Chart, newChartSize: Size) => void, + + beforeUpdate?: (chartInstance: Chart) => void, + afterScaleUpdate?: (chartInstance: Chart) => void, + beforeDatasetsUpdate?: (chartInstance: Chart) => void, + afterDatasetsUpdate?: (chartInstance: Chart) => void, + afterUpdate?: (chartInstance: Chart) => void, + + // This is called at the start of a render. It is only called once, even if the animation will run for a number of frames. Use beforeDraw or afterDraw + // to do something on each animation frame + beforeRender?: (chartInstance: Chart) => void, + + // Easing is for animation + beforeDraw?: (chartInstance: Chart, easing: string) => void, + afterDraw?: (chartInstance: Chart, easing: string) => void, + // Before the datasets are drawn but after scales are drawn + beforeDatasetsDraw?: (chartInstance: Chart, easing: string) => void, + afterDatasetsDraw?: (chartInstance: Chart, easing: string) => void, + + destroy?: (chartInstance: Chart) => void, + + // Called when an event occurs on the chart + beforeEvent?: (chartInstance: Chart, event: Event) => void, + afterEvent?: (chartInstance: Chart, event: Event) => void +} + +declare interface Size { + height: number; + width: number; +} declare namespace Chart { export type ChartType = 'line' | 'bar' | 'radar' | 'doughnut' | 'polarArea' | 'bubble';