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.53 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("./BaseChartRenderer.cjs"),T=require("../utils/validation.cjs");class C extends v.BaseChartRenderer{render(e,a,r){if(!T.validateChartData(a)){this.drawNoDataMessage(e,r);return}const t=this.normalizeData(a);if(!t.length){this.drawNoDataMessage(e,r);return}const{width:n,height:l}=this.getDimensions(r),f=Math.max(20,n/Math.max(1,t.length)/1.5),o=Math.max(1,...t.map(g=>g.value||0)),i=l/o;this.drawGrid(e,r,o),this.drawBars(e,t,r,{barWidth:f,scale:i})}normalizeData(e){var r;return e.length?"value"in e[0]?e:((r=e[0])==null?void 0:r.data)||[]:[]}drawBars(e,a,r,{barWidth:t,scale:n}){const{padding:l}=this.getDimensions(r),o=(r.width-l*2)/a.length;a.forEach((i,g)=>{const c=i.value||0,s=l+o*g+(o-t)/2,d=c*n,h=r.height-l-d;e.fillStyle="rgba(0, 0, 0, 0.1)",e.fillRect(s+2,h+2,t,d);const u=e.createLinearGradient(s,h,s,h+d),m=i.color||this.colors[g%this.colors.length];u.addColorStop(0,m),u.addColorStop(1,this.colorWithOpacity(m,.7)),e.fillStyle=u,this.roundRect(e,s,h,t,d,4),e.fill(),e.fillStyle="#374151",e.textAlign="center",e.font="12px Inter, system-ui, sans-serif",e.fillText(c.toString(),s+t/2,h-8),e.save(),e.translate(s+t/2,r.height-l+8),e.rotate(-Math.PI/6),e.fillText(i.label||"",0,0),e.restore()})}roundRect(e,a,r,t,n,l){e.beginPath(),e.moveTo(a+l,r),e.lineTo(a+t-l,r),e.quadraticCurveTo(a+t,r,a+t,r+l),e.lineTo(a+t,r+n),e.lineTo(a,r+n),e.lineTo(a,r+l),e.quadraticCurveTo(a,r,a+l,r),e.closePath()}}exports.BarChartRenderer=C;