chartjs-chart-wordcloud
Advanced tools
Comparing version 3.0.0-beta.9 to 3.0.0-beta.11
@@ -64,4 +64,10 @@ /** | ||
inYRange(mouseY: number): boolean; | ||
getCenterPoint(): Pick<IWordElementProps, "x" | "y">; | ||
tooltipPosition(): Pick<IWordElementProps, "x" | "y">; | ||
getCenterPoint(): { | ||
x: number; | ||
y: number; | ||
}; | ||
tooltipPosition(): { | ||
x: number; | ||
y: number; | ||
}; | ||
draw(ctx: CanvasRenderingContext2D): void; | ||
@@ -109,3 +115,3 @@ } | ||
label: string; | ||
value: string; | ||
value: any; | ||
}; | ||
@@ -112,0 +118,0 @@ } |
@@ -76,3 +76,3 @@ /** | ||
size: (ctx) => { | ||
const v = ctx.dataPoint.y; | ||
const v = ctx.parsed.y; | ||
return v; | ||
@@ -179,5 +179,4 @@ }, | ||
const hb = bounds[1].y - bounds[0].y; | ||
const scale = this._config.fit | ||
? Math.min(w / wb, h / hb) | ||
: 1; | ||
const dsOptions = this.options; | ||
const scale = dsOptions.fit ? Math.min(w / wb, h / hb) : 1; | ||
const indices = new Set(labels.map((_, i) => i)); | ||
@@ -184,0 +183,0 @@ tags.forEach((tag) => { |
@@ -84,3 +84,3 @@ /** | ||
size: (ctx) => { | ||
const v = ctx.dataPoint.y; | ||
const v = ctx.parsed.y; | ||
return v; | ||
@@ -187,5 +187,4 @@ }, | ||
const hb = bounds[1].y - bounds[0].y; | ||
const scale = this._config.fit | ||
? Math.min(w / wb, h / hb) | ||
: 1; | ||
const dsOptions = this.options; | ||
const scale = dsOptions.fit ? Math.min(w / wb, h / hb) : 1; | ||
const indices = new Set(labels.map((_, i) => i)); | ||
@@ -192,0 +191,0 @@ tags.forEach((tag) => { |
@@ -24,3 +24,3 @@ /** | ||
(function (global, factory) { | ||
factory(exports) ; | ||
factory(exports) ; | ||
}(commonjsGlobal, function (exports) { | ||
@@ -218,4 +218,4 @@ var noop = {value: function() {}}; | ||
function place(board, tag, bounds) { | ||
var perimeter = [{x: 0, y: 0}, {x: size[0], y: size[1]}], | ||
startX = tag.x, | ||
[{x: 0, y: 0}, {x: size[0], y: size[1]}]; | ||
var startX = tag.x, | ||
startY = tag.y, | ||
@@ -582,3 +582,3 @@ maxDelta = Math.sqrt(size[0] * size[0] + size[1] * size[1]), | ||
size: (ctx) => { | ||
const v = ctx.dataPoint.y; | ||
const v = ctx.parsed.y; | ||
return v; | ||
@@ -685,5 +685,4 @@ }, | ||
const hb = bounds[1].y - bounds[0].y; | ||
const scale = this._config.fit | ||
? Math.min(w / wb, h / hb) | ||
: 1; | ||
const dsOptions = this.options; | ||
const scale = dsOptions.fit ? Math.min(w / wb, h / hb) : 1; | ||
const indices = new Set(labels.map((_, i) => i)); | ||
@@ -690,0 +689,0 @@ tags.forEach((tag) => { |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("chart.js"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["exports","chart.js","chart.js/helpers"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ChartWordCloud={},t.Chart,t.Chart.helpers)}(this,(function(t,e,n){"use strict";"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var r=function(t){var e={exports:{}};return t(e,e.exports),e.exports}((function(t,e){!function(t){var e={value:function(){}};function n(){for(var t,e=0,n=arguments.length,o={};e<n;++e){if(!(t=arguments[e]+"")||t in o||/[\s.]/.test(t))throw new Error("illegal type: "+t);o[t]=[]}return new r(o)}function r(t){this._=t}function o(t,e){return t.trim().split(/^|\s+/).map((function(t){var n="",r=t.indexOf(".");if(r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}}))}function a(t,e){for(var n,r=0,o=t.length;r<o;++r)if((n=t[r]).name===e)return n.value}function i(t,n,r){for(var o=0,a=t.length;o<a;++o)if(t[o].name===n){t[o]=e,t=t.slice(0,o).concat(t.slice(o+1));break}return null!=r&&t.push({name:n,value:r}),t}r.prototype=n.prototype={constructor:r,on:function(t,e){var n,r=this._,s=o(t+"",r),l=-1,u=s.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++l<u;)if(n=(t=s[l]).type)r[n]=i(r[n],t.name,e);else if(null==e)for(n in r)r[n]=i(r[n],t.name,null);return this}for(;++l<u;)if((n=(t=s[l]).type)&&(n=a(r[n],t.name)))return n},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new r(t)},call:function(t,e){if((n=arguments.length-2)>0)for(var n,r,o=new Array(n),a=0;a<n;++a)o[a]=arguments[a+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(a=0,n=(r=this._[t]).length;a<n;++a)r[a].value.apply(e,o)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var r=this._[t],o=0,a=r.length;o<a;++o)r[o].value.apply(e,n)}},t.dispatch=n,Object.defineProperty(t,"__esModule",{value:!0})}(e)})).dispatch,o=Math.PI/180,a=2048,i=function(){var t=[256,256],e=s,n=l,o=h,i=u,w=u,b=c,M=f,S=x,E=[],C=1/0,R=r("word","end"),_=null,k=Math.random,z={},P=g;function T(e,n,r){t[0],t[1];for(var o,a,i,s,l,u=n.x,h=n.y,c=Math.sqrt(t[0]*t[0]+t[1]*t[1]),f=S(t),d=k()<.5?1:-1,p=-d;(o=f(p+=d))&&(a=~~o[0],i=~~o[1],!(Math.min(Math.abs(a),Math.abs(i))>=c));)if(n.x=u+a,n.y=h+i,!(n.x+n.x0<0||n.y+n.y0<0||n.x+n.x1>t[0]||n.y+n.y1>t[1]||r&&y(n,e,t[0])||r&&(l=r,!((s=n).x+s.x1>l[0].x&&s.x+s.x0<l[1].x&&s.y+s.y1>l[0].y&&s.y+s.y0<l[1].y)))){for(var x,g=n.sprite,m=n.width>>5,v=t[0]>>5,w=n.x-(m<<4),b=127&w,M=32-b,E=n.y1-n.y0,C=(n.y+n.y0)*v+(w>>5),R=0;R<E;R++){x=0;for(var _=0;_<=m;_++)e[C+_]|=x<<M|(_<m?(x=g[R*m+_])>>>b:0);C+=v}return delete n.sprite,!0}return!1}return z.canvas=function(t){return arguments.length?(P=m(t),z):P},z.start=function(){var r=function(t){t.width=t.height=1;var e=Math.sqrt(t.getContext("2d").getImageData(0,0,1,1).data.length>>2);t.width=2048/e,t.height=a/e;var n=t.getContext("2d");return n.fillStyle=n.strokeStyle="red",n.textAlign="center",{context:n,ratio:e}}(P()),s=function(t){var e=[],n=-1;for(;++n<t;)e[n]=0;return e}((t[0]>>5)*t[1]),l=null,u=E.length,h=-1,c=[],f=E.map((function(t,r){return t.text=e.call(this,t,r),t.font=n.call(this,t,r),t.style=i.call(this,t,r),t.weight=w.call(this,t,r),t.rotate=b.call(this,t,r),t.size=~~o.call(this,t,r),t.padding=M.call(this,t,r),t})).sort((function(t,e){return e.size-t.size}));return _&&clearInterval(_),_=setInterval(y,0),y(),z;function y(){for(var e=Date.now();Date.now()-e<C&&++h<u&&_;){var n=f[h];n.x=t[0]*(k()+.5)>>1,n.y=t[1]*(k()+.5)>>1,d(r,n,f,h),n.hasText&&T(s,n,l)&&(c.push(n),R.call("word",z,n),l?p(l,n):l=[{x:n.x+n.x0,y:n.y+n.y0},{x:n.x+n.x1,y:n.y+n.y1}],n.x-=t[0]>>1,n.y-=t[1]>>1)}h>=u&&(z.stop(),R.call("end",z,c,l))}},z.stop=function(){return _&&(clearInterval(_),_=null),z},z.timeInterval=function(t){return arguments.length?(C=null==t?1/0:t,z):C},z.words=function(t){return arguments.length?(E=t,z):E},z.size=function(e){return arguments.length?(t=[+e[0],+e[1]],z):t},z.font=function(t){return arguments.length?(n=m(t),z):n},z.fontStyle=function(t){return arguments.length?(i=m(t),z):i},z.fontWeight=function(t){return arguments.length?(w=m(t),z):w},z.rotate=function(t){return arguments.length?(b=m(t),z):b},z.text=function(t){return arguments.length?(e=m(t),z):e},z.spiral=function(t){return arguments.length?(S=v[t]||t,z):S},z.fontSize=function(t){return arguments.length?(o=m(t),z):o},z.padding=function(t){return arguments.length?(M=m(t),z):M},z.random=function(t){return arguments.length?(k=t,z):k},z.on=function(){var t=R.on.apply(R,arguments);return t===R?z:t},z};function s(t){return t.text}function l(){return"serif"}function u(){return"normal"}function h(t){return Math.sqrt(t.value)}function c(){return 30*(~~(6*Math.random())-3)}function f(){return 1}function d(t,e,n,r){if(!e.sprite){var i=t.context,s=t.ratio;i.clearRect(0,0,2048/s,a/s);var l=0,u=0,h=0,c=n.length;for(--r;++r<c;){e=n[r],i.save(),i.font=e.style+" "+e.weight+" "+~~((e.size+1)/s)+"px "+e.font;var f=i.measureText(e.text+"m").width*s,d=e.size<<1;if(e.rotate){var y=Math.sin(e.rotate*o),p=Math.cos(e.rotate*o),x=f*p,g=f*y,m=d*p,v=d*y;f=Math.max(Math.abs(x+v),Math.abs(x-v))+31>>5<<5,d=~~Math.max(Math.abs(g+m),Math.abs(g-m))}else f=f+31>>5<<5;if(d>h&&(h=d),l+f>=2048&&(l=0,u+=h,h=0),u+d>=a)break;i.translate((l+(f>>1))/s,(u+(d>>1))/s),e.rotate&&i.rotate(e.rotate*o),i.fillText(e.text,0,0),e.padding&&(i.lineWidth=2*e.padding,i.strokeText(e.text,0,0)),i.restore(),e.width=f,e.height=d,e.xoff=l,e.yoff=u,e.x1=f>>1,e.y1=d>>1,e.x0=-e.x1,e.y0=-e.y1,e.hasText=!0,l+=f}for(var w=i.getImageData(0,0,2048/s,a/s).data,b=[];--r>=0;)if((e=n[r]).hasText){for(var M=(f=e.width)>>5,S=(d=e.y1-e.y0,0);S<d*M;S++)b[S]=0;if(null==(l=e.xoff))return;u=e.yoff;for(var E=0,C=-1,R=0;R<d;R++){for(S=0;S<f;S++){var _=M*R+(S>>5),k=w[2048*(u+R)+(l+S)<<2]?1<<31-S%32:0;b[_]|=k,E|=k}E?C=R:(e.y0++,d--,R--,u++)}e.y1=e.y0+C,e.sprite=b.slice(0,(e.y1-e.y0)*M)}}}function y(t,e,n){n>>=5;for(var r,o=t.sprite,a=t.width>>5,i=t.x-(a<<4),s=127&i,l=32-s,u=t.y1-t.y0,h=(t.y+t.y0)*n+(i>>5),c=0;c<u;c++){r=0;for(var f=0;f<=a;f++)if((r<<l|(f<a?(r=o[c*a+f])>>>s:0))&e[h+f])return!0;h+=n}return!1}function p(t,e){var n=t[0],r=t[1];e.x+e.x0<n.x&&(n.x=e.x+e.x0),e.y+e.y0<n.y&&(n.y=e.y+e.y0),e.x+e.x1>r.x&&(r.x=e.x+e.x1),e.y+e.y1>r.y&&(r.y=e.y+e.y1)}function x(t){var e=t[0]/t[1];return function(t){return[e*(t*=.1)*Math.cos(t),t*Math.sin(t)]}}function g(){return document.createElement("canvas")}function m(t){return"function"==typeof t?t:function(){return t}}var v={archimedean:x,rectangular:function(t){var e=4*t[0]/t[1],n=0,r=0;return function(t){var o=t<0?-1:1;switch(Math.sqrt(1+4*o*t)-o&3){case 0:n+=e;break;case 1:r+=4;break;case 2:n-=e;break;default:r-=4}return[n,r]}}};class w extends e.Element{static computeRotation(t,e){if(t.rotationSteps<=1)return 0;if(t.minRotation===t.maxRotation)return t.minRotation;const n=Math.min(t.rotationSteps,Math.floor(e()*t.rotationSteps))/(t.rotationSteps-1),r=t.maxRotation-t.minRotation;return t.minRotation+n*r}inRange(t,e){const n=this.getProps(["x","y","width","height","scale"]);if(n.scale<=0)return!1;const r=Number.isNaN(t)?n.x:t,o=Number.isNaN(e)?n.y:e;return r>=n.x-n.width/2&&r<=n.x+n.width/2&&o>=n.y-n.height/2&&o<=n.y+n.height/2}inXRange(t){return this.inRange(t,Number.NaN)}inYRange(t){return this.inRange(Number.NaN,t)}getCenterPoint(){return this.getProps(["x","y"])}tooltipPosition(){return this.getCenterPoint()}draw(t){const e=this.options,r=this.getProps(["x","y","width","height","text","scale"]);if(r.scale<=0)return;t.save();const o=n.toFont(Object.assign({},e,{size:e.size*r.scale}));t.font=o.string,t.fillStyle=e.color,t.textAlign="center",t.translate(r.x,r.y),t.rotate(e.rotate/180*Math.PI),e.strokeStyle&&(t.strokeStyle=e.strokeStyle,t.strokeText(r.text,0,0)),t.fillText(r.text,0,0),t.restore()}}w.id="word",w.defaults={minRotation:-90,maxRotation:0,rotationSteps:2,padding:1,weight:"normal",size:t=>t.dataPoint.y,hoverColor:"#ababab"},w.defaultRoutes={color:"color",family:"font.family"};class b extends e.DatasetController{constructor(){super(...arguments),this.wordLayout=i().text(t=>t.text).padding(t=>t.options.padding).rotate(t=>t.options.rotate).font(t=>t.options.family).fontSize(t=>t.options.size).fontStyle(t=>t.options.style).fontWeight(t=>t.options.weight),this.rand=Math.random}update(t){super.update(t),this.rand=function(t=Date.now()){let e="number"==typeof t?t:Array.from(t).reduce((t,e)=>t+e.charCodeAt(0),0);return()=>(e=(9301*e+49297)%233280,e/233280)}(this.chart.id);const e=this._cachedMeta.data||[];this.updateElements(e,0,e.length,t)}updateElements(t,e,r,o){this.wordLayout.stop();const a=this._cachedMeta.xScale,i=this._cachedMeta.yScale,s=a.right-a.left,l=i.bottom-i.top,u=this.chart.data.labels,h=[];for(let t=e;t<e+r;t++){const e=this.resolveDataElementOptions(t,o);null==e.rotate&&(e.rotate=w.computeRotation(e,this.rand));const r={options:Object.assign({},n.toFont(e),e),x:this._cachedMeta.xScale.getPixelForDecimal(.5),y:this._cachedMeta.yScale.getPixelForDecimal(.5),width:10,height:10,scale:1,index:t,text:u[t]};h.push(r)}if("reset"===o)return void h.forEach(e=>{this.updateElement(t[e.index],e.index,e,o)});this.wordLayout.random(this.rand).words(h);const c=(e=1,n=3)=>{this.wordLayout.size([s*e,l*e]).on("end",(r,h)=>{if(r.length<u.length){if(n>0)return c(1.2*e,n-1);console.warn("cannot fit all text elements in three tries")}const f=h[1].x-h[0].x,d=h[1].y-h[0].y,y=this._config.fit?Math.min(s/f,l/d):1,p=new Set(u.map((t,e)=>e));r.forEach(e=>{p.delete(e.index),this.updateElement(t[e.index],e.index,{options:e.options,scale:y,x:a.left+y*e.x+s/2,y:i.top+y*e.y+l/2,width:y*e.width,height:y*e.height,text:e.text},o)}),p.forEach(e=>this.updateElement(t[e],e,{scale:0},o))}).start()};c()}draw(){const t=this._cachedMeta.data,e=this.chart.ctx;t.forEach(t=>t.draw(e))}getLabelAndValue(t){const e=super.getLabelAndValue(t),n=this.chart.data.labels;return e.label=n[t],e}}b.id="wordCloud",b.defaults={scales:{x:{type:"linear",min:-1,max:1,display:!1},y:{type:"linear",min:-1,max:1,display:!1}},datasets:{fit:!0,animation:{colors:{properties:["color","strokeStyle"]},numbers:{properties:["x","y","size","rotate"]}}},maintainAspectRatio:!1,dataElementType:w.id,dataElementOptions:["color","family","size","style","weight","strokeStyle","rotate","minRotation","maxRotation","rotationSteps","hoverColor","hoverSize","hoverWeight","hoverStyle"]};class M extends e.Chart{constructor(t,n){super(t,function(t,n,r,o=[],a=[]){e.registry.addControllers(r),Array.isArray(o)?e.registry.addElements(...o):e.registry.addElements(o),Array.isArray(a)?e.registry.addScales(...a):e.registry.addScales(a);const i=n;return i.type=t,i}("wordCloud",n,b,w))}}M.id=b.id,e.registry.addControllers(b),e.registry.addElements(w),t.WordCloudChart=M,t.WordCloudController=b,t.WordElement=w,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("chart.js"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["exports","chart.js","chart.js/helpers"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ChartWordCloud={},t.Chart,t.Chart.helpers)}(this,(function(t,e,n){"use strict";"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var r=function(t){var e={exports:{}};return t(e,e.exports),e.exports}((function(t,e){!function(t){var e={value:function(){}};function n(){for(var t,e=0,n=arguments.length,o={};e<n;++e){if(!(t=arguments[e]+"")||t in o||/[\s.]/.test(t))throw new Error("illegal type: "+t);o[t]=[]}return new r(o)}function r(t){this._=t}function o(t,e){return t.trim().split(/^|\s+/).map((function(t){var n="",r=t.indexOf(".");if(r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}}))}function a(t,e){for(var n,r=0,o=t.length;r<o;++r)if((n=t[r]).name===e)return n.value}function i(t,n,r){for(var o=0,a=t.length;o<a;++o)if(t[o].name===n){t[o]=e,t=t.slice(0,o).concat(t.slice(o+1));break}return null!=r&&t.push({name:n,value:r}),t}r.prototype=n.prototype={constructor:r,on:function(t,e){var n,r=this._,s=o(t+"",r),l=-1,u=s.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++l<u;)if(n=(t=s[l]).type)r[n]=i(r[n],t.name,e);else if(null==e)for(n in r)r[n]=i(r[n],t.name,null);return this}for(;++l<u;)if((n=(t=s[l]).type)&&(n=a(r[n],t.name)))return n},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new r(t)},call:function(t,e){if((n=arguments.length-2)>0)for(var n,r,o=new Array(n),a=0;a<n;++a)o[a]=arguments[a+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(a=0,n=(r=this._[t]).length;a<n;++a)r[a].value.apply(e,o)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var r=this._[t],o=0,a=r.length;o<a;++o)r[o].value.apply(e,n)}},t.dispatch=n,Object.defineProperty(t,"__esModule",{value:!0})}(e)})).dispatch,o=Math.PI/180,a=2048,i=function(){var t=[256,256],e=s,n=l,o=h,i=u,w=u,b=c,M=f,S=x,E=[],C=1/0,R=r("word","end"),k=null,_=Math.random,z={},P=g;function T(e,n,r){t[0],t[1];for(var o,a,i,s,l,u=n.x,h=n.y,c=Math.sqrt(t[0]*t[0]+t[1]*t[1]),f=S(t),d=_()<.5?1:-1,p=-d;(o=f(p+=d))&&(a=~~o[0],i=~~o[1],!(Math.min(Math.abs(a),Math.abs(i))>=c));)if(n.x=u+a,n.y=h+i,!(n.x+n.x0<0||n.y+n.y0<0||n.x+n.x1>t[0]||n.y+n.y1>t[1]||r&&y(n,e,t[0])||r&&(l=r,!((s=n).x+s.x1>l[0].x&&s.x+s.x0<l[1].x&&s.y+s.y1>l[0].y&&s.y+s.y0<l[1].y)))){for(var x,g=n.sprite,m=n.width>>5,v=t[0]>>5,w=n.x-(m<<4),b=127&w,M=32-b,E=n.y1-n.y0,C=(n.y+n.y0)*v+(w>>5),R=0;R<E;R++){x=0;for(var k=0;k<=m;k++)e[C+k]|=x<<M|(k<m?(x=g[R*m+k])>>>b:0);C+=v}return delete n.sprite,!0}return!1}return z.canvas=function(t){return arguments.length?(P=m(t),z):P},z.start=function(){var r=function(t){t.width=t.height=1;var e=Math.sqrt(t.getContext("2d").getImageData(0,0,1,1).data.length>>2);t.width=2048/e,t.height=a/e;var n=t.getContext("2d");return n.fillStyle=n.strokeStyle="red",n.textAlign="center",{context:n,ratio:e}}(P()),s=function(t){var e=[],n=-1;for(;++n<t;)e[n]=0;return e}((t[0]>>5)*t[1]),l=null,u=E.length,h=-1,c=[],f=E.map((function(t,r){return t.text=e.call(this,t,r),t.font=n.call(this,t,r),t.style=i.call(this,t,r),t.weight=w.call(this,t,r),t.rotate=b.call(this,t,r),t.size=~~o.call(this,t,r),t.padding=M.call(this,t,r),t})).sort((function(t,e){return e.size-t.size}));return k&&clearInterval(k),k=setInterval(y,0),y(),z;function y(){for(var e=Date.now();Date.now()-e<C&&++h<u&&k;){var n=f[h];n.x=t[0]*(_()+.5)>>1,n.y=t[1]*(_()+.5)>>1,d(r,n,f,h),n.hasText&&T(s,n,l)&&(c.push(n),R.call("word",z,n),l?p(l,n):l=[{x:n.x+n.x0,y:n.y+n.y0},{x:n.x+n.x1,y:n.y+n.y1}],n.x-=t[0]>>1,n.y-=t[1]>>1)}h>=u&&(z.stop(),R.call("end",z,c,l))}},z.stop=function(){return k&&(clearInterval(k),k=null),z},z.timeInterval=function(t){return arguments.length?(C=null==t?1/0:t,z):C},z.words=function(t){return arguments.length?(E=t,z):E},z.size=function(e){return arguments.length?(t=[+e[0],+e[1]],z):t},z.font=function(t){return arguments.length?(n=m(t),z):n},z.fontStyle=function(t){return arguments.length?(i=m(t),z):i},z.fontWeight=function(t){return arguments.length?(w=m(t),z):w},z.rotate=function(t){return arguments.length?(b=m(t),z):b},z.text=function(t){return arguments.length?(e=m(t),z):e},z.spiral=function(t){return arguments.length?(S=v[t]||t,z):S},z.fontSize=function(t){return arguments.length?(o=m(t),z):o},z.padding=function(t){return arguments.length?(M=m(t),z):M},z.random=function(t){return arguments.length?(_=t,z):_},z.on=function(){var t=R.on.apply(R,arguments);return t===R?z:t},z};function s(t){return t.text}function l(){return"serif"}function u(){return"normal"}function h(t){return Math.sqrt(t.value)}function c(){return 30*(~~(6*Math.random())-3)}function f(){return 1}function d(t,e,n,r){if(!e.sprite){var i=t.context,s=t.ratio;i.clearRect(0,0,2048/s,a/s);var l=0,u=0,h=0,c=n.length;for(--r;++r<c;){e=n[r],i.save(),i.font=e.style+" "+e.weight+" "+~~((e.size+1)/s)+"px "+e.font;var f=i.measureText(e.text+"m").width*s,d=e.size<<1;if(e.rotate){var y=Math.sin(e.rotate*o),p=Math.cos(e.rotate*o),x=f*p,g=f*y,m=d*p,v=d*y;f=Math.max(Math.abs(x+v),Math.abs(x-v))+31>>5<<5,d=~~Math.max(Math.abs(g+m),Math.abs(g-m))}else f=f+31>>5<<5;if(d>h&&(h=d),l+f>=2048&&(l=0,u+=h,h=0),u+d>=a)break;i.translate((l+(f>>1))/s,(u+(d>>1))/s),e.rotate&&i.rotate(e.rotate*o),i.fillText(e.text,0,0),e.padding&&(i.lineWidth=2*e.padding,i.strokeText(e.text,0,0)),i.restore(),e.width=f,e.height=d,e.xoff=l,e.yoff=u,e.x1=f>>1,e.y1=d>>1,e.x0=-e.x1,e.y0=-e.y1,e.hasText=!0,l+=f}for(var w=i.getImageData(0,0,2048/s,a/s).data,b=[];--r>=0;)if((e=n[r]).hasText){for(var M=(f=e.width)>>5,S=(d=e.y1-e.y0,0);S<d*M;S++)b[S]=0;if(null==(l=e.xoff))return;u=e.yoff;for(var E=0,C=-1,R=0;R<d;R++){for(S=0;S<f;S++){var k=M*R+(S>>5),_=w[2048*(u+R)+(l+S)<<2]?1<<31-S%32:0;b[k]|=_,E|=_}E?C=R:(e.y0++,d--,R--,u++)}e.y1=e.y0+C,e.sprite=b.slice(0,(e.y1-e.y0)*M)}}}function y(t,e,n){n>>=5;for(var r,o=t.sprite,a=t.width>>5,i=t.x-(a<<4),s=127&i,l=32-s,u=t.y1-t.y0,h=(t.y+t.y0)*n+(i>>5),c=0;c<u;c++){r=0;for(var f=0;f<=a;f++)if((r<<l|(f<a?(r=o[c*a+f])>>>s:0))&e[h+f])return!0;h+=n}return!1}function p(t,e){var n=t[0],r=t[1];e.x+e.x0<n.x&&(n.x=e.x+e.x0),e.y+e.y0<n.y&&(n.y=e.y+e.y0),e.x+e.x1>r.x&&(r.x=e.x+e.x1),e.y+e.y1>r.y&&(r.y=e.y+e.y1)}function x(t){var e=t[0]/t[1];return function(t){return[e*(t*=.1)*Math.cos(t),t*Math.sin(t)]}}function g(){return document.createElement("canvas")}function m(t){return"function"==typeof t?t:function(){return t}}var v={archimedean:x,rectangular:function(t){var e=4*t[0]/t[1],n=0,r=0;return function(t){var o=t<0?-1:1;switch(Math.sqrt(1+4*o*t)-o&3){case 0:n+=e;break;case 1:r+=4;break;case 2:n-=e;break;default:r-=4}return[n,r]}}};class w extends e.Element{static computeRotation(t,e){if(t.rotationSteps<=1)return 0;if(t.minRotation===t.maxRotation)return t.minRotation;const n=Math.min(t.rotationSteps,Math.floor(e()*t.rotationSteps))/(t.rotationSteps-1),r=t.maxRotation-t.minRotation;return t.minRotation+n*r}inRange(t,e){const n=this.getProps(["x","y","width","height","scale"]);if(n.scale<=0)return!1;const r=Number.isNaN(t)?n.x:t,o=Number.isNaN(e)?n.y:e;return r>=n.x-n.width/2&&r<=n.x+n.width/2&&o>=n.y-n.height/2&&o<=n.y+n.height/2}inXRange(t){return this.inRange(t,Number.NaN)}inYRange(t){return this.inRange(Number.NaN,t)}getCenterPoint(){return this.getProps(["x","y"])}tooltipPosition(){return this.getCenterPoint()}draw(t){const e=this.options,r=this.getProps(["x","y","width","height","text","scale"]);if(r.scale<=0)return;t.save();const o=n.toFont(Object.assign({},e,{size:e.size*r.scale}));t.font=o.string,t.fillStyle=e.color,t.textAlign="center",t.translate(r.x,r.y),t.rotate(e.rotate/180*Math.PI),e.strokeStyle&&(t.strokeStyle=e.strokeStyle,t.strokeText(r.text,0,0)),t.fillText(r.text,0,0),t.restore()}}w.id="word",w.defaults={minRotation:-90,maxRotation:0,rotationSteps:2,padding:1,weight:"normal",size:t=>t.parsed.y,hoverColor:"#ababab"},w.defaultRoutes={color:"color",family:"font.family"};class b extends e.DatasetController{constructor(){super(...arguments),this.wordLayout=i().text((t=>t.text)).padding((t=>t.options.padding)).rotate((t=>t.options.rotate)).font((t=>t.options.family)).fontSize((t=>t.options.size)).fontStyle((t=>t.options.style)).fontWeight((t=>t.options.weight)),this.rand=Math.random}update(t){super.update(t),this.rand=function(t=Date.now()){let e="number"==typeof t?t:Array.from(t).reduce(((t,e)=>t+e.charCodeAt(0)),0);return()=>(e=(9301*e+49297)%233280,e/233280)}(this.chart.id);const e=this._cachedMeta.data||[];this.updateElements(e,0,e.length,t)}updateElements(t,e,r,o){this.wordLayout.stop();const a=this._cachedMeta.xScale,i=this._cachedMeta.yScale,s=a.right-a.left,l=i.bottom-i.top,u=this.chart.data.labels,h=[];for(let t=e;t<e+r;t++){const e=this.resolveDataElementOptions(t,o);null==e.rotate&&(e.rotate=w.computeRotation(e,this.rand));const r={options:Object.assign({},n.toFont(e),e),x:this._cachedMeta.xScale.getPixelForDecimal(.5),y:this._cachedMeta.yScale.getPixelForDecimal(.5),width:10,height:10,scale:1,index:t,text:u[t]};h.push(r)}if("reset"===o)return void h.forEach((e=>{this.updateElement(t[e.index],e.index,e,o)}));this.wordLayout.random(this.rand).words(h);const c=(e=1,n=3)=>{this.wordLayout.size([s*e,l*e]).on("end",((r,h)=>{if(r.length<u.length){if(n>0)return c(1.2*e,n-1);console.warn("cannot fit all text elements in three tries")}const f=h[1].x-h[0].x,d=h[1].y-h[0].y,y=this.options.fit?Math.min(s/f,l/d):1,p=new Set(u.map(((t,e)=>e)));r.forEach((e=>{p.delete(e.index),this.updateElement(t[e.index],e.index,{options:e.options,scale:y,x:a.left+y*e.x+s/2,y:i.top+y*e.y+l/2,width:y*e.width,height:y*e.height,text:e.text},o)})),p.forEach((e=>this.updateElement(t[e],e,{scale:0},o)))})).start()};c()}draw(){const t=this._cachedMeta.data,e=this.chart.ctx;t.forEach((t=>t.draw(e)))}getLabelAndValue(t){const e=super.getLabelAndValue(t),n=this.chart.data.labels;return e.label=n[t],e}}b.id="wordCloud",b.defaults={scales:{x:{type:"linear",min:-1,max:1,display:!1},y:{type:"linear",min:-1,max:1,display:!1}},datasets:{fit:!0,animation:{colors:{properties:["color","strokeStyle"]},numbers:{properties:["x","y","size","rotate"]}}},maintainAspectRatio:!1,dataElementType:w.id,dataElementOptions:["color","family","size","style","weight","strokeStyle","rotate","minRotation","maxRotation","rotationSteps","hoverColor","hoverSize","hoverWeight","hoverStyle"]};class M extends e.Chart{constructor(t,n){super(t,function(t,n,r,o=[],a=[]){e.registry.addControllers(r),Array.isArray(o)?e.registry.addElements(...o):e.registry.addElements(o),Array.isArray(a)?e.registry.addScales(...a):e.registry.addScales(a);const i=n;return i.type=t,i}("wordCloud",n,b,w))}}M.id=b.id,e.registry.addControllers(b),e.registry.addElements(w),t.WordCloudChart=M,t.WordCloudController=b,t.WordElement=w,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.min.js.map |
{ | ||
"name": "chartjs-chart-wordcloud", | ||
"description": "Chart.js module for word clouds", | ||
"version": "3.0.0-beta.9", | ||
"version": "3.0.0-beta.11", | ||
"author": { | ||
@@ -36,3 +36,3 @@ "name": "Samuel Gratzl", | ||
"peerDependencies": { | ||
"chart.js": "^3.0.0-beta" | ||
"chart.js": "^3.0.0-beta.11" | ||
}, | ||
@@ -45,12 +45,12 @@ "browserslist": [ | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^17.0.0", | ||
"@rollup/plugin-node-resolve": "^11.1.0", | ||
"@rollup/plugin-replace": "^2.3.4", | ||
"@rollup/plugin-typescript": "^8.1.0", | ||
"@rollup/plugin-commonjs": "^17.1.0", | ||
"@rollup/plugin-node-resolve": "^11.2.0", | ||
"@rollup/plugin-replace": "^2.4.1", | ||
"@rollup/plugin-typescript": "^8.2.0", | ||
"@types/jest": "^26.0.20", | ||
"@types/jest-image-snapshot": "^4.1.3", | ||
"@types/node": "^14.14.21", | ||
"@types/node": "^14.14.31", | ||
"@types/seedrandom": "^2.4.28", | ||
"@typescript-eslint/eslint-plugin": "^4.13.0", | ||
"@typescript-eslint/parser": "^4.13.0", | ||
"@typescript-eslint/eslint-plugin": "^4.15.2", | ||
"@typescript-eslint/parser": "^4.15.2", | ||
"@yarnpkg/pnpify": "^2.4.0", | ||
@@ -60,6 +60,6 @@ "canvas": "^2.6.1", | ||
"chart.js": "^3.0.0-beta.9", | ||
"eslint": "^7.18.0", | ||
"eslint-config-prettier": "^7.1.0", | ||
"eslint": "^7.20.0", | ||
"eslint-config-prettier": "^8.1.0", | ||
"eslint-config-react-app": "^6.0.0", | ||
"eslint-plugin-flowtype": "^5.2.0", | ||
"eslint-plugin-flowtype": "^5.3.1", | ||
"eslint-plugin-import": "^2.22.1", | ||
@@ -73,5 +73,5 @@ "eslint-plugin-jsx-a11y": "^6.4.1", | ||
"prettier": "^2.2.1", | ||
"release-it": "^14.2.2", | ||
"release-it": "^14.4.1", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.36.2", | ||
"rollup": "^2.40.0", | ||
"rollup-plugin-cleanup": "^3.2.1", | ||
@@ -81,6 +81,6 @@ "rollup-plugin-dts": "^2.0.1", | ||
"seedrandom": "^3.0.5", | ||
"ts-jest": "^26.4.4", | ||
"ts-jest": "^26.5.2", | ||
"tslib": "^2.1.0", | ||
"typedoc": "^0.20.16", | ||
"typescript": "^4.1.3", | ||
"typedoc": "^0.20.28", | ||
"typescript": "~4.1.5", | ||
"us-atlas": "^3.0.0", | ||
@@ -92,3 +92,3 @@ "world-atlas": "^2.0.2" | ||
"compile": "tsc -p tsconfig.json --noEmit", | ||
"start": "npm run watch", | ||
"start": "yarn run watch", | ||
"watch": "rollup -c -w", | ||
@@ -99,10 +99,10 @@ "build": "rollup -c", | ||
"test:coverage": "jest --passWithNoTests --coverage", | ||
"lint": "npm run eslint && npm run prettier", | ||
"fix": "npm run eslint:fix && npm run prettier:write", | ||
"prettier:write": "prettier */** --write", | ||
"prettier": "prettier */** --check", | ||
"lint": "yarn run eslint && yarn run prettier", | ||
"fix": "yarn run eslint:fix && yarn run prettier:write", | ||
"prettier:write": "prettier \"*/**\" --write", | ||
"prettier": "prettier \"*/**\" --check", | ||
"eslint": "eslint src --ext .ts,.tsx", | ||
"eslint:fix": "npm run eslint -- --fix", | ||
"eslint:fix": "yarn run eslint --fix", | ||
"docs": "typedoc", | ||
"prepare": "npm run build", | ||
"prepare": "yarn run build", | ||
"release": "release-it --disable-metrics --npm.skipChecks", | ||
@@ -109,0 +109,0 @@ "release:pre": "release-it --disable-metrics --npm.skipChecks --preRelease=alpha --npm.tag=next", |
@@ -19,3 +19,3 @@ /// <reference types="jest" /> | ||
export async function expectMatchSnapshot(canvas: HTMLCanvasElement) { | ||
export async function expectMatchSnapshot(canvas: HTMLCanvasElement): Promise<void> { | ||
const image = await toBuffer(canvas); | ||
@@ -25,2 +25,3 @@ expect(image).toMatchImageSnapshot(); | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
export default function createChart< | ||
@@ -27,0 +28,0 @@ TYPE extends ChartType, |
@@ -93,3 +93,3 @@ import { | ||
update(mode: UpdateMode) { | ||
update(mode: UpdateMode): void { | ||
super.update(mode); | ||
@@ -103,3 +103,3 @@ this.rand = rnd(this.chart.id); | ||
updateElements(elems: WordElement[], start: number, count: number, mode: UpdateMode) { | ||
updateElements(elems: WordElement[], start: number, count: number, mode: UpdateMode): void { | ||
this.wordLayout.stop(); | ||
@@ -113,3 +113,3 @@ const xScale = this._cachedMeta.xScale as { left: number; right: number }; | ||
const words: ICloudWord[] = []; | ||
const words: (ICloudWord & Record<string, unknown>)[] = []; | ||
for (let i = start; i < start + count; i++) { | ||
@@ -120,3 +120,3 @@ const o = (this.resolveDataElementOptions(i, mode) as unknown) as IWordElementOptions; | ||
} | ||
const properties: ICloudWord = { | ||
const properties: ICloudWord & Record<string, unknown> = { | ||
options: Object.assign({}, toFont(o), o), | ||
@@ -156,5 +156,5 @@ x: this._cachedMeta.xScale!.getPixelForDecimal(0.5)!, | ||
const hb = bounds[1].y - bounds[0].y; | ||
const scale = ((this as any)._config as IWordCloudControllerDatasetOptions).fit | ||
? Math.min(w / wb, h / hb) | ||
: 1; | ||
const dsOptions = (this as any).options as IWordCloudControllerDatasetOptions; | ||
const scale = dsOptions.fit ? Math.min(w / wb, h / hb) : 1; | ||
const indices = new Set(labels.map((_, i) => i)); | ||
@@ -186,3 +186,3 @@ tags.forEach((tag) => { | ||
draw() { | ||
draw(): void { | ||
const elements = this._cachedMeta.data; | ||
@@ -193,3 +193,3 @@ const ctx = this.chart.ctx; | ||
getLabelAndValue(index: number) { | ||
getLabelAndValue(index: number): { label: string; value: any } { | ||
const r = super.getLabelAndValue(index); | ||
@@ -196,0 +196,0 @@ const labels = this.chart.data.labels as string[]; |
@@ -60,3 +60,3 @@ import { Element, FontSpec, VisualElement, ScriptableAndArrayOptions, ScriptableContext } from 'chart.js'; | ||
size: (ctx) => { | ||
const v = ctx.dataPoint.y; | ||
const v = ((ctx.parsed as unknown) as { y: number }).y; | ||
return v; | ||
@@ -72,3 +72,3 @@ }, | ||
static computeRotation(o: IWordElementOptions, rnd: () => number) { | ||
static computeRotation(o: IWordElementOptions, rnd: () => number): number { | ||
if (o.rotationSteps <= 1) { | ||
@@ -85,3 +85,3 @@ return 0; | ||
inRange(mouseX: number, mouseY: number) { | ||
inRange(mouseX: number, mouseY: number): boolean { | ||
const p = this.getProps(['x', 'y', 'width', 'height', 'scale']); | ||
@@ -96,19 +96,19 @@ if (p.scale <= 0) { | ||
inXRange(mouseX: number) { | ||
inXRange(mouseX: number): boolean { | ||
return this.inRange(mouseX, Number.NaN); | ||
} | ||
inYRange(mouseY: number) { | ||
inYRange(mouseY: number): boolean { | ||
return this.inRange(Number.NaN, mouseY); | ||
} | ||
getCenterPoint() { | ||
getCenterPoint(): { x: number; y: number } { | ||
return this.getProps(['x', 'y']); | ||
} | ||
tooltipPosition() { | ||
tooltipPosition(): { x: number; y: number } { | ||
return this.getCenterPoint(); | ||
} | ||
draw(ctx: CanvasRenderingContext2D) { | ||
draw(ctx: CanvasRenderingContext2D): void { | ||
const options = this.options; | ||
@@ -115,0 +115,0 @@ const props = this.getProps(['x', 'y', 'width', 'height', 'text', 'scale']); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
174493
1862