in Hands-on lab/lab-files/starter-project/NorthwindMVC/wwwroot/lib/Chart.js/chart.js [11861:11944]
function generateTicks$1(generationOptions, dataRange) {
const ticks = [];
const MIN_SPACING = 1e-14;
const {bounds, step, min, max, precision, count, maxTicks, maxDigits, includeBounds} = generationOptions;
const unit = step || 1;
const maxSpaces = maxTicks - 1;
const {min: rmin, max: rmax} = dataRange;
const minDefined = !isNullOrUndef(min);
const maxDefined = !isNullOrUndef(max);
const countDefined = !isNullOrUndef(count);
const minSpacing = (rmax - rmin) / (maxDigits + 1);
let spacing = niceNum((rmax - rmin) / maxSpaces / unit) * unit;
let factor, niceMin, niceMax, numSpaces;
if (spacing < MIN_SPACING && !minDefined && !maxDefined) {
return [{value: rmin}, {value: rmax}];
}
numSpaces = Math.ceil(rmax / spacing) - Math.floor(rmin / spacing);
if (numSpaces > maxSpaces) {
spacing = niceNum(numSpaces * spacing / maxSpaces / unit) * unit;
}
if (!isNullOrUndef(precision)) {
factor = Math.pow(10, precision);
spacing = Math.ceil(spacing * factor) / factor;
}
if (bounds === 'ticks') {
niceMin = Math.floor(rmin / spacing) * spacing;
niceMax = Math.ceil(rmax / spacing) * spacing;
} else {
niceMin = rmin;
niceMax = rmax;
}
if (minDefined && maxDefined && step && almostWhole((max - min) / step, spacing / 1000)) {
numSpaces = Math.round(Math.min((max - min) / spacing, maxTicks));
spacing = (max - min) / numSpaces;
niceMin = min;
niceMax = max;
} else if (countDefined) {
niceMin = minDefined ? min : niceMin;
niceMax = maxDefined ? max : niceMax;
numSpaces = count - 1;
spacing = (niceMax - niceMin) / numSpaces;
} else {
numSpaces = (niceMax - niceMin) / spacing;
if (almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
numSpaces = Math.round(numSpaces);
} else {
numSpaces = Math.ceil(numSpaces);
}
}
const decimalPlaces = Math.max(
_decimalPlaces(spacing),
_decimalPlaces(niceMin)
);
factor = Math.pow(10, isNullOrUndef(precision) ? decimalPlaces : precision);
niceMin = Math.round(niceMin * factor) / factor;
niceMax = Math.round(niceMax * factor) / factor;
let j = 0;
if (minDefined) {
if (includeBounds && niceMin !== min) {
ticks.push({value: min});
if (niceMin < min) {
j++;
}
if (almostEquals(Math.round((niceMin + j * spacing) * factor) / factor, min, relativeLabelSize(min, minSpacing, generationOptions))) {
j++;
}
} else if (niceMin < min) {
j++;
}
}
for (; j < numSpaces; ++j) {
ticks.push({value: Math.round((niceMin + j * spacing) * factor) / factor});
}
if (maxDefined && includeBounds && niceMax !== max) {
if (almostEquals(ticks[ticks.length - 1].value, max, relativeLabelSize(max, minSpacing, generationOptions))) {
ticks[ticks.length - 1].value = max;
} else {
ticks.push({value: max});
}
} else if (!maxDefined || niceMax === max) {
ticks.push({value: niceMax});
}
return ticks;
}