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

Function drawFunnelText

front/components/u-charts/u-charts.js:3935–4001  ·  view source on GitHub ↗
(series, opts, context, eachSpacing, labelAlign,activeWidth, centerPosition)

Source from the content-addressed store, hash-verified

3933}
3934
3935function drawFunnelText(series, opts, context, eachSpacing, labelAlign,activeWidth, centerPosition){
3936 for(let i=0;i<series.length;i++){
3937 let item = series[i];
3938 let startX,endX,startY,fontSize;
3939 let text = item.format ? item.format(+item._proportion_.toFixed(2)) : util.toFixed(item._proportion_ * 100) +'%';
3940 if(labelAlign == 'right'){
3941 if(i==0){
3942 startX=(item.funnelArea[2]+centerPosition.x)/2;
3943 }else{
3944 startX=(item.funnelArea[2]+series[i-1].funnelArea[2])/2;
3945 }
3946 endX=startX+activeWidth*2;
3947 startY=item.funnelArea[1]+eachSpacing/2;
3948 fontSize = item.textSize || opts.fontSize;
3949 context.setLineWidth(1 * opts.pixelRatio);
3950 context.setStrokeStyle(item.color);
3951 context.setFillStyle(item.color);
3952 context.beginPath();
3953 context.moveTo(startX,startY );
3954 context.lineTo(endX,startY);
3955 context.stroke();
3956 context.closePath();
3957 context.beginPath();
3958 context.moveTo(endX, startY);
3959 context.arc(endX, startY, 2, 0, 2 * Math.PI);
3960 context.closePath();
3961 context.fill();
3962 context.beginPath();
3963 context.setFontSize(fontSize);
3964 context.setFillStyle(item.textColor || '#666666');
3965 context.fillText(text, endX+5, startY + fontSize/2 -2);
3966 context.closePath();
3967 context.stroke();
3968 context.closePath();
3969 }else{
3970 if(i==0){
3971 startX=(item.funnelArea[0]+centerPosition.x)/2;
3972 }else{
3973 startX=(item.funnelArea[0]+series[i-1].funnelArea[0])/2;
3974 }
3975 endX=startX-activeWidth*2;
3976 startY=item.funnelArea[1]+eachSpacing/2;
3977 fontSize = item.textSize || opts.fontSize;
3978 context.setLineWidth(1 * opts.pixelRatio);
3979 context.setStrokeStyle(item.color);
3980 context.setFillStyle(item.color);
3981 context.beginPath();
3982 context.moveTo(startX,startY );
3983 context.lineTo(endX,startY);
3984 context.stroke();
3985 context.closePath();
3986 context.beginPath();
3987 context.moveTo(endX, startY);
3988 context.arc(endX, startY, 2, 0, 2 * Math.PI);
3989 context.closePath();
3990 context.fill();
3991 context.beginPath();
3992 context.setFontSize(fontSize);

Callers 1

drawFunnelDataPointsFunction · 0.85

Calls 1

measureTextFunction · 0.85

Tested by

no test coverage detected