lucaong / jQCloud

jQuery plugin for drawing neat word clouds that actually look like clouds
MIT License
647 stars 293 forks source link

Ensuring words fit within word cloud container #35

Open Moussa opened 11 years ago

Moussa commented 11 years ago

Is there a way to ensure all the words fit within the container and not spill out/get clipped off? Can the font sizes for each span weighting be calculated such that after rendering everything fits within the container boundaries?

lucaong commented 11 years ago

Hello, This would be an awesome addition to jQCloud. Unfortunately it is far from trivial to implement. One simple possibility would be to add an option for not drawing at all words which would overflow the container. While this would work, it would be obviously suboptimal, giving no guarantee on which words would appear in the cloud. Scaling down the font-size and redrawing the cloud until it fits would work too, but would be terribly inefficient for large clouds. If anyone has an idea that could work I'll be very happy to add this.

Luca

On 21/feb/2013, at 01:34, Moussekateer notifications@github.com wrote:

Is there a way to ensure all the words fit within the container and not spill out/get clipped off? Can the font sizes for each span weighting be calculated such that after rendering everything fits within the container boundaries?

— Reply to this email directly or view it on GitHub.

Moussa commented 11 years ago

I thought this might be difficult to implement. How about a 'binary search' attempt to redrawing the cloud? Such that it gets redrawn at most a few times before the text fits. This is still pretty inefficient for large word clouds but seems feasible for users like me who produce a lot of relatively small word clouds. Just throwing ideas out there.

The real issue with my word clouds is when I have one or two weight 10 words, many weight 5 and a few weight 1 or 2. The abundance of weight 5s means hardly any words fit in the container. In this situation it would be ideal to ignore the weight 1/2's and scale down the others to weight 5s and weight 1s. Perhaps situations like these can be detected and processed before rendering? So that the words will almost certainly fit at the cost of losing some low weighted ones.

drewB commented 11 years ago

I think having option to not draw words that would be cut off would be a nice step until a more robust solution is created. I would be happy to work on a pull request for that. I am thinking at https://github.com/lucaong/jQCloud/blob/master/src/jqcloud/jqcloud.js.erb#L182 we test to see if the style would put any of the words outside the container and if so remove the word.

lucaong commented 11 years ago

That's actually a good option. I would definitely support this feature.

On Monday, May 6, 2013, Drew Batshaw wrote:

I think having option to not draw words that would be cut off would be a nice step until a more robust solution is created. I would be happy to work on a pull request for that. I am thinking at https://github.com/lucaong/jQCloud/blob/master/src/jqcloud/jqcloud.js.erb#L182we test to see if the style would put any of the words outside the container and if so remove the word.

— Reply to this email directly or view it on GitHubhttps://github.com/lucaong/jQCloud/issues/35#issuecomment-17508809 .

drewB commented 11 years ago

I have implemented this in https://github.com/lucaong/jQCloud/pull/39

drewB commented 11 years ago

I would say the one downside to dropping words is it will end up dropping the larger words while you would rather drop smaller words if you are going to drop any. Still better than having words cut off but I do think a more robust solution would be good.

One option that may be cheaper than trying to redraw everything again would be to automatically drop the base font size whenever we find a word is about to be rendered outside the container.