Skip to content

Commit 4bb92bf

Browse files
committed
Review comments, additional fixes
1 parent 9776bae commit 4bb92bf

File tree

10 files changed

+107
-62
lines changed

10 files changed

+107
-62
lines changed

docs/developers/plugins.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,6 @@ var chart = new Chart(ctx, {
104104
});
105105
```
106106

107-
## Plugin Core API
107+
## Plugin Core API
108108

109-
Read more about the [existing plugin extension hooks](../jsdoc/IPlugin.html).
109+
Read more about the [existing plugin extension hooks](../typedoc/IPlugin.html).

docs/getting-started/v3-migration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Animation system was completely rewritten in Chart.js v3. Each property can now
9393
* `Chart.offsetY`
9494
* `Chart.outerRadius`
9595
* `Chart.prototype.generateLegend`
96+
* `Chart.radiusLength`
9697
* `Chart.types`
9798
* `Chart.Tooltip` is now provided by the tooltip plugin. The positioners can be accessed from `tooltipPlugin.positioners`
9899
* `DatasetController.addElementAndReset`

src/controllers/controller.doughnut.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ function getRatioAndOffset(rotation, circumference, cutout) {
132132

133133
class DoughnutController extends DatasetController {
134134

135+
/**
136+
* @param {Chart} chart
137+
* @param {number} datasetIndex
138+
*/
135139
constructor(chart, datasetIndex) {
136140
super(chart, datasetIndex);
137141

@@ -145,6 +149,8 @@ class DoughnutController extends DatasetController {
145149

146150
/**
147151
* Override data parsing, since we are not using scales
152+
* @param {number} start
153+
* @param {number} count
148154
* @private
149155
*/
150156
_parse(start, count) {
@@ -156,7 +162,10 @@ class DoughnutController extends DatasetController {
156162
}
157163
}
158164

159-
// Get index of the dataset in relation to the visible datasets. This allows determining the inner and outer radius correctly
165+
/**
166+
* Get index of the dataset in relation to the visible datasets. This allows determining the inner and outer radius correctly
167+
* @param {number} datasetIndex
168+
*/
160169
getRingIndex(datasetIndex) {
161170
var ringIndex = 0;
162171

@@ -174,7 +183,6 @@ class DoughnutController extends DatasetController {
174183
*/
175184
update(mode) {
176185
const me = this;
177-
/** @type {Chart} */
178186
const chart = me.chart;
179187
const {chartArea, options} = chart;
180188
const meta = me._cachedMeta;
@@ -202,6 +210,9 @@ class DoughnutController extends DatasetController {
202210

203211
/**
204212
* @private
213+
* @param {number} i
214+
* @param {boolean} reset
215+
* @return {number}
205216
*/
206217
_circumference(i, reset) {
207218
const me = this;
@@ -218,7 +229,6 @@ class DoughnutController extends DatasetController {
218229
updateElements(arcs, start, mode) {
219230
const me = this;
220231
const reset = mode === 'reset';
221-
/** @type {Chart} */
222232
const chart = me.chart;
223233
const chartArea = chart.chartArea;
224234
const opts = chart.options;
@@ -260,6 +270,9 @@ class DoughnutController extends DatasetController {
260270
me._updateSharedOptions(sharedOptions, mode);
261271
}
262272

273+
/**
274+
* @return {number}
275+
*/
263276
calculateTotal() {
264277
const meta = this._cachedMeta;
265278
const metaData = meta.data;
@@ -278,6 +291,7 @@ class DoughnutController extends DatasetController {
278291

279292
/**
280293
* @param {number} value
294+
* @return {number}
281295
*/
282296
calculateCircumference(value) {
283297
var total = this._cachedMeta.total;
@@ -288,8 +302,9 @@ class DoughnutController extends DatasetController {
288302
}
289303

290304
/**
291-
* gets the max border or hover width to properly scale pie charts
305+
* Gets the max border or hover width to properly scale pie charts
292306
* @param {Arc[]} [arcs]
307+
* @return {number}
293308
*/
294309
getMaxBorderWidth(arcs) {
295310
var me = this;
@@ -328,6 +343,7 @@ class DoughnutController extends DatasetController {
328343
/**
329344
* Get radius length offset of the dataset in relation to the visible datasets weights. This allows determining the inner and outer radius correctly
330345
* @param {number} datasetIndex
346+
* @return {number}
331347
* @private
332348
*/
333349
_getRingWeightOffset(datasetIndex) {
@@ -344,6 +360,7 @@ class DoughnutController extends DatasetController {
344360

345361
/**
346362
* @param {number} datasetIndex
363+
* @return {number}
347364
* @private
348365
*/
349366
_getRingWeight(datasetIndex) {
@@ -352,6 +369,7 @@ class DoughnutController extends DatasetController {
352369

353370
/**
354371
* Returns the sum of all visibile data set weights. This value can be 0.
372+
* @return {number}
355373
* @private
356374
*/
357375
_getVisibleDatasetWeightTotal() {

src/controllers/controller.polarArea.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ class PolarAreaController extends DatasetController {
130130
var opts = chart.options;
131131
var minSize = Math.min(chartArea.right - chartArea.left, chartArea.bottom - chartArea.top);
132132

133-
chart.outerRadius = Math.max(minSize / 2, 0);
134-
chart.innerRadius = Math.max(opts.cutoutPercentage ? (chart.outerRadius / 100) * (opts.cutoutPercentage) : 1, 0);
135-
chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
133+
const outerRadius = Math.max(minSize / 2, 0);
134+
const innerRadius = Math.max(opts.cutoutPercentage ? (outerRadius / 100) * (opts.cutoutPercentage) : 1, 0);
135+
const radiusLength = (outerRadius - innerRadius) / chart.getVisibleDatasetCount();
136136

137-
me.outerRadius = chart.outerRadius - (chart.radiusLength * me.index);
138-
me.innerRadius = me.outerRadius - chart.radiusLength;
137+
me.outerRadius = outerRadius - (radiusLength * me.index);
138+
me.innerRadius = me.outerRadius - radiusLength;
139139
}
140140

141141
updateElements(arcs, start, mode) {

src/core/core.controller.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import scaleService from '../core/core.scaleService';
1212

1313
/**
1414
* @typedef { import("../platform/platform.base").IEvent } IEvent
15+
* @typedef { import("./core.interaction").InteractionItem} InteractionItem
1516
*/
1617

1718
const valueOrDefault = helpers.valueOrDefault;
@@ -790,10 +791,11 @@ class Chart {
790791
}
791792

792793
/**
793-
* @param {IEvent} e
794-
* @param {string} mode
795-
* @param {any} options
796-
* @param {boolean} [useFinalPosition]
794+
* @param {IEvent} e - the event
795+
* @param {string} mode - interaction mode
796+
* @param {import('./core.interaction').InteractionOptions} options - options
797+
* @param {boolean} [useFinalPosition] - evaluate elements by their final position (animation target)
798+
* @return {InteractionItem[]}
797799
*/
798800
getElementsAtEventForMode(e, mode, options, useFinalPosition) {
799801
const method = Interaction.modes[mode];
@@ -969,7 +971,7 @@ class Chart {
969971
}
970972

971973
/**
972-
* @param {{datasetIndex: number, index: number, element: Element}[]} items
974+
* @param {InteractionItem[]} items
973975
* @param {string} mode
974976
* @param {boolean} enabled
975977
*/
@@ -1010,8 +1012,9 @@ class Chart {
10101012
}
10111013

10121014
/**
1013-
* @param {IEvent} e
1014-
* @param {boolean} [replay]
1015+
* @param {IEvent} e - the event
1016+
* @param {boolean} [replay] - true if the event was replayed by `update`
1017+
* @return {Chart}
10151018
* @private
10161019
*/
10171020
_eventHandler(e, replay) {
@@ -1033,22 +1036,23 @@ class Chart {
10331036
/**
10341037
* Handle an event
10351038
* @param {IEvent} e the event to handle
1036-
* @param {boolean} [replay]
1039+
* @param {boolean} [replay] - true if the event was replayed by `update`
10371040
* @return {boolean} true if the chart needs to re-render
10381041
* @private
10391042
*/
10401043
_handleEvent(e, replay) {
10411044
const me = this;
10421045
const options = me.options;
10431046
const hoverOptions = options.hover;
1047+
const useFinalPosition = replay;
10441048
let changed = false;
10451049

10461050
// Find Active Elements for hover and tooltips
10471051
if (e.type === 'mouseout') {
10481052
me.active = [];
10491053
me._lastEvent = null;
10501054
} else {
1051-
me.active = me.getElementsAtEventForMode(e, hoverOptions.mode, hoverOptions, replay);
1055+
me.active = me.getElementsAtEventForMode(e, hoverOptions.mode, hoverOptions, useFinalPosition);
10521056
me._lastEvent = e.type === 'click' ? me._lastEvent : e;
10531057
}
10541058

src/core/core.datasetController.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import Animations from './core.animations';
55

66
const resolve = helpers.options.resolve;
77

8+
/**
9+
* @typedef { import("../core/core.controller").default } Chart
10+
* @typedef { import("../core/core.element").default } Element
11+
* @typedef {{ target: object, options: object }} SharedOptions
12+
*/
13+
814
const arrayEvents = ['push', 'pop', 'shift', 'splice', 'unshift'];
915

1016
/**
@@ -217,6 +223,10 @@ function getFirstScaleId(chart, axis) {
217223

218224
class DatasetController {
219225

226+
/**
227+
* @param {Chart} chart
228+
* @param {number} datasetIndex
229+
*/
220230
constructor(chart, datasetIndex) {
221231
this.chart = chart;
222232
this._ctx = chart.ctx;
@@ -953,6 +963,10 @@ class DatasetController {
953963

954964
/**
955965
* Utility for checking if the options are shared and should be animated separately.
966+
* @param {string} mode
967+
* @param {Element} el
968+
* @param {{ $shared?: boolean }} options
969+
* @return {SharedOptions}
956970
* @private
957971
*/
958972
_getSharedOptions(mode, el, options) {
@@ -968,7 +982,8 @@ class DatasetController {
968982
/**
969983
* Utility for determining if `options` should be included in the updated properties
970984
* @param {string} mode
971-
* @param {{ target: any; options: any; }} sharedOptions
985+
* @param {SharedOptions} sharedOptions
986+
* @return {boolean}
972987
* @private
973988
*/
974989
_includeOptions(mode, sharedOptions) {
@@ -980,7 +995,7 @@ class DatasetController {
980995

981996
/**
982997
* Utility for updating a element with new properties, using animations when appropriate.
983-
* @param {import("../core/core.element").default} element
998+
* @param {Element} element
984999
* @param {number} index
9851000
* @param {object} properties
9861001
* @param {string} mode
@@ -996,7 +1011,7 @@ class DatasetController {
9961011

9971012
/**
9981013
* Utility to animate the shared options, that are potentially affecting multiple elements.
999-
* @param {{ target: any; options: any; }} sharedOptions
1014+
* @param {SharedOptions} sharedOptions
10001015
* @param {string} mode
10011016
* @private
10021017
*/
@@ -1007,7 +1022,7 @@ class DatasetController {
10071022
}
10081023

10091024
/**
1010-
* @param {import("../core/core.element").default} element
1025+
* @param {Element} element
10111026
* @param {number} index
10121027
* @param {string} mode
10131028
* @param {boolean} active
@@ -1019,7 +1034,7 @@ class DatasetController {
10191034
}
10201035

10211036
/**
1022-
* @param {import("../core/core.element").default} element
1037+
* @param {Element} element
10231038
* @param {number} datasetIndex
10241039
* @param {number} index
10251040
*/
@@ -1028,7 +1043,7 @@ class DatasetController {
10281043
}
10291044

10301045
/**
1031-
* @param {import("../core/core.element").default} element
1046+
* @param {Element} element
10321047
* @param {number} datasetIndex
10331048
* @param {number} index
10341049
*/
@@ -1105,7 +1120,12 @@ class DatasetController {
11051120
me.updateElements(elements, start, 'reset');
11061121
}
11071122

1108-
updateElements(element, start, mode) {} // eslint-disable-line no-unused-vars
1123+
/**
1124+
* @param {Element[]} elements
1125+
* @param {number} start
1126+
* @param {string} mode
1127+
*/
1128+
updateElements(elements, start, mode) {} // eslint-disable-line no-unused-vars
11091129

11101130
/**
11111131
* @private

src/core/core.element.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,27 @@
33
import {extend, inherits} from '../helpers/helpers.core';
44
import {isNumber} from '../helpers/helpers.math';
55

6+
/**
7+
* @typedef {import("./core.animation").default} Animation
8+
*/
9+
610
class Element {
711

812
/**
9-
* @param {object} [cfg] optional configuration
13+
* @param {{x?: number, y?: number, hidden?: boolean, active?: boolean, options?: object}} [cfg] optional configuration
1014
*/
1115
constructor(cfg) {
16+
/** @type {number} */
1217
this.x = undefined;
18+
/** @type {number} */
1319
this.y = undefined;
14-
this.hidden = undefined;
15-
this.active = undefined;
20+
/** @type {boolean} */
21+
this.hidden = false;
22+
/** @type {boolean} */
23+
this.active = false;
24+
/** @type {object} */
25+
this.options = undefined;
26+
/** @type {Animation[]} */
1627
this.$animations = undefined;
1728

1829
if (cfg) {

0 commit comments

Comments
 (0)