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

Function computeMinSampleSize

src/controllers/controller.bar.ts:149–178  ·  view source on GitHub ↗

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

(meta: BarMeta)

Source from the content-addressed store, hash-verified

147 * @private
148 */
149function computeMinSampleSize(meta: BarMeta): number {
150 const scale = meta.iScale;
151 const values = getAllScaleValues(scale, meta.type);
152 let min = scale._length;
153 let i: number, ilen: number, curr: number, prev: number | undefined;
154 const updateMinAndPrev = () => {
155 if (curr === 32767 || curr === -32768) {
156 // Ignore truncated pixels
157 return;
158 }
159 if (defined(prev)) {
160 // curr - prev === 0 is ignored
161 min = Math.min(min, Math.abs(curr - prev) || min);
162 }
163 prev = curr;
164 };
165
166 for (i = 0, ilen = values.length; i < ilen; ++i) {
167 curr = scale.getPixelForValue(values[i]);
168 updateMinAndPrev();
169 }
170
171 prev = undefined;
172 for (i = 0, ilen = scale.ticks.length; i < ilen; ++i) {
173 curr = scale.getPixelForTick(i);
174 updateMinAndPrev();
175 }
176
177 return min;
178}
179
180/**
181 * Computes an "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