@makechart/wordcloud 0.0.1 → 0.0.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Change Logs
2
2
 
3
+ ## v0.0.2
4
+
5
+ - extend the lite base ( `@makechart/base` `lite/index.html`, no d3 ): needs `@makechart/base` >= 0.2.0
6
+ and `@plotdb/chart` >= 3.7.0
7
+ d3 is replaced by `d3-cloud` 1.2.5
8
+ - layout is seeded, so the same data always gives the same layout
9
+ - fix bug: it didn't render. the svg is now positioned at the top left instead of being pushed below
10
+ the base layout block
11
+ - fix bug: `resize` threw when no palette is set
12
+ - remove debug `console.log`
13
+ - add test cases ( `test/index.ls`, run with `npm test` via `@makechart/viewer` )
14
+
15
+
3
16
  ## v0.0.1
4
17
 
5
18
  init release
package/index.html CHANGED
@@ -1 +1 @@
1
- <div><script type="@plotdb/block">var mod;module.exports={pkg:{name:"wordcloud",version:"0.0.1",extend:{name:"@makechart/base"},dependencies:[{url:"https://unpkg.com/d3-cloud@1.2.5/build/d3.layout.cloud.js"},{name:"@xlfont/load",version:"main"}]},init:function(t){var e,n,a;e=t.root,n=t.ctx,a=t.pubsub;return a.fire("init",{mod:mod({ctx:n}),layout:false}).then(function(t){return t[0]})}};mod=function(t){var e,n,i,a,o,r,s;e=t.ctx,n=t.root;i=e.d3,a=e.forceBoundary,o=e.ldcolor,r=e.chart,s=e.xfl;return{sample:function(){return{raw:["cover","scandal","seem","consumption","garbage","hunter","pepper","west","guilt","conspiracy","pupil","boat","muscle","nightmare","gene","royalty","salon","difficult","management","brainstorm","aid","moving","plaster","cake","issue","realism","subject","speed","railcar","break","grass","collapse","is","leave","retiree","looting","transaction","copyright","serve","guard","colony","spell","ask","ranch","cell","sensation","name","default","reflection"].map(function(t,e){return{text:t,value:1.5*e+10}}),binding:{value:{key:"value"},text:{key:"text"}}}},config:{palette:{type:"palette"},color:{random:{type:"boolean",default:false}},background:{type:"color"},font:{size:{type:"number",min:1,max:256,step:1,default:64},family:{type:"font"}},cloud:{rotate:{angle:{type:"number",default:0,min:0,max:360,step:.1},variant:{type:"number",default:0,min:0,max:180,step:.1}}}},dimension:{value:{type:"R",name:"size"},text:{type:"NCO",name:"name"}},init:function(){var t,n=this;this.tint=t=new r.utils.tint;this.cloud=i.layout.cloud();this.cloud.canvas(function(){var t,e;t=document.createElement("canvas");e=t.getContext("2d",{willReadFrequently:true});return t}).rotate(function(){var t,e;t=n.cfg.cloud.rotate.angle||0;e=n.cfg.cloud.rotate.variant||0;return t+e*(Math.random()*2-1)}).padding(2).fontSize(function(t){return n.cfg.font.size*t.value}).on("end",function(){return n.render()});return this.fonts={h:{},active:null,name:function(){return(n.fonts.active||{}).name||(n.cfg.font.family||{}).name||"arial"}}},parse:function(){var t,e=this;this.parsed=this.data.map(function(t){var e;e=import$({},t);e._value=e.value;e.value=Math.sqrt(e._value);return e});this._max=Math.max.apply(Math,this.parsed.map(function(t){return t.value}));this.parsed.map(function(t){return t.value=t.value/e._max});if(this.cfg.font.family){console.log(this.cfg.font.family.isXl)}if(this.cfg.font.family&&this.cfg.font.family.isXl){if(!(t=this.fonts.h[this.cfg.font.family.path])){this.fonts.h[this.cfg.font.family.path]={loading:true};s.load(this.cfg.font.family.path).then(function(t){e.fonts.h[e.cfg.font.family.path]=e.fonts.active=t;if(!t.sync){return}return t.sync(e.parsed.map(function(t){return t.text}).join("")).then(function(){e.resize();return e.render()})})}if(t&&t.sync){return t.sync(this.parsed.map(function(t){return t.text}).join("")).then(function(){e.resize();return e.render()})}}},resize:function(){this.cloud.size([this.box.width,this.box.height].map(function(t){return Math.round(t)})).words(this.parsed).font(this.fonts.name()).start();return this.tint.set(this.cfg.palette.colors)},render:function(){var e,t,n,a,r=this;e=i.interpolateTurbo;if(this.cfg!=null&&this.cfg.palette){e=i.interpolateDiscrete(this.cfg.palette.colors.map(function(t){return o.web(t.value||t)}))}t=i.extent(this.parsed.map(function(t){return t.value}));n=i.scaleLinear().domain(t).range([0,1]);a=i.select(this.svg).selectAll("text").data(this.parsed);a.exit().remove();a.enter().append("text");return i.select(this.svg).selectAll("text").attr("transform",function(t){return"translate("+(t.x+r.box.width/2)+" "+(t.y+r.box.height/2)+") rotate("+t.rotate+")"}).attr("text-anchor","middle").attr("font-size",function(t){return t.size}).attr("font-family",this.fonts.name()).attr("fill",function(t){if(r.cfg.color.random){return r.tint.get(t.text)}else{return e(n(t.value))}}).text(function(t){return t.text})},tick:function(){}}};function import$(t,e){var n={}.hasOwnProperty;for(var a in e)if(n.call(e,a))t[a]=e[a];return t}</script></div>
1
+ <div><script type="@plotdb/block">var mod;module.exports={pkg:{name:"wordcloud",version:"0.0.1",extend:{name:"@makechart/base",path:"lite/index.html"},dependencies:[{name:"d3-cloud",version:"1.2.5",path:"build/d3.layout.cloud.js",async:false},{name:"@xlfont/load",version:"main"}]},init:function(t){var e,n,r;e=t.root,n=t.ctx,r=t.pubsub;return r.fire("init",{mod:mod({ctx:n}),layout:false}).then(function(t){return t[0]})}};mod=function(t){var e,n,r,i,a,o,u,s,l,f,c,d,m,h;e=t.ctx,n=t.root;r=e.d3,i=e.ldcolor,a=e.chart,o=e.xfl;u=a.utils,s=u.scale,l=u.color,f=l.turbo,c=l.discrete,d=u.anim.join;m=function(t){var e,n,r,a,i;e=[1664525,1013904223,1/4294967296],n=e[0],r=e[1],a=e[2];i=(0<=t&&t<1?t/a:Math.abs(t))|0;return function(){return a*((i=n*i+r|0)>>>0)}};h=function(t){var e;e=t.filter(function(t){return t!=null&&+t>=+t});if(e.length){return[e.reduce(function(t,e){if(e<t){return e}else{return t}}),e.reduce(function(t,e){if(e>t){return e}else{return t}})]}else{return[undefined,undefined]}};return{sample:function(){return{raw:["cover","scandal","seem","consumption","garbage","hunter","pepper","west","guilt","conspiracy","pupil","boat","muscle","nightmare","gene","royalty","salon","difficult","management","brainstorm","aid","moving","plaster","cake","issue","realism","subject","speed","railcar","break","grass","collapse","is","leave","retiree","looting","transaction","copyright","serve","guard","colony","spell","ask","ranch","cell","sensation","name","default","reflection"].map(function(t,e){return{text:t,value:1.5*e+10}}),binding:{value:{key:"value"},text:{key:"text"}}}},config:{palette:{type:"palette"},color:{random:{type:"boolean",default:false}},background:{type:"color"},font:{size:{type:"number",min:1,max:256,step:1,default:64},family:{type:"font"}},cloud:{rotate:{angle:{type:"number",default:0,min:0,max:360,step:.1},variant:{type:"number",default:0,min:0,max:180,step:.1}}}},dimension:{value:{type:"R",name:"size"},text:{type:"NCO",name:"name"}},init:function(){var t,e,n=this;t=this.svg.style;t.position="absolute";t.left=0;t.top=0;this.tint=e=new a.utils.tint;this.cloud=r.layout.cloud();this.cloud.canvas(function(){var t,e;t=document.createElement("canvas");e=t.getContext("2d",{willReadFrequently:true});return t}).rotate(function(){var t,e;t=n.cfg.cloud.rotate.angle||0;e=n.cfg.cloud.rotate.variant||0;return t+e*(n.rng()*2-1)}).padding(2).fontSize(function(t){return n.cfg.font.size*t.value}).on("end",function(){return n.render()});return this.fonts={h:{},active:null,name:function(){return(n.fonts.active||{}).name||(n.cfg.font.family||{}).name||"arial"}}},parse:function(){var t,e=this;this.parsed=this.data.map(function(t){var e;e=import$({},t);e._value=e.value;e.value=Math.sqrt(e._value);return e});this._max=Math.max.apply(Math,this.parsed.map(function(t){return t.value}));this.parsed.map(function(t){return t.value=t.value/e._max});if(this.cfg.font.family&&this.cfg.font.family.isXl){if(!(t=this.fonts.h[this.cfg.font.family.path])){this.fonts.h[this.cfg.font.family.path]={loading:true};o.load(this.cfg.font.family.path).then(function(t){e.fonts.h[e.cfg.font.family.path]=e.fonts.active=t;if(!t.sync){return}return t.sync(e.parsed.map(function(t){return t.text}).join("")).then(function(){e.resize();return e.render()})})}if(t&&t.sync){return t.sync(this.parsed.map(function(t){return t.text}).join("")).then(function(){e.resize();return e.render()})}}},resize:function(){this.rng=m(1);this.cloud.random(this.rng).size([this.box.width,this.box.height].map(function(t){return Math.round(t)})).words(this.parsed).font(this.fonts.name()).start();if(this.cfg.palette){return this.tint.set(this.cfg.palette.colors)}},render:function(){var n,t,r,e,a=this;n=f;if(this.cfg!=null&&this.cfg.palette){n=c(this.cfg.palette.colors.map(function(t){return i.web(t.value||t)}))}t=h(this.parsed.map(function(t){return t.value}));r=s.linear().domain(t).range([0,1]);e=d({root:this.svg,tag:"text",data:this.parsed});e.exit.map(function(t){return t.remove()});return Array.from(this.svg.querySelectorAll(":scope > text")).map(function(t){var e;e=t.__data__;t.setAttribute("transform","translate("+(e.x+a.box.width/2)+" "+(e.y+a.box.height/2)+") rotate("+e.rotate+")");t.setAttribute("text-anchor","middle");t.setAttribute("font-size",e.size);t.setAttribute("font-family",a.fonts.name());t.setAttribute("fill",a.cfg.color.random?a.tint.get(e.text):n(r(e.value)));return t.textContent=e.text})},tick:function(){}}};function import$(t,e){var n={}.hasOwnProperty;for(var r in e)if(n.call(e,r))t[r]=e[r];return t}</script></div>
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@makechart/wordcloud","version":"0.0.1","description":"","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":[],"author":"zbryikt","license":"MIT","dependencies":{"@plotdb/srcbuild":"^0.0.69","fedep":"1.6.0","livescript":"^1.6.0"}}
1
+ {"name":"@makechart/wordcloud","version":"0.0.2","description":"","scripts":{"test":"mctest","test:serve":"mctest serve -o","test:dev":"mctest -l \"@makechart/base:../base;@plotdb/chart:../../../plotdb/projects/chart;@plotdb/dash:../../../plotdb/projects/dash\"","test:dev:serve":"mctest serve -o -l \"@makechart/base:../base;@plotdb/chart:../../../plotdb/projects/chart;@plotdb/dash:../../../plotdb/projects/dash\""},"keywords":[],"author":"zbryikt","license":"MIT","dependencies":{"@plotdb/srcbuild":"^0.0.69","fedep":"1.6.0","livescript":"^1.6.0"},"devDependencies":{"@makechart/viewer":"^0.0.3"}}