MCPcopy Create free account
hub / github.com/chartjs/Chart.js / determineUnitForFormatting

Function determineUnitForFormatting

src/scales/scale.time.js:111–120  ·  view source on GitHub ↗

* Figures out what unit to format a set of ticks with * @param {TimeScale} scale * @param {number} numTicks * @param {Unit} minUnit * @param {number} min * @param {number} max * @return {Unit}

(scale, numTicks, minUnit, min, max)

Source from the content-addressed store, hash-verified

109 * @return {Unit}
110 */
111function determineUnitForFormatting(scale, numTicks, minUnit, min, max) {
112 for (let i = UNITS.length - 1; i >= UNITS.indexOf(minUnit); i--) {
113 const unit = UNITS[i];
114 if (INTERVALS[unit].common && scale._adapter.diff(max, min, unit) >= numTicks - 1) {
115 return unit;
116 }
117 }
118
119 return UNITS[minUnit ? UNITS.indexOf(minUnit) : 0];
120}
121
122/**
123 * @param {Unit} unit

Callers 1

buildTicksMethod · 0.85

Calls 1

diffMethod · 0.65

Tested by

no test coverage detected