From: Jukka Kurkela Date: Sun, 21 Mar 2021 14:20:05 +0000 (+0200) Subject: Modify Scale typing (#8681) X-Git-Tag: v3.0.0-rc.2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=537064be9cc221b9c68a68cdc7f4e823eabda52e;p=thirdparty%2FChart.js.git Modify Scale typing (#8681) --- diff --git a/types/index.esm.d.ts b/types/index.esm.d.ts index 65b1d2b88..0dbbce546 100644 --- a/types/index.esm.d.ts +++ b/types/index.esm.d.ts @@ -1260,10 +1260,9 @@ export interface Scale extends El isFullSize(): boolean; } -export const Scale: { - prototype: Scale; - new (cfg: AnyObject): Scale; -}; +export declare class Scale { + constructor(cfg: {id: string, type: string, ctx: CanvasRenderingContext2D, chart: Chart}); +} export interface ScriptableScaleContext { chart: Chart; diff --git a/types/tests/extensions/scale.ts b/types/tests/extensions/scale.ts new file mode 100644 index 000000000..fdf1c89e4 --- /dev/null +++ b/types/tests/extensions/scale.ts @@ -0,0 +1,48 @@ +import { AnyObject } from '../../basic'; +import { CartesianScaleOptions, Chart, Scale } from '../../index.esm'; + +export type TestScaleOptions = CartesianScaleOptions & { + testOption?: boolean +} + +export class TestScale extends Scale { + static id: 'test'; + + getBasePixel(): number { + return 0; + } + + testMethod(): void { + // + } +} + +declare module '../../index.esm' { + interface CartesianScaleTypeRegistry { + test: { + options: TestScaleOptions + } + } +} + + +Chart.register(TestScale); + +const chart = new Chart('id', { + type: 'line', + data: { + datasets: [] + }, + options: { + scales: { + x: { + type: 'test', + position: 'bottom', + testOption: true, + min: 0 + } + } + } +}); + +Chart.unregister([TestScale]);