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
3 lines (2 loc) • 2.79 kB
JavaScript
/*! on-codemerge v1.3.1 @author Pavel Kuzmin @license MIT @homepage https://s00d.github.io/on-codemerge/ @repository git+https://github.com/s00d/on-codemerge.git Copyright (c) 2026 Pavel Kuzmin - Built on 2026-07-02T13:39:17.947Z */
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./BaseChartRenderer.cjs");class S extends P.BaseChartRenderer{render(e,d,l){if(!d||d.length===0){this.drawNoDataMessage(e,l);return}const a=d.filter(i=>i.value>0),o=a.reduce((i,f)=>i+f.value,0);if(o<=0||a.length===0){this.drawNoDataMessage(e,l);return}const s=l.orientation||"vertical",{centerX:g,centerY:r,radius:t}=this.getCircleDimensions(l);this.drawBackground(e,l),this.drawTitle(e,l),s==="vertical"?(this.drawVerticalSlices(e,a,o,g,r,t,l),this.drawVerticalLabels(e,a,o,g,r,t,l)):(this.drawHorizontalSlices(e,a,o,g,r,t,l),this.drawHorizontalLabels(e,a,o,g,r,t,l)),this.drawAxisLabels(e,l),this.drawLegend(e,d,l)}drawVerticalSlices(e,d,l,a,o,s,g){let r=-Math.PI/2;const t=this.getColors(g);d.forEach((i,f)=>{if(!i.value||i.value<=0)return;const n=i.value/l*(Math.PI*2),u=r+n;e.beginPath(),e.moveTo(a,o),e.arc(a,o,s,r,u),e.closePath();const v=i.color||t[f%t.length],h=e.createRadialGradient(a,o,0,a,o,s);h.addColorStop(0,this.colorWithOpacity(v,.8)),h.addColorStop(1,v),e.fillStyle=h,e.fill(),e.strokeStyle="#ffffff",e.lineWidth=2,e.stroke(),r=u})}drawHorizontalSlices(e,d,l,a,o,s,g){let r=Math.PI/2;const t=this.getColors(g);d.forEach((i,f)=>{if(!i.value||i.value<=0)return;const n=i.value/l*(Math.PI*2),u=r+n;e.beginPath(),e.moveTo(a,o),e.arc(a,o,s,r,u),e.closePath();const v=i.color||t[f%t.length],h=e.createRadialGradient(a,o,0,a,o,s);h.addColorStop(0,this.colorWithOpacity(v,.8)),h.addColorStop(1,v),e.fillStyle=h,e.fill(),e.strokeStyle="#ffffff",e.lineWidth=2,e.stroke(),r=u})}drawVerticalLabels(e,d,l,a,o,s,g){let r=-Math.PI/2;d.forEach((t,i)=>{if(!t.value||t.value<=0)return;const f=t.value/l*(Math.PI*2),n=r+f/2,u=s*1.2,v=a+Math.cos(n)*u,h=o+Math.sin(n)*u;e.beginPath(),e.moveTo(a+Math.cos(n)*s,o+Math.sin(n)*s),e.lineTo(v,h),e.strokeStyle="#9ca3af",e.lineWidth=1,e.stroke(),e.fillStyle=this.getTextColor(g),e.textAlign=n<Math.PI?"left":"right",e.textBaseline="middle";const M=(t.value/l*100).toFixed(1);e.fillText(`${t.label} (${M}%)`,v,h),r+=f})}drawHorizontalLabels(e,d,l,a,o,s,g){let r=Math.PI/2;d.forEach((t,i)=>{if(!t.value||t.value<=0)return;const f=t.value/l*(Math.PI*2),n=r+f/2,u=s*1.2,v=a+Math.cos(n)*u,h=o+Math.sin(n)*u;e.beginPath(),e.moveTo(a+Math.cos(n)*s,o+Math.sin(n)*s),e.lineTo(v,h),e.strokeStyle="#9ca3af",e.lineWidth=1,e.stroke(),e.fillStyle=this.getTextColor(g),e.textAlign=n<Math.PI?"left":"right",e.textBaseline="middle";const M=(t.value/l*100).toFixed(1);e.fillText(`${t.label} (${M}%)`,v,h),r+=f})}}exports.PieChartRenderer=S;