wordcloud2.js icon indicating copy to clipboard operation
wordcloud2.js copied to clipboard

Can't read list from huge variable

Open ammoradi opened this issue 7 years ago • 8 comments

I couldn't pass list through a huge variable even using Promise / setTimout. I have an array in the format of [['txt',123],...] and it has about 2000 items. my code :

$(document).ready(() => {
    let xhr = new XMLHttpRequest();
    let xhrPromise = new Promise((resolve, reject) => {
        xhr.onreadystatechange = function() {
            if (xhr.readyState == XMLHttpRequest.DONE) {
                resolve(xhr.responseText);
            }
        }
        xhr.open('GET', 'http://sth.com', true);
        xhr.send(null);
    }).then(result => {
        setTimeout(() => {
            WordCloud(document.getElementById('my_canvas'), { list: result } );
        },2000)
    })
})

and i will see :

Uncaught DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The source width is 0. at getTextInfo (http://localhost:8080/wordcloud.js:612:34) at putWord (http://localhost:8080/wordcloud.js:913:24) at Array.loop (http://localhost:8080/wordcloud.js:1179:29) at setZeroTimeoutMessage (http://localhost:8080/wordcloud.js:53:34)

p.s : I checked your source code using console.log() and I found the fontWeight couldn't be generated and it is NaN

I Sliced result to (0,10) but also gave me same error.

Then I tried to push some statics data on list it worked for about 20 items but didn't work for more than 100 items.

ammoradi avatar Apr 20 '18 22:04 ammoradi

DId it work outside of Promise/setTimeout? It’s unlikey that it breaks just because it’s in a Promise/setTimeout.

timdream avatar Apr 21 '18 00:04 timdream

@timdream no it didn't work

your module is sync and xhr req is async then i used Promise ( i thought maybe the list first passed to module then filled with xhr ... )

ammoradi avatar Apr 21 '18 17:04 ammoradi

Probably because the list itself is faulty. If you post it here people will be able to see what's wrong.

timdream avatar Apr 22 '18 16:04 timdream

@timdream ok i'll send it . But I tested that list in static mode and it was correct ( but for a list with more than 400 item it didn't work )

ammoradi avatar Apr 22 '18 18:04 ammoradi

Any news about this?

lucasa avatar Oct 20 '18 16:10 lucasa

@lucasa nothing! i used another library...

ammoradi avatar Oct 21 '18 17:10 ammoradi

@ammoradi Which library did you use?

raviraj16 avatar Jan 03 '19 13:01 raviraj16

@raviraj16 i used d3-cloud library. an implementation example could be found here.

ammoradi avatar Jan 03 '19 15:01 ammoradi