@@ -320,29 +320,32 @@ export abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
320
320
// Search by closest to y-value
321
321
if ( closest >= 1 && ! isNaN ( closestToY ) ) {
322
322
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 ;
325
326
326
- let closestYValue = Utils . getArrayItem ( values , closest ) [ yKey ] ;
327
- let closestYIndex = closest ;
327
+ let closestYValue = Utils . getArrayItem ( values , closest ) [ yKey ] ;
328
+ let closestYIndex = closest ;
328
329
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 ;
333
334
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 ) ;
336
338
337
- if ( xValue !== closestXValue ) break ;
339
+ if ( xValue !== closestXValue ) break ;
338
340
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
+ }
342
345
}
343
- }
344
346
345
- closest = closestYIndex ;
347
+ closest = closestYIndex ;
348
+ }
346
349
}
347
350
}
348
351
0 commit comments