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

Function ticker

external/.d3.js:15951–15992  ·  view source on GitHub ↗
(year, month, week, day, hour, minute)

Source from the content-addressed store, hash-verified

15949const utcYears = utcYear.range;
15950
15951function ticker(year, month, week, day, hour, minute) {
15952
15953 const tickIntervals = [
15954 [second, 1, durationSecond],
15955 [second, 5, 5 * durationSecond],
15956 [second, 15, 15 * durationSecond],
15957 [second, 30, 30 * durationSecond],
15958 [minute, 1, durationMinute],
15959 [minute, 5, 5 * durationMinute],
15960 [minute, 15, 15 * durationMinute],
15961 [minute, 30, 30 * durationMinute],
15962 [ hour, 1, durationHour ],
15963 [ hour, 3, 3 * durationHour ],
15964 [ hour, 6, 6 * durationHour ],
15965 [ hour, 12, 12 * durationHour ],
15966 [ day, 1, durationDay ],
15967 [ day, 2, 2 * durationDay ],
15968 [ week, 1, durationWeek ],
15969 [ month, 1, durationMonth ],
15970 [ month, 3, 3 * durationMonth ],
15971 [ year, 1, durationYear ]
15972 ];
15973
15974 function ticks(start, stop, count) {
15975 const reverse = stop < start;
15976 if (reverse) [start, stop] = [stop, start];
15977 const interval = count && typeof count.range === "function" ? count : tickInterval(start, stop, count);
15978 const ticks = interval ? interval.range(start, +stop + 1) : []; // inclusive stop
15979 return reverse ? ticks.reverse() : ticks;
15980 }
15981
15982 function tickInterval(start, stop, count) {
15983 const target = Math.abs(stop - start) / count;
15984 const i = bisector(([,, step]) => step).right(tickIntervals, target);
15985 if (i === tickIntervals.length) return year.every(tickStep(start / durationYear, stop / durationYear, count));
15986 if (i === 0) return millisecond.every(Math.max(tickStep(start, stop, count), 1));
15987 const [t, step] = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
15988 return t.every(step);
15989 }
15990
15991 return [ticks, tickInterval];
15992}
15993
15994const [utcTicks, utcTickInterval] = ticker(utcYear, utcMonth, utcSunday, unixDay, utcHour, utcMinute);
15995const [timeTicks, timeTickInterval] = ticker(timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute);

Callers 1

.d3.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected