MCPcopy Create free account
hub / github.com/CoderOpen/waimai / getWordCloudPoint

Function getWordCloudPoint

front/components/u-charts/u-charts.js:3701–3773  ·  view source on GitHub ↗
(opts,type)

Source from the content-addressed store, hash-verified

3699}
3700
3701function getWordCloudPoint(opts,type){
3702 let points = opts.series.sort(function(a,b){return parseInt(b.textSize)-parseInt(a.textSize);});
3703 switch (type) {
3704 case 'normal':
3705 for (let i = 0; i < points.length; i++) {
3706 let text = points[i].name;
3707 let tHeight = points[i].textSize;
3708 let tWidth = measureText(text,tHeight);
3709 let x,y;
3710 let area;
3711 let breaknum=0;
3712 while(true) {
3713 breaknum++;
3714 x = normalInt(-opts.width/2, opts.width/2,5) - tWidth/2;
3715 y = normalInt(-opts.height/2, opts.height/2,5) + tHeight/2;
3716 area=[x-5+opts.width/2,y-5-tHeight+opts.height/2,x+tWidth+5+opts.width/2,y+5+opts.height/2];
3717 let isCollision = collisionNew(area,points,opts.width,opts.height);
3718 if (!isCollision) break;
3719 if (breaknum==1000){
3720 area=[-100,-100,-100,-100];
3721 break;
3722 }
3723 };
3724 points[i].area=area;
3725 }
3726 break;
3727 case 'vertical':
3728 function Spin(){
3729 //获取均匀随机值,是否旋转,旋转的概率为(1-0.5)
3730 if (Math.random()>0.7) {
3731 return true;
3732 }else {return false};
3733 };
3734 for (let i = 0; i < points.length; i++) {
3735 let text = points[i].name;
3736 let tHeight = points[i].textSize;
3737 let tWidth = measureText(text,tHeight);
3738 let isSpin = Spin();
3739 let x,y,area,areav;
3740 let breaknum=0;
3741 while(true) {
3742 breaknum++;
3743 let isCollision;
3744 if (isSpin) {
3745 x = normalInt(-opts.width/2, opts.width/2,5) - tWidth/2;
3746 y = normalInt(-opts.height/2, opts.height/2,5)+tHeight/2;
3747 area=[y-5-tWidth+opts.width/2,(-x-5+opts.height/2),y+5+opts.width/2,(-x+tHeight+5+opts.height/2)];
3748 areav=[opts.width-(opts.width/2-opts.height/2)-(-x+tHeight+5+opts.height/2)-5,(opts.height/2-opts.width/2)+(y-5-tWidth+opts.width/2)-5,opts.width-(opts.width/2-opts.height/2)-(-x+tHeight+5+opts.height/2)+tHeight,(opts.height/2-opts.width/2)+(y-5-tWidth+opts.width/2)+tWidth+5];
3749 isCollision = collisionNew(areav,points,opts.height,opts.width);
3750 }else{
3751 x = normalInt(-opts.width/2, opts.width/2,5) - tWidth/2;
3752 y = normalInt(-opts.height/2, opts.height/2,5)+tHeight/2;
3753 area=[x-5+opts.width/2,y-5-tHeight+opts.height/2,x+tWidth+5+opts.width/2,y+5+opts.height/2];
3754 isCollision = collisionNew(area,points,opts.width,opts.height);
3755 }
3756 if (!isCollision) break;
3757 if (breaknum==1000){
3758 area=[-1000,-1000,-1000,-1000];

Callers 1

drawChartsFunction · 0.85

Calls 4

measureTextFunction · 0.85
normalIntFunction · 0.85
collisionNewFunction · 0.85
SpinFunction · 0.85

Tested by

no test coverage detected