wvengen / d3-wordcloud

Plug-and-play wordcloud with D3
MIT License
81 stars 66 forks source link

Font size differs from render to render #5

Open okravchuk opened 7 years ago

okravchuk commented 7 years ago

It's very noticable for "service" word. Scale is different in <g> tag, "transform" attribute Text used for chart: "Great service. Kept ringing. Good data plan for my business needs. Great service. I can't complain. I would like the latest and greatest and it doesn't offer that. Slow service as well. They do a wonderful job. OK. Excellent service! Settle claims quickly. Every single problem has always been solved promptly. Accessibility, responsiveness, professionalism, and knowledge. Not so sure I liked the service."

default default

Thanks, Oleksiy

wvengen commented 7 years ago

It looks like the relative sizes of the fonts could still match. Would this be caused by #6, in the sence that a different random seed / order of picking words and laying them out results in a different total size, which results in different font sizes when scaled back to the desired size?

okravchuk commented 7 years ago

I fixed this for myself with replacing

  scaling = bounds ? Math.min(
    w / Math.abs(bounds[1].x - w / 2),
    w / Math.abs(bounds[0].x - w / 2),
    h / Math.abs(bounds[1].y - h / 2),
    h / Math.abs(bounds[0].y - h / 2)) / 2 : 1;

with scaling = 1;

because scaling used in vis.transition() .attr("transform", "translate(" + [w >> 1, h >> 1] + ")scale(" + scaling + ")");

in d3.wordcloud.js

wvengen commented 7 years ago

Thanks, this could be an improvement, to make the scaling optional.

okravchuk commented 7 years ago

But drawback is that too much space left from actual chart drawing to borders of whole chart placeholder.

okravchuk commented 7 years ago

As you mentioned - this case can be fixed due to fix of case #6.