mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Modify Scale typing (#8681)
This commit is contained in:
parent
375d856a87
commit
537064be9c
7
types/index.esm.d.ts
vendored
7
types/index.esm.d.ts
vendored
@ -1260,10 +1260,9 @@ export interface Scale<O extends CoreScaleOptions = CoreScaleOptions> extends El
|
||||
|
||||
isFullSize(): boolean;
|
||||
}
|
||||
export const Scale: {
|
||||
prototype: Scale;
|
||||
new <O extends CoreScaleOptions = CoreScaleOptions>(cfg: AnyObject): Scale<O>;
|
||||
};
|
||||
export declare class Scale {
|
||||
constructor(cfg: {id: string, type: string, ctx: CanvasRenderingContext2D, chart: Chart});
|
||||
}
|
||||
|
||||
export interface ScriptableScaleContext {
|
||||
chart: Chart;
|
||||
|
||||
48
types/tests/extensions/scale.ts
Normal file
48
types/tests/extensions/scale.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { AnyObject } from '../../basic';
|
||||
import { CartesianScaleOptions, Chart, Scale } from '../../index.esm';
|
||||
|
||||
export type TestScaleOptions = CartesianScaleOptions & {
|
||||
testOption?: boolean
|
||||
}
|
||||
|
||||
export class TestScale<O extends TestScaleOptions = TestScaleOptions> extends Scale<O> {
|
||||
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]);
|
||||
Loading…
x
Reference in New Issue
Block a user