Skip to content

Commit

Permalink
Add missing feature for disabling plugins in TyeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
stockiNail committed Jul 13, 2023
1 parent c392a7c commit 9432030
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
9 changes: 8 additions & 1 deletion docs/developers/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,17 @@ For example, to provide typings for the [`canvas backgroundColor plugin`](../con
import {ChartType, Plugin} from 'chart.js';

declare module 'chart.js' {
interface PluginOptionsByType<TType extends ChartType> {
// For defaults options
interface DefaultsPluginOptionsByType<TType extends ChartType> {
customCanvasBackgroundColor?: {
color?: string
}
}
// for chart options
interface PluginOptionsByType<TType extends ChartType> {
customCanvasBackgroundColor?: {
color?: string
} | false
}
}
```
23 changes: 19 additions & 4 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ export interface DatasetControllerChartComponent extends ChartComponent {
};
}

export interface Defaults extends CoreChartOptions<ChartType>, ElementChartOptions<ChartType>, PluginChartOptions<ChartType> {
export interface Defaults extends CoreChartOptions<ChartType>, ElementChartOptions<ChartType>, DefaultsPluginChartOptions<ChartType> {

scale: ScaleOptionsByType;
scales: {
Expand Down Expand Up @@ -701,7 +701,7 @@ export type Overrides = {
[key in ChartType]:
CoreChartOptions<key> &
ElementChartOptions<key> &
PluginChartOptions<key> &
DefaultsPluginChartOptions<key> &
DatasetChartOptions<ChartType> &
ScaleChartOptions<key> &
ChartTypeRegistry[key]['chartOptions'];
Expand Down Expand Up @@ -2912,7 +2912,7 @@ export interface TooltipItem<TType extends ChartType> {
element: Element;
}

export interface PluginOptionsByType<TType extends ChartType> {
export interface DefaultsPluginOptionsByType<TType extends ChartType> {
colors: ColorsPluginOptions;
decimation: DecimationOptions;
filler: FillerOptions;
Expand All @@ -2921,8 +2921,23 @@ export interface PluginOptionsByType<TType extends ChartType> {
title: TitleOptions;
tooltip: TooltipOptions<TType>;
}

export interface PluginOptionsByType<TType extends ChartType> {
colors: ColorsPluginOptions | false;
decimation: DecimationOptions | false;
filler: FillerOptions | false;
legend: LegendOptions<TType> | false;
subtitle: TitleOptions | false;
title: TitleOptions | false;
tooltip: TooltipOptions<TType> | false;
}

export interface DefaultsPluginChartOptions<TType extends ChartType> {
plugins: DefaultsPluginOptionsByType<TType>;
}

export interface PluginChartOptions<TType extends ChartType> {
plugins: PluginOptionsByType<TType>;
plugins: PluginOptionsByType<TType> | false;
}

export interface BorderOptions {
Expand Down
29 changes: 29 additions & 0 deletions test/types/plugins/disable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Chart } from '../../../src/types.js';

const chart = new Chart('id', {
type: 'bubble',
data: {
labels: [],
datasets: [{
data: []
}]
},
options: {
plugins: false
}
});

const chart1 = new Chart('id', {
type: 'bubble',
data: {
labels: [],
datasets: [{
data: []
}]
},
options: {
plugins: {
legend: false
}
}
});

0 comments on commit 9432030

Please sign in to comment.