realchart
Version:
Wooritech charting library
8 lines (6 loc) • 14.3 kB
JavaScript
/**
* RealChart Split v1.3.17
* Copyright (C) 2023-2025 WooriTech Inc.
* All Rights Reserved.
*/
import{extend as s,Body as t,ChartItem as e,isArray as i,maxv as o,pickNum as r,isObject as n,isString as h,PaneContainer as a,RectElement as c,LayerElement as _,SectionView as l,BodyView as p,RcControl as u,AxisView as d}from"./index.mjs";class w{constructor(){this._axes=[]}}class g{constructor(s,t){this.chart=s,this.isX=t}rows(){return this._matrix.length}cols(){return this._matrix[0].length}get(s,t){return this._matrix[s][t]}getRow(s){return this._matrix[s]}getColumn(s){return this._matrix.map((t=>t[s]))}_buildTicks(s){const t=this.isX;this._matrix.forEach(((e,i)=>{e.forEach(((e,i)=>{e._axes.forEach((e=>{e.isBased()||e._buildTicks(s[t?e.options.col:e.options.row])}))}))})),this._matrix.forEach(((e,i)=>{e.forEach(((e,i)=>{e._axes.forEach((e=>{e.isBased()&&e._buildTicks(s[t?e.options.col:e.options.row])}))}))}))}_calcPoints(s,t){const e=this.isX;this._matrix.forEach((i=>{i.forEach(((i,o)=>{i._axes.forEach((i=>{const o=e?i.options.col:i.options.row;i._calcPoints(s[o],t)}))}))}))}}class f extends g{constructor(s){super(s,!0)}_prepare(s,t,e){const i=this._matrix=new Array(t+1);for(let s=0;s<i.length;s++){i[s]=[];for(let t=0;t<e;t++)i[s].push(new w)}s.forEach((s=>{const e=s.options.position;let o=s._row;"opposite"===e?(o++,s._runPos=e):o<t-1&&"between"===e?(o++,s._runPos="normal"):s._runPos=e,i[o][s._col]._axes.push(s)}))}}class x extends g{constructor(s){super(s,!1)}_prepare(s,t,e){const i=this._matrix=new Array(t);for(let s=0;s<i.length;s++){i[s]=[];for(let t=0;t<=e;t++)i[s].push(new w)}s.forEach((s=>{const t=s.options.position;let o=s._col;"opposite"===t?(o++,s._runPos=t):s._col<e-1&&"between"===t?(o++,s._runPos="normal"):s._runPos=t,i[s._row][o]._axes.push(s)}))}}class y extends t{constructor(s){super(s.chart),this.pane=s}base(){return this.chart._body}contains(s){return s.options.col===this.pane.col||s.options.row===this.pane.row}}y.defaults=s(t.defaults,{radius:void 0,centerX:void 0,centerY:void 0});class m extends e{constructor(s,t,e){super(s),this.row=t,this.col=e}_doInitChildren(s){s.body=(this._body=new y(this)).init()}get body(){return this._body}_prepareRender(){this.body._prepareRender()}}class v extends e{constructor(s){super(s),this._cols=1,this._rows=1,this._panes={},this._vcols=1,this._vrows=1,this._vpanes=[],this._xAxes=new f(s),this._yAxes=new x(s)}count(){return this._vrows*this._vcols}rowCount(){return this._vrows}colCount(){return this._vcols}paneCount(){return this._vrows*this._vcols}getPane(s,t){return this._vpanes[s][t]}getRow(s){return this._vpanes[s]}getColumn(s){return this._vpanes.map((t=>t[s]))}_doLoadProp(s,t){return["panes","cols","rows"].indexOf(s)>=0||super._doLoadProp(s,t)}_doSetSimple(s){if(i(s)&&s.length>0){const t=this._op;return t.rows=o(1,+s[0]),t.cols=o(1,r(+s[1],t.rows)),t.rows>0&&t.cols>0&&(this.$_parsePanes(t.rows,t.cols),this.visible=!0),!0}return super._doSetSimple(s)}_load(s){return super._load(s),n(s)&&(this.$_parsePanes(this._op.rows=s.rows,this._op.cols=s.cols),this._panes=this.$_loadPanes(s.panes)),this}_doPrepareRender(s){this._vpanes=this.$_collectPanes(s),this._vpanes.forEach((s=>s.forEach((s=>s._prepareRender()))))}getXLens(s){return new Array(this._vcols).fill(s/this._vcols)}getYLens(s){return new Array(this._vrows).fill(s/this._vrows)}layoutAxes(s,t,e,i){const o=this.getXLens(e?t:s),r=this.getYLens(e?s:t);this._xAxes._buildTicks(o),this._yAxes._buildTicks(r),this.$_calcAxesPoints(o,r,0)}$_calcAxesPoints(s,t,e){this._xAxes._calcPoints(s,e),this._yAxes._calcPoints(t,e)}calcAxesPoints(s,t){this.$_calcAxesPoints(s,t,101)}calcSizes(s,t){this._widths=this.$_calcSizes(s,this._widths),this._heights=this.$_calcSizes(t,this._heights)}getAnnotation(s){for(const t in this._panes){const e=this._panes[t].body.getAnnotation(s);if(e)return e}}prepareRender(s,t){this._prepareRender(),this._xAxes._prepare(s,this._vrows,this._vcols),this._yAxes._prepare(t,this._vrows,this._vcols)}$_parseSizes(s){let t;return t=i(s)&&s.length>0?s.slice(0):s>0?new Array(s).fill("*"):["*"],t.map((s=>{if(h(s)){const t=s.trim();return{size:"*"===t?1:parseFloat(t)}}return+s||{size:1}}))}$_parsePanes(s,t){this._widths=this.$_parseSizes(t),this._heights=this.$_parseSizes(s),this._cols=this._widths.length,this._rows=this._heights.length}$_loadPanes(s){const t={};return s=i(s)?s:n(s)?[s]:null,i(s)&&s.forEach((s=>{const e=+s.row||0,i=+s.col||0;if(i>=0&&i<this._cols&&e>=0&&e<this._rows){const o=new m(this.chart,e,i);o.init(),o._load(s),t[e+","+i]=o}})),t}$_collectPanes(s){const t=s._getXAxes()._internalItems(),e=s._getYAxes()._internalItems(),i=[],o=[],r=[];t.concat(e).forEach((s=>{const t=s.options.row||0,e=s.options.col||0;s._row=t,s._col=e,e>=0&&e<this._cols&&i.indexOf(e)<0&&i.push(e),t>=0&&t<this._rows&&o.indexOf(t)<0&&o.push(t)})),i.sort(),o.sort();for(let t=0;t<o.length;t++){const e=[];for(let o=0;o<i.length;o++){const i=this._panes[t+","+o]||new m(s,t,o)._initObject();e.push(i)}r.push(e)}return this._vrows=r.length,this._vcols=r[0].length,r}$_calcSizes(s,t){}}v.defaults=s(e.defaults,{visible:!1,gap:0});class E extends l{constructor(){super(...arguments),this.views=[],this._gap=0}isEmpty(){return 0===this.views.length}prepare(s,t,e,i,o){const r=this.views,n=[];for(this.isX=t,e&&e._axes.forEach((s=>{n.push(s)}));r.length<n.length;){const t=new d(s);this.add(t),r.push(t)}for(;r.length>n.length;)r.pop().remove();if(r.forEach(((s,t)=>{n[t]._runPos,s.model=n[t]})),this.axes=n,this.setVis(r.length>0)){const s=r[0].model;this._gap=s.chart.getAxesGap()}}prepareGuides(s,t,e){const i=this.views,o=this.axes;i.forEach(((e,i)=>{const r=o[i];t.forEach((t=>{t.forEach((t=>{t.isConnected(r)&&e.setVis(this.visible)&&e.prepareGuides(s,t.row,t.col,t._guideContainer,t._frontGuideContainer)}))}))}))}checkHeights(s,t,e){return this.views.length>0?this.$_checkHeights(this.views,s,t,e):0}$_checkHeights(s,t,e,i){let o=0;return s&&(s.forEach((s=>{o+=s.checkHeight(t,e,i)})),o+=(this.views.length-1)*this._gap),o}checkWidths(s,t,e){return this.views.length>0?this.$_checkWidths(this.views,s,t,e):0}$_checkWidths(s,t,e,i){let o=0;return s&&(s.forEach((s=>{o+=s.checkWidth(t,e,i)})),o+=(this.views.length-1)*this._gap),o}getScrollView(s){var t;for(const e of this.views)if(null===(t=e._scrollView)||void 0===t?void 0:t.contains(s))return e._scrollView}setMargins(s,t,e,i){this.views.forEach((o=>o.setMargins(s,t,e,i)))}_setInverted(s){super._setInverted(s),this.isHorz=s&&!this.isX||!s&&this.isX}_doMeasure(s,t,e,i,o){const r=this.axes;if(this.isHorz){let t=0;return this.views.forEach(((n,h)=>{t+=n.measure(s,r[h],e,i,o).height})),{width:e,height:t}}{let t=0;return this.views.forEach(((n,h)=>{t+=n.measure(s,r[h],e,i,o).width})),{width:t,height:i}}}_doLayout(s){this.isHorz?this.views.forEach((s=>{s.resize(this.width,s.mh),s.layout()})):this.views.forEach((s=>{s.resize(s.mw,this.height),s.transX(this.width-s.mw),s.layout()}))}}class C extends l{constructor(s,t){super(s,"rct-axis-container"),this.isX=t,this.sections=[]}prepare(s,t,e,i){const o=this.isX?e.getRow(i):e.getColumn(i);for(;this.sections.length<o.length;){const t=new E(s);this.add(t),this.sections.push(t)}for(;this.sections.length>o.length;)this.sections.pop().remove();this.sections.forEach(((r,n)=>{this.isX?(r.row=i,r.col=n):(r.col=i,r.row=n),r.prepare(s,this.isX,o[n],t,e)}))}prepareGuides(s,t,e,i){const o=this.isX?e.getRow(i):e.getColumn(i);for(;this.sections.length<o.length;){const t=new E(s);this.add(t),this.sections.push(t)}for(;this.sections.length>o.length;)this.sections.pop().remove();this.sections.forEach(((o,r)=>{this.isX?(o.row=i,o.col=r):(o.col=i,o.row=r),o.prepareGuides(s,t,e)}))}checkWidths(s,t,e){return this.sections.length>0?this.sections.reduce(((i,o)=>i+o.checkWidths(s,t,e)),0):0}checkHeights(s,t,e){return this.sections.length>0?this.sections.reduce(((i,o)=>i+o.checkHeights(s,t,e)),0):0}_setInverted(s){super._setInverted(s),this._isHorz=s&&!this.isX||!s&&this.isX}_doMeasure(s,t,e,i,r){let n=0,h=0;return this._isHorz?this.sections.forEach((n=>{h=o(h,n.measure(s,t,e,i,r).height)})):this.sections.forEach((h=>{n=o(n,h.measure(s,t,e,i,r).width)})),{width:n,height:h}}_doLayout(s){this._isHorz?this.height>0&&this.sections.forEach(((t,e)=>{t.resize(s[2*(e+1)]-s[2*(e+1)-1],this.height),t.trans(s[2*e+1]-s[1],0),t.layout()})):this.width>0&&this.sections.forEach(((t,e)=>{t.resize(this.width,s[2*(e+1)]-s[2*(e+1)-1]),t.trans(0,this.height-(s[2*(e+1)]-s[1])),t.layout()}))}}class b extends p{constructor(){super(...arguments),this.row=0,this.col=0}prepareRender(s,t){const e=this.row,i=this.col,o=t._split.getPane(e,i).body,r=t._getSeries().getPaneSeries(e,i),n=t._getGauges().getPaneVisibles(e,i);this._animatable=u._animatable&&t.animatable(),this._prepareSeries(s,t,r),this._prepareGauges(s,t,n),this._prepareAnnotations(s,o.getAnnotations())}getTooltipPos(){return{x:this.parent.parent.tx+this.tx,y:this.parent.parent.ty+this.ty}}}class A extends a{constructor(s,t){super(s,A.STYLE_NAME),this._bodies=[],this._xContainers=[],this._yContainers=[],this._owner=t}get bodies(){return this._bodies}bodyViewOf(s){return this._bodies.find((t=>t.contains(s)))}prepare(s,t){t.chart,this.$_init(s),this._model=t,this.$_prepareBodies(s,t)}measure(s,t,e,i,o){const r=t.chart,n=this._inverted=t.chart.isInverted(),h=t._xAxes,a=t._yAxes,c=e,_=i;this.$_prepareAxes(s,h,!0),this.$_prepareAxes(s,a,!1),t.layoutAxes(e,i,n,o),n?(e-=this._xContainers.reduce(((t,o)=>t+o.checkWidths(s,e,i)),0),i-=this._yContainers.reduce(((t,o)=>t+o.checkHeights(s,e,i)),0)):(i-=this._xContainers.reduce(((t,o)=>t+o.checkHeights(s,e,i)),0),e-=this._yContainers.reduce(((t,o)=>t+o.checkWidths(s,e,i)),0)),t.layoutAxes(e,i,n,o),this._xContainers.forEach((t=>t.measure(s,r,e,i,o))),this._yContainers.forEach((t=>t.measure(s,r,e,i,o))),e=c,i=_,n?(e-=this._xContainers.reduce(((s,t)=>s+t.mw),0),i-=this._yContainers.reduce(((s,t)=>s+t.mh),0)):(i-=this._xContainers.reduce(((s,t)=>s+t.mh),0),e-=this._yContainers.reduce(((s,t)=>s+t.mw),0)),t.layoutAxes(e,i,n,o),this.$_prepareAxisGuides(s,h,!0),this.$_prepareAxisGuides(s,h,!1),this._xContainers.forEach((t=>t.measure(s,r,e,i,o))),this._yContainers.forEach((t=>t.measure(s,r,e,i,o)));const l=t.getXLens(n?i:e),p=t.getYLens(n?e:i);t.calcAxesPoints(l,p)}layout(){const s=this._model,t=this.width,e=this.height;this._back.resize(t,e),this.$_calcExtents(s,t,e),this.$_layoutAxes(s,!0,t,e),this.$_layoutAxes(s,!1,t,e),this.$_layoutBodies(s,t,e)}seriesByDom(s){for(const t of this._bodies){const e=t.seriesByDom(s);if(e)return e}}getSeries(s){for(const t of this.bodies){const e=t.findSeries(s);if(e)return e}}$_init(s){this._back||(this.add(this._back=new c(s)),this._back.setStyles({fill:"none"}),this.add(this._bodyContainer=new _(s,void 0)),this.add(this._axisContainer=new _(s,void 0)))}$_prepareBodies(s,t){const e=t.chart,i=t.paneCount(),o=this._bodies,r=this._bodyMap=[];for(;o.length<i;){const t=new b(s,this._owner);this._bodyContainer.add(t),o.push(t)}for(;o.length>i;)o.pop().remove();for(let s=0;s<t.rowCount();s++){const e=[];for(let i=0;i<t.colCount();i++){const r=o[s*t.colCount()+i];e.push(r),r.row=s,r.col=i}r.push(e)}o.forEach((t=>{t.prepareRender(s,e),t.prepareGuideContainers(),t._gridRowContainer.prepare()}))}$_prepareAxes(s,t,e){const i=e?this._xContainers:this._yContainers,o=e?t.rows():t.cols();for(;i.length<o;){const t=new C(s,e);this._axisContainer.add(t),i.push(t)}for(;i.length>o;)i.pop().remove();i.forEach(((e,i)=>{e.prepare(s,this._bodyMap,t,i)}))}$_prepareAxisGuides(s,t,e){(e?this._xContainers:this._yContainers).forEach(((e,i)=>{e.prepareGuides(s,this._bodyMap,t,i)}))}$_calc(s,t,e,i){const o=new Array(2*(t+1)),r=e-s.reduce(((s,t)=>s+t[i]),0),n=new Array(t);let h=0,a=0;for(a=0;a<t;a++)n[a]=r/t;for(a=0;a<t;a++)o[2*a]=h,o[2*a+1]=h+=s[a][i],h+=n[a];return o[2*a]=h,o[2*a+1]=h+s[a][i],o}$_calcExtents(s,t,e){this._inverted?(this._rowPoints=this.$_calc(this._xContainers,s.rowCount(),t,"mw"),this._colPoints=this.$_calc(this._yContainers,s.colCount(),e,"mh")):(this._rowPoints=this.$_calc(this._xContainers,s.rowCount(),e,"mh"),this._colPoints=this.$_calc(this._yContainers,s.colCount(),t,"mw"))}$_layoutAxes(s,t,e,i){const o=this.control._padding,r=this._rowPoints,n=this._colPoints,h=t?this._xContainers:this._yContainers;if(this._inverted)if(t){const s=n[1],t=n[n.length-2]-s;h.forEach(((s,e)=>{s.resize(s.mw,t),s.trans(r[2*e],i-n[n.length-2]),s.layout(n)}))}else{const s=r[1],t=r[r.length-2]-s;h.forEach(((e,h)=>{const a=e.sections;for(let s=0,t=a.length;s<t;s++){const e=a[s],i=0===s?o.left:0,n=s===t-1?o.right:0;let h=0,c=0;t>1&&(h=r[2*s+1]-r[2*s],c=r[2*(s+1)+1]-r[2*(s+1)],0===s?a[s+1].isEmpty()?c=r[2*(s+1)]-r[2*(s+1)-1]:c/=2:s===t-1?a[s-1].isEmpty()?h=r[2*(s-1)]-r[2*(s-1)-1]:h/=2:(a[s-1].isEmpty()?h=r[2*(s-1)]-r[2*(s-1)-1]:h/=2,a[s+1].isEmpty()?c=r[2*(s+1)]-r[2*(s+1)-1]:c/=2)),e.setMargins(i,h,c,n)}e.resize(t,e.mh),e.trans(s,i-n[2*h+1]),e.layout(r)}))}else if(t){const s=n[1];e=n[n.length-2]-s,h.forEach(((t,a)=>{const c=t.sections;for(let s=0,t=c.length;s<t;s++){const e=c[s],i=0===a?o.left:0,_=a===h.length-1?o.right:0;let l=0,p=0;t>1&&(l=n[2*s+1]-n[2*s],p=n[2*(s+1)+1]-n[2*(s+1)],0===s?c[s+1].isEmpty()?p=n[2*(s+1)]-n[2*(s+1)-1]:p/=2:s===t-1?c[s-1].isEmpty()?l=n[2*(s-1)]-n[2*(s-1)-1]:l/=2:(c[s-1].isEmpty()?l=n[2*(s-1)]-n[2*(s-1)-1]:l/=2,c[s+1].isEmpty()?p=n[2*(s+1)]-r[2*(s+1)-1]:p/=2)),e.setMargins(i,l,p,_)}t.resize(e,t.mh),t.trans(s,i-r[2*a+1]),t.layout(n)}))}else{const s=r[r.length-2],t=s-r[1];h.forEach(((e,o)=>{e.resize(e.mw,t),e.trans(n[2*o],i-s),e.layout(r)}))}}$_layoutBodies(s,t,e){s.chart._body;const i=s.rowCount(),o=s.colCount(),r=this._rowPoints,n=this._colPoints,h=this._bodies;if(this._inverted)for(let t=0;t<i;t++){const e=r[2*(t+1)-1],i=r[2*(t+1)];for(let r=0;r<o;r++){const a=h[t*o+r],c=n[2*r+1],_=n[2*(r+1)];a.measure(this.doc,s.getPane(t,r).body,i-e,_-c,1),a.resize(i-e,_-c),a.trans(e,this.height-_),a.layout()}}else for(let t=0;t<i;t++){const i=r[2*(t+1)-1],a=r[2*(t+1)];for(let r=0;r<o;r++){const c=h[t*o+r],_=n[2*(r+1)-1],l=n[2*(r+1)];c.measure(this.doc,s.getPane(t,r).body,l-_,a-i,1),c.resize(l-_,a-i),c.trans(_,e-a),c.layout()}}}}function P(s){(function(s){return s.Series&&s.SeriesView})(s)&&(s.ChartObject.registerSplitClass(v),s.ChartView.registerPaneClass(A))}A.STYLE_NAME="rct-panes";export{v as Split,P as default,P as registerSplit};