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) • 1.59 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 u=require("./BaseChartRenderer.cjs"),w=require("../utils/validation.cjs");class m extends u.BaseChartRenderer{render(e,i,a){if(!w.validateChartData(i)){this.drawNoDataMessage(e,a);return}const{height:o}=this.getDimensions(a),h=this.getColors(a),r=Array.isArray(i)?i:[i],d=Math.max(...r.flatMap(t=>t.data.map(n=>n.value||0))),l=o/(d*1.1);this.drawBackground(e,a),this.drawTitle(e,a),this.drawGrid(e,a,d,!0,r[0].data.map(t=>t.label),"line"),r.forEach((t,n)=>{const s=t.color||h[n%h.length];this.drawLine(e,t,a,l,s),this.drawPoints(e,t,a,l,s)}),this.drawAxisLabels(e,a),this.drawLegend(e,r,a)}drawLine(e,i,a,o,h){const{padding:r,width:d}=this.getDimensions(a),l=i.data;e.beginPath(),l.forEach((t,n)=>{const s=r+d/(l.length-1)*n,g=a.height-r-(t.value||0)*o;n===0?e.moveTo(s,g):e.lineTo(s,g)}),e.strokeStyle=h,e.lineWidth=2,e.stroke()}drawPoints(e,i,a,o,h){const{padding:r,width:d}=this.getDimensions(a),l=i.data;l.forEach((t,n)=>{var f;const s=r+d/(l.length-1)*n,g=a.height-r-(t.value||0)*o;e.beginPath(),e.arc(s,g,4,0,Math.PI*2),e.fillStyle="#fff",e.fill(),e.strokeStyle=h,e.lineWidth=2,e.stroke(),e.fillStyle=this.getTextColor(a),e.textAlign="center",e.textBaseline="bottom",e.fillText(((f=t.value)==null?void 0:f.toString())||"0",s,g-8)})}}exports.LineChartRenderer=m;