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

Method _generate

src/scales/scale.time.js:450–489  ·  view source on GitHub ↗

* Generates a maximum of `capacity` timestamps between min and max, rounded to the * `minor` unit using the given scale time `options`. * Important: this method can return ticks outside the min and max range, it's the * responsibility of the calling code to clamp values if needed. * @protect

()

Source from the content-addressed store, hash-verified

448 * @protected
449 */
450 _generate() {
451 const adapter = this._adapter;
452 const min = this.min;
453 const max = this.max;
454 const options = this.options;
455 const timeOpts = options.time;
456 // @ts-ignore
457 const minor = timeOpts.unit || determineUnitForAutoTicks(timeOpts.minUnit, min, max, this._getLabelCapacity(min));
458 const stepSize = valueOrDefault(options.ticks.stepSize, 1);
459 const weekday = minor === 'week' ? timeOpts.isoWeekday : false;
460 const hasWeekday = isNumber(weekday) || weekday === true;
461 const ticks = {};
462 let first = min;
463 let time, count;
464
465 // For 'week' unit, handle the first day of week option
466 if (hasWeekday) {
467 first = +adapter.startOf(first, 'isoWeek', weekday);
468 }
469
470 // Align first ticks on unit
471 first = +adapter.startOf(first, hasWeekday ? 'day' : minor);
472
473 // Prevent browser from freezing in case user options request millions of milliseconds
474 if (adapter.diff(max, min, minor) > 100000 * stepSize) {
475 throw new Error(min + ' and ' + max + ' are too far apart with stepSize of ' + stepSize + ' ' + minor);
476 }
477
478 const timestamps = options.ticks.source === 'data' && this.getDataTimestamps();
479 for (time = first, count = 0; time < max; time = +adapter.add(time, stepSize, minor), count++) {
480 addTick(ticks, time, timestamps);
481 }
482
483 if (time === max || options.bounds === 'ticks' || count === 1) {
484 addTick(ticks, time, timestamps);
485 }
486
487 // @ts-ignore
488 return Object.keys(ticks).sort(sorter).map(x => +x);
489 }
490
491 /**
492 * @param {number} value

Callers 1

buildTicksMethod · 0.95

Calls 9

_getLabelCapacityMethod · 0.95
getDataTimestampsMethod · 0.95
valueOrDefaultFunction · 0.85
isNumberFunction · 0.85
addTickFunction · 0.85
startOfMethod · 0.65
diffMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected