Skip to content

Commit e456f10

Browse files
committed
fix: prevent undefined errors
1 parent 83fcd45 commit e456f10

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/charting/data/DataSet.ts

+19-16
Original file line numberDiff line numberDiff line change
@@ -320,29 +320,32 @@ export abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
320320
// Search by closest to y-value
321321
if (closest >= 1 && !isNaN(closestToY)) {
322322
e = Utils.getArrayItem(values, closest - 1);
323-
xValue = getEntryXValue(e, xKey, closest - 1);
324-
while (closest > 0 && xValue === closestXValue) closest -= 1;
323+
if (e) {
324+
xValue = getEntryXValue(e, xKey, closest - 1);
325+
while (closest > 0 && xValue === closestXValue) closest -= 1;
325326

326-
let closestYValue = Utils.getArrayItem(values, closest)[yKey];
327-
let closestYIndex = closest;
327+
let closestYValue = Utils.getArrayItem(values, closest)[yKey];
328+
let closestYIndex = closest;
328329

329-
// eslint-disable-next-line no-constant-condition
330-
while (true) {
331-
closest += 1;
332-
if (closest >= values.length) break;
330+
// eslint-disable-next-line no-constant-condition
331+
while (true) {
332+
closest += 1;
333+
if (closest >= values.length) break;
333334

334-
e = Utils.getArrayItem(values, closest);
335-
xValue = getEntryXValue(e, xKey, closest);
335+
e = Utils.getArrayItem(values, closest);
336+
if (!e) break;
337+
xValue = getEntryXValue(e, xKey, closest);
336338

337-
if (xValue !== closestXValue) break;
339+
if (xValue !== closestXValue) break;
338340

339-
if (Math.abs(e[yKey] - closestToY) < Math.abs(closestYValue - closestToY)) {
340-
closestYValue = closestToY;
341-
closestYIndex = closest;
341+
if (Math.abs(e[yKey] - closestToY) < Math.abs(closestYValue - closestToY)) {
342+
closestYValue = closestToY;
343+
closestYIndex = closest;
344+
}
342345
}
343-
}
344346

345-
closest = closestYIndex;
347+
closest = closestYIndex;
348+
}
346349
}
347350
}
348351

0 commit comments

Comments
 (0)