]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Modify Scale typing (#8681)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Sun, 21 Mar 2021 14:20:05 +0000 (16:20 +0200)
committerGitHub <noreply@github.com>
Sun, 21 Mar 2021 14:20:05 +0000 (10:20 -0400)
types/index.esm.d.ts
types/tests/extensions/scale.ts [new file with mode: 0644]

index 65b1d2b88ceffa7a851f30c2b59b51d24c3a6017..0dbbce5464f51872b33bf5f2fb4f8886d2bb1a2e 100644 (file)
@@ -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;
diff --git a/types/tests/extensions/scale.ts b/types/tests/extensions/scale.ts
new file mode 100644 (file)
index 0000000..fdf1c89
--- /dev/null
@@ -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]);