Skip to content

Commit

Permalink
fix(types): typings for lower levels of plugin configuration to be bo…
Browse files Browse the repository at this point in the history
…olean
  • Loading branch information
artus9033 committed Aug 18, 2024
1 parent c553447 commit 1bef761
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
15 changes: 4 additions & 11 deletions src/typeAugmentations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,11 @@ declare module "chart.js" {
* Configuration controlling the dragdata plugin behaviour.
* The scope depends on where the configuration is applied. The possible locations are:
* - per-chart (inside `plugins` section in chart configuration)
* - per-scale (inside)
* - per-dataset
* - per-data-point
* - per-scale (inside a scale's configuration)
* - per-dataset (inside a dataset's configuration)
* - per-data-point (inside a data point's object, for object data points only)
*
* Each next level from the listing above overrides any preceding configuration by entirely ignoring it.
*
* Example 1: applying a per-chart `round: 2` property and for one of the points `round: 3` will cause this point
* to round to `3` decimal places and all other points of this chart to `2` decimal places.
*
* Example 2: applying a per-chart `round: 2` property and for one of the points `false` (disabling the plugin)
* will disable the plugin for that poi
* nt.
* Each next level from the listing above overrides any preceding configuration (if applicable with respect to the configuration options available).
*
* To entirely disable the plugin, pass `false`. By default, the plugin is enabled for every data point but only
* on the y-axis, unless a lower-level configuration specifies otherwise.
Expand Down
17 changes: 9 additions & 8 deletions src/types/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@ type CoreConfiguration = {
showTooltip: boolean;
};

// per-scale configuration; docstring located in types.d.ts to be visible to the end users
// per-scale configuration; docstring located in typeAugmentations.d.ts to be visible to the end users
export type ScaleDraggingConfiguration = boolean;

// per-dataset configuration; docstring located in types.d.ts to be visible to the end users
export type DatasetDraggingConfiguration = CoreConfiguration;
// per-dataset configuration; docstring located in typeAugmentations.d.ts to be visible to the end users
export type DatasetDraggingConfiguration = boolean;

// per-data-point configuration; docstring located in types.d.ts to be visible to the end users
// per-data-point configuration; docstring located in typeAugmentations.d.ts to be visible to the end users
export type DataPointDraggingConfiguration = boolean;

// plugin (per-chart) configuration; docstring located in types.d.ts to be visible to the end users
// plugin (per-chart) configuration; docstring located in typeAugmentations.d.ts to be visible to the end users
export type PluginConfiguration<TType extends ChartType = ChartType> =
CoreConfiguration & {
/**
* Whether to allow for dragging on the x-axis.
*
* **Note**: This solely works for continuous, numerical x-axis scales (no categories or dates)!
* **Disabled by default.**
*
* @default `false`
Expand All @@ -57,8 +58,7 @@ export type PluginConfiguration<TType extends ChartType = ChartType> =
/**
* Callback fired during the drag numerous times.
*
* If the callback returns `false`, the drag is prevented and the previous
* value of the data point is still effective while the new one is discarded.
* If the callback returns `false`, the drag is prevented and the new value is discarded.
*
* May be used e.g. to process the data point value or to prevent the drag.
*
Expand All @@ -81,6 +81,7 @@ export type PluginConfiguration<TType extends ChartType = ChartType> =

/**
* Callback fired during the drag numerous times.
*
* If the callback returns `false`, the drag is prevented and the previous
* value of the data point is still effective while the new one is discarded.
*
Expand Down Expand Up @@ -111,7 +112,7 @@ export type PluginConfiguration<TType extends ChartType = ChartType> =
onDragEnd: DragEventCallback<TType>;

/**
*
* The 'magnet' function to apply to the dragged value. Can be used to round the values, e.g. snap them to the grid.
*/
magnet: {
to: (value: ChartDataItemType<TType>) => ChartDataItemType<TType>;
Expand Down

0 comments on commit 1bef761

Please sign in to comment.