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

Method determineDataLimits

src/scales/scale.time.js:311–348  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

309 }
310
311 determineDataLimits() {
312 const options = this.options;
313 const adapter = this._adapter;
314 const unit = options.time.unit || 'day';
315 // eslint-disable-next-line prefer-const
316 let {min, max, minDefined, maxDefined} = this.getUserBounds();
317
318 /**
319 * @param {object} bounds
320 */
321 function _applyBounds(bounds) {
322 if (!minDefined && !isNaN(bounds.min)) {
323 min = Math.min(min, bounds.min);
324 }
325 if (!maxDefined && !isNaN(bounds.max)) {
326 max = Math.max(max, bounds.max);
327 }
328 }
329
330 // If we have user provided `min` and `max` labels / data bounds can be ignored
331 if (!minDefined || !maxDefined) {
332 // Labels are always considered, when user did not force bounds
333 _applyBounds(this._getLabelBounds());
334
335 // If `bounds` is `'ticks'` and `ticks.source` is `'labels'`,
336 // data bounds are ignored (and don't need to be determined)
337 if (options.bounds !== 'ticks' || options.ticks.source !== 'labels') {
338 _applyBounds(this.getMinMax(false));
339 }
340 }
341
342 min = isFinite(min) && !isNaN(min) ? min : +adapter.startOf(Date.now(), unit);
343 max = isFinite(max) && !isNaN(max) ? max : +adapter.endOf(Date.now(), unit) + 1;
344
345 // Make sure that max is strictly higher than min (required by the timeseries lookup table)
346 this.min = Math.min(min, max - 1);
347 this.max = Math.max(min + 1, max);
348 }
349
350 /**
351 * @private

Callers

nothing calls this directly

Calls 5

_getLabelBoundsMethod · 0.95
getUserBoundsMethod · 0.65
getMinMaxMethod · 0.65
startOfMethod · 0.65
endOfMethod · 0.65

Tested by

no test coverage detected