Skip to content

Commit f287be4

Browse files
authored
Add missing feature for disabling plugins in TyeScript (#11403)
* Add missing feature for disabling plugins in TyeScript * apply review * remove empty line
1 parent cc7ee8a commit f287be4

File tree

7 files changed

+34
-17
lines changed

7 files changed

+34
-17
lines changed

docs/developers/plugins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ declare module 'chart.js' {
197197
interface PluginOptionsByType<TType extends ChartType> {
198198
customCanvasBackgroundColor?: {
199199
color?: string
200-
}
200+
} | false
201201
}
202202
}
203203
```

src/types/index.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2913,13 +2913,13 @@ export interface TooltipItem<TType extends ChartType> {
29132913
}
29142914

29152915
export interface PluginOptionsByType<TType extends ChartType> {
2916-
colors: ColorsPluginOptions;
2917-
decimation: DecimationOptions;
2918-
filler: FillerOptions;
2919-
legend: LegendOptions<TType>;
2920-
subtitle: TitleOptions;
2921-
title: TitleOptions;
2922-
tooltip: TooltipOptions<TType>;
2916+
colors: ColorsPluginOptions | false;
2917+
decimation: DecimationOptions | false;
2918+
filler: FillerOptions | false;
2919+
legend: LegendOptions<TType> | false;
2920+
subtitle: TitleOptions | false;
2921+
title: TitleOptions | false;
2922+
tooltip: TooltipOptions<TType> | false;
29232923
}
29242924
export interface PluginChartOptions<TType extends ChartType> {
29252925
plugins: PluginOptionsByType<TType>;

test/types/defaults.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Chart } from '../../src/types.js';
1+
import { Chart, TitleOptions, TooltipOptions } from '../../src/types.js';
22

33
Chart.defaults.scales.time.time.minUnit = 'day';
44

5-
Chart.defaults.plugins.title.display = false;
5+
(Chart.defaults.plugins.title as TitleOptions).display = false;
66

77
Chart.defaults.datasets.bar.backgroundColor = 'red';
88

@@ -27,4 +27,4 @@ Chart.defaults.layout = {
2727
},
2828
};
2929

30-
Chart.defaults.plugins.tooltip.boxPadding = 3;
30+
(Chart.defaults.plugins.tooltip as TooltipOptions).boxPadding = 3;

test/types/overrides.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Chart } from '../../src/types.js';
1+
import { Chart, TitleOptions } from '../../src/types.js';
22

33
Chart.overrides.bar.scales.x.type = 'time';
44

5-
Chart.overrides.bar.plugins.title.display = false;
5+
(Chart.overrides.bar.plugins.title as TitleOptions).display = false;
66

77
Chart.overrides.line.datasets.bar.backgroundColor = 'red';
88

test/types/plugins/defaults.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { defaults } from '../../../src/types.js';
1+
import { defaults, LegendOptions } from '../../../src/types.js';
22

33
// https://github.com/chartjs/Chart.js/issues/8711
4-
const original = defaults.plugins.legend.labels.generateLabels;
4+
const original = (defaults.plugins.legend as LegendOptions<"line">).labels.generateLabels;
55

6+
// @ts-ignore
67
defaults.plugins.legend.labels.generateLabels = function(chart) {
78
return [{
89
datasetIndex: 0,

test/types/plugins/disable.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Chart } from '../../../src/types.js';
2+
3+
const chart = new Chart('id', {
4+
type: 'bubble',
5+
data: {
6+
labels: [],
7+
datasets: [{
8+
data: []
9+
}]
10+
},
11+
options: {
12+
plugins: {
13+
legend: false
14+
}
15+
}
16+
});

test/types/plugins/plugin.tooltip/tooltip_parsed_data_chart_defaults.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Chart } from '../../../../src/types.js';
1+
import { Chart, TooltipOptions } from '../../../../src/types.js';
22

3-
Chart.overrides.bubble.plugins.tooltip.callbacks.label = (item) => {
3+
(Chart.overrides.bubble.plugins.tooltip as TooltipOptions<'bubble'>).callbacks.label = (item) => {
44
const { x, y, _custom: r } = item.parsed;
55
return `${item.label}: (${x}, ${y}, ${r})`;
66
};

0 commit comments

Comments
 (0)