Skip to content

Commit

Permalink
Updates to scale type definitions (#11419)
Browse files Browse the repository at this point in the history
While adding some type definitions to chartjs-plugin-zoom
(see chartjs/chartjs-plugin-zoom#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
  • Loading branch information
joshkel authored Jul 25, 2023
1 parent e7b8164 commit dd03016
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/scales/scale.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
18 changes: 17 additions & 1 deletion src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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[];
Expand Down

0 comments on commit dd03016

Please sign in to comment.