UNPKG

realchart

Version:

Wooritech charting library

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