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.36 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("./BaseChartRenderer.cjs");class S extends y.BaseChartRenderer{render(e,r,s){if(!r||r.length===0){this.drawNoDataMessage(e,s);return}const{width:d,height:i}=this.getDimensions(s),n=r.flatMap(o=>o.data),h=Math.max(...n.map(o=>o.x||0)),t=Math.max(...n.map(o=>o.y||0)),a=d/h,l=i/t;this.drawGrid(e,s,t),this.drawAxes(e,s,h,t),r.forEach((o,g)=>{const f=this.colors[g%this.colors.length];this.drawPoints(e,o,a,l,f,s)}),this.drawLegend(e,r,s)}drawAxes(e,r,s,d){const{padding:i,width:n,height:h}=this.getDimensions(r);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 a=i+n*t/5,l=Math.round(s*t/5);e.textAlign="center",e.fillText(l.toString(),a,r.height-i+20)}for(let t=0;t<=5;t++){const a=r.height-i-h*t/5,l=Math.round(d*t/5);e.textAlign="right",e.fillText(l.toString(),i-10,a+4)}e.restore()}drawPoints(e,r,s,d,i,n){const{padding:h}=this.getDimensions(n);r.data.forEach(t=>{if(!t.x||!t.y)return;const a=h+t.x*s,l=n.height-h-t.y*d;e.beginPath(),e.arc(a,l,6,0,Math.PI*2),e.fillStyle=this.colorWithOpacity(i,.2),e.fill(),e.strokeStyle=i,e.lineWidth=2,e.stroke(),e.fillStyle="#374151",e.textAlign="center",e.textBaseline="top",e.fillText(t.label,a,l+10)})}}exports.ScatterChartRenderer=S;