MCPcopy
hub / github.com/chartjs/Chart.js / computeMinSampleSize

Function computeMinSampleSize

src/controllers/controller.bar.js:24–53  ·  src/controllers/controller.bar.js::computeMinSampleSize

* Computes the "optimal" sample size to maintain bars equally sized while preventing overlap. * @private

(meta)

Source from the content-addressed store, hash-verified

22 * @private
23 */
24function computeMinSampleSize(meta) {
25 const scale = meta.iScale;
26 const values = getAllScaleValues(scale, meta.type);
27 let min = scale._length;
28 let i, ilen, curr, prev;
29 const updateMinAndPrev = () => {
30 if (curr === 32767 || curr === -32768) {
31 class="cm">// Ignore truncated pixels
32 return;
33 }
34 if (defined(prev)) {
35 class="cm">// curr - prev === 0 is ignored
36 min = Math.min(min, Math.abs(curr - prev) || min);
37 }
38 prev = curr;
39 };
40
41 for (i = 0, ilen = values.length; i < ilen; ++i) {
42 curr = scale.getPixelForValue(values[i]);
43 updateMinAndPrev();
44 }
45
46 prev = undefined;
47 for (i = 0, ilen = scale.ticks.length; i < ilen; ++i) {
48 curr = scale.getPixelForTick(i);
49 updateMinAndPrev();
50 }
51
52 return min;
53}
54
55/**
56 * Computes an class="st">"ideal" category based on the absolute bar thickness or, if undefined or null,

Callers 1

_getRulerMethod · 0.85

Calls 4

getAllScaleValuesFunction · 0.85
updateMinAndPrevFunction · 0.85
getPixelForValueMethod · 0.65
getPixelForTickMethod · 0.65

Tested by

no test coverage detected