echarts-wordcloud
echarts-wordcloud copied to clipboard
shape可以支持矩形吗
shape可以支持矩形吗? 目前的square和diamond一样都是菱形
实际上菱形和矩形的算法是一样的,当词汇足够多的时候,就会沿着矩形的两条对角线不断堆积,最终形成完整的矩形。
你可以调整一些东西来完善这个形状,比如说提高字体尺寸的上限,让频次高的词更多的占据主轴,同时也可以提高下限,让低频词的占位体积大一些,更快的填充形状。同时你可以试试调大间距(gridSize),或者缩小 canvas 的整体尺寸。
说白了就是词不够多。
wordcloud2 (https://github.com/timdream/wordcloud2.js)原生支持矩形, 在echarts-wordcloud中指定shape为下面的callback function, 是可以绘制出矩形的,echarts-wordcloud却不支持‘square’参数,而且在数据足够多的时候 无论指定任何形状, 都会绘制出矩形,这是个bug吧?
function shapeSquare(theta) { return Math.min( 1 / Math.abs(Math.cos(theta)), 1 / Math.abs(Math.sin(theta)) ); };
echart-wordcloud现有的对shape的实现中 diamond和square是同样的逻辑 case 'diamond': case 'square': // http://www.wolframalpha.com/input/?i=plot+r+%3D+1%2F%28cos%28mod+ // %28t%2C+PI%2F2%29%29%2Bsin%28mod+%28t%2C+PI%2F2%29%29%29%2C+t+%3D // +0+..+2*PI settings.shape = function shapeSquare(theta) { var thetaPrime = theta % (2 * Math.PI / 4); return 1 / (Math.cos(thetaPrime) + Math.sin(thetaPrime)); }; break;
@nightire
function shapeSquare(theta) { return Math.min( 1 / Math.abs(Math.cos(theta)), 1 / Math.abs(Math.sin(theta)) ); };
亲测可用,谢谢老哥。
@ToughRover 多谢,这方面的算法我还真不擅长。
This is a bug. Through the gridsize adjustment, a rectangle can be formed, but the word display will be incomplete when the chart drawing area is small. For example, there are 100 words, but only 50 words will be displayed. I'm trying to solve it. Markimage configuration item