Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an overflow option that will draw words even if they don't fit #37

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

john-guerra
Copy link

When creating word clouds in svgs with small sizes the big words (arguably the most important ones) might not be drawn because they won't fit. This change adds an overflow option to the wordcloud that will draw words even if they don't fit on the available space, this will truncate words, but at least will guarantee that the most significant word is (at least partially) displayed. The default value is false.

@jasondavies
Copy link
Owner

Related #36.

@SebT
Copy link

SebT commented Sep 22, 2017

@jasondavies Hi. First thanks for your work.

But why isn't this PR merged yet?

@ptandler
Copy link

I did some testing with this patch, and it works nicely in most cases. However, I noticed that it has a HUGE impact on performance when creating the word cloud. With overflow=true the time to create a 250-300 words cloud increased on my machine from something around 1-3 sec to 40-60 sec.

I'm not sure what exactly causes this dramatically increase, one thought is that it might be sufficient to only have the overflow option enabled for the first few biggest words, and not for every word in the cloud. But I didn't have the time to test this or to understand how the algorithm actually works ...

Does someone have any experiences with this option?

@bjuergens
Copy link

here is my guess why this takes so much longer: with this option instead of silently dropping the words, it tries to fit them in anyways. Which requires looking for collisions as well as actually placing the words, which are both things that will probably take a longer time, if more words are there to begin with. If you have many words, that would be dropped without overflow, than enabling overflow will slow down your code a lot.

My guess is that in your cloud with 250+ words, less than half are actually rendered. You can check the number of words that actually get rendered with something like this:

  .on("end", function(output) {
      if (word.length !== output.length) console.log(word.length - output.length)
   })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants