MCPcopy Create free account
hub / github.com/breck7/scroll / tickSpec

Function tickSpec

external/.d3.js:599–621  ·  view source on GitHub ↗
(start, stop, count)

Source from the content-addressed store, hash-verified

597 e2 = Math.sqrt(2);
598
599function tickSpec(start, stop, count) {
600 const step = (stop - start) / Math.max(0, count),
601 power = Math.floor(Math.log10(step)),
602 error = step / Math.pow(10, power),
603 factor = error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1;
604 let i1, i2, inc;
605 if (power < 0) {
606 inc = Math.pow(10, -power) / factor;
607 i1 = Math.round(start * inc);
608 i2 = Math.round(stop * inc);
609 if (i1 / inc < start) ++i1;
610 if (i2 / inc > stop) --i2;
611 inc = -inc;
612 } else {
613 inc = Math.pow(10, power) * factor;
614 i1 = Math.round(start / inc);
615 i2 = Math.round(stop / inc);
616 if (i1 * inc < start) ++i1;
617 if (i2 * inc > stop) --i2;
618 }
619 if (i2 < i1 && 0.5 <= count && count < 2) return tickSpec(start, stop, count * 2);
620 return [i1, i2, inc];
621}
622
623function ticks(start, stop, count) {
624 stop = +stop, start = +start, count = +count;

Callers 2

ticksFunction · 0.85
tickIncrementFunction · 0.85

Calls 1

maxMethod · 0.80

Tested by

no test coverage detected