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

Function nice

src/nice.js:3–23  ·  view source on GitHub ↗
(start, stop, count)

Source from the content-addressed store, hash-verified

1import {tickIncrement} from "./ticks.js";
2
3export default function nice(start, stop, count) {
4 let prestep;
5 while (true) {
6 const step = tickIncrement(start, stop, count);
7 if (step === prestep || step === 0 || !isFinite(step)) {
8 return [start, stop];
9 } else if (step > 0) {
10 const i = Math.ceil(start / step);
11 const j = Math.floor(stop / step);
12 start = (i - (i * step > start)) * step;
13 stop = (j + (j * step < stop)) * step;
14 } else if (step < 0) {
15 const s = -step;
16 const i = Math.ceil(start * s);
17 const j = Math.floor(stop * s);
18 start = (i - (i / s > start)) / s;
19 stop = (j + (j / s < stop)) / s;
20 }
21 prestep = step;
22 }
23}

Callers 2

nice-test.jsFile · 0.85
histogramFunction · 0.85

Calls 1

tickIncrementFunction · 0.90

Tested by

no test coverage detected