From f85daa3d6e814a682148384afb1a5f903c457c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Em=C4=ABls=20Gulbis?= Date: Mon, 7 Oct 2019 14:45:16 +0300 Subject: [PATCH] Fix: Sometimes index === -1 Sometimes when mouse-overing container, i got `vendors.app.js:8427 Uncaught TypeError: Cannot read property 'xPos' of undefined` that is caused by `-1` index --- src/js/charts/AxisChart.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/js/charts/AxisChart.js b/src/js/charts/AxisChart.js index 39a2b8b9..5e91fa8f 100644 --- a/src/js/charts/AxisChart.js +++ b/src/js/charts/AxisChart.js @@ -405,17 +405,19 @@ export default class AxisChart extends BaseChart { if(!s.yExtremes) return; let index = getClosestInArray(relX, s.xAxis.positions, true); - let dbi = this.dataByIndex[index]; - - this.tip.setValues( - dbi.xPos + this.tip.offset.x, - dbi.yExtreme + this.tip.offset.y, - {name: dbi.formattedLabel, value: ''}, - dbi.values, - index - ); - - this.tip.showTip(); + if (index >= 0) { + let dbi = this.dataByIndex[index]; + + this.tip.setValues( + dbi.xPos + this.tip.offset.x, + dbi.yExtreme + this.tip.offset.y, + {name: dbi.formattedLabel, value: ''}, + dbi.values, + index + ); + + this.tip.showTip(); + } } renderLegend() {