From 5d8ff34ff2746f9ace97cc5a8d8723c0bc994116 Mon Sep 17 00:00:00 2001 From: Conrad Holtzhausen Date: Mon, 17 Sep 2018 15:02:03 +0200 Subject: [PATCH] @types/chart.js: added missing legendCallback to ChartOptions --- types/chart.js/chart.js-tests.ts | 32 ++++++++++++++++++++++---------- types/chart.js/index.d.ts | 2 ++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/types/chart.js/chart.js-tests.ts b/types/chart.js/chart.js-tests.ts index 36f25643d9..41ab453e0f 100644 --- a/types/chart.js/chart.js-tests.ts +++ b/types/chart.js/chart.js-tests.ts @@ -5,8 +5,8 @@ import { Chart, ChartData, Point } from "chart.js"; // => chartjs.Chart const plugin = { - afterDraw: (chartInstance: Chart, easing: string, options?: any) => { - } + afterDraw: (chartInstance: Chart, easing: string, options?: any) => { + } }; const chart: Chart = new Chart(new CanvasRenderingContext2D(), { @@ -82,6 +82,18 @@ if (chart.chartArea) { console.log(chart.chartArea.left); } +// Testing custom legends +chart.config.options = { + ...chart.config.options, + legend: { + display: false, + }, + legendCallback: () => 'legend replacement' +}; +chart.update(); +const customLegend = chart.generateLegend(); +console.log(customLegend === 'legend replacement'); + // Testing radial chart const tickOptions: Chart.LinearTickOptions = { max: 100, @@ -107,14 +119,14 @@ const chartConfig: Chart.ChartConfiguration = { data: { labels: ['#apples', '#pears', '#apricots', '#acorns', '#amigas', "#orics"], datasets: [{ - label: "test", - lineTension: 0.15, - data: [1, 1, 2, 3, 5], - backgroundColor: '#37738353', - borderColor: '#37738353', - borderWidth: 3, - fill: true - }] + label: "test", + lineTension: 0.15, + data: [1, 1, 2, 3, 5], + backgroundColor: '#37738353', + borderColor: '#37738353', + borderWidth: 3, + fill: true + }] }, options: radarChartOptions }; diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index 49027a2bea..81b35185ae 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -14,6 +14,7 @@ // Francesco Benedetto // Alexandros Dorodoulis // Manuel Heidrich +// Conrad Holtzhausen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -264,6 +265,7 @@ declare namespace Chart { aspectRatio?: number; maintainAspectRatio?: boolean; events?: string[]; + legendCallback?(chart: Chart): string; onHover?(this: Chart, event: MouseEvent, activeElements: Array<{}>): any; onClick?(event?: MouseEvent, activeElements?: Array<{}>): any; onResize?(this: Chart, newSize: ChartSize): void;