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

Function _getStartAndCountOfVisiblePoints

src/helpers/helpers.extras.ts:88–136  ·  view source on GitHub ↗
(meta: ChartMeta<'line' | 'scatter'>, points: PointElement[], animationsDisabled: boolean)

Source from the content-addressed store, hash-verified

86 * @private
87 */
88export function _getStartAndCountOfVisiblePoints(meta: ChartMeta<'line' | 'scatter'>, points: PointElement[], animationsDisabled: boolean) {
89 const pointCount = points.length;
90
91 let start = 0;
92 let count = pointCount;
93
94 if (meta._sorted) {
95 const {iScale, vScale, _parsed} = meta;
96 const spanGaps = meta.dataset ? meta.dataset.options ? meta.dataset.options.spanGaps : null : null;
97 const axis = iScale.axis;
98 const {min, max, minDefined, maxDefined} = iScale.getUserBounds();
99
100 if (minDefined) {
101 start = Math.min(
102 // @ts-expect-error Need to type _parsed
103 _lookupByKey(_parsed, axis, min).lo,
104 // @ts-expect-error Need to fix types on _lookupByKey
105 animationsDisabled ? pointCount : _lookupByKey(points, axis, iScale.getPixelForValue(min)).lo);
106 if (spanGaps) {
107 const distanceToDefinedLo = (_parsed
108 .slice(0, start + 1)
109 .reverse()
110 .findIndex(
111 point => !isNullOrUndef(point[vScale.axis])));
112 start -= Math.max(0, distanceToDefinedLo);
113 }
114 start = _limitValue(start, 0, pointCount - 1);
115 }
116 if (maxDefined) {
117 let end = Math.max(
118 // @ts-expect-error Need to type _parsed
119 _lookupByKey(_parsed, iScale.axis, max, true).hi + 1,
120 // @ts-expect-error Need to fix types on _lookupByKey
121 animationsDisabled ? 0 : _lookupByKey(points, axis, iScale.getPixelForValue(max), true).hi + 1);
122 if (spanGaps) {
123 const distanceToDefinedHi = (_parsed
124 .slice(end - 1)
125 .findIndex(
126 point => !isNullOrUndef(point[vScale.axis])));
127 end += Math.max(0, distanceToDefinedHi);
128 }
129 count = _limitValue(end, start, pointCount) - start;
130 } else {
131 count = pointCount - start;
132 }
133 }
134
135 return {start, count};
136}
137
138/**
139 * Checks if the scale ranges have changed.

Callers 2

updateMethod · 0.85
updateMethod · 0.85

Calls 5

_lookupByKeyFunction · 0.85
isNullOrUndefFunction · 0.85
_limitValueFunction · 0.85
getUserBoundsMethod · 0.65
getPixelForValueMethod · 0.65

Tested by

no test coverage detected