in src/visualComponent/axes/helpers/axisHelper.ts [433:507]
export function getRecommendedTickValuesForAQuantitativeRange(
maxTicks: number,
scale: ScaleLinear<number, number>,
minInterval?: number,
shouldTheMinValueBeIncluded: boolean = false): number[] {
let tickLabels: number[] = [];
// if maxticks is zero return none
if (maxTicks === 0) {
return tickLabels;
}
if (scale.ticks) {
if (shouldTheMinValueBeIncluded && scale.domain) {
const domain: number[] = scale.domain();
const minValue: number = domain[0];
const maxValue: number = domain[1] !== undefined && domain[1] !== null
? domain[1]
: minValue;
const span: number = Math.abs(maxValue - minValue);
let step: number = Math.pow(10, Math.floor(Math.log(span / maxTicks) / Math.LN10));
const err: number = maxTicks / span * step;
if (err <= .15) {
step *= 10;
} else if (err <= .35) {
step *= 5;
} else if (err <= .75) {
step *= 2;
}
if (!isNaN(step) && isFinite(step)) {
tickLabels = d3Range(minValue, maxValue, step);
}
} else {
tickLabels = scale.ticks(maxTicks);
if (tickLabels.length > maxTicks && maxTicks > 1) {
tickLabels = scale.ticks(maxTicks - 1);
}
if (tickLabels.length < MinTickCount) {
tickLabels = scale.ticks(maxTicks + 1);
}
}
tickLabels = createTrueZeroTickLabel(tickLabels);
if (minInterval && tickLabels.length > 1) {
let tickInterval: number = tickLabels[1] - tickLabels[0];
while (tickInterval > 0 && tickInterval < minInterval) {
for (let i = 1; i < tickLabels.length; i++) {
tickLabels.splice(i, 1);
}
tickInterval = tickInterval * 2;
}
if (tickLabels.length === 1) {
tickLabels.push(tickLabels[0] + minInterval);
}
}
return tickLabels;
}
return tickLabels;
}