]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Updates to scale type definitions (#11419)
authorJosh Kelley <joshkel@gmail.com>
Tue, 25 Jul 2023 22:39:25 +0000 (18:39 -0400)
committerGitHub <noreply@github.com>
Tue, 25 Jul 2023 22:39:25 +0000 (18:39 -0400)
While adding some type definitions to chartjs-plugin-zoom
(see https://github.com/chartjs/chartjs-plugin-zoom/pull/774), I noticed
a few limitations in Chart.js's scale types:

* The zoom plugin calls `Scale.parse` with no index parameter.  Scale's
  JSDoc allows this, but its TypeScript definitions did not.
* The zoom plugin alters scale options' min and max.  The specific types
  of these depend on which scale is in use, but every scale has them, so
  `unknown` seems appropriate

src/scales/scale.time.js
src/types/index.d.ts

index 6bcef6c03e6c8d001d58792abe735a8bb25101e8..184937466598b49a7e06fcd65fbfd844fa30cbce 100644 (file)
@@ -56,7 +56,7 @@ function parse(scale, input) {
     value = parser(value);
   }
 
-  // Only parse if its not a timestamp already
+  // Only parse if it's not a timestamp already
   if (!isFinite(value)) {
     value = typeof parser === 'string'
       ? adapter.parse(value, /** @type {Unit} */ (parser))
index 65e1213dcd7fb5945c89d4675a5ec67e4d5a2e65..0eb9b5eb679f2fffc5f2bbfe1545628d2a87b3c3 100644 (file)
@@ -1176,6 +1176,22 @@ export interface CoreScaleOptions {
    * @default true
    */
   weight: number;
+  /**
+   * User defined minimum value for the scale, overrides minimum value from data.
+   */
+  min: unknown;
+  /**
+   * User defined maximum value for the scale, overrides maximum value from data.
+   */
+  max: unknown;
+  /**
+   * Adjustment used when calculating the maximum data value.
+   */
+  suggestedMin: unknown;
+  /**
+   * Adjustment used when calculating the minimum data value.
+   */
+  suggestedMax: unknown;
   /**
    * Callback called before the update process starts.
    */
@@ -1316,7 +1332,7 @@ export interface Scale<O extends CoreScaleOptions = CoreScaleOptions> extends El
   getBasePixel(): number;
 
   init(options: O): void;
-  parse(raw: unknown, index: number): unknown;
+  parse(raw: unknown, index?: number): unknown;
   getUserBounds(): { min: number; max: number; minDefined: boolean; maxDefined: boolean };
   getMinMax(canStack: boolean): { min: number; max: number };
   getTicks(): Tick[];