in libs/display/graph.ts [189:261]
function generateSteps(start: number, end: number, numberOfTicks: number): number[] {
let bases = [1, 5, 2, 3]; // Tick bases selection
let currentBase: number;
let n: number;
let intervalSize: number, upperBound: number, lowerBound: number;
let nIntervals: number, nMaxIntervals: number;
let the_intervalsize = 0.1;
let exponentYmax =
Math.floor(Math.max(log10(Math.abs(start)), log10(Math.abs(end))));
let mantissaYmax = end / Math.pow(10.0, exponentYmax);
// now check if numbers can be cleaned...
// make it pretty
let significative_numbers = Math.min(3, Math.abs(exponentYmax) + 1);
let expo = Math.pow(10.0, significative_numbers);
let start_norm = Math.abs(start) * expo;
let end_norm = Math.abs(end) * expo;
let mant_norm = Math.abs(mantissaYmax) * expo;
// trunc ends
let ip_start = Math.floor(start_norm * Math.sign(start));
let ip_end = Math.ceil(end_norm * Math.sign(end));
start = ip_start;
end = ip_end;
mantissaYmax = Math.ceil(mant_norm);
nMaxIntervals = 0;
for (let k = 0; k < bases.length; ++k) {
// Loop initialisation
currentBase = bases[k];
n = 4; // This value only allows results smaller than about 1000 = 10^n
do // Tick vector length reduction
{
--n;
intervalSize = currentBase * Math.pow(10.0, exponentYmax - n);
upperBound =
Math.ceil(mantissaYmax * Math.pow(10.0, n) / currentBase)
* intervalSize;
nIntervals =
Math.ceil((upperBound - start) / intervalSize);
lowerBound = upperBound - nIntervals * intervalSize;
}
while (nIntervals > numberOfTicks);
if (nIntervals > nMaxIntervals) {
nMaxIntervals = nIntervals;
ip_start = ip_start = lowerBound;
ip_end = upperBound;
the_intervalsize = intervalSize;
}
}
// trunc ends
if (start < 0)
start = Math.floor(ip_start) / expo;
else
start = Math.ceil(ip_start) / expo;
if (end < 0)
end = Math.floor(ip_end) / expo;
else
end = Math.ceil(ip_end) / expo;
return [start, end, nMaxIntervals];
}