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.89 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 w=require("./BaseChartRenderer.cjs");class S extends w.BaseChartRenderer{render(e,n,s){if(!n||n.length===0){this.drawNoDataMessage(e,s);return}const l=s.orientation||"vertical",a=this.getColors(s),o=n.flatMap(i=>i.data),r=Math.max(...o.map(i=>i.x||0)),t=Math.max(...o.map(i=>i.y||0));this.drawBackground(e,s),this.drawTitle(e,s),l==="vertical"?(this.drawGrid(e,s,t),this.drawAxes(e,s,r,t),n.forEach((i,h)=>{const d=i.color||a[h%a.length];this.drawPoints(e,i,r,t,d,s)})):(this.drawHorizontalGrid(e,s,r),this.drawHorizontalAxes(e,s,r,t),n.forEach((i,h)=>{const d=i.color||a[h%a.length];this.drawHorizontalPoints(e,i,r,t,d,s)})),this.drawAxisLabels(e,s),this.drawLegend(e,n,s)}drawAxes(e,n,s,l){const{padding:a,width:o,height:r}=this.getDimensions(n);e.save(),e.strokeStyle="#e5e7eb",e.fillStyle="#6b7280",e.font="12px Inter, system-ui, sans-serif",e.lineWidth=1;for(let t=0;t<=5;t++){const i=a+o*t/5,h=Math.round(s*t/5);e.textAlign="center",e.fillText(h.toString(),i,n.height-a+20)}for(let t=0;t<=5;t++){const i=n.height-a-r*t/5,h=Math.round(l*t/5);e.textAlign="right",e.fillText(h.toString(),a-10,i+4)}e.restore()}drawPoints(e,n,s,l,a,o){const{padding:r}=this.getDimensions(o);n.data.forEach(t=>{if(!t.x||!t.y)return;const i=r+t.x*s,h=o.height-r-t.y*l;e.beginPath(),e.arc(i,h,6,0,Math.PI*2),e.fillStyle=this.colorWithOpacity(a,.2),e.fill(),e.strokeStyle=a,e.lineWidth=2,e.stroke()})}drawHorizontalGrid(e,n,s){const{padding:l,width:a,height:o}=this.getDimensions(n);e.save(),e.strokeStyle="#e5e7eb",e.fillStyle="#6b7280",e.font="12px Inter, system-ui, sans-serif",e.lineWidth=1;for(let r=0;r<=5;r++){const t=l+a*r/5;e.beginPath(),e.moveTo(t,l),e.lineTo(t,n.height-l),e.stroke()}for(let r=0;r<=5;r++){const t=l+o*r/5;e.beginPath(),e.moveTo(l,t),e.lineTo(n.width-l,t),e.stroke()}e.restore()}drawHorizontalAxes(e,n,s,l){const{padding:a,width:o,height:r}=this.getDimensions(n);e.save(),e.strokeStyle="#e5e7eb",e.fillStyle="#6b7280",e.font="12px Inter, system-ui, sans-serif",e.lineWidth=1;for(let t=0;t<=5;t++){const i=a+o*t/5,h=Math.round(s*t/5);e.textAlign="center",e.fillText(h.toString(),i,n.height-a+20)}for(let t=0;t<=5;t++){const i=a+r*t/5,h=Math.round(l*t/5);e.textAlign="right",e.fillText(h.toString(),a-10,i+4)}e.restore()}drawHorizontalPoints(e,n,s,l,a,o){const{padding:r,width:t,height:i}=this.getDimensions(o),h=i/s,d=t/l;n.data.forEach(g=>{if(!g.x||!g.y)return;const f=r+g.y*h,y=o.height-r-g.x*d;e.beginPath(),e.arc(f,y,6,0,Math.PI*2),e.fillStyle=this.colorWithOpacity(a,.2),e.fill(),e.strokeStyle=a,e.lineWidth=2,e.stroke()})}}exports.ScatterChartRenderer=S;