realchart
Version:
Wooritech charting library
8 lines (6 loc) • 34.4 kB
JavaScript
/**
* RealChart Gauge v1.3.17
* Copyright (C) 2023-2025 WooriTech Inc.
* All Rights Reserved.
*/
import{extend as e,ChartItem as t,GaugeScale as s,CircleGaugeType as i,CircleGaugeGroupType as a,CircularGaugeGroup as n,GaugeItem as l,buildValueRanges as r,calcPercent as h,CircularGauge as o,GaugeRangeBand as c,maxv as d,SectorElement as _,TextElement as u,LayerElement as g,minv as p,pickNum as b,pixel as w,RAD_DEG as y,TextAnchor as V,GaugeGroupView as x,ElementPool as m,ValueGaugeView as v,ScaleView as f,ArcElement as k,cos as C,sin as S,fixnum as R,ChartElement as B,PathElement as L,PathBuilder as E,GaugeLabel as T,ValueGauge as D,LinearGaugeType as O,GaugeGroup as N,LinearGaugeGroupType as I,RectElement as G,isEmptyRect as H,LineElement as A,rectToSize as $,assignObj as M,createRect as P,pickProp as z,copyObj as W,BulletGaugeType as F,BulletGaugeGroupType as Y,ChartText as X,ClockGaugeType as U,Gauge as j,isString as q,parsePercentSize as J,GaugeView as K,CircleElement as Q,TextLayout as Z,absv as ee,ORG_ANGLE as te,PI_2 as se,RcAnimation as ie}from"./index.mjs";class ae extends l{getRange(e,t){const s=this.$_internalRanges(e);if(s)for(const e of s)if(t>=e.fromValue&&t<e.toValue)return e}_doApply(e){const t=this;var s;super._doApply(e),(s=e.ranges)!==t._ranges&&(t._ranges=s,t._runRanges=null)}$_internalRanges(e){return this._runRanges||(this._runRanges=r(this._ranges,e.minValue,e.maxValue,this._op.rangeInclusive)),this._runRanges}}ae.defaults=e(t.defaults,{rangeInclusive:!0});class ne extends ae{getSegmentThickness(e){return h(this._segmentThicknessDim,e,e)}_doApply(e){super._doApply(e),this._setDim(e,"segmentThickness")}}ne.defaults=e(ae.defaults,{segmentGap:0});class le extends ae{getThickness(e){return h(this._thicknessDim,e,e)}_doApply(e){super._doApply(e),this._setDim(e,"thickness")}}le.defaults=e(ae.defaults,{thickness:"100%",stroked:!1});(class extends l{}).defaults=e(t.defaults,{visible:!1});class re extends l{getExtents(e){return{radius:h(this._radiusDim,e,0),length:h(this._lengthDim,e,0),offset:h(this._offsetDim,e,0)}}_doApply(e){super._doApply(e),this._setDims(e,"radius","length","offset")}}re.defaults=e(t.defaults,{visible:!1,radius:3,length:"100%",offset:0});class he extends l{getRadius(e){return h(this._radiusDim,e,0)}_doApply(e){super._doApply(e),this._setDim(e,"radius")}}he.defaults=e(t.defaults,{visible:!1,radius:5});class oe extends s{_getStepMultiples(e){return[1,2,2.5,5,10]}}oe.defaults=e(s.defaults,{visible:!1,stepPixels:72});class ce extends o{_doInitChildren(e){super._doInitChildren(e),e.band=(this._band=new c(this)).init(),e.scale=(this._scale=new oe(this)).init(),e.rim=(this._rim=new ne(this)).init(),e.valueRim=(this._valueRim=new le(this)).init(),e.hand=(this._hand=new re(this)).init(),e.pin=(this._pin=new he(this)).init()}get band(){return this._band}get scale(){return this._scale}get rim(){return this._rim}get valueRim(){return this._valueRim}get hand(){return this._hand}get pin(){return this._pin}getExtents(e){const t=super.getExtents(e),s=this.scale,i=this.band;let a=t.radius;const n=a-t.inner;if(i.visible)switch(t.bandThick=i.getThickness(n),i.options.position){case"inside":t.band=a-(n-t.bandThick)/2;break;case"opposite":t.band=t.inner-i.options.gap,t.inner=t.band-t.bandThick;break;default:t.band=a+=t.bandThick+i.options.gap}if(t.scaleTick=d(1,s.tick.options.length||0),t.scaleLabel=16,"opposite"===s.options.position)t.scale=t.inner-s.options.gap,t.inner=t.scale-t.scaleTick-t.scaleLabel;else t.scale=a+s.options.gap;return t}}ce.type=i;class de extends n{_gaugesType(){return"circle"}}de.type=a,de.gaugeType=i,de.defaults=e(n.defaults,{innerRadius:"50%"});class _e extends v{}class ue extends f{setExtents(e,t){this._center=e,this._exts=t}_createLine(e,t){return new k(e,t)}_doMeasure(e,t,s,i,a){const n=t._steps.length-(360===t.gauge.options.sweepAngle?1:0);return this._line.setVis(t.line.visible)&&this._line.internalSetStyleOrClass(t.line._style),this._tickContainer.setVis(t.tick.visible)&&(this._tickContainer.internalSetStyleOrClass(t.tick._style),this._ticks.prepare(n)),this._labelContainer.setVis(t.label.visible)&&(this._labelContainer.internalSetStyleOrClass(t.label._style),this._labels.prepare(n,(e=>{}))),{width:s,height:i}}_doLayout(e){const t=this.model,s=t._steps,i=t.gauge,a=i.options,n="opposite"===t.options.position?-1:1,l=i._props,r=this._center.x,h=this._center.y,o=this._exts.scale,c=o+this.model.tick.options.length*n,d=l._sweepRad,_=l._startRad,u=a.maxValue-a.minValue,g=a.clockwise;let p,b,w,y;if(this._line.visible&&this._line.setArc(r,h,o,_,g?d:-d,g),this._tickContainer.visible&&this._ticks.forEach(((e,i,a)=>{const n=t.getRate(s[i])*(g?d:-d)+_;p=r+C(n)*o,b=h+S(n)*o,w=r+C(n)*c,y=h+S(n)*c,e.setLine(p,b,w,y)})),this._labelContainer.visible){this._labels.get(0).setText(String(a.maxValue));const e=c+.2*this._labels.get(0).getBBox().height*n;this._labels.forEach(((i,l,o)=>{const c=t.getRate(s[l])*(g?d:-d)+_;i.setText(String(R(a.minValue+t.getRate(s[l])*u)));const p=i.getBBox();w=r+C(c)*(e+p.width/2*n)-p.width/2,y=h+S(c)*(e+p.height/2*n)-p.height/2,i.trans(w,y)}))}}}let ge=class extends B{constructor(e){super(e,"rct-circle-gauge-band"),this._sectorViews=new m(this,_),this.add(this._labelContainer=new g(e,"rct-circle-gauge-band-tick-labels")),this._labels=new m(this._labelContainer,u)}setExtends(e,t){this._center=e,this._exts=t}_doLayout(e){const t=this.model,s=t.gauge,i=s.scale,a=s._props,n=this._center.x,l=this._center.y,r=this._exts.band,h=s.options.clockwise,o=1-this._exts.bandThick/r,c=t.getRanges(),d=a._sweepRad;s.options.maxValue,s.options.minValue;let _=a._startRad;this._sectorViews.prepare(c.length).forEach(((e,t)=>{const s=i.getRate(c[t].toValue-c[t].fromValue)*d;e.setSector({cx:n,cy:l,rx:r,ry:r,innerRadius:o,start:_,angle:s,clockwise:h}),e.internalClearStyleAndClass(),e.setFill(c[t].color),c[t].style&&e.addStyleOrClass(c[t].style),_+=h?s:-s}))}};class pe extends L{render(e,t){const s=e.getRadius(t);return s!==this._radius&&(this._radius=s,this.setPath((new E).circle(0,0,s).end())),this.internalSetStyleOrClass(e._style),this}}class be extends L{render(e,t){const s=e.getExtents(t);if(s.radius!==this._radius||s.length!==this._length||s.offset!==this._offset){const e=this._radius=s.radius,t=this._offset=s.offset;if(this._length=s.length,this._radius>0&&this._length>0){const s=new E;s.move(-e,t).line(0,-this._length+t).line(e,t),this.setPath(s.end())}else this.setPath("")}return this.internalSetStyleOrClass(e._style),this}}class we extends _e{constructor(e){super(e,"rct-circle-gauge")}_doInitContents(e,t){t.add(this._rimView=new _(e,"rct-circle-gauge-rim")),t.add(this._valueView=new _(e,"rct-circle-gauge-value")),t.add(this._innerView=new _(e,"rct-circle-gauge-inner")),t.add(this._textView=new u(e,"rct-circle-gauge-label")),t.add(this._handContainer=new g(e,void 0)),t.add(this._scaleView=new ue(e)),t.add(this._bandView=new ge(e))}_backgroundView(){return this._rimView}_prepareGauge(e,t){this._rimView.setVis(t.rim.visible),this._scaleView.setVis(t.scale.visible),this._bandView.setVis(t.band.visible),this._valueView.setVis(t.valueRim.visible),t.hand.visible?(this._handView||this._handContainer.add(this._handView=new be(e,"rct-circle-gauge-hand")),this._handView.visible=!0):this._handView&&(this._handView.visible=!1),t.pin.visible?(this._pinView||this._handContainer.add(this._pinView=new pe(e,"rct-circle-gauge-pin")),this._pinView.visible=!0):this._pinView&&(this._pinView.visible=!1),this._textView.setVis(t.labelVisible())&&this._textView.setStyleOrClass(t.label._style)}_renderGauge(e,t){const s=this.model,i=s.getCenter(e,t),a=s.getExtents(p(e,t));this.$_renderBackground(s,i,a),this._renderValue()}_renderValue(){const e=this.model,t=e.options,s=e.scale,i=e.getProps(),a=this._getValue(e),n=s.getRate(b(a,0)),l=this._center,r=this._exts,h=e.valueRim.getThickness(r.radiusThick),o=this._textView;if(this._valueView.visible){const s=e.valueRim,o=s.options,c=s.getRange(t,a),d=r.value+(o.stroked?0:h/2),_=this._valueView;_.setStyleOrClass(s._style),c&&(_.setStyle(o.stroked?"stroke":"fill",c.color),c.style&&_.addStyleOrClass(c.style)),o.stroked&&(_.setFill("none"),_.setStyle("strokeWidth",w(h))),_.setBoolData("stroked",o.stroked),_.setSectorEx({cx:l.x,cy:l.y,rx:d,ry:d,innerRadius:(d-h)/d,start:i._startRad,angle:i._sweepRad*n,clockwise:t.clockwise},o.stroked)}if(this._handView){const t=(i._handRad+i._sweepRad*n)*y;this._handView.render(e.hand,r.radius).transp(l).rotate(e.options.clockwise?t:-t)}if(o.visible){const s=e.label;if(s.setText(e.getLabel(s,s.options.animatable?a:t.value)),o.text=s.options.text,s.buildSvg(o,null,NaN,NaN,e,s._domain),o.setBoolData("grouped",!!e._group),e._group)this.$_layoutGroupedLabel(e,o,r);else{const e=o.getBBox(),t=s.getOffset(this.width,this.height);o.trans(l.x+t.x,l.y-e.height/2+t.y)}}}$_renderBackground(e,t,s){const i=e.getProps(),a=i._startRad;this._center=t,this._exts=s,e.scale.buildSteps(s.scale*i._sweepRad,NaN),this._rimView.visible&&(this._rimView.internalSetStyleOrClass(e.rim._style),this._rimView.setSector({cx:t.x,cy:t.y,rx:s.radius,ry:s.radius,innerRadius:1-s.radiusThick/s.radius,start:a,angle:i._sweepRad,clockwise:e.options.clockwise})),this._scaleView.visible&&(this._scaleView.setStyleOrClass(e.scale._style),this._scaleView.measure(this.doc,e.scale,this.width,this.height,0),this._scaleView.setExtents(t,s),this._scaleView.layout()),this._bandView.visible&&(this._bandView.setStyleOrClass(e.band._style),this._bandView.measure(this.doc,e.band,this.width,this.height,0),this._bandView.setExtends(t,s),this._bandView.layout()),this._innerView.setStyleOrClass(e.options.innerStyle);let n=s.inner;const l=getComputedStyle(this._innerView.dom),r=parseFloat(l.strokeWidth);r>1&&(n-=r/2),this._innerView.setSector({cx:t.x,cy:t.y,rx:n,ry:n,innerRadius:0,start:0,angle:2*Math.PI,clockwise:!0}),this._pinView&&this._pinView.render(e.pin,n).trans(t.x,t.y)}$_layoutGroupedLabel(e,t,s){const i=t.getBBox(),a=this._rimView.getBBox(),n=+e._group.options.labelGap||0;t.anchor=V.END,t.trans(a.x+a.width/2-n,a.y+(s.radius-s.inner-i.height)/2)}}class ye extends x{constructor(e){super(e,"rct-circle-gauge-group")}_createPool(e){return new m(e,we)}_doRenderGauges(e,t,s,i){const a=this.doc,n=this.model,l=n.props.getCenter(s,i),r=n.props.getExtents(p(s,i));n.setChildExtents(r),s=i=2*r.radius,t.forEach(((e,t)=>{e.measure(a,n.getVisible(t),s,i,0),e.resize(s,i),e.layout()})),e.trans(l.x-r.radius,l.y-r.radius)}}class Ve extends s{}class xe extends T{getWidth(e){return h(this._widthDim,e)}getHeight(e){return h(this._heightDim,e)}getMaxWidth(e){return h(this._maxWidthDim,e)}getMaxHeight(e){return h(this._maxHeightDim,e)}getGap(e){return h(this._gapDim,e,0)}_doApply(e){super._doApply(e),this._setDims(e,"width","height","maxWidth","maxHeight","gap")}}xe.defaults=e(T.defaults,{maxWidth:"30%",maxHeight:"30%",gap:10});class me extends D{_doInitChildren(e){super._doInitChildren(e),e.label=(this._label=new xe(this.chart)).init(),e.scale=(this._scale=new Ve(this)).init()}get label(){return this._label}get scale(){return this._scale}isVertical(){return this._group?this._group.options.vertical:this._op.vertical}scaleVisible(){return!this._group&&this._scale.visible}calcedMinMax(){return this._scale.range()}_doPrepareRender(e){super._doPrepareRender(e),this._label._prepareRender()}}me.defaults=e(D.defaults,{reversed:!1});class ve extends l{constructor(){super(...arguments),this._args={gauge:null,value:NaN}}getStyle(e,t){if(this._op.styleCallback){this._args.gauge=e,this._args.value=t;return this._op.styleCallback(this._args)}}}class fe extends me{_doInitChildren(e){super._doInitChildren(e),e.valueBar=(this._valueBar=new ve(this)).init(),e.band=(this._band=new c(this)).init()}get valueBar(){return this._valueBar}get band(){return this._band}}fe.type=O;class ke extends t{}ke.defaults=e(t.defaults,{opposite:!1,gap:10});class Ce extends xe{}Ce.defaults=e(xe.defaults,{gap:10});class Se extends N{_doInitChildren(e){super._doInitChildren(e),e.label=(this._label=new Ce(this.chart)).init(),e.itemLabel=(this._itemLabel=new ke(this.chart)).init(),e.scale=(this._scale=new Ve(this)).init()}get label(){return this._label}get itemLabel(){return this._itemLabel}get scale(){return this._scale}calcedMinMax(){return this.scale.range()}}Se.defaults=e(N.defaults,{vertical:!1,itemGap:10});class Re extends Se{_doInitChildren(e){super._doInitChildren(e),e.band=(this._band=new c(this)).init()}get band(){return this._band}_gaugesType(){return"linear"}_doPrepareRender(e){super._doPrepareRender(e),this.band.visible&&this.band._prepareRender()}}Re.type=I,Re.gaugeType=O;class Be extends f{_createLine(e,t){return new A(e,t)}_doMeasure(e,t,s,i,a){const n=t.options,l=t._reversed,r=t._vertical,h=t.label,o=t.tick,c=t._steps,_=c.length;let u=r?n.gap:s,g=r?i:n.gap;if(this._tickContainer.setVis(o.visible)&&(this._tickContainer.setStyleOrClass(o._style),this._ticks.prepare(_)),r?u+=o.options.length:g+=o.options.length,this._labelContainer.setVis(h.visible)&&(this._labelContainer.setStyleOrClass(h._style),this._labels.prepare(_,(t=>{t.setModel(e,h,null,null)})),_>0))if(r){let e=0;this._labels.forEach(((t,s)=>{t.setText(h.getText(c[l?s:_-1-s])),e=d(t.getBBox().width)})),u+=e}else{let e=0;this._labels.forEach(((t,s)=>{t.setText(h.getText(c[l?_-1-s:s])),e=d(t.getBBox().height)})),g+=e}return{width:u,height:g}}_doLayout(){const e=this.model;e._vertical?this.$_layoutVert(e,this.width,this.height):this.$_layoutHorz(e,this.width,this.height)}$_layoutHorz(e,t,s){const i=e.options,a=this._line,n=e.tick,l=e._steps;l.length;const r="opposite"===i.position,h=r?-n.options.length:n.options.length;let o,c=r?s-i.gap:i.gap;if(a.setVis(e.line.visible)&&(a.setStyleOrClass(e.line._style),a.setHLine(c,0,t)),this._tickContainer.setVis(n.visible)&&this._ticks.forEach(((s,i)=>{o=e.getRate(l[i])*t,s.setVLine(o,c,c+h)})),this._labelContainer.visible){const s=this._labelContainer.textAlign()||"center";let i=Number.MIN_SAFE_INTEGER;c=r?0:c+h,this._labels.forEach(((a,n)=>{a.layout(s);const r=a.getBBox();o=e.getRate(l[n])*t,a.setVis(o-r.width/2>i)&&(a.trans(o-r.width/2,c),i=o+r.width/2)}))}}$_layoutVert(e,t,s){const i=e.options,a=this._line,n=e.tick,l=e._steps;this.height,l.length;const r="opposite"===i.position,h=r?n.options.length:-n.options.length;let o,c=r?i.gap:t-i.gap;if(a.setVis(e.line.visible)&&(a.setStyleOrClass(e.line._style),a.setVLine(c,0,s)),this._tickContainer.setVis(n.visible)&&this._ticks.forEach(((t,i)=>{o=e.getRate(l[i])*s,t.setHLine(o,c,c+h)})),this._labelContainer.visible){const a=this._labelContainer.textAlign()||(r?"left":"right");c=r?c+h:t-i.gap+h,this._labels.forEach(((t,i)=>{t.layout(a);const n=t.getBBox(),h=r?c:c-n.width;o=e.getRate(l[i])*s,t.trans(h,o-n.height/2)}))}}}class Le extends v{_measureLabelSize(e,t,s){const i=e.label,a=this.labelView();return i.setText(e.getLabel(i,e.options.value)),a.text=i.options.text,i.buildSvg(a,null,t,s,e,i._domain),$(a.getBBox())}_renderGauge(e,t){const s=this.model,i=b(this._runValue,s.options.value);this._measureGauge(s,s.label,this.labelView(),i,s.isVertical(),e,t),this._renderValue()}_renderValue(){const e=this.model,t=e.label,s=e.scale,i=this.labelView(),a=b(this._runValue,e.options.value),n=M({},this._rBand);if(this._renderScale(n),this.background().setRect(n),n.height>0&&this._renderBand(e,n,a),"top"!==t._runPos&&"bottom"!==t._runPos||(this._rLabel.height=n.height),this._renderLabel(e,t,i,a),!this._vertical&&("left"===t._runPos||"right"===t._runPos)&&s.visible&&"opposite"===s.options.position){const e=i.getBBox();i.ty+e.height>this.height&&i.transY(d(0,this.height-e.height))}}_measureGauge(e,t,s,i,a,n,l){const r=this._rBand=P(0,0,n,l);if(this._vertical=e._group instanceof Se?e._group.options.vertical:a,t.visible){const a=t._runPos=z(t.options.position,this._vertical?"top":"left"),h=t._runVert="top"===a||"bottom"===a,o=e._group?e._group.itemLabel.options.gap:t._runGap=t.getGap(h?l:n);let c=h?n:t.getWidth(n),_=h?t.getHeight(l):l;const u=h?n:t.getMaxWidth(n),g=h?t.getMaxHeight(l):l,p=this._rLabel=P(0,0,n,l);s.setStyleOrClass(t._style),t.setText(e.getLabel(t,t.options.animatable?i:e.options.value)),s.text=t.options.text,t.buildSvg(s,null,b(c,u),b(_,g),e,t._domain);const w=s.getBBox();switch(h?(p.height=b(_,w.height),r.height=d(0,r.height-(p.height+o))):(p.width=b(c,w.width),this._wLabel=e._group?e._group._labelWidth:p.width,r.width=d(0,r.width-(this._wLabel+o))),a){case"top":r.y=p.height+o;break;case"bottom":p.y=r.height+o;break;case"right":p.x=r.width+o;break;default:r.x=this._wLabel+o}}else this._rLabel=null}_renderLabel(e,t,s,i){if(s.visible){const e=this._rLabel,i=s.getBBox();let a=e.x,n=e.y;switch(t._runPos){case"top":case"bottom":a+=e.width/2;break;case"right":a=this.width-e.width,s.anchor=V.START,n+=d(0,(e.height-i.height)/2);break;default:s.anchor=V.END,a+=this._wLabel,n+=d(0,(e.height-i.height)/2)}s.trans(a,n)}}_renderScale(e){const t=this.model,s=t.label,i=t.scale,a=this.scaleView(),n=this._vertical?e.height:e.width;let l,r;if(i._vertical=this._vertical,i._reversed=t.options.reversed,isNaN(this._runValue)&&i.buildSteps(n,t.options.value),a.setVis(t.scaleVisible())){const t=a.measure(this.doc,i,e.width,e.height,1);this._vertical?(l=0,r=e.y,e.width=d(0,e.width-t.width),"opposite"===i.options.position?l=e.x+e.width:(s._runVert||(l=e.x),e.x+=t.width)):(l=e.x,e.height=d(0,e.height-t.height),"opposite"===i.options.position?s._runVert?(r=e.y,e.y+=t.height):(this._rLabel.y=e.y+=t.height,r=e.y-t.height):r=e.y+e.height),a.resizeByMeasured().layout().trans(l,r)}}}class Ee extends B{constructor(e){super(e,"rct-linear-gauge-band"),this._thick=0,this._gap=0,this._labelGap=3,this._barViews=new m(this,G),this.add(this._labelContainer=new g(e,"rct-linear-gauge-band-tick-labels")),this._labels=new m(this._labelContainer,u)}_doMeasure(e,t,s,i,a){const n=t.gauge,l=this._vertical=n instanceof fe?n.isVertical():n.options.vertical,r="inside"===t.options.position,h=this._thick=r?l?s:i:t.getThickness(l?s:i)+(this._gap=b(t.options.gap,0));let o=l?h:s,c=l?i:h;const _=this._ranges=t.getRanges();if(this._labelContainer.setVis(t.tickLabel.visible&&_.length>0)){const e=[_[0].fromValue].concat(_.map((e=>e.toValue)));if(this._labelContainer.setStyleOrClass(t.tickLabel._style),this._labels.prepare(_.length+1),l){let t=0;this._labels.forEach(((s,i)=>{s.text=String(e[i]),t=d(s.getBBox().width)})),o+=t+this._labelGap}else{let t=0;this._labels.forEach(((s,i)=>{s.text=String(e[i]),t=d(s.getBBox().height)})),c+=t}}return{width:o,height:c}}_doLayout(e){const t=this.model,s=t.gauge,i=s.scale,a=i._max-i._min;this._labelContainer.setVis(this.$_layoutBars(s,a,this._ranges)&&this._labelContainer.visible&&"inside"!==t.options.position)&&this.$_layoutLabels(s,a,this._ranges)}$_layoutBars(e,t,s){if(this._barViews.prepare(s.length),!this._barViews.isEmpty&&t>0){const e=this._vertical,i="inside"===this.model.options.position,a="opposite"===this.model.options.position,n=this.width,l=this.height,r=e?l:n,h=this._thick;let o=0;return this._barViews.prepare(s.length).forEach(((c,d)=>{const _=s[d],u=r*(_.toValue-_.fromValue)/t;if(e){const e=i||a?0:n-h;c.setBounds(e,l-o-u,h,u)}else{const e=a?l-h:0;c.setBounds(o,e,u,this._thick)}c.internalClearStyleAndClass(),c.setFill(_.color),_.style&&c.addStyleOrClass(_.style),o+=u})),!0}}$_layoutLabels(e,t,s){const i="opposite"===this.model.options.position;if(this._vertical){const e=this.height,a=i?V.START:V.END,n=i?this._thick+this._labelGap:this.width-this._thick-this._labelGap;let l=this._labels.get(0);l.anchor=a,l.trans(n,e-l.getBBox().height/2);for(let i=1;i<=s.length;i++){const r=e-e*s[i-1].toValue/t;l=this._labels.get(i),l.anchor=a,l.trans(n,r-l.getBBox().height/2)}}else{const e=this.width,a=i?0:this._thick;this._labels.get(0).trans(0,a);for(let i=1;i<=s.length;i++){const n=e*s[i-1].toValue/t;this._labels.get(i).trans(n,a)}}}}class Te extends Le{constructor(e){super(e,"rct-linear-gauge")}_doInitContents(e,t){t.add(this._background=new G(e,"rct-linear-gauge-background")),t.add(this._bandView=new Ee(e)),t.add(this._scaleView=new Be(e)),t.add(this._valueView=new G(e,"rct-linear-gauge-value")),t.add(this._labelView=new u(e))}_backgroundView(){return this._background}labelView(){return this._labelView}scaleView(){return this._scaleView}background(){return this._background}_prepareGauge(e,t){}_renderScale(e){const t=this.model.band,s=this._bandView;if(super._renderScale(e),s.setVis(t.visible)){const i=+t.options.gap||0,a=s.measure(this.doc,t,e.width,e.height,1);s.resizeByMeasured().layout(),this._vertical?"inside"===t.options.position?s.trans(e.x,e.y):"opposite"===t.options.position?(s.trans(e.x+e.width-a.width,e.y),e.width-=a.width+i):(s.trans(e.x,e.y),e.width-=a.width+i,e.x+=a.width+i):"inside"===t.options.position?s.trans(e.x,e.y):"opposite"===t.options.position?(s.trans(e.x,e.y),e.height-=a.height+i,e.y+=a.height+i):(s.trans(e.x,e.y+e.height-a.height),e.height-=a.height+i)}}_renderBand(e,t,s){const i=this._valueView,a=e.options.reversed,n=e.valueBar,l=e._group?e._group.scale:e.scale;if(i.setVis(!H(t)&&n.visible&&!l.isEmpty()&&!isNaN(e.options.value)))if(i.setStyleOrClass(n._style),i.internalSetStyleOrClass(n.getStyle(e,s)),this._vertical){const e=t.height*l.getRate(s),n=a?t.y:t.y+t.height-e;i.setBounds(t.x,n,t.width,e)}else{const e=t.width*l.getRate(s),n=a?t.x+t.width-e:t.x;i.setBounds(n,t.y,e,t.height)}}}class De extends x{constructor(e,t){super(e,t)}_doInitContents(e,t){super._doInitContents(e,t),t.insertFirst(this._scaleView=new Be(e)),t.insertFirst(this._textView=new u(e,"rct-linear-gauge-group-label"))}_prepareGauge(e,t){this._textView.setVis(t.label.visible)&&this._textView.setStyleOrClass(t.label._style),this._scaleView.setVis(t.scale.visible)&&this._scaleView.setStyleOrClass(t.scale._style),super._prepareGauge(e,t)}_doRenderGauges(e,t,s,i){const a=this.model,n=a.options,l=this._textView,r=P(0,0,s,i);if(l.visible){l.text=a.label.options.text,a.label.buildSvg(l,null,NaN,NaN,a,null);const e=this._textView.getBBox().height+a.label.getGap(i);r.y+=e,r.height-=e,l.trans(this.width/2,0)}a._labelWidth=a._labelHeight=0,this._gaugeViews.forEach(((e,t)=>{const n=e._measureLabelSize(a.get(t),s,i);a._labelWidth=d(a._labelWidth,n.width),a._labelHeight=d(a._labelHeight,n.height)}));const h=W(r),o=a.itemLabel.options.gap;n.vertical?(h.height-=a._labelHeight+o,a.itemLabel.options.opposite||(h.y+=a._labelHeight+o)):(h.width-=a._labelWidth+o,a.itemLabel.options.opposite||(h.x+=a._labelWidth+o)),this._renderScale(a,r,h),n.vertical?this.$_layoutVert(this.doc,a,t,r):this.$_layoutHorz(this.doc,a,t,r)}_renderScale(e,t,s){const i=this._scaleView,a=e.scale,n=e.options.vertical,l=n?t.height:t.width,r=[];let h,o;if(this._gaugeViews.forEach(((t,s)=>{r.push(b(t._runValue,e.get(s).options.value))})),a.buildGroupSteps(l,r),a._vertical=n,i.setVis(a.visible)){const e=i.measure(this.doc,a,s.width,s.height,1);if(n){const i=e.width;s.width-=i,t.width-=i,o=s.y,"opposite"===a.options.position?h=s.x+s.width:(h=s.x,s.x+=i,t.x+=i)}else{const i=e.height;s.height-=i,t.height-=i,h=s.x,"opposite"===a.options.position?(o=s.y,s.y+=i,t.y+=i):o=s.y+s.height}i.resizeByMeasured().layout().trans(h,o)}}$_layoutVert(e,t,s,i){const a=i.height,n=(i.width-t.options.itemGap*(s.count-1))/s.count,l=i.y;let r=i.x;s.forEach(((s,i)=>{s.measure(e,t.get(i),n,a,0),s.resize(n,a),s.layout(),s.trans(r,l),r+=n+t.options.itemGap}))}$_layoutHorz(e,t,s,i){const a=t.options.itemGap,n=i.width,l=(i.height-a*(s.count-1))/s.count,r=i.x;let h=i.y;s.forEach(((s,i)=>{s.measure(e,t.get(i),n,l,0),s.resize(n,l),s.layout(),s.trans(r,h),h+=l+a}))}}class Oe extends De{constructor(e){super(e,"rct-linear-gauge-group")}_doInitContents(e,t){super._doInitContents(e,t),t.insertChild(this._bandView=new Ee(e),this._scaleView)}_createPool(e){return new m(e,Te)}_renderScale(e,t,s){super._renderScale(e,t,s);const i=this._bandView,a=e.band;let n,l;if(i.setVis(a.visible)){const r=+a.options.gap||0,h=i.measure(this.doc,a,s.width,s.height,1);if(e.options.vertical){const e=h.width+r;s.width-=e,t.width-=e,l=s.y,"opposite"===a.options.position?n=s.x+s.width+r:(n=s.x,s.x+=e,t.x+=e)}else{const e=h.height+r;s.height-=e,t.height-=e,n=s.x,"opposite"===a.options.position?(l=s.y,s.y+=e,t.y+=e):l=s.y+s.height+r}i.resizeByMeasured().layout().trans(n,l)}}}class Ne extends t{constructor(e){super(e.chart),this.gauge=e}getRanges(){var e;return null===(e=this.$_internalRanges())||void 0===e?void 0:e.slice(0)}_doApply(e){const t=this;var s;super._doApply(e),(s=e.ranges)!==t._ranges&&(t._ranges=s,t._runRanges=null)}$_internalRanges(){if(!this._runRanges){const e=this.gauge.options;this._runRanges=r(this._ranges,e.minValue,e.maxValue,this._op.rangeInclusive)}return this._runRanges}}Ne.defaults=e(t.defaults,{vertical:!0,rangeInclusive:!0});class Ie extends l{}Ie.defaults=e(t.defaults,{visible:!0});class Ge extends ve{}class He extends me{_doInitChildren(e){super._doInitChildren(e),e.band=(this._band=new Ne(this)).init(),e.targetBar=(this._targetBar=new Ie(this)).init(),e.valueBar=(this._valueBar=new Ge(this)).init()}get band(){return this._band}get targetBar(){return this._targetBar}get valueBar(){return this._valueBar}getRanges(e,t,s){return r(this._op.ranges,e,t,z(s,this._op.rangeInclusive))}}He.type=F,He.defaults=e(me.defaults,{rangeInclusive:!0});class Ae extends Se{getRanges(e,t,s){return r(this._op.ranges,e,t,z(s,this._op.rangeInclusive))}_gaugesType(){return"bullet"}}Ae.type=Y,Ae.gaugeType=F,Ae.defaults=e(Se.defaults,{rangeInclusive:!0});class $e extends Le{constructor(e){super(e,"rct-bullet-gage")}_doInitContents(e,t){t.add(this._background=new G(e,"rct-bullet-gauge-background")),t.add(this._barContainer=new g(e,void 0)),this._barViews=new m(this._barContainer,G),t.add(this._valueView=new G(e,"rct-bullet-gauge-value")),t.add(this._targetView=new G(e,"rct-bullet-gauge-target")),t.add(this._scaleView=new Be(e)),t.add(this._labelView=new u(e))}_backgroundView(){return this._background}labelView(){return this._labelView}scaleView(){return this._scaleView}background(){return this._background}_prepareGauge(e,t){}_renderBand(e,t,s){const i=e.options,a=e._group,n=e.options.reversed,l=this._vertical,r=a?a.scale:e.scale,h=this._valueView,o=this._targetView;if(this._barContainer.setVis(!H(t)&&!r.isEmpty())){const s=e.getRanges(r._min,r._max,!1)||(null==a?void 0:a.getRanges(r._min,r._max,!1));s&&(this._barContainer.setRect(t),this._barViews.prepare(s.length),l?this._barViews.forEach(((e,i)=>{const a=s[i],l=t.height*r.getRate(a.toValue-a.fromValue),h=t.height*r.getRate(a.fromValue);e.setBounds(0,n?h:t.height-h-l,t.width,l),e.internalClearStyleAndClass(),e.setFill(a.color),a.style&&e.addStyleOrClass(a.style)})):this._barViews.forEach(((e,i)=>{const a=s[i],l=t.width*r.getRate(a.toValue-a.fromValue),h=t.width*r.getRate(a.fromValue);e.setBounds(n?t.width-l-h:h,0,l,t.height),e.internalClearStyleAndClass(),e.setFill(a.color),a.style&&e.addStyleOrClass(a.style)})))}if(h.setVis(e.valueBar.visible&&!r.isEmpty()&&!isNaN(s)))if(h.setStyleOrClass(e.valueBar._style),s<i.targetValue&&e.valueBar.options.belowStyle&&h.internalSetStyleOrClass(e.valueBar.options.belowStyle),h.internalSetStyleOrClass(e.valueBar.getStyle(e,s)),l){const e=t.height*r.getRate(s),i=n?t.y:t.y+t.height-e;h.setBounds(t.x+t.width/3,i,t.width/3,e)}else{const e=t.width*r.getRate(s),i=n?t.x+t.width-e:t.x;h.setBounds(i,t.y+t.height/3,e,t.height/3)}if(o.setVis(e.targetBar.visible&&!r.isEmpty()&&!isNaN(i.targetValue)))if(o.setStyleOrClass(e.targetBar._style),l&&t.width>10){let e=t.height*r.getRate(i.targetValue);e=n?t.y+e:t.y+t.height-e,o.setBounds(t.x+5,e-1,t.width-10,3)}else if(!l&&t.height>10){let e=t.width*r.getRate(i.targetValue);e=n?t.x+t.width-e:t.x+e,o.setBounds(e-1,t.y+5,3,t.height-10)}}}class Me extends De{constructor(e){super(e,"rct-bullet-gauge-group")}_createPool(e){return new m(e,$e)}}class Pe extends l{getThickness(e){return h(this._thicknessDim,e,e)}_doApply(e){super._doApply(e),this._setDim(e,"thickness")}}Pe.defaults=e(t.defaults,{thickness:7});class ze extends l{getLength(e){return h(this._lengthDim,e,e)}_doApply(e){super._doApply(e),this._setDim(e,"length")}}ze.defaults=e(t.defaults,{thickness:7,length:"60%"});class We extends ze{}We.defaults=e(ze.defaults,{thickness:5,length:"85%"});class Fe extends ze{}Fe.defaults=e(ze.defaults,{thickness:2,length:"95%",animatable:!1,duration:200});class Ye extends l{constructor(e,t){super(e),this.length=t}}class Xe extends l{}Xe.defaults=e(t.defaults,{step:1,offset:1});class Ue extends l{constructor(e,t){super(e),this.raidus=t}}class je extends X{constructor(e){super(e.chart)}}je.defaults=e(X.defaults,{text:"RealChart Clock<br>ver1.0",position:"top"});class qe extends j{_doInitChildren(e){super._doInitChildren(e),e.rim=(this.rim=new Pe(this)).init(),e.hourHand=(this.hourHand=new ze(this)).init(),e.minuteHand=(this.minuteHand=new We(this)).init(),e.secondHand=(this.secondHand=new Fe(this)).init(),e.tick=(this.tick=new Ye(this,10)).init(),e.minorTick=(this.minorTick=new Ye(this,5)).init(),e.tickLabel=(this.tickLabel=new Xe(this)).init(),e.pin=(this.pin=new Ue(this,5)).init(),e.label=(this.label=new je(this)).init()}getTime(){const e=this._op;return e.time instanceof Date?e.time:q(e.time)?new Date(e.time):isNaN(e.time)?void 0:new Date(e.time)}getExtents(e,t){const s=p(e,t);return{cx:h(this._centerXDim,e,e/2),cy:h(this._centerYDim,t,t/3),rd:h(this._radiusDim,s,s/2)}}_doApply(e){const t=this;var s,i,a;super._doApply(e),s=e.centerX,i=e.centerY,a=e.radius,(t._centerXDim||s!==t._centerX)&&(t._centerXDim=J(z(t._centerX=s,o.DEF_CENTER),!0)),t._centerYDim&&i===t._centerY||(t._centerYDim=J(z(t._centerY=i,o.DEF_CENTER),!0)),t._radiusDim&&a===t._radius||(t._radiusDim=J(z(t._radius=a,o.DEF_RADIUS),!0))}}qe.type=U,qe.defaults=e(j.defaults,{centerX:"50%",centerY:"50%",radius:"40%",active:!0});class Je extends ie{constructor(e){super(),this.view=e}_doUpdate(e){return this.view._secRate=e,this.view.$_renderHands(this.view.model,this.view._exts),!0}}class Ke extends K{constructor(e){super(e,"rct-clock-gauge"),this._rimThick=0,this._secRate=1}_doInitContents(e,t){t.add(this._faceView=new Q(e,"rct-clock-gauge-face")),t.add(this._rimView=new _(e,"rct-clock-gauge-rim")),t.add(this._labelView=new u(e,"rct-clock-gauge-label")),this._labelView.layout=Z.MIDDLE,t.add(this._tickContainer=new g(e,"rct-clock-gauge-ticks")),t.add(this._tickLabelContainer=new g(e,"rct-clock-gauge-tick-labels")),t.add(this._hourView=new L(e,"rct-clock-gauge-hour")),t.add(this._minuteView=new L(e,"rct-clock-gauge-minute")),t.add(this._secondView=new L(e,"rct-clock-gauge-second")),t.add(this._pinView=new Q(e,"rct-clock-gauge-pin")),this._tickViews=new m(this._tickContainer,A,"rct-clock-gauge-tick"),this._minorTickViews=new m(this._tickContainer,A,"rct-clock-gauge-minor-tick"),this._tickLabelViews=new m(this._tickLabelContainer,u,"rct-clock-gauge-tick-label")}_prepareGauge(e,t){this._tickViews.prepare(t.tick.visible?12:0),this._minorTickViews.prepare(t.minorTick.visible?48:0);const s=Math.round(12/d(1,Math.floor(t.tickLabel.options.step)||1));this._tickLabelViews.prepare(t.tickLabel.visible?s:0,(e=>{e.layout=Z.MIDDLE}))}_renderGauge(e,t){const s=this.model,i=this._exts=s.getExtents(e,t);this._secRate=1,this.$_renderFace(s,i),this.$_renderHands(s,i),s.options.active&&!s.getTime()?this._runner||(this._runner=setInterval((()=>{const e=this._prevSec;this.$_renderHands(this.model,this._exts),ee(e-this._prevSec)>=1&&this._secondView.visible&&s.chart.animatable()&&s.secondHand.options.animatable&&this.$_moveSecond(e)}),1e3)):this._runner&&(clearInterval(this._runner),this._runner=void 0)}$_renderFace(e,t){const s=this._labelView,i=this._rimView,a=this._minorTickViews,n=this._tickLabelViews,l=this._pinView,{cx:r,cy:h,rd:o}=t,c=this._rimThick=i.visible?e.rim.getThickness(o):0;this._faceView.setCircle(r,h,o),i.setVis(e.rim.visible)&&(i.internalSetStyleOrClass(e.rim._style),i.setSector({cx:r,cy:h,rx:o,ry:o,innerRadius:1-c/o,start:0,angle:2*Math.PI,clockwise:!0}));const d=o-c;let _=d-e.tick.length,u=te,g=se/12;if(this._tickViews.forEach(((t,s)=>{t.setLine(r+C(u)*d,h+S(u)*d,r+C(u)*_,h+S(u)*_),t.internalSetStyleOrClass(e.tick._style),u+=g})),!a.isEmpty){let t=0;_=d-e.minorTick.length,u=te,g=se/60,a.forEach((s=>{t%5==0&&(u+=g,t++),s.setLine(r+C(u)*d,h+S(u)*d,r+C(u)*_,h+S(u)*_),s.internalSetStyleOrClass(e.minorTick._style),u+=g,t++}))}if(!n.isEmpty){const t=12/n.count,s=se/12*t;u=te,n.get(0).text="12",_=d-(e.tick.length+e.tickLabel.options.offset||0),_-=.5*n.get(0).getBBox().height,n.forEach(((i,a,n)=>{i.text=String(0===a?12:a*t),i.trans(r+C(u)*_,h+S(u)*_),i.internalSetStyleOrClass(e.tickLabel._style),u+=s}))}l.setVis(e.pin.visible)&&(l.setCircle(r,h,e.pin.raidus),l.setStyleOrClass(e.pin._style)),s.setVis(e.label.visible)&&(s.internalSetStyleOrClass(e.label._style),e.label.buildSvg(s,null,NaN,NaN,null,null),"bottom"===e.label.options.position?s.trans(r,h+_/2):s.trans(r,h-_/2))}$_getNow(){const e=this.model.options.timezone;let t=this.model.getTime()||new Date;if(!isNaN(e)){const s=t.getMinutes()+(t.getTimezoneOffset()+e);t.setMinutes(s)}return t}$_renderHands(e,t){const s=this.$_getNow(),i=s.getHours(),a=s.getMinutes(),n=s.getSeconds(),{cx:l,cy:r,rd:h}=t,o=new E;let c,d,_,u;c=e.hourHand,d=this._hourView,d.setVis(c.visible)&&(u=se*(i/12+a/60/12+n/60/60/12),_=c.getLength(h-this._rimThick),o.rect(-c.options.thickness/2,-_,c.options.thickness,_),d.internalSetStyleOrClass(c._style),d.setPath(o.close(!0)).trans(l,r).rotate(u*y)),c=e.minuteHand,d=this._minuteView,d.setVis(c.visible)&&(u=se*(a/60+n/60/60),_=c.getLength(h-this._rimThick),o.rect(-c.options.thickness/2,-_,c.options.thickness,_),d.internalSetStyleOrClass(c._style),d.setPath(o.close(!0)).trans(l,r).rotate(u*y)),c=e.secondHand,d=this._secondView,d.setVis(c.visible)&&(u=this._secRate<1?se*(this._aniSec+this._secRate)/60:se*n/60,_=c.getLength(h-this._rimThick),o.rect(-c.options.thickness/2,-_,c.options.thickness,_),d.internalSetStyleOrClass(c._style),d.setPath(o.close(!0)).trans(l,r).rotate(u*y),this._prevSec=n)}$_moveSecond(e){if(!isNaN(e)){this._aniSec=e;const t=new Je(this);t.duration=this.model.secondHand.options.duration||200,t.start()}}}function Qe(e){(function(e){return e.Series&&e.SeriesView})(e)&&(e.Gauge.register(He,ce,qe,fe),e.GaugeGroup.register(Ae,de,Re),e.GaugeView.register([ce,we],[fe,Te],[He,$e],[qe,Ke],[de,ye],[Re,Oe],[Ae,Me]))}export{He as BulletGauge,ce as CircleGauge,qe as ClockGauge,fe as LinearGauge,Qe as default,Qe as registerGauge};