realchart 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/gauge.js +1 -1
- package/gauge.mjs +1 -1
- package/heatmap.js +1 -1
- package/heatmap.mjs +1 -1
- package/index.d.ts +52 -5
- package/index.js +2 -2
- package/index.mjs +2 -2
- package/package.json +1 -1
- package/split.js +1 -1
- package/split.mjs +1 -1
- package/treemap.js +1 -1
- package/treemap.mjs +1 -1
- package/vector.js +1 -1
- package/vector.mjs +1 -1
- package/wordcloud.js +2 -2
- package/wordcloud.mjs +2 -2
package/package.json
CHANGED
package/split.js
CHANGED
package/split.mjs
CHANGED
package/treemap.js
CHANGED
package/treemap.mjs
CHANGED
package/vector.js
CHANGED
package/vector.mjs
CHANGED
package/wordcloud.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
|
-
* RealChart Wordcloud v1.3.
|
|
3
|
+
* RealChart Wordcloud v1.3.3
|
|
4
4
|
* Copyright (C) 2023-2025 WooriTech Inc.
|
|
5
5
|
* All Rights Reserved.
|
|
6
6
|
*/
|
|
7
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("realchart")):"function"==typeof define&&define.amd?define(["exports","realchart"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).RealChartWordCloud={},t.RealChart)}(this,(function(t,e){"use strict";function i(t){var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var s=i(e);class n extends e.WidgetSeriesPoint{}class r extends e.WidgetSeries{$_denormalizeFontSize(t,i,s){let n,o;return"min"==t?(n=e.calcPercent(e.parsePercentSize(r.MinFontSize,!1),i),o=e.calcPercent(e.parsePercentSize(r.MaxMinFontSize,!1),i)):(n=e.calcPercent(e.parsePercentSize(r.MinMaxFontSize,!1),i),o=e.calcPercent(e.parsePercentSize(r.MaxFontSize,!1),i)),s>1?o:s<0?n:s*(o-n)+n}calcFontRatio(t,i,s,n){return e.calcPercent(i,s,n)}getMinFontSize(t,i){const{fixed:s,size:n}=this._minFontSizeDim,o=s&&n<=1?this.$_denormalizeFontSize("min",t,n):e.calcPercent(this._minFontSizeDim,t,i);return Math.max(e.calcPercent(e.parsePercentSize(r.MinFontSize,!1),t),o)}getMaxFontSize(t,i){const{fixed:s,size:n}=this._maxFontSizeDim,o=s&&n<=1?this.$_denormalizeFontSize("max",t,n):e.calcPercent(this._maxFontSizeDim,t,i);return Math.min(e.calcPercent(e.parsePercentSize(r.MaxFontSize,!1),t),o)}getLogFunc(){const t=this._op.logBase;return t>=2?function(e){return Math.max(Math.log(e)/Math.log(t))}:function(t){return t}}_colorByPoint(){return this._op.colorByPoint}_createPoint(t){return new n(t)}_doApply(t){var i;super._doApply(t),(t.text!==this._text||e.Utils.equalArrays(this._excludes,t.excludes))&&(this._text=t.text,this._excludes=null===(i=t.excludes)||void 0===i?void 0:i.slice(),this._dataSourceDirty=!0),this._setDims(t,"minFontSize","maxFontSize")}_doLoadPoints(t){const e=this._op,i=e.text;if(i){const s=Math.max(e.minLength||1,1),n={};let r=[],o=e.excludes,a=i.split(/\s+/g);Array.isArray(o)&&o.length>0&&(a=a.filter((t=>o.indexOf(t)<0))),a.forEach((t=>{t.length>=s&&(t in n?n[t]++:n[t]=1)}));for(const t in n)r.push({x:t,y:n[t]});r=r.sort(((t,e)=>e.y-t.y)),r.length>0&&(t=r)}else t=[];super._doLoadPoints(t)}isPointLabelVisible(t){return!1}_prepareRender(){super._prepareRender(),this.pointValuesPrepared(null),this.collectValues(null,null),this.collectRanges(null)}}r.type=e.WordCloudSeriesType,r.MinFontSize=8,r.MaxMinFontSize=15,r.MaxFontSize="15%",r.MinMaxFontSize="5%",r.defaults=e.extend(e.WidgetSeries.defaults,{frame:"rectangle",maxCount:100,maxFontSize:1,minFontSize:0,colorByPoint:!0,autoScale:!0});const o=Math.floor;class a{start(t,i,s,n,r,o){this._container=t;const a="circle"===s.frame||"ellipse"===s.frame,h=s.autoScale,l=e.pickNum(s.seed,0)*Math.PI*2/360,c=Math.max(0,e.pickNum(s.wordGap,0));let d=n,_=0,u=r,x=0,p=0;this.$_prepare(s,n,r),i.forEach((t=>{const e=t.point;if(this.$_findPos(t,a,s.shuffle,this._radius,l,c)){const i=t.getBBox(),s=t.box.c1*this._unit,n=t.box.r1*this._unit;this.$_placeWord(t),e.xPos=(t.wx=s)+i.width/2,e.yPos=t.wy=n,d=Math.min(d,s),_=Math.max(_,s+i.width),u=Math.min(u,n),x=Math.max(x,n+i.height),p++}else t.setVis(!1)})),e.Utils.log("Words placed.",p,"of",i.length);const m=_-d,f=x-u,g=n/2,M=r/2,P=h?1/(Math.max(m/n,f/r)+.02):1,S=~~((d+m/2-g)*P),w=~~((u+f/2-M)*P);return this._trans={x:S,y:w,cx:g,cy:M,rate:P},i.forEach((t=>{const e=t.point;e.xPos=g-S+(e.xPos-g)*P,e.yPos=M-w+(e.yPos-M)*P})),this.$_transform(),null==o||o(i),this}stop(){}$_transform(t=1){let{x:e,y:i,cx:s,cy:n,rate:r}=this._trans;e=~~(e*t),i=~~(i*t),this._container.dom.setAttribute("transform-origin",`${s} ${n}`),this._container.trans(-e,-i),this._container.scale(r)}$_prepare(t,e,i){const s=this._unit=8;this._grid=[],this._cols=o(e/s),this._rows=o(i/s),this._radius=o(Math.sqrt(this._cols*this._cols+this._rows*this._rows)/2);const n=2*this._radius;this._center={c:this._radius,r:this._radius};for(let t=0;t<n;t++)this._grid.push([]);this._rdPoints=[],this._ellipticity="ellipse"===t.frame||"rectangle"===t.frame?i/e:1}$_isOverlapping(t){const e=this._grid;for(let i=t.r1;i<=t.r2;i++)for(let s=t.c1;s<=t.c2;s++)if(e[i]||(e[i]=[]),e[i][s])return!0;return!1}$_placeWord(t){const e=this._grid,i=t.box;for(let s=i.r1;s<=i.r2;s++)for(let n=i.c1;n<=i.c2;n++)e[s][n]=t}$_getPoints(t,e,i){if(this._rdPoints[t])return this._rdPoints[t];const s=this._center,n=this._ellipticity,r=t*this._unit;let o=0,a=[];for(0===t&&a.push([s.c,s.r]);o<r;){const h=o/r*2*Math.PI+i;let l=t*Math.cos(h)/n,c=t*Math.sin(h);if(!e){const t=Math.max(Math.abs(Math.cos(h)),Math.abs(Math.sin(h)));l/=t,c/=t}a.push([~~(s.c+l),~~(s.r+c)]),o++}return this._rdPoints[t]=a}$_getBox(t,e,i,s){const n=this._unit,r=t.getBBox(),a=t.hText,h=Math.max(0,e-o(r.width/2/n)),l=Math.max(0,i-o(a/2/n));return{c1:h,r1:l,c2:h+o(r.width/n)+s,r2:l+o(a/n)}}$_findPos(t,i,s,n,r,o){let a=0,h=0;for(n=Math.max(n,this._grid.length+1);a<n;){const n=this.$_getPoints(a,i,r+h++%4*(Math.PI/4));s&&e.Utils.shuffle(n);if(n.some((e=>{const i=this.$_getBox(t,e[0],e[1],o);if(!this.$_isOverlapping(i))return t.box=i,!0})))return!0;a++}}}class h extends a{$_findPos(t,e,i,s,n,r){if(this.$_getPoints(s,e,i?Math.random()*Math.PI*2:n).some((e=>{const i=this.$_getBox(t,e[0],e[1],r);if(!this.$_isOverlapping(i))return t.box=i,!0})))return!0}$_getPoints(t,e,i){const s=this._center,n=this._ellipticity,r=2*t*this._unit;let o=-1,a=[];0===t&&a.push([s.c,s.r]);const h=i>Math.PI?1:-1;if(e)for(;++o<r;){const e=o/r,l=i+o*e*h,c=t*e,d=c*Math.cos(l)/n,_=c*Math.sin(l),u=s.c+d,x=s.r+_;a.push([~~u,~~x])}else{let e=this._unit>>1,r=e/n,l=s.c+r*Math.cos(i),c=s.r+e*Math.sin(i);const d=Math.max(1,this._unit>>1),_=d-Math.max(1,d>>1),u=.99;for(;++o>=0;){e=1+_*Math.pow(u,o),r=e/n;switch(3&(h*Math.sqrt(1+8*o)-1)/2){case 0:l+=r;break;case 1:c+=e;break;case 2:l-=r;break;default:c-=e}if(Math.max(Math.abs(l-t),Math.abs(c-t))>t)break;a.push([~~l,~~c])}}return a}$_getBox(t,e,i,s){const n=this._unit,r=t.getBBox(),a=t.hText,h=Math.min(2*this._radius,Math.max(0,e-o(r.width/2/n))),l=Math.min(2*this._radius,Math.max(0,i-o(a/2/n)));return{c1:h,r1:l,c2:h+o(r.width/n)+s,r2:l+o(a/n)}}}class l extends e.RcElement{constructor(t){super(t,e.SeriesView.POINT_CLASS),this.add(this.hintView=new e.RectElement(t)),this.hintView.setStyles({stroke:"none",fill:"transparent"}),this.add(this.textView=new e.TextElement(t)),this.textView.setStyle("pointerEvents","none")}layout(){const t=this.getBBox();this.hintView.setRect({x:0,y:this.yText*l.TOP_PAD,width:t.width,height:this.hText-this.yText}),this.textView.transY(-this.yText*l.TOP_PAD)}}l.TOP_PAD=.5;class c extends e.WidgetSeriesView{constructor(t){super(t,"rct-wordcloud-series"),this._pointContainer.add(this._wordContainer=new e.LayerElement(t,null)),this._words=new e.ElementPool(this._wordContainer,l)}_getPointPool(){return this._words}needFronting(){return!1}isEmptyView(){return this._empty}_renderSeries(t,i){const s=this.model.options,n=s.text;if(t!==this._wSave||i!==this._hSave||n!==this._tSave){const r=+new Date;let o=this._visPoints.slice();if(s.minWeight>0&&(o=o.filter((t=>t.yValue>=s.minWeight))),s.minLength>1&&(o=o.filter((t=>t.x.length>=s.minLength))),s.maxCount<o.length&&(o.length=Math.max(0,s.maxCount)),this.$_prepareWords(this.doc,this.model,o),"spiral"===s.placer)this._placer=(new h).start(this._wordContainer,this._words._internalItems(),s,t,i,(e=>{this.$_layoutWords(t,i)}));else this._placer=(new a).start(this._wordContainer,this._words._internalItems(),s,t,i,(e=>{this.$_layoutWords(t,i)}));this._wSave=t,this._hSave=i,this._tSave=n,this._empty=o.length<1,e.Utils.log(o.length+" words placed in "+(+new Date-r)+"ms.")}else this.$_layoutWords(t,i)}_runShowEffect(t){t&&e.SeriesAnimation.spread(this,(()=>{}))}_doPosRateChanged(t){this.$_layoutWords(this.width,this.height)}$_prepareWords(t,i,s){const n=i._minY,r=i._maxY,o=r-n,a=this.height,h=i.getMaxFontSize(a,1);let c=Math.min(h,i.getMinFontSize(a,0));const d=n===r||c===h,_=d?NaN:i.options.logBase,u=getComputedStyle(this._wordContainer.dom).fontFamily,x=Math.min(2,Math.max(.1,+i.options.textHeight)),p=isNaN(x)?t.createElement("canvas").getContext("2d"):null,m=1-l.TOP_PAD;let f;this._words.prepare(s.length,((r,a)=>{const l=r.point=s[a],g=r.textView;let M=(l.y-n)/o;_>1&&(M=1-(Math.pow(_,1-M)-1)/(_-1));let P=c+(d?(h-c)/2:M*(h-c));const S=l.x;this._preparePoint(t,i,l,r),delete r.box,g.text=S,g.anchor=e.TextAnchor.START,g.setStyles({fontSize:e.pixel(P)}),g.layoutText(),p?(p.font=`${e.pixel(P)} ${u}`,f=p.measureText(S),r.yText=.9*Math.max(0,f.fontBoundingBoxAscent-f.actualBoundingBoxAscent),r.hText=Math.ceil((f.actualBoundingBoxAscent+f.actualBoundingBoxDescent)*(P<=10?1.1:1.08)-.1)+r.yText*m):(r.yText=0,r.hText=r.getBBox().height*x),r.layout(),r.setVis(!0)}))}$_layoutWords(t,e){var i;let s=this._getPosRate();null===(i=this._placer)||void 0===i||i.$_transform(s),s=1-s,this._words.forEach((i=>{const n=i.getBBox(),r=(t-n.width)/2;let o=(e-n.height)/2;i.trans(i.wx-(i.wx-r)*s,i.wy-(i.wy-o)*s)}))}}function d(t){(function(t){return t.Series&&t.SeriesView})(t)&&(t.Series.register(r),t.SeriesView.register([r,c]))}d(s),t.WordCloudSeries=r,t.default=d,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
7
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("realchart")):"function"==typeof define&&define.amd?define(["exports","realchart"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).RealChartWordCloud={},t.RealChart)}(this,(function(t,e){"use strict";function i(t){var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var s=i(e);class n extends e.WidgetSeriesPoint{}class o extends e.WidgetSeries{$_denormalizeFontSize(t,i,s){let n,r;return"min"==t?(n=e.calcPercent(e.parsePercentSize(o.MinFontSize,!1),i),r=e.calcPercent(e.parsePercentSize(o.MaxMinFontSize,!1),i)):(n=e.calcPercent(e.parsePercentSize(o.MinMaxFontSize,!1),i),r=e.calcPercent(e.parsePercentSize(o.MaxFontSize,!1),i)),s>1?r:s<0?n:s*(r-n)+n}calcFontRatio(t,i,s,n){return e.calcPercent(i,s,n)}getMinFontSize(t,i){const{fixed:s,size:n}=this._minFontSizeDim,r=s&&n<=1?this.$_denormalizeFontSize("min",t,n):e.calcPercent(this._minFontSizeDim,t,i);return Math.max(e.calcPercent(e.parsePercentSize(o.MinFontSize,!1),t),r)}getMaxFontSize(t,i){const{fixed:s,size:n}=this._maxFontSizeDim,r=s&&n<=1?this.$_denormalizeFontSize("max",t,n):e.calcPercent(this._maxFontSizeDim,t,i);return Math.min(e.calcPercent(e.parsePercentSize(o.MaxFontSize,!1),t),r)}getLogFunc(){const t=this._op.logBase;return t>=2?function(e){return Math.max(Math.log(e)/Math.log(t))}:function(t){return t}}_colorByPoint(){return this._op.colorByPoint}_createPoint(t){return new n(t)}_doApply(t){var i;super._doApply(t),(t.text!==this._text||e.Utils.equalArrays(this._excludes,t.excludes))&&(this._text=t.text,this._excludes=null===(i=t.excludes)||void 0===i?void 0:i.slice(),this._dataSourceDirty=!0),this._setDims(t,"minFontSize","maxFontSize")}_doLoadPoints(t){const e=this._op,i=e.text;if(i){const s=Math.max(e.minLength||1,1),n={};let o=[],r=e.excludes,a=i.split(/\s+/g);Array.isArray(r)&&r.length>0&&(a=a.filter((t=>r.indexOf(t)<0))),a.forEach((t=>{t.length>=s&&(t in n?n[t]++:n[t]=1)}));for(const t in n)o.push({x:t,y:n[t]});o=o.sort(((t,e)=>e.y-t.y)),o.length>0&&(t=o)}else t=[];super._doLoadPoints(t)}isPointLabelVisible(t){return!1}_prepareRender(){super._prepareRender(),this.pointValuesPrepared(null),this.collectValues(null,null),this.collectRanges(null)}}o.type=e.WordCloudSeriesType,o.MinFontSize=8,o.MaxMinFontSize=15,o.MaxFontSize="15%",o.MinMaxFontSize="5%",o.defaults=e.extend(e.WidgetSeries.defaults,{frame:"rectangle",maxCount:100,maxFontSize:1,minFontSize:0,colorByPoint:!0,autoScale:!0});const r=Math.floor;class a{constructor(t){this._options=t}start(t,i,s,n,o,r){this._container=t;const a="circle"===s.frame||"ellipse"===s.frame,h=s.autoScale,l=e.pickNum(s.seed,0)*Math.PI*2/360,c=Math.max(0,e.pickNum(s.wordGap,0));let d=n,u=0,_=o,x=0,p=0;this.$_prepare(s,n,o),this._unit,i.forEach((t=>{const e=t.point;if(this.$_findPos(t,a,s.shuffle,this._radius,l,c)){const{x:i,y:s,width:n,height:o}=t.box.bounds;this.$_placeWord(t),e.xPos=i+n/2,e.yPos=s,d=Math.min(d,i),u=Math.max(u,i+n),_=Math.min(_,s),x=Math.max(x,s+o),p++}else t.setVis(!1)})),e.Utils.log("Words placed.",p,"of",i.length);const m=u-d,f=x-_,g=n/2,M=o/2,y=h?1/(Math.max(m/n,f/o)+.02):1,P=~~((d+m/2-g)*y),w=~~((_+f/2-M)*y);return this._trans={x:P,y:w,cx:g,cy:M,rate:y},i.forEach((t=>{const e=t.point;e.xPos=g-P+(e.xPos-g)*y,e.yPos=M-w+(e.yPos-M)*y})),this.$_transform(),null==r||r(i),this}stop(){}$_transform(t=1){let{x:e,y:i,cx:s,cy:n,rate:o}=this._trans;e=~~(e*t),i=~~(i*t),this._container.dom.setAttribute("transform-origin",`${s} ${n}`),this._container.trans(-e,-i),this._container.scale(o*t)}$_prepare(t,e,i){const s=this._unit=8;this._grid=[],this._cols=r(e/s),this._rows=r(i/s),this._radius=r(Math.sqrt(this._cols*this._cols+this._rows*this._rows)/2);const n=2*this._radius;this._center={c:this._radius,r:this._radius};for(let t=0;t<n;t++)this._grid.push([]);this._rdPoints=[],this._ellipticity="ellipse"===t.frame||"rectangle"===t.frame?i/e:1}$_isOverlapping(t){const e=this._grid;for(let i=t.r1;i<=t.r2;i++)for(let s=t.c1;s<=t.c2;s++)if(e[i]||(e[i]=[]),e[i][s])return!0;return!1}$_placeWord(t){const e=this._grid,i=t.box;for(let s=i.r1;s<=i.r2;s++)for(let n=i.c1;n<=i.c2;n++)e[s][n]=t}$_getPoints(t,e,i){if(this._rdPoints[t])return this._rdPoints[t];const s=this._center,n=this._ellipticity,o=t*this._unit;let r=0,a=[];for(0===t&&a.push([s.c,s.r]);r<o;){const h=r/o*2*Math.PI+i;let l=t*Math.cos(h)/n,c=t*Math.sin(h);if(!e){const t=Math.max(Math.abs(Math.cos(h)),Math.abs(Math.sin(h)));l/=t,c/=t}a.push([~~(s.c+l),~~(s.r+c)]),r++}return this._rdPoints[t]=a}$_rotatePoint(t,e,i){const s=e*Math.PI/180,n=Math.cos(s),o=Math.sin(s),{x:r,y:a,width:h,height:l}=t,c=r+h,d=a+l,u=r+h/2,_=a+l/2,x=[{x:r,y:a},{x:c,y:a},{x:r,y:d},{x:c,y:d}].map((t=>({x:u+(t.x-u)*n-(t.y-_)*o,y:_+(t.x-u)*o+(t.y-_)*n}))),p=Math.min(...x.map((t=>t.x))),m=Math.min(...x.map((t=>t.y))),f=Math.max(...x.map((t=>t.x))),g=Math.max(...x.map((t=>t.y))),M=this._unit,y=f-p,P=g-m;return{c1:Math.max(0,~~(p/M)),r1:Math.max(0,~~(m/M)),c2:~~(f/M),r2:~~(g/M)+i,bounds:{x:p,y:m,width:y,height:P}}}$_getBox(t,e,i,s,n=0){const o=this._unit,{width:r}=t.getBBox(),a=t.hText,h=r/o,l=a/o,c=Math.ceil(h/2),d=Math.ceil(l/2),u=Math.max(0,e-c),_=Math.max(0,i-d),x=u+Math.ceil(h),p=_+Math.ceil(l),m={x:(e-c)*o,y:(i-d)*o,width:r,height:a};return n?this.$_rotatePoint(m,n,s):{c1:u,r1:_,c2:x+s,r2:p,bounds:m}}$_drawDebugBox(t,i){const{doc:s}=this._container,{x:n,y:o,width:r,height:a}=t.bounds,h=e.RectElement.create(s,"",n,o,r,a);h.setFill((null==i?void 0:i.fill)||"#ff000055"),h.setStroke((null==i?void 0:i.stroke)||"none"),h.setAttr("stroke-dasharray",(null==i?void 0:i.strokeDashArray)||"4"),this._container.add(h)}$_findPos(t,i,s,n,o,r){let a=0,h=0;n=Math.max(n,this._grid.length+1);const l=[0,-90],c=l.length;for(;a<n;){const n=this.$_getPoints(a,i,o+h++%4*(Math.PI/4));s&&e.Utils.shuffle(n);if(n.some(((i,s)=>{let n=this._options.rotation?l[~~(e.Utils.randomLike(s+o)*c)]:0;const a=this.$_getBox(t,i[0],i[1],r,n);if(!this.$_isOverlapping(a)){if(a.bounds.x<0||a.bounds.y<0)return!1;const e=this.$_getBox(t,i[0],i[1],r),{bounds:s}=e,o={x:s.width/2,y:s.height/2};return t.wx=s.x,t.wy=s.y,t.setRotation(o.x,o.y,n),t.box=a,!0}})))return!0;a++}}}class h extends a{$_findPos(t,e,i,s,n,o){if(this.$_getPoints(s,e,i?Math.random()*Math.PI*2:n).some((e=>{const i=this.$_getBox(t,e[0],e[1],o);if(!this.$_isOverlapping(i))return t.box=i,!0})))return!0}$_getPoints(t,e,i){const s=this._center,n=this._ellipticity,o=2*t*this._unit;let r=-1,a=[];0===t&&a.push([s.c,s.r]);const h=i>Math.PI?1:-1;if(e)for(;++r<o;){const e=r/o,l=i+r*e*h,c=t*e,d=c*Math.cos(l)/n,u=c*Math.sin(l),_=s.c+d,x=s.r+u;a.push([~~_,~~x])}else{let e=this._unit>>1,o=e/n,l=s.c+o*Math.cos(i),c=s.r+e*Math.sin(i);const d=Math.max(1,this._unit>>1),u=d-Math.max(1,d>>1),_=.99;for(;++r>=0;){e=1+u*Math.pow(_,r),o=e/n;switch(3&(h*Math.sqrt(1+8*r)-1)/2){case 0:l+=o;break;case 1:c+=e;break;case 2:l-=o;break;default:c-=e}if(Math.max(Math.abs(l-t),Math.abs(c-t))>t)break;a.push([~~l,~~c])}}return a}$_getBox(t,e,i,s){const n=this._unit,o=t.getBBox(),a=t.hText,h=Math.min(2*this._radius,Math.max(0,e-r(o.width/2/n))),l=Math.min(2*this._radius,Math.max(0,i-r(a/2/n)));return{c1:h,r1:l,c2:h+r(o.width/n)+s,r2:l+r(a/n),w:t.width,h:a}}}class l extends e.RcElement{constructor(t){super(t,e.SeriesView.POINT_CLASS),this.add(this.hintView=new e.RectElement(t)),this.hintView.setStyles({stroke:"none",fill:"transparent"}),this.add(this.textView=new e.TextElement(t)),this.textView.setStyle("pointerEvents","none")}layout(){const t=this.getBBox();this.hintView.setRect({x:0,y:this.yText*l.TOP_PAD,width:t.width,height:this.hText-this.yText}),this.textView.transY(-this.yText*l.TOP_PAD)}}l.TOP_PAD=.5;class c extends e.WidgetSeriesView{constructor(t){super(t,"rct-wordcloud-series"),this._pointContainer.add(this._wordContainer=new e.LayerElement(t,null)),this._words=new e.ElementPool(this._wordContainer,l)}_getPointPool(){return this._words}needFronting(){return!1}isEmptyView(){return this._empty}_renderSeries(t,i){const s=this.model.options,n=s.text;if(t!==this._wSave||i!==this._hSave||n!==this._tSave){const o=+new Date;let r=this._visPoints.slice();if(s.minWeight>0&&(r=r.filter((t=>t.yValue>=s.minWeight))),s.minLength>1&&(r=r.filter((t=>t.x.length>=s.minLength))),s.maxCount<r.length&&(r.length=Math.max(0,s.maxCount)),this.$_prepareWords(this.doc,this.model,r),"spiral"===s.placer)this._placer=new h(s).start(this._wordContainer,this._words._internalItems(),s,t,i,(e=>{this.$_layoutWords(t,i)}));else this._placer=new a(s).start(this._wordContainer,this._words._internalItems(),s,t,i,(e=>{this.$_layoutWords(t,i)}));this._wSave=t,this._hSave=i,this._tSave=n,this._empty=r.length<1,e.Utils.log(r.length+" words placed in "+(+new Date-o)+"ms.")}else this.$_layoutWords(t,i)}_runShowEffect(t){t&&e.SeriesAnimation.spread(this,(()=>{}))}_doPosRateChanged(t){this.$_layoutWords(this.width,this.height)}$_prepareWords(t,i,s){const n=i._minY,o=i._maxY,r=o-n,a=this.height,h=i.getMaxFontSize(a,1);let c=Math.min(h,i.getMinFontSize(a,0));const d=n===o||c===h,u=d?NaN:i.options.logBase,_=getComputedStyle(this._wordContainer.dom).fontFamily,x=Math.min(2,Math.max(.1,+i.options.textHeight)),p=isNaN(x)?t.createElement("canvas").getContext("2d"):null,m=1-l.TOP_PAD;let f;this._words.prepare(s.length,((o,a)=>{const l=o.point=s[a],g=o.textView;let M=(l.y-n)/r;u>1&&(M=1-(Math.pow(u,1-M)-1)/(u-1));let y=c+(d?(h-c)/2:M*(h-c));const P=l.x;this._preparePoint(t,i,l,o),delete o.box,g.text=P,g.anchor=e.TextAnchor.START,g.setStyles({fontSize:e.pixel(y)}),g.layoutText(),p?(p.font=`${e.pixel(y)} ${_}`,f=p.measureText(P),o.yText=.9*Math.max(0,f.fontBoundingBoxAscent-f.actualBoundingBoxAscent),o.hText=Math.ceil((f.actualBoundingBoxAscent+f.actualBoundingBoxDescent)*(y<=10?1.1:1.08)-.1)+o.yText*m):(o.yText=0,o.hText=o.getBBox().height*x),o.layout(),o.setVis(!0)}))}$_layoutWords(t,e){var i;let s=this._getPosRate();null===(i=this._placer)||void 0===i||i.$_transform(s),s=1-s,this._words.forEach((i=>{const{bounds:n}=i.box,o=n.width,r=n.height,a=(t-o)/2;let h=(e-r)/2;i.trans(i.wx-(i.wx-a)*s,i.wy-(i.wy-h)*s)}))}}function d(t){(function(t){return t.Series&&t.SeriesView})(t)&&(t.Series.register(o),t.SeriesView.register([o,c]))}d(s),t.WordCloudSeries=o,t.default=d,Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/wordcloud.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
|
-
* RealChart Wordcloud v1.3.
|
|
3
|
+
* RealChart Wordcloud v1.3.3
|
|
4
4
|
* Copyright (C) 2023-2025 WooriTech Inc.
|
|
5
5
|
* All Rights Reserved.
|
|
6
6
|
*/
|
|
7
|
-
import{WordCloudSeriesType as t,extend as e,WidgetSeries as i,calcPercent as s,parsePercentSize as n,Utils as o,WidgetSeriesPoint as r,RcElement as a,SeriesView as h,RectElement as l,TextElement as c,WidgetSeriesView as _,LayerElement as d,ElementPool as x,SeriesAnimation as u,TextAnchor as m,pixel as p,pickNum as
|
|
7
|
+
import{WordCloudSeriesType as t,extend as e,WidgetSeries as i,calcPercent as s,parsePercentSize as n,Utils as o,WidgetSeriesPoint as r,RcElement as a,SeriesView as h,RectElement as l,TextElement as c,WidgetSeriesView as _,LayerElement as d,ElementPool as x,SeriesAnimation as u,TextAnchor as m,pixel as p,pickNum as M}from"./index.mjs";class g extends r{}class f extends i{$_denormalizeFontSize(t,e,i){let o,r;return"min"==t?(o=s(n(f.MinFontSize,!1),e),r=s(n(f.MaxMinFontSize,!1),e)):(o=s(n(f.MinMaxFontSize,!1),e),r=s(n(f.MaxFontSize,!1),e)),i>1?r:i<0?o:i*(r-o)+o}calcFontRatio(t,e,i,n){return s(e,i,n)}getMinFontSize(t,e){const{fixed:i,size:o}=this._minFontSizeDim,r=i&&o<=1?this.$_denormalizeFontSize("min",t,o):s(this._minFontSizeDim,t,e);return Math.max(s(n(f.MinFontSize,!1),t),r)}getMaxFontSize(t,e){const{fixed:i,size:o}=this._maxFontSizeDim,r=i&&o<=1?this.$_denormalizeFontSize("max",t,o):s(this._maxFontSizeDim,t,e);return Math.min(s(n(f.MaxFontSize,!1),t),r)}getLogFunc(){const t=this._op.logBase;return t>=2?function(e){return Math.max(Math.log(e)/Math.log(t))}:function(t){return t}}_colorByPoint(){return this._op.colorByPoint}_createPoint(t){return new g(t)}_doApply(t){var e;super._doApply(t),(t.text!==this._text||o.equalArrays(this._excludes,t.excludes))&&(this._text=t.text,this._excludes=null===(e=t.excludes)||void 0===e?void 0:e.slice(),this._dataSourceDirty=!0),this._setDims(t,"minFontSize","maxFontSize")}_doLoadPoints(t){const e=this._op,i=e.text;if(i){const s=Math.max(e.minLength||1,1),n={};let o=[],r=e.excludes,a=i.split(/\s+/g);Array.isArray(r)&&r.length>0&&(a=a.filter((t=>r.indexOf(t)<0))),a.forEach((t=>{t.length>=s&&(t in n?n[t]++:n[t]=1)}));for(const t in n)o.push({x:t,y:n[t]});o=o.sort(((t,e)=>e.y-t.y)),o.length>0&&(t=o)}else t=[];super._doLoadPoints(t)}isPointLabelVisible(t){return!1}_prepareRender(){super._prepareRender(),this.pointValuesPrepared(null),this.collectValues(null,null),this.collectRanges(null)}}f.type=t,f.MinFontSize=8,f.MaxMinFontSize=15,f.MaxFontSize="15%",f.MinMaxFontSize="5%",f.defaults=e(i.defaults,{frame:"rectangle",maxCount:100,maxFontSize:1,minFontSize:0,colorByPoint:!0,autoScale:!0});const y=Math.floor;class w{constructor(t){this._options=t}start(t,e,i,s,n,r){this._container=t;const a="circle"===i.frame||"ellipse"===i.frame,h=i.autoScale,l=M(i.seed,0)*Math.PI*2/360,c=Math.max(0,M(i.wordGap,0));let _=s,d=0,x=n,u=0,m=0;this.$_prepare(i,s,n),this._unit,e.forEach((t=>{const e=t.point;if(this.$_findPos(t,a,i.shuffle,this._radius,l,c)){const{x:i,y:s,width:n,height:o}=t.box.bounds;this.$_placeWord(t),e.xPos=i+n/2,e.yPos=s,_=Math.min(_,i),d=Math.max(d,i+n),x=Math.min(x,s),u=Math.max(u,s+o),m++}else t.setVis(!1)})),o.log("Words placed.",m,"of",e.length);const p=d-_,g=u-x,f=s/2,y=n/2,w=h?1/(Math.max(p/s,g/n)+.02):1,S=~~((_+p/2-f)*w),P=~~((x+g/2-y)*w);return this._trans={x:S,y:P,cx:f,cy:y,rate:w},e.forEach((t=>{const e=t.point;e.xPos=f-S+(e.xPos-f)*w,e.yPos=y-P+(e.yPos-y)*w})),this.$_transform(),null==r||r(e),this}stop(){}$_transform(t=1){let{x:e,y:i,cx:s,cy:n,rate:o}=this._trans;e=~~(e*t),i=~~(i*t),this._container.dom.setAttribute("transform-origin",`${s} ${n}`),this._container.trans(-e,-i),this._container.scale(o*t)}$_prepare(t,e,i){const s=this._unit=8;this._grid=[],this._cols=y(e/s),this._rows=y(i/s),this._radius=y(Math.sqrt(this._cols*this._cols+this._rows*this._rows)/2);const n=2*this._radius;this._center={c:this._radius,r:this._radius};for(let t=0;t<n;t++)this._grid.push([]);this._rdPoints=[],this._ellipticity="ellipse"===t.frame||"rectangle"===t.frame?i/e:1}$_isOverlapping(t){const e=this._grid;for(let i=t.r1;i<=t.r2;i++)for(let s=t.c1;s<=t.c2;s++)if(e[i]||(e[i]=[]),e[i][s])return!0;return!1}$_placeWord(t){const e=this._grid,i=t.box;for(let s=i.r1;s<=i.r2;s++)for(let n=i.c1;n<=i.c2;n++)e[s][n]=t}$_getPoints(t,e,i){if(this._rdPoints[t])return this._rdPoints[t];const s=this._center,n=this._ellipticity,o=t*this._unit;let r=0,a=[];for(0===t&&a.push([s.c,s.r]);r<o;){const h=r/o*2*Math.PI+i;let l=t*Math.cos(h)/n,c=t*Math.sin(h);if(!e){const t=Math.max(Math.abs(Math.cos(h)),Math.abs(Math.sin(h)));l/=t,c/=t}a.push([~~(s.c+l),~~(s.r+c)]),r++}return this._rdPoints[t]=a}$_rotatePoint(t,e,i){const s=e*Math.PI/180,n=Math.cos(s),o=Math.sin(s),{x:r,y:a,width:h,height:l}=t,c=r+h,_=a+l,d=r+h/2,x=a+l/2,u=[{x:r,y:a},{x:c,y:a},{x:r,y:_},{x:c,y:_}].map((t=>({x:d+(t.x-d)*n-(t.y-x)*o,y:x+(t.x-d)*o+(t.y-x)*n}))),m=Math.min(...u.map((t=>t.x))),p=Math.min(...u.map((t=>t.y))),M=Math.max(...u.map((t=>t.x))),g=Math.max(...u.map((t=>t.y))),f=this._unit,y=M-m,w=g-p;return{c1:Math.max(0,~~(m/f)),r1:Math.max(0,~~(p/f)),c2:~~(M/f),r2:~~(g/f)+i,bounds:{x:m,y:p,width:y,height:w}}}$_getBox(t,e,i,s,n=0){const o=this._unit,{width:r}=t.getBBox(),a=t.hText,h=r/o,l=a/o,c=Math.ceil(h/2),_=Math.ceil(l/2),d=Math.max(0,e-c),x=Math.max(0,i-_),u=d+Math.ceil(h),m=x+Math.ceil(l),p={x:(e-c)*o,y:(i-_)*o,width:r,height:a};return n?this.$_rotatePoint(p,n,s):{c1:d,r1:x,c2:u+s,r2:m,bounds:p}}$_drawDebugBox(t,e){const{doc:i}=this._container,{x:s,y:n,width:o,height:r}=t.bounds,a=l.create(i,"",s,n,o,r);a.setFill((null==e?void 0:e.fill)||"#ff000055"),a.setStroke((null==e?void 0:e.stroke)||"none"),a.setAttr("stroke-dasharray",(null==e?void 0:e.strokeDashArray)||"4"),this._container.add(a)}$_findPos(t,e,i,s,n,r){let a=0,h=0;s=Math.max(s,this._grid.length+1);const l=[0,-90],c=l.length;for(;a<s;){const s=this.$_getPoints(a,e,n+h++%4*(Math.PI/4));i&&o.shuffle(s);if(s.some(((e,i)=>{let s=this._options.rotation?l[~~(o.randomLike(i+n)*c)]:0;const a=this.$_getBox(t,e[0],e[1],r,s);if(!this.$_isOverlapping(a)){if(a.bounds.x<0||a.bounds.y<0)return!1;const i=this.$_getBox(t,e[0],e[1],r),{bounds:n}=i,o={x:n.width/2,y:n.height/2};return t.wx=n.x,t.wy=n.y,t.setRotation(o.x,o.y,s),t.box=a,!0}})))return!0;a++}}}class S extends w{$_findPos(t,e,i,s,n,o){if(this.$_getPoints(s,e,i?Math.random()*Math.PI*2:n).some((e=>{const i=this.$_getBox(t,e[0],e[1],o);if(!this.$_isOverlapping(i))return t.box=i,!0})))return!0}$_getPoints(t,e,i){const s=this._center,n=this._ellipticity,o=2*t*this._unit;let r=-1,a=[];0===t&&a.push([s.c,s.r]);const h=i>Math.PI?1:-1;if(e)for(;++r<o;){const e=r/o,l=i+r*e*h,c=t*e,_=c*Math.cos(l)/n,d=c*Math.sin(l),x=s.c+_,u=s.r+d;a.push([~~x,~~u])}else{let e=this._unit>>1,o=e/n,l=s.c+o*Math.cos(i),c=s.r+e*Math.sin(i);const _=Math.max(1,this._unit>>1),d=_-Math.max(1,_>>1),x=.99;for(;++r>=0;){e=1+d*Math.pow(x,r),o=e/n;switch(3&(h*Math.sqrt(1+8*r)-1)/2){case 0:l+=o;break;case 1:c+=e;break;case 2:l-=o;break;default:c-=e}if(Math.max(Math.abs(l-t),Math.abs(c-t))>t)break;a.push([~~l,~~c])}}return a}$_getBox(t,e,i,s){const n=this._unit,o=t.getBBox(),r=t.hText,a=Math.min(2*this._radius,Math.max(0,e-y(o.width/2/n))),h=Math.min(2*this._radius,Math.max(0,i-y(r/2/n)));return{c1:a,r1:h,c2:a+y(o.width/n)+s,r2:h+y(r/n),w:t.width,h:r}}}class P extends a{constructor(t){super(t,h.POINT_CLASS),this.add(this.hintView=new l(t)),this.hintView.setStyles({stroke:"none",fill:"transparent"}),this.add(this.textView=new c(t)),this.textView.setStyle("pointerEvents","none")}layout(){const t=this.getBBox();this.hintView.setRect({x:0,y:this.yText*P.TOP_PAD,width:t.width,height:this.hText-this.yText}),this.textView.transY(-this.yText*P.TOP_PAD)}}P.TOP_PAD=.5;class $ extends _{constructor(t){super(t,"rct-wordcloud-series"),this._pointContainer.add(this._wordContainer=new d(t,null)),this._words=new x(this._wordContainer,P)}_getPointPool(){return this._words}needFronting(){return!1}isEmptyView(){return this._empty}_renderSeries(t,e){const i=this.model.options,s=i.text;if(t!==this._wSave||e!==this._hSave||s!==this._tSave){const n=+new Date;let r=this._visPoints.slice();if(i.minWeight>0&&(r=r.filter((t=>t.yValue>=i.minWeight))),i.minLength>1&&(r=r.filter((t=>t.x.length>=i.minLength))),i.maxCount<r.length&&(r.length=Math.max(0,i.maxCount)),this.$_prepareWords(this.doc,this.model,r),"spiral"===i.placer)this._placer=new S(i).start(this._wordContainer,this._words._internalItems(),i,t,e,(i=>{this.$_layoutWords(t,e)}));else this._placer=new w(i).start(this._wordContainer,this._words._internalItems(),i,t,e,(i=>{this.$_layoutWords(t,e)}));this._wSave=t,this._hSave=e,this._tSave=s,this._empty=r.length<1,o.log(r.length+" words placed in "+(+new Date-n)+"ms.")}else this.$_layoutWords(t,e)}_runShowEffect(t){t&&u.spread(this,(()=>{}))}_doPosRateChanged(t){this.$_layoutWords(this.width,this.height)}$_prepareWords(t,e,i){const s=e._minY,n=e._maxY,o=n-s,r=this.height,a=e.getMaxFontSize(r,1);let h=Math.min(a,e.getMinFontSize(r,0));const l=s===n||h===a,c=l?NaN:e.options.logBase,_=getComputedStyle(this._wordContainer.dom).fontFamily,d=Math.min(2,Math.max(.1,+e.options.textHeight)),x=isNaN(d)?t.createElement("canvas").getContext("2d"):null,u=1-P.TOP_PAD;let M;this._words.prepare(i.length,((n,r)=>{const g=n.point=i[r],f=n.textView;let y=(g.y-s)/o;c>1&&(y=1-(Math.pow(c,1-y)-1)/(c-1));let w=h+(l?(a-h)/2:y*(a-h));const S=g.x;this._preparePoint(t,e,g,n),delete n.box,f.text=S,f.anchor=m.START,f.setStyles({fontSize:p(w)}),f.layoutText(),x?(x.font=`${p(w)} ${_}`,M=x.measureText(S),n.yText=.9*Math.max(0,M.fontBoundingBoxAscent-M.actualBoundingBoxAscent),n.hText=Math.ceil((M.actualBoundingBoxAscent+M.actualBoundingBoxDescent)*(w<=10?1.1:1.08)-.1)+n.yText*u):(n.yText=0,n.hText=n.getBBox().height*d),n.layout(),n.setVis(!0)}))}$_layoutWords(t,e){var i;let s=this._getPosRate();null===(i=this._placer)||void 0===i||i.$_transform(s),s=1-s,this._words.forEach((i=>{const{bounds:n}=i.box,o=n.width,r=n.height,a=(t-o)/2;let h=(e-r)/2;i.trans(i.wx-(i.wx-a)*s,i.wy-(i.wy-h)*s)}))}}function z(t){(function(t){return t.Series&&t.SeriesView})(t)&&(t.Series.register(f),t.SeriesView.register([f,$]))}export{f as WordCloudSeries,z as default};
|