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

Method buildTicks

src/scales/scale.time.js:368–399  ·  view source on GitHub ↗

* @return {object[]}

()

Source from the content-addressed store, hash-verified

366 * @return {object[]}
367 */
368 buildTicks() {
369 const options = this.options;
370 const timeOpts = options.time;
371 const tickOpts = options.ticks;
372 const timestamps = tickOpts.source === 'labels' ? this.getLabelTimestamps() : this._generate();
373
374 if (options.bounds === 'ticks' && timestamps.length) {
375 this.min = this._userMin || timestamps[0];
376 this.max = this._userMax || timestamps[timestamps.length - 1];
377 }
378
379 const min = this.min;
380 const max = this.max;
381
382 const ticks = _filterBetween(timestamps, min, max);
383
384 // PRIVATE
385 // determineUnitForFormatting relies on the number of ticks so we don't use it when
386 // autoSkip is enabled because we don't yet know what the final number of ticks will be
387 this._unit = timeOpts.unit || (tickOpts.autoSkip
388 ? determineUnitForAutoTicks(timeOpts.minUnit, this.min, this.max, this._getLabelCapacity(min))
389 : determineUnitForFormatting(this, ticks.length, timeOpts.minUnit, this.min, this.max));
390 this._majorUnit = !tickOpts.major.enabled || this._unit === 'year' ? undefined
391 : determineMajorUnit(this._unit);
392 this.initOffsets(timestamps);
393
394 if (options.reverse) {
395 ticks.reverse();
396 }
397
398 return ticksFromTimestamps(this, ticks, this._majorUnit);
399 }
400
401 afterAutoSkip() {
402 // Offsets for bar charts need to be handled with the auto skipped

Callers

nothing calls this directly

Calls 9

getLabelTimestampsMethod · 0.95
_generateMethod · 0.95
_getLabelCapacityMethod · 0.95
initOffsetsMethod · 0.95
_filterBetweenFunction · 0.85
determineMajorUnitFunction · 0.85
ticksFromTimestampsFunction · 0.85

Tested by

no test coverage detected