MCPcopy Create free account
hub / github.com/d3/d3-array / tickSpec

Function tickSpec

src/ticks.js:5–27  ·  view source on GitHub ↗
(start, stop, count)

Source from the content-addressed store, hash-verified

3 e2 = Math.sqrt(2);
4
5function tickSpec(start, stop, count) {
6 const step = (stop - start) / Math.max(0, count),
7 power = Math.floor(Math.log10(step)),
8 error = step / Math.pow(10, power),
9 factor = error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1;
10 let i1, i2, inc;
11 if (power < 0) {
12 inc = Math.pow(10, -power) / factor;
13 i1 = Math.round(start * inc);
14 i2 = Math.round(stop * inc);
15 if (i1 / inc < start) ++i1;
16 if (i2 / inc > stop) --i2;
17 inc = -inc;
18 } else {
19 inc = Math.pow(10, power) * factor;
20 i1 = Math.round(start / inc);
21 i2 = Math.round(stop / inc);
22 if (i1 * inc < start) ++i1;
23 if (i2 * inc > stop) --i2;
24 }
25 if (i2 < i1 && 0.5 <= count && count < 2) return tickSpec(start, stop, count * 2);
26 return [i1, i2, inc];
27}
28
29export default function ticks(start, stop, count) {
30 stop = +stop, start = +start, count = +count;

Callers 2

ticksFunction · 0.85
tickIncrementFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…