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

Method initOffsets

src/scales/scale.time.js:417–441  ·  view source on GitHub ↗

* Returns the start and end offsets from edges in the form of {start, end} * where each value is a relative width to the scale and ranges between 0 and 1. * They add extra margins on the both sides by scaling down the original scale. * Offsets are added when the `offset` option is true. * @p

(timestamps = [])

Source from the content-addressed store, hash-verified

415 * @protected
416 */
417 initOffsets(timestamps = []) {
418 let start = 0;
419 let end = 0;
420 let first, last;
421
422 if (this.options.offset && timestamps.length) {
423 first = this.getDecimalForValue(timestamps[0]);
424 if (timestamps.length === 1) {
425 start = 1 - first;
426 } else {
427 start = (this.getDecimalForValue(timestamps[1]) - first) / 2;
428 }
429 last = this.getDecimalForValue(timestamps[timestamps.length - 1]);
430 if (timestamps.length === 1) {
431 end = last;
432 } else {
433 end = (last - this.getDecimalForValue(timestamps[timestamps.length - 2])) / 2;
434 }
435 }
436 const limit = timestamps.length < 3 ? 0.5 : 0.25;
437 start = _limitValue(start, 0, limit);
438 end = _limitValue(end, 0, limit);
439
440 this._offsets = {start, end, factor: 1 / (start + 1 + end)};
441 }
442
443 /**
444 * Generates a maximum of `capacity` timestamps between min and max, rounded to the

Callers 2

buildTicksMethod · 0.95
afterAutoSkipMethod · 0.95

Calls 2

getDecimalForValueMethod · 0.95
_limitValueFunction · 0.85

Tested by

no test coverage detected