Skip to content

Commit

Permalink
apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
stockiNail committed Jul 14, 2023
1 parent 9432030 commit 920ee64
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 46 deletions.
7 changes: 0 additions & 7 deletions docs/developers/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,6 @@ For example, to provide typings for the [`canvas backgroundColor plugin`](../con
import {ChartType, Plugin} from 'chart.js';

declare module 'chart.js' {
// For defaults options
interface DefaultsPluginOptionsByType<TType extends ChartType> {
customCanvasBackgroundColor?: {
color?: string
}
}
// for chart options
interface PluginOptionsByType<TType extends ChartType> {
customCanvasBackgroundColor?: {
color?: string
Expand Down
20 changes: 3 additions & 17 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>, DefaultsPluginChartOptions<ChartType> {
export interface Defaults extends CoreChartOptions<ChartType>, ElementChartOptions<ChartType>, PluginChartOptions<ChartType> {

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

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

export interface PluginOptionsByType<TType extends ChartType> {
colors: ColorsPluginOptions | false;
decimation: DecimationOptions | false;
Expand All @@ -2932,12 +2922,8 @@ export interface PluginOptionsByType<TType extends ChartType> {
tooltip: TooltipOptions<TType> | false;
}

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

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

export interface BorderOptions {
Expand Down
6 changes: 3 additions & 3 deletions test/types/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Chart } from '../../src/types.js';
import { Chart, TitleOptions, TooltipOptions } from '../../src/types.js';

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

Chart.defaults.plugins.title.display = false;
(Chart.defaults.plugins.title as TitleOptions).display = false;

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

Expand All @@ -27,4 +27,4 @@ Chart.defaults.layout = {
},
};

Chart.defaults.plugins.tooltip.boxPadding = 3;
(Chart.defaults.plugins.tooltip as TooltipOptions).boxPadding = 3;
4 changes: 2 additions & 2 deletions test/types/overrides.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Chart } from '../../src/types.js';
import { Chart, TitleOptions } from '../../src/types.js';

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

Chart.overrides.bar.plugins.title.display = false;
(Chart.overrides.bar.plugins.title as TitleOptions).display = false;

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

Expand Down
5 changes: 3 additions & 2 deletions test/types/plugins/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { defaults } from '../../../src/types.js';
import { defaults, LegendOptions } from '../../../src/types.js';

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

// @ts-ignore
defaults.plugins.legend.labels.generateLabels = function(chart) {
return [{
datasetIndex: 0,
Expand Down
13 changes: 0 additions & 13 deletions test/types/plugins/disable.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
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: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Chart } from '../../../../src/types.js';
import { Chart, TooltipOptions } from '../../../../src/types.js';

Chart.overrides.bubble.plugins.tooltip.callbacks.label = (item) => {
(Chart.overrides.bubble.plugins.tooltip as TooltipOptions<'bubble'>).callbacks.label = (item) => {
const { x, y, _custom: r } = item.parsed;
return `${item.label}: (${x}, ${y}, ${r})`;
};
Expand Down

0 comments on commit 920ee64

Please sign in to comment.