Fatal Error On Hover
AbhiThakare opened this issue · comments
I really appreciate your work for workdcloud2, its amazing plugin.
Whenever I hover an empty area of a wordcloud canvas, sometimes I keep on receiving this error:
Uncaught TypeError: Cannot read property [ANY NUMBER] of undefined
Do you have any workaround for this?
Regards
Abhi
Hey!
really nice work with workcloud2!
So what i also experienced was through the gridSize and rectangle calculation you can end up with floating rect positions: (top, right, left, bottom);
When hovering/clicking you calculate the position and get the element through the filled infoGrid.
But in the code it is assumed that x will always have an entry and that throws the error.
Fix would be to either to set a min of 0 for x or do some kind of defensive approach and check if x exists in infoGrid.
In function getInfoGridFromMouseTouchEvent
var eventX = Math.max(clientX - rect.left, 0);
var eventY = Math.max(clientY - rect.top, 0);
... or ...
var info = null;
if (infoGrid[x] && infoGrid[x][y]) {
info = infoGrid[x][y];
}
return info;