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

3 lines (2 loc) 3.19 kB
/*! 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 */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("./BaseChartRenderer.cjs");class P extends S.BaseChartRenderer{render(e,d,l){if(!d||d.length===0){this.drawNoDataMessage(e,l);return}const t=d.filter(o=>o.value>0),r=t.reduce((o,i)=>o+i.value,0);if(r<=0||t.length===0){this.drawNoDataMessage(e,l);return}const s=l.orientation||"vertical",{centerX:n,centerY:h,radius:a}=this.getCircleDimensions(l),g=a*.6;this.drawBackground(e,l),this.drawTitle(e,l),s==="vertical"?(this.drawVerticalSlices(e,t,r,n,h,a,g,l),this.drawVerticalLabels(e,t,r,n,h,a,l)):(this.drawHorizontalSlices(e,t,r,n,h,a,g,l),this.drawHorizontalLabels(e,t,r,n,h,a,l)),this.drawCenterInfo(e,r,n,h,g,l),this.drawAxisLabels(e,l),this.drawLegend(e,d,l)}drawVerticalSlices(e,d,l,t,r,s,n,h){let a=-Math.PI/2;const g=this.getColors(h);d.forEach((o,i)=>{if(!o.value||o.value<=0)return;const M=o.value/l*(Math.PI*2),f=a+M;e.beginPath(),e.arc(t,r,s,a,f),e.arc(t,r,n,f,a,!0),e.closePath();const u=o.color||g[i%g.length],v=e.createRadialGradient(t,r,n,t,r,s);v.addColorStop(0,this.colorWithOpacity(u,.8)),v.addColorStop(1,u),e.fillStyle=v,e.fill(),e.strokeStyle="#ffffff",e.lineWidth=2,e.stroke(),a=f})}drawHorizontalSlices(e,d,l,t,r,s,n,h){let a=Math.PI/2;const g=this.getColors(h);d.forEach((o,i)=>{if(!o.value||o.value<=0)return;const M=o.value/l*(Math.PI*2),f=a+M;e.beginPath(),e.arc(t,r,s,a,f),e.arc(t,r,n,f,a,!0),e.closePath();const u=o.color||g[i%g.length],v=e.createRadialGradient(t,r,n,t,r,s);v.addColorStop(0,this.colorWithOpacity(u,.8)),v.addColorStop(1,u),e.fillStyle=v,e.fill(),e.strokeStyle="#ffffff",e.lineWidth=2,e.stroke(),a=f})}drawVerticalLabels(e,d,l,t,r,s,n){let h=-Math.PI/2;d.forEach((a,g)=>{if(!a.value||a.value<=0)return;const o=a.value/l*(Math.PI*2),i=h+o/2,M=s*1.2,f=t+Math.cos(i)*M,u=r+Math.sin(i)*M;e.beginPath(),e.moveTo(t+Math.cos(i)*s,r+Math.sin(i)*s),e.lineTo(f,u),e.strokeStyle="#9ca3af",e.lineWidth=1,e.stroke(),e.fillStyle=this.getTextColor(n),e.textAlign=i<Math.PI?"left":"right",e.textBaseline="middle";const v=(a.value/l*100).toFixed(1);e.fillText(`${a.label} (${v}%)`,f,u),h+=o})}drawHorizontalLabels(e,d,l,t,r,s,n){let h=Math.PI/2;d.forEach((a,g)=>{if(!a.value||a.value<=0)return;const o=a.value/l*(Math.PI*2),i=h+o/2,M=s*1.2,f=t+Math.cos(i)*M,u=r+Math.sin(i)*M;e.beginPath(),e.moveTo(t+Math.cos(i)*s,r+Math.sin(i)*s),e.lineTo(f,u),e.strokeStyle="#9ca3af",e.lineWidth=1,e.stroke(),e.fillStyle=this.getTextColor(n),e.textAlign=i<Math.PI?"left":"right",e.textBaseline="middle";const v=(a.value/l*100).toFixed(1);e.fillText(`${a.label} (${v}%)`,f,u),h+=o})}drawCenterInfo(e,d,l,t,r,s){e.beginPath(),e.arc(l,t,r-2,0,Math.PI*2),e.fillStyle="#ffffff",e.fill(),e.strokeStyle="#e5e7eb",e.lineWidth=2,e.stroke(),e.textAlign="center",e.textBaseline="middle",e.fillStyle=this.getTextColor(s),e.font="bold 16px Inter, system-ui, sans-serif",e.fillText("Total",l,t-10),e.fillText(d.toString(),l,t+10)}}exports.DoughnutChartRenderer=P;