From 958fad8fcfd8a48bd6f4a530e76046aec6127e22 Mon Sep 17 00:00:00 2001 From: nat1130NS Date: Tue, 9 May 2017 09:06:30 -0700 Subject: [PATCH 1/2] Adding pluginService functionality for chart.js --- types/chart.js/index.d.ts | 61 ++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index cad58a2aa8..5c3b654459 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -13,22 +13,61 @@ declare class Chart { ); config: Chart.ChartConfiguration; data: Chart.ChartData; - destroy: () => {}; - update: (duration?: any, lazy?: any) => {}; - render: (duration?: any, lazy?: any) => {}; - stop: () => {}; - resize: () => {}; - clear: () => {}; - toBase64: () => string; - generateLegend: () => {}; - getElementAtEvent: (e: any) => {}; - getElementsAtEvent: (e: any) => {}[]; - getDatasetAtEvent: (e: any) => {}[]; + public destroy: () => {}; + public update: (duration?: any, lazy?: any) => {}; + public render: (duration?: any, lazy?: any) => {}; + public stop: () => {}; + public resize: () => {}; + public clear: () => {}; + public toBase64: () => string; + public generateLegend: () => {}; + public getElementAtEvent: (e: any) => {}; + public getElementsAtEvent: (e: any) => {}[]; + public getDatasetAtEvent: (e: any) => {}[]; + public static pluginService: PluginServiceStatic; static defaults: { global: Chart.ChartOptions; } } +declare class PluginServiceStatic { + public 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'; From b2c4bfefaa7fa35d47639eb2509dba4b0721b831 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 1 Jun 2017 08:58:37 -0700 Subject: [PATCH 2/2] Undo style changes --- types/chart.js/index.d.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index 5c3b654459..ec8a7c0c03 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -13,25 +13,25 @@ declare class Chart { ); config: Chart.ChartConfiguration; data: Chart.ChartData; - public destroy: () => {}; - public update: (duration?: any, lazy?: any) => {}; - public render: (duration?: any, lazy?: any) => {}; - public stop: () => {}; - public resize: () => {}; - public clear: () => {}; - public toBase64: () => string; - public generateLegend: () => {}; - public getElementAtEvent: (e: any) => {}; - public getElementsAtEvent: (e: any) => {}[]; - public getDatasetAtEvent: (e: any) => {}[]; - public static pluginService: PluginServiceStatic; + destroy: () => {}; + update: (duration?: any, lazy?: any) => {}; + render: (duration?: any, lazy?: any) => {}; + stop: () => {}; + resize: () => {}; + clear: () => {}; + toBase64: () => string; + generateLegend: () => {}; + getElementAtEvent: (e: any) => {}; + getElementsAtEvent: (e: any) => {}[]; + getDatasetAtEvent: (e: any) => {}[]; + static pluginService: PluginServiceStatic; static defaults: { global: Chart.ChartOptions; } } declare class PluginServiceStatic { - public register(plugin?: PluginServiceRegistrationOptions): void; + register(plugin?: PluginServiceRegistrationOptions): void; } declare interface PluginServiceRegistrationOptions {