export default function(domain, count, specifier) { var start = domain[0], stop = domain[domain.length - 1], step = tickStep(start, stop, count == null ? 10 : count); if (specifier == null) { specifier = ",." + precisionFixed(step) + "f"; } else { switch (specifier = formatSpecifier(specifier), specifier.type) { case "s": { var value = Math.max(Math.abs(start), Math.abs(stop)); if (specifier.precision == null) specifier.precision = precisionPrefix(step, value); return formatPrefix(specifier, value); } case "": case "e": case "g": case "p": case "r": { if (specifier.precision == null) specifier.precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))) - (specifier.type === "e"); break; } case "f": case "%": { if (specifier.precision == null) specifier.precision = precisionFixed(step) - (specifier.type === "%") * 2; break; } } } return format(specifier); };
scale.nice = function(count) { var d = domain(), i = d.length - 1, n = count == null ? 10 : count, start = d[0], stop = d[i], step = tickStep(start, stop, n); if (step) { step = tickStep(Math.floor(start / step) * step, Math.ceil(stop / step) * step, n); d[0] = Math.floor(start / step) * step; d[i] = Math.ceil(stop / step) * step; domain(d); } return scale; };
function tickInterval(interval, start, stop, step) { if (interval == null) interval = 10; // If a desired tick count is specified, pick a reasonable tick interval // based on the extent of the domain and a rough estimate of tick size. // Otherwise, assume interval is already a time interval and use it. if (typeof interval === "number") { var target = Math.abs(stop - start) / interval, i = bisector(function(i) { return i[2]; }).right(tickIntervals, target); if (i === tickIntervals.length) { step = tickStep(start / durationYear, stop / durationYear, interval); interval = year; } else if (i) { i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i]; step = i[1]; interval = i[0]; } else { step = Math.max(tickStep(start, stop, interval), 1); interval = millisecond; } } return step == null ? interval : interval.every(step); }