timdream / wordcloud2.js

Tag cloud/Wordle presentation on 2D canvas or HTML

Home Page:https://wordcloud2-js.timdream.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fatal Error On Hover

AbhiThakare opened this issue · comments

@timdream

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

commented

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.
image

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;

Thanks @alabama

I appreciate your help here!

Regards
Abhi

@timdream great library. It seems this fix has not been released. Could you please release it?