]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
JSDoc and other cleanup (#7057)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Wed, 5 Feb 2020 13:27:02 +0000 (05:27 -0800)
committerGitHub <noreply@github.com>
Wed, 5 Feb 2020 13:27:02 +0000 (08:27 -0500)
src/core/core.interaction.js
src/core/core.layouts.js
src/core/core.plugins.js
src/elements/element.rectangle.js
src/plugins/plugin.tooltip.js
src/scales/scale.radialLinear.js

index ceda10d8c58ba9727b53f32ee47d01573357cf63..88c6cc3bd92860cfced77c170bed704a4ba57347 100644 (file)
@@ -117,7 +117,7 @@ function getDistanceMetricForAxis(axis) {
  * @param {Chart} chart - the chart
  * @param {object} position - the point to be nearest to
  * @param {string} axis - the axis mode. x|y|xy
- * @return {ChartElement[]} the nearest items
+ * @return {object[]} the nearest items
  */
 function getIntersectItems(chart, position, axis) {
        const items = [];
@@ -142,7 +142,7 @@ function getIntersectItems(chart, position, axis) {
  * @param {object} position - the point to be nearest to
  * @param {string} axis - the axes along which to measure distance
  * @param {boolean} [intersect] - if true, only consider items that intersect the position
- * @return {ChartElement[]} the nearest items
+ * @return {object[]} the nearest items
  */
 function getNearestItems(chart, position, axis, intersect) {
        const distanceMetric = getDistanceMetricForAxis(axis);
index ff8cc7d71da5701b81d23e7205795f9bb1cd3458..d56162bb25073998e653105f43e6cb15bbd75c2c 100644 (file)
@@ -1,9 +1,8 @@
 'use strict';
 
 import defaults from './core.defaults';
-import helpers from '../helpers';
-
-const extend = helpers.extend;
+import {each, extend} from '../helpers/helpers.core';
+import {toPadding} from '../helpers/helpers.options';
 
 const STATIC_POSITIONS = ['left', 'top', 'right', 'bottom'];
 
@@ -302,7 +301,7 @@ export default {
                }
 
                var layoutOptions = chart.options.layout || {};
-               var padding = helpers.options.toPadding(layoutOptions.padding);
+               var padding = toPadding(layoutOptions.padding);
 
                var availableWidth = width - padding.width;
                var availableHeight = height - padding.height;
@@ -385,7 +384,7 @@ export default {
                };
 
                // Finally update boxes in chartArea (radial scale for example)
-               helpers.each(boxes.chartArea, function(layout) {
+               each(boxes.chartArea, function(layout) {
                        var box = layout.box;
                        extend(box, chart.chartArea);
                        box.update(chartArea.w, chartArea.h);
index df5da2ec224586da0ea9d50d0b9d77312a4f8664..0ae1033b2240d72cae61244d9689860549c028f5 100644 (file)
@@ -176,20 +176,20 @@ export default {
 /**
  * @method IPlugin#beforeInit
  * @desc Called before initializing `chart`.
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  */
 /**
  * @method IPlugin#afterInit
  * @desc Called after `chart` has been initialized and before the first update.
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  */
 /**
  * @method IPlugin#beforeUpdate
  * @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.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  * @returns {boolean} `false` to cancel the chart update.
  */
@@ -197,13 +197,13 @@ export default {
  * @method IPlugin#afterUpdate
  * @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.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  */
 /**
  * @method IPlugin#reset
  * @desc Called during chart reset
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  * @since version 3.0.0
  */
@@ -211,7 +211,7 @@ export default {
  * @method IPlugin#beforeDatasetsUpdate
  * @desc Called before updating the `chart` datasets. If any plugin returns `false`,
  * the datasets update is cancelled until another `update` is triggered.
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  * @returns {boolean} false to cancel the datasets update.
  * @since version 2.1.5
@@ -220,7 +220,7 @@ export default {
  * @method IPlugin#afterDatasetsUpdate
  * @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.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  * @since version 2.1.5
  */
@@ -249,7 +249,7 @@ export default {
  * @method IPlugin#beforeLayout
  * @desc Called before laying out `chart`. If any plugin returns `false`,
  * the layout update is cancelled until another `update` is triggered.
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  * @returns {boolean} `false` to cancel the chart layout.
  */
@@ -257,14 +257,14 @@ export default {
  * @method IPlugin#afterLayout
  * @desc Called after the `chart` has been layed out. Note that this hook will not
  * be called if the layout update has been previously cancelled.
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  */
 /**
  * @method IPlugin#beforeRender
  * @desc Called before rendering `chart`. If any plugin returns `false`,
  * the rendering is cancelled until another `render` is triggered.
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  * @returns {boolean} `false` to cancel the chart rendering.
  */
@@ -272,14 +272,14 @@ export default {
  * @method IPlugin#afterRender
  * @desc Called after the `chart` has been fully rendered (and animation completed). Note
  * that this hook will not be called if the rendering has been previously cancelled.
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  */
 /**
  * @method IPlugin#beforeDraw
  * @desc Called before drawing `chart` at every animation frame. If any plugin returns `false`,
  * the frame drawing is cancelled untilanother `render` is triggered.
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  * @returns {boolean} `false` to cancel the chart drawing.
  */
@@ -287,14 +287,14 @@ export default {
  * @method IPlugin#afterDraw
  * @desc Called after the `chart` has been drawn. Note that this hook will not be called
  * if the drawing has been previously cancelled.
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  */
 /**
  * @method IPlugin#beforeDatasetsDraw
  * @desc Called before drawing the `chart` datasets. If any plugin returns `false`,
  * the datasets drawing is cancelled until another `render` is triggered.
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  * @returns {boolean} `false` to cancel the chart datasets drawing.
  */
@@ -302,7 +302,7 @@ export default {
  * @method IPlugin#afterDatasetsDraw
  * @desc Called after the `chart` datasets have been drawn. Note that this hook
  * will not be called if the datasets drawing has been previously cancelled.
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  */
 /**
@@ -351,7 +351,7 @@ export default {
  * @method IPlugin#beforeEvent
  * @desc Called before processing the specified `event`. If any plugin returns `false`,
  * the event will be discarded.
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {IEvent} event - The event object.
  * @param {object} options - The plugin options.
  */
@@ -359,20 +359,20 @@ export default {
  * @method IPlugin#afterEvent
  * @desc Called after the `event` has been consumed. Note that this hook
  * will not be called if the `event` has been previously discarded.
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {IEvent} event - The event object.
  * @param {object} options - The plugin options.
  */
 /**
  * @method IPlugin#resize
  * @desc Called after the chart as been resized.
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {number} size - The new canvas display size (eq. canvas.style width & height).
  * @param {object} options - The plugin options.
  */
 /**
  * @method IPlugin#destroy
  * @desc Called after the chart as been destroyed.
- * @param {Chart.Controller} chart - The chart instance.
+ * @param {Chart} chart - The chart instance.
  * @param {object} options - The plugin options.
  */
index 977b256977b46770c136b6b972df780937c5eb5d..b6aaeafe3294c72037aa181298694ccd58e70f41 100644 (file)
@@ -17,8 +17,8 @@ defaults._set('elements', {
 
 /**
  * Helper function to get the bounds of the bar regardless of the orientation
- * @param bar {Chart.Element.Rectangle} the bar
- * @return {Bounds} bounds of the bar
+ * @param bar {Rectangle} the bar
+ * @return {object} bounds of the bar
  * @private
  */
 function getBarBounds(bar) {
index 4659ded2951af15cea8dc672e1d2ba5a211fed90..be378e9fd4bc00142834088df6340fddb57a0bfc 100644 (file)
@@ -115,11 +115,11 @@ var positioners = {
        /**
         * Average mode places the tooltip at the average position of the elements shown
         * @function Chart.Tooltip.positioners.average
-        * @param elements {ChartElement[]} the elements being displayed in the tooltip
+        * @param items {object[]} the items being displayed in the tooltip
         * @returns {object} tooltip position
         */
-       average: function(elements) {
-               if (!elements.length) {
+       average: function(items) {
+               if (!items.length) {
                        return false;
                }
 
@@ -128,8 +128,8 @@ var positioners = {
                var y = 0;
                var count = 0;
 
-               for (i = 0, len = elements.length; i < len; ++i) {
-                       var el = elements[i].element;
+               for (i = 0, len = items.length; i < len; ++i) {
+                       var el = items[i].element;
                        if (el && el.hasValue()) {
                                var pos = el.tooltipPosition();
                                x += pos.x;
@@ -147,18 +147,18 @@ var positioners = {
        /**
         * Gets the tooltip position nearest of the item nearest to the event position
         * @function Chart.Tooltip.positioners.nearest
-        * @param elements {Chart.Element[]} the tooltip elements
+        * @param items {object[]} the tooltip items
         * @param eventPosition {object} the position of the event in canvas coordinates
         * @returns {object} the tooltip position
         */
-       nearest: function(elements, eventPosition) {
+       nearest: function(items, eventPosition) {
                var x = eventPosition.x;
                var y = eventPosition.y;
                var minDistance = Number.POSITIVE_INFINITY;
                var i, len, nearestElement;
 
-               for (i = 0, len = elements.length; i < len; ++i) {
-                       var el = elements[i].element;
+               for (i = 0, len = items.length; i < len; ++i) {
+                       var el = items[i].element;
                        if (el && el.hasValue()) {
                                var center = el.getCenterPoint();
                                var d = helpers.math.distanceBetweenPoints(eventPosition, center);
@@ -199,8 +199,8 @@ function pushOrConcat(base, toPush) {
 
 /**
  * Returns array of strings split by newline
- * @param {string} str - The value to split by newline.
- * @returns {string[]} value if newline present - Returned from String split() method
+ * @param {string|undefined} str - The value to split by newline.
+ * @returns {string|string[]} value if newline present - Returned from String split() method
  * @function
  */
 function splitNewlines(str) {
index 03d2c4163a341b77a5102c856a38dd73302ad40c..013091741e3f5ee4ffea524394785478f9d5451a 100644 (file)
@@ -329,8 +329,8 @@ class RadialLinearScale extends LinearScaleBase {
                LinearScaleBase.prototype.generateTickLabels.call(me, ticks);
 
                // Point labels
-               me.pointLabels = me.chart.data.labels.map(function() {
-                       var label = helpers.callback(me.options.pointLabels.callback, arguments, me);
+               me.pointLabels = me.chart.data.labels.map(function(value, index) {
+                       var label = helpers.callback(me.options.pointLabels.callback, [value, index], me);
                        return label || label === 0 ? label : '';
                });
        }