]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix some JSDoc errors (#7026)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Mon, 3 Feb 2020 12:52:55 +0000 (04:52 -0800)
committerGitHub <noreply@github.com>
Mon, 3 Feb 2020 12:52:55 +0000 (07:52 -0500)
* Fix some JSDoc errors

* Fix helpers.dom JSDoc errors

* Add scale JSDoc errors

* Address review comment

* Fix additional errors

* Document optional parameters

* JSDoc fixes for datasetController

* Remove undefined

12 files changed:
src/core/core.controller.js
src/core/core.datasetController.js
src/core/core.interaction.js
src/core/core.scale.js
src/helpers/helpers.dom.js
src/platform/platform.base.js
src/plugins/plugin.filler.js
src/plugins/plugin.legend.js
src/plugins/plugin.tooltip.js
src/scales/scale.linearbase.js
src/scales/scale.logarithmic.js
src/scales/scale.time.js

index 3b98da0879bc861587fd47f6265c394fa579412d..ccae7a0443bef95c42ea4e40617dd9906846e65d 100644 (file)
@@ -981,7 +981,7 @@ class Chart {
        /**
         * Handle an event
         * @private
-        * @param {IEvent} event the event to handle
+        * @param {IEvent} e the event to handle
         * @return {boolean} true if the chart needs to re-render
         */
        handleEvent(e) {
index 2e1b31fb43400d6a7f003c6f5a28b27c419f60e3..1f8a6e7d36f632813ca530f8f7d7047f59a828ab 100644 (file)
@@ -461,7 +461,7 @@ helpers.extend(DatasetController.prototype, {
 
                // Re-sync meta data in case the user replaced the data array or if we missed
                // any updates and so make sure that we handle number of datapoints changing.
-               me.resyncElements(dataChanged | labelsChanged | scaleChanged | stackChanged);
+               me.resyncElements(dataChanged || labelsChanged || scaleChanged || stackChanged);
 
                // if stack changed, update stack values for the whole dataset
                if (stackChanged) {
@@ -783,7 +783,10 @@ helpers.extend(DatasetController.prototype, {
                me._cacheScaleStackStatus();
        },
 
-       update: helpers.noop,
+       /**
+        * @param {string} mode
+        */
+       update: function(mode) {}, // eslint-disable-line no-unused-vars
 
        draw: function() {
                const ctx = this._ctx;
@@ -820,6 +823,7 @@ helpers.extend(DatasetController.prototype, {
         * Returns a set of predefined style properties that should be used to represent the dataset
         * or the data if the index is specified
         * @param {number} index - data index
+        * @param {boolean} [active] - true if hover
         * @return {IStyleInterface} style object
         */
        getStyle: function(index, active) {
index 797dca4cd87084beece5562650219d74b5a22dc8..8927636ec3b49888f82202452d7cbf25ff17496e 100644 (file)
@@ -6,7 +6,7 @@ import {_lookup, _rlookup} from '../helpers/helpers.collection';
 
 /**
  * Helper function to get relative position for an event
- * @param {Event|IEvent} event - The event to get the position for
+ * @param {Event|IEvent} e - The event to get the position for
  * @param {Chart} chart - The chart
  * @returns {object} the event position
  */
@@ -47,7 +47,7 @@ function evaluateAllVisibleItems(chart, handler) {
  * @param {string} axis - the axis mide. x|y|xy
  * @param {number} value - the value to find
  * @param {boolean} intersect - should the element intersect
- * @returns {lo, hi} indices to search data array between
+ * @returns {{lo:number, hi:number}} indices to search data array between
  */
 function binarySearch(metaset, axis, value, intersect) {
        const {controller, data, _sorted} = metaset;
@@ -79,7 +79,7 @@ function binarySearch(metaset, axis, value, intersect) {
  * @param {string} axis - the axis mode. x|y|xy
  * @param {object} position - the point to be nearest to
  * @param {function} handler - the callback to execute for each visible item
- * @param {boolean} intersect - consider intersecting items
+ * @param {boolean} [intersect] - consider intersecting items
  */
 function optimizedEvaluateItems(chart, axis, position, handler, intersect) {
        const metasets = chart._getSortedVisibleDatasetMetas();
@@ -140,8 +140,8 @@ function getIntersectItems(chart, position, axis) {
  * Helper function to get the items nearest to the event position considering all visible items in the chart
  * @param {Chart} chart - the chart to look at elements from
  * @param {object} position - the point to be nearest to
- * @param {function} axis - the axes along which to measure distance
- * @param {boolean} intersect - if true, only consider items that intersect the position
+ * @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
  */
 function getNearestItems(chart, position, axis, intersect) {
index 9cd20d1c121c18131583b0ca22f029a2a1b84d56..92e6d7089c66841decf6bf82afbe54ce2c7ed78e 100644 (file)
@@ -299,7 +299,7 @@ class Scale extends Element {
         * Get the padding needed for the scale
         * @method getPadding
         * @private
-        * @returns {Padding} the necessary padding
+        * @returns {object} the necessary padding
         */
        getPadding() {
                const me = this;
@@ -491,6 +491,9 @@ class Scale extends Element {
        beforeBuildTicks() {
                call(this.options.beforeBuildTicks, [this]);
        }
+       /**
+        * @return {object[]} the ticks
+        */
        buildTicks() {}
        afterBuildTicks() {
                call(this.options.afterBuildTicks, [this]);
@@ -800,17 +803,15 @@ class Scale extends Element {
         * Returns the location of the given data point. Value can either be an index or a numerical value
         * The coordinate (0, 0) is at the upper-left corner of the canvas
         * @param value
-        * @param index
-        * @param datasetIndex
         */
-       getPixelForValue() {}
+       getPixelForValue(value) {} // eslint-disable-line no-unused-vars
 
        /**
         * Used to get the data value from a given pixel. This is the inverse of getPixelForValue
         * The coordinate (0, 0) is at the upper-left corner of the canvas
         * @param pixel
         */
-       getValueForPixel() {}
+       getValueForPixel(pixel) {} // eslint-disable-line no-unused-vars
 
        /**
         * Returns the location of the tick at the given index
index 4db17b6dc5b7939693c2182ba0821cd89e61c137..899dc086b3e225597139c0d5903bfcf88d8c2f7e 100644 (file)
@@ -39,6 +39,7 @@ function parseMaxStyle(styleValue, node, parentProperty) {
  * @param {HTMLElement} domNode - the node to check the constraint on
  * @param {string} maxStyle - the style that defines the maximum for the direction we are using ('max-width' / 'max-height')
  * @param {string} percentageProperty - property of parent to use when calculating width as a percentage
+ * @return {number|undefined} number or undefined if no constraint
  * @see {@link https://www.nathanaeljones.com/blog/2013/reading-max-width-cross-browser}
  */
 function getConstraintDimension(domNode, maxStyle, percentageProperty) {
@@ -55,8 +56,6 @@ function getConstraintDimension(domNode, maxStyle, percentageProperty) {
                        hasCNode ? parseMaxStyle(constrainedNode, domNode, percentageProperty) : infinity,
                        hasCContainer ? parseMaxStyle(constrainedContainer, parentNode, percentageProperty) : infinity);
        }
-
-       return 'none';
 }
 
 export function getStyle(el, property) {
@@ -65,12 +64,12 @@ export function getStyle(el, property) {
                document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
 }
 
-// returns Number or undefined if no constraint
+/** @return {number|undefined} number or undefined if no constraint */
 function getConstraintWidth(domNode) {
        return getConstraintDimension(domNode, 'max-width', 'clientWidth');
 }
 
-// returns Number or undefined if no constraint
+/** @return {number|undefined} number or undefined if no constraint */
 function getConstraintHeight(domNode) {
        return getConstraintDimension(domNode, 'max-height', 'clientHeight');
 }
index 5ef81f744987482d35ad4107c4619eccaf9f8d4d..3a62403ef282aa84dbc1df02c2ef2268a80026dc 100644 (file)
@@ -16,7 +16,7 @@ export default class BasePlatform {
         * @param {object} options - The chart options
         * @returns {CanvasRenderingContext2D} context2d instance
         */
-       acquireContext() {}
+       acquireContext(canvas, options) {} // eslint-disable-line no-unused-vars
 
        /**
         * Called at chart destruction time, releases any resources associated to the context
@@ -24,7 +24,7 @@ export default class BasePlatform {
         * @param {CanvasRenderingContext2D} context - The context2d instance
         * @returns {boolean} true if the method succeeded, else false
         */
-       releaseContext() {}
+       releaseContext(context) {} // eslint-disable-line no-unused-vars
 
        /**
         * Registers the specified listener on the given chart.
@@ -33,7 +33,7 @@ export default class BasePlatform {
         * @param {function} listener - Receives a notification (an object that implements
         * the {@link IEvent} interface) when an event of the specified type occurs.
         */
-       addEventListener() {}
+       addEventListener(chart, type, listener) {} // eslint-disable-line no-unused-vars
 
        /**
         * Removes the specified listener previously registered with addEventListener.
@@ -41,7 +41,7 @@ export default class BasePlatform {
         * @param {string} type - The ({@link IEvent}) type to remove
         * @param {function} listener - The listener function to remove from the event target.
         */
-       removeEventListener() {}
+       removeEventListener(chart, type, listener) {} // eslint-disable-line no-unused-vars
 
        /**
         * @returns {number} the current devicePixelRatio of the device this platform is connected to.
index 03ea9dcaa631ab6a1848210615bd52269792f281..f9343c655b4825a28549670acac65123046849ec 100644 (file)
@@ -47,7 +47,7 @@ function parseFillOption(line) {
 // @todo if (fill[0] === '#')
 function decodeFill(line, index, count) {
        const fill = parseFillOption(line);
-       let target = parseFloat(fill, 10);
+       let target = parseFloat(fill);
 
        if (isFinite(target) && Math.floor(target) === target) {
                if (fill[0] === '-' || fill[0] === '+') {
index 62c13efe182a0c9911381e8d26a78fd07fb14c10..4c0ebb4d36710f44462c949a51672f63761d4c91 100644 (file)
@@ -83,7 +83,7 @@ defaults._set('legend', {
 
 /**
  * Helper function to get the box width based on the usePointStyle option
- * @param {object} labelopts - the label options on the legend
+ * @param {object} labelOpts - the label options on the legend
  * @param {number} fontSize - the label font size
  * @return {number} width of the color box area
  */
@@ -616,8 +616,8 @@ class Legend extends Element {
 
        /**
         * Handle an event
+        * @param {IEvent} e - The event to handle
         * @private
-        * @param {IEvent} event - The event to handle
         */
        handleEvent(e) {
                var me = this;
index a1ef6f181cf00abc50f4a3edba113e211820af68..4659ded2951af15cea8dc672e1d2ba5a211fed90 100644 (file)
@@ -199,7 +199,7 @@ function pushOrConcat(base, toPush) {
 
 /**
  * Returns array of strings split by newline
- * @param {string} value - The value to split by newline.
+ * @param {string} str - The value to split by newline.
  * @returns {string[]} value if newline present - Returned from String split() method
  * @function
  */
@@ -959,7 +959,7 @@ class Tooltip extends Element {
        /**
         * Handle an event
         * @private
-        * @param {IEvent} event - The event to handle
+        * @param {IEvent} e - The event to handle
         * @returns {boolean} true if the tooltip changed
         */
        handleEvent(e) {
index 0932642dd36e67255ebdbc4e86a52256f3ae90c0..7ebbec0142e98e16ac5c2f8978bd32318d3081aa 100644 (file)
@@ -37,7 +37,7 @@ function niceNum(range, round) {
  * Generate a set of linear ticks
  * @param generationOptions the options used to generate the ticks
  * @param dataRange the range of the data
- * @returns {number[]} array of tick values
+ * @returns {object[]} array of tick objects
  */
 function generateTicks(generationOptions, dataRange) {
        const ticks = [];
index 33de08c9bc37616a2838d56a2846f1ddcbeb0c4c..2cd0d9f4a4b8836f20d555ecb4d20c0b78e90411 100644 (file)
@@ -19,7 +19,7 @@ function finiteOrDefault(value, def) {
  * Generate a set of logarithmic ticks
  * @param generationOptions the options used to generate the ticks
  * @param dataRange the range of the data
- * @returns {number[]} array of tick values
+ * @returns {object[]} array of tick objects
  */
 function generateTicks(generationOptions, dataRange) {
        const endExp = Math.floor(log10(dataRange.max));
index 8a3f20a07b2ee8d13fb41c92b8f04adf813d06ce..d93b190db99e3737fde26bf529f2fab7449b898b 100644 (file)
@@ -430,9 +430,9 @@ function getLabelBounds(scale) {
 /**
  * Return subset of `timestamps` between `min` and `max`.
  * Timestamps are assumend to be in sorted order.
- * @param {int[]} timestamps - array of timestamps
- * @param {int} min - min value (timestamp)
- * @param {int} max - max value (timestamp)
+ * @param {number[]} timestamps - array of timestamps
+ * @param {number} min - min value (timestamp)
+ * @param {number} max - max value (timestamp)
  */
 function filterBetween(timestamps, min, max) {
        let start = 0;