@g20/grid
Version:
3 lines (2 loc) • 1.87 kB
JavaScript
import{Group as e,Arrow as t,G20 as s,Text as i,is_color as o,Line as l}from"@g20/core";class n extends e{xAxis;yAxis;xLabel;yLabel;constructor(e,o={}){super(e,[],o);const l=e.getBoundingBox(),n=Math.abs(l.right-l.left),d=Math.abs(l.top-l.bottom),a=.05*n,h=.05*d,p=[(e.crazy?l.left:l.right)-a,0],x=[(e.crazy?l.right:l.left)+a,0],c=[0,(e.goofy?l.bottom:l.top)-h],y=[0,(e.goofy?l.top:l.bottom)+h];this.xAxis=new t(e,s.ex.scale(n-2*a),{position:x,headLength:.025*n}),this.add(this.xAxis),this.yAxis=new t(e,s.ey.scale(d-2*h),{position:y,headLength:.025*d}),this.add(this.yAxis),this.xLabel=new i(e,"x",{position:p,anchor:"start",baseline:"middle",dx:9.6}),this.add(this.xLabel),r(this.xLabel,e),this.yLabel=new i(e,"y",{position:c,anchor:"middle",baseline:"middle",dy:16}),this.add(this.yLabel),r(this.yLabel,e)}dispose(){this.xLabel.dispose(),this.yLabel.dispose(),this.xAxis.dispose(),this.yAxis.dispose(),super.dispose()}render(e,t,s){this.zzz.viewee||super.render(e,t,s)}}function r(e,t){e.sx=1/t.sx,e.sy=1/t.sy}function d(e,t){return o(e)?e:t}function a(e,t){return"number"==typeof e?e:t}function h(e,t){return"number"==typeof e?e:3/t.sx}class p extends e{constructor(e,t={}){super(e,[],t);const s=e.getBoundingBox(),i=(s.right-s.left)/10,o=(s.top-s.bottom)/10,n={fillColor:d(t.lineColor,e.defaults.line.fillColor),fillOpacity:a(t.lineOpacity,e.defaults.line.fillOpacity),strokeColor:d(t.lineColor,e.defaults.line.strokeColor),strokeOpacity:a(t.lineOpacity,e.defaults.line.strokeOpacity),strokeWidth:h(a(t.lineWidth,e.defaults.line.strokeWidth),e)};for(let t=0;t<9;t++){const i=new l(e,[s.left,o*(t-4)],[s.right,o*(t-4)],n);this.add(i)}for(let t=0;t<9;t++){const o=new l(e,[i*(t-4),s.bottom],[i*(t-4),s.top],n);this.add(o)}}dispose(){super.dispose()}render(e,t,s){this.zzz.viewee||super.render(e,t,s)}}export{n as Axes,p as Grid};
//# sourceMappingURL=index.min.js.map