mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
JSDoc and other cleanup (#7057)
This commit is contained in:
parent
c79e8090e8
commit
f9cd9fdf76
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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.
|
||||
*/
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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 : '';
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user