From: Jukka Kurkela Date: Sun, 8 Nov 2020 13:43:55 +0000 (+0200) Subject: Add type to context objects (#8007) X-Git-Tag: 3.0.0-beta.6~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d74a5d7552c8cecd895de1edb92ed7e54a8250a0;p=thirdparty%2FChart.js.git Add type to context objects (#8007) --- diff --git a/docs/docs/general/options.md b/docs/docs/general/options.md index 399c1d43c..695f1ba3e 100644 --- a/docs/docs/general/options.md +++ b/docs/docs/general/options.md @@ -54,6 +54,7 @@ The context object contains the following properties: ### chart - `chart`: the associated chart +- `type`: `'chart'` ### dataset @@ -63,6 +64,7 @@ In addition to [chart](#chart) - `dataset`: dataset at index `datasetIndex` - `datasetIndex`: index of the current dataset - `index`: getter for `datasetIndex` +- `type`: `'dataset'` ### data @@ -73,12 +75,14 @@ In addition to [dataset](#dataset) - `dataPoint`: the parsed data values for the given `dataIndex` and `datasetIndex` - `element`: the element (point, arc, bar, etc.) for this data - `index`: getter for `dataIndex` +- `type`: `'data'` ### scale In addition to [chart](#chart) - `scale`: the associated scale +- `type`: `'scale'` ### tick @@ -86,3 +90,4 @@ In addition to [scale](#scale) - `tick`: the associated tick object - `index`: tick index +- `type`: `'tick'` diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 6ff953add..fa160c6ed 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -735,6 +735,9 @@ class Chart { return this.$context || (this.$context = Object.create(null, { chart: { value: this + }, + type: { + value: 'chart' } })); } diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index 83566956d..d7bfab12b 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -164,6 +164,9 @@ function createDatasetContext(parent, index, dataset) { get() { return this.datasetIndex; } + }, + type: { + value: 'dataset' } }); } @@ -187,6 +190,9 @@ function createDataContext(parent, index, point, element) { get() { return this.dataIndex; } + }, + type: { + value: 'data', } }); } diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 84cd4e3d5..eac35448a 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -274,6 +274,9 @@ function createScaleContext(parent, scale) { scale: { value: scale }, + type: { + value: 'scale' + } }); } @@ -284,6 +287,9 @@ function createTickContext(parent, index, tick) { }, index: { value: index + }, + type: { + value: 'tick' } }); }