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

Method _getLabelCapacity

src/scales/scale.time.js:610–622  ·  view source on GitHub ↗

* @param {number} exampleTime * @return {number} * @private

(exampleTime)

Source from the content-addressed store, hash-verified

608 * @private
609 */
610 _getLabelCapacity(exampleTime) {
611 const timeOpts = this.options.time;
612 const displayFormats = timeOpts.displayFormats;
613
614 // pick the longest format (milliseconds) for guesstimation
615 const format = displayFormats[timeOpts.unit] || displayFormats.millisecond;
616 const exampleLabel = this._tickFormatFunction(exampleTime, 0, ticksFromTimestamps(this, [exampleTime], this._majorUnit), format);
617 const size = this._getLabelSize(exampleLabel);
618 // subtract 1 - if offset then there's one less label than tick
619 // if not offset then one half label padding is added to each end leaving room for one less label
620 const capacity = Math.floor(this.isHorizontal() ? this.width / size.w : this.height / size.h) - 1;
621 return capacity > 0 ? capacity : 1;
622 }
623
624 /**
625 * @protected

Callers 2

buildTicksMethod · 0.95
_generateMethod · 0.95

Calls 4

_tickFormatFunctionMethod · 0.95
_getLabelSizeMethod · 0.95
ticksFromTimestampsFunction · 0.85
isHorizontalMethod · 0.65

Tested by

no test coverage detected