UNPKG

on-codemerge

Version:

A WYSIWYG editor for on-codemerge is a user-friendly interface that allows users to edit and view their code in real time, exactly as it will appear in the final product

2 lines (1 loc) 1.77 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("./BaseChartRenderer.cjs"),P=require("../utils/validation.cjs");class m extends v.BaseChartRenderer{render(e,i,t){if(!P.validateChartData(i)){this.drawNoDataMessage(e,t);return}const l=this.normalizeData(i);if(!l.length){this.drawNoDataMessage(e,t);return}const{centerX:a,centerY:r,radius:n}=this.getCircleDimensions(t),s=l.reduce((g,o)=>g+(o.value||0),0);if(s<=0){this.drawNoDataMessage(e,t);return}this.drawSlices(e,l,s,a,r,n),this.drawLabels(e,l,s,a,r,n),this.drawCenterInfo(e,s,a,r)}normalizeData(e){var t;return e.length?"value"in e[0]?e:((t=e[0])==null?void 0:t.data)||[]:[]}drawSlices(e,i,t,l,a,r){let n=-Math.PI/2;i.forEach((s,g)=>{const o=s.value||0;if(o<=0)return;const u=o/t*(Math.PI*2),h=n+u;e.beginPath(),e.moveTo(l,a),e.arc(l,a,r,n,h),e.closePath();const f=s.color||this.colors[g%this.colors.length],d=e.createRadialGradient(l,a,0,l,a,r);d.addColorStop(0,this.colorWithOpacity(f,.8)),d.addColorStop(1,f),e.fillStyle=d,e.fill(),e.strokeStyle="#ffffff",e.lineWidth=2,e.stroke(),n=h})}drawLabels(e,i,t,l,a,r){let n=-Math.PI/2;i.forEach((s,g)=>{const o=s.value||0;if(o<=0)return;const u=o/t*(Math.PI*2),h=n+u/2,f=r*1.2,d=l+Math.cos(h)*f,M=a+Math.sin(h)*f;e.beginPath(),e.moveTo(l+Math.cos(h)*r,a+Math.sin(h)*r),e.lineTo(d,M),e.strokeStyle="#9ca3af",e.lineWidth=1,e.stroke(),e.fillStyle="#374151",e.textAlign=h<Math.PI?"left":"right",e.textBaseline="middle";const S=(o/t*100).toFixed(1);e.fillText(`${s.label||""} (${S}%)`,d,M),n+=u})}drawCenterInfo(e,i,t,l){e.textAlign="center",e.textBaseline="middle",e.fillStyle="#374151",e.font="bold 16px Inter, system-ui, sans-serif",e.fillText("Total",t,l-10),e.fillText(i.toLocaleString(),t,l+10)}}exports.PieChartRenderer=m;