/**
* @typedef { import("./core.controller").default } Chart
+ * @typedef {{value:any, label?:string, major?:boolean}} Tick
*/
defaults.set('scale', {
}
});
-/** Returns a new array containing numItems from arr */
+/**
+ * Returns a new array containing numItems from arr
+ * @param {any[]} arr
+ * @param {number} numItems
+ */
function sample(arr, numItems) {
const result = [];
const increment = arr.length / numItems;
return result;
}
+/**
+ * @param {Scale} scale
+ * @param {number} index
+ * @param {boolean} offsetGridLines
+ */
function getPixelForGridLine(scale, index, offsetGridLines) {
const length = scale.ticks.length;
const validIndex = Math.min(index, length - 1);
return lineValue;
}
+/**
+ * @param {object} caches
+ * @param {number} length
+ */
function garbageCollect(caches, length) {
each(caches, (cache) => {
const gc = cache.gc;
});
}
+/**
+ * @param {object} options
+ */
function getTickMarkLength(options) {
return options.drawTicks ? options.tickMarkLength : 0;
}
+/**
+ * @param {object} options
+ */
function getScaleLabelHeight(options) {
if (!options.display) {
return 0;
return font.lineHeight + padding.height;
}
+/**
+ * @param {number[]} arr
+ */
function getEvenSpacing(arr) {
const len = arr.length;
let i, diff;
return diff;
}
+/**
+ * @param {number[]} majorIndices
+ * @param {Tick[]} ticks
+ * @param {number} axisLength
+ * @param {number} ticksLimit
+ */
function calculateSpacing(majorIndices, ticks, axisLength, ticksLimit) {
const evenMajorSpacing = getEvenSpacing(majorIndices);
const spacing = ticks.length / ticksLimit;
return Math.max(spacing, 1);
}
+/**
+ * @param {Tick[]} ticks
+ */
function getMajorIndices(ticks) {
const result = [];
let i, ilen;
return result;
}
+/**
+ * @param {Tick[]} ticks
+ * @param {Tick[]} newTicks
+ * @param {number[]} majorIndices
+ * @param {number} spacing
+ */
function skipMajors(ticks, newTicks, majorIndices, spacing) {
let count = 0;
let next = majorIndices[0];
}
}
+/**
+ * @param {Tick[]} ticks
+ * @param {Tick[]} newTicks
+ * @param {number} spacing
+ * @param {number} [majorStart]
+ * @param {number} [majorEnd]
+ */
function skip(ticks, newTicks, spacing, majorStart, majorEnd) {
const start = valueOrDefault(majorStart, 0);
const end = Math.min(valueOrDefault(majorEnd, ticks.length), ticks.length);
this.labelRotation = undefined;
this.min = undefined;
this.max = undefined;
- /** @type {object[]} */
+ /** @type {Tick[]} */
this.ticks = [];
/** @type {object[]|null} */
this._gridLineItems = null;
}
/**
- * Returns the scale tick objects ({label, major})
- * @return {object[]}
+ * Returns the scale tick objects
+ * @return {Tick[]}
* @since 2.7
*/
getTicks() {
}
/**
* Convert ticks to label strings
- * @param {object[]} ticks
+ * @param {Tick[]} ticks
*/
generateTickLabels(ticks) {
const me = this;
}
/**
- * @param {object[]} ticks
+ * @param {Tick[]} ticks
* @private
*/
_convertTicksToLabels(ticks) {
/**
* Returns a subset of ticks to be plotted to avoid overlapping labels.
- * @param {object[]} ticks
- * @return {object[]}
+ * @param {Tick[]} ticks
+ * @return {Tick[]}
* @private
*/
_autoSkip(ticks) {
const alignBorderValue = function(pixel) {
return _alignPixel(chart, pixel, axisWidth);
};
- let borderValue, i, tick, lineValue, alignedLineValue;
+ let borderValue, i, lineValue, alignedLineValue;
let tx1, ty1, tx2, ty2, x1, y1, x2, y2;
if (position === 'top') {
}
for (i = 0; i < ticksLength; ++i) {
- tick = ticks[i] || {};
+ /** @type {Tick|object} */
+ const tick = ticks[i] || {};
context = {
scale: me,