Add args.mode to before/after update plugin hooks (#7949)

This commit is contained in:
Jukka Kurkela 2020-10-24 18:36:31 +03:00 committed by GitHub
parent 93fabd1f26
commit 58d1911d05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 951 additions and 928 deletions

View File

@ -487,3 +487,8 @@ All helpers are now exposed in a flat hierarchy, e.g., `Chart.helpers.canvas.cli
* `Chart.platforms` is an object that contains two usable platform classes, `BasicPlatform` and `DomPlatform`. It also contains `BasePlatform`, a class that all platforms must extend from.
* If the canvas passed in is an instance of `OffscreenCanvas`, the `BasicPlatform` is automatically used.
* `isAttached` method was added to platform.
#### IPlugin interface
* `afterDatasetsUpdate`, `afterUpdate`, `beforeDatasetsUpdate`, and `beforeUpdate` now receive `args` object as second argument. `options` argument is always the last and thus was moved from 2nd to 3rd place.
* `afterEvent` and `beforeEvent` now receive a wrapped `event` as the second argument. The native event is available via `event.native`.

View File

@ -587,6 +587,7 @@ class Chart {
update(mode) {
const me = this;
const args = {mode};
let i, ilen;
me._updating = true;
@ -600,7 +601,7 @@ class Chart {
// https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167
me._plugins.invalidate();
if (me._plugins.notify(me, 'beforeUpdate') === false) {
if (me._plugins.notify(me, 'beforeUpdate', [args]) === false) {
return;
}
@ -622,7 +623,7 @@ class Chart {
me._updateDatasets(mode);
// Do this before render so that any plugins that need final scale updates can use it
me._plugins.notify(me, 'afterUpdate');
me._plugins.notify(me, 'afterUpdate', [args]);
me._layers.sort(compare2Level('z', '_idx'));
@ -675,8 +676,9 @@ class Chart {
_updateDatasets(mode) {
const me = this;
const isFunction = typeof mode === 'function';
const args = {mode};
if (me._plugins.notify(me, 'beforeDatasetsUpdate') === false) {
if (me._plugins.notify(me, 'beforeDatasetsUpdate', [args]) === false) {
return;
}
@ -684,7 +686,7 @@ class Chart {
me._updateDataset(i, isFunction ? mode({datasetIndex: i}) : mode);
}
me._plugins.notify(me, 'afterDatasetsUpdate');
me._plugins.notify(me, 'afterDatasetsUpdate', [args]);
}
/**

View File

@ -126,6 +126,8 @@ function createDescriptors(plugins, options) {
* @desc Called before updating `chart`. If any plugin returns `false`, the update
* is cancelled (and thus subsequent render(s)) until another `update` is triggered.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {string} args.mode - The update mode
* @param {object} options - The plugin options.
* @returns {boolean} `false` to cancel the chart update.
*/
@ -134,6 +136,8 @@ function createDescriptors(plugins, options) {
* @desc Called after `chart` has been updated and before rendering. Note that this
* hook will not be called if the chart update has been previously cancelled.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {string} args.mode - The update mode
* @param {object} options - The plugin options.
*/
/**
@ -148,6 +152,8 @@ function createDescriptors(plugins, options) {
* @desc Called before updating the `chart` datasets. If any plugin returns `false`,
* the datasets update is cancelled until another `update` is triggered.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {string} args.mode - The update mode
* @param {object} options - The plugin options.
* @returns {boolean} false to cancel the datasets update.
* @since version 2.1.5
@ -157,6 +163,8 @@ function createDescriptors(plugins, options) {
* @desc Called after the `chart` datasets have been updated. Note that this hook
* will not be called if the datasets update has been previously cancelled.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {string} args.mode - The update mode
* @param {object} options - The plugin options.
* @since version 2.1.5
*/
@ -168,6 +176,7 @@ function createDescriptors(plugins, options) {
* @param {object} args - The call arguments.
* @param {number} args.index - The dataset index.
* @param {object} args.meta - The dataset metadata.
* @param {string} args.mode - The update mode
* @param {object} options - The plugin options.
* @returns {boolean} `false` to cancel the chart datasets drawing.
*/
@ -179,6 +188,7 @@ function createDescriptors(plugins, options) {
* @param {object} args - The call arguments.
* @param {number} args.index - The dataset index.
* @param {object} args.meta - The dataset metadata.
* @param {string} args.mode - The update mode
* @param {object} options - The plugin options.
*/
/**

View File

@ -525,7 +525,7 @@ function doFill(ctx, cfg) {
export default {
id: 'filler',
afterDatasetsUpdate(chart, options) {
afterDatasetsUpdate(chart, _args, options) {
const count = (chart.data.datasets || []).length;
const propagate = options.propagate;
const sources = [];

1852
types/core/index.d.ts vendored

File diff suppressed because it is too large Load Diff