@makechart/bar-race 0.0.1 → 0.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Change Logs
2
2
 
3
+ ## v0.0.3
4
+
5
+ - add `desc` ( en / zh-TW ) to the config items, shown under the label in the makechart style panel
6
+
7
+
8
+ ## v0.0.2
9
+
10
+ - rewrite: it couldn't run before. bars and ranks interpolate between adjacent orders by a playhead,
11
+ so the same playhead always draws the same frame. add config `top`, `duration`, `autoplay`, `loop`, `gap`,
12
+ `label.format` and `xaxis`
13
+ - extend the lite base ( `@makechart/base` `lite/index.html`, no d3 ): needs `@makechart/base` >= 0.2.0
14
+ and `@plotdb/chart` >= 3.7.0. scales / shapes / transitions use `chart.utils`, and transitions run on
15
+ `chart.anim`, so animation can be recorded frame by frame ( `anim.manual` / `step` )
16
+ - add test cases ( `test/index.ls`, run with `npm test` via `@makechart/viewer` )
17
+
18
+
3
19
  ## v0.0.1
4
20
 
5
21
  init release
package/index.html CHANGED
@@ -1 +1 @@
1
- <div><div plug="layout"><div class="pdl-layout"><div data-type="layout"><div class="pdl-cell" data-name="view"></div><div class="pdl-cell" data-name="axis">&nbsp;</div><div class="pdl-cell" data-name="legend">&nbsp;</div></div><div data-type="render"></div></div></div><style type="text/css">g[data-name=axis]{font-size:11px}.pdl-layout>div[data-type=layout]{display:grid;grid-template-columns:1fr fit-content(10em);grid-template-rows:1fr fit-content(1em)}.pdl-layout>div[data-type=layout]>.pdl-cell[data-name=legend]{grid-column:2;grid-row:1/span 2;padding-left:1em}</style><script type="@plotdb/block">var mod;module.exports={pkg:{name:"bar-race",version:"0.0.1",extend:{name:"@makechart/base"},dependencies:[],i18n:{"zh-TW":{height:"高度"}}},init:function(t){var e,n,a,i;e=t.root,n=t.context,a=t.t,i=t.pubsub;return i.fire("init",{mod:mod({context:n,t:a})})}};mod=function(t){var e,n,a,r,i;e=t.context,n=t.t;a=e.chart,r=e.d3,i=e.debounce;return{sample:function(){return{raw:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100].map(function(t){var e,n,a,i;e=[t%10,Math.floor(t/10)],n=e[0],a=e[1];i={name:n,value:Math.random(),order:a};return i}),binding:{order:{key:"order"},value:{key:"value"},name:{key:"name"}}}},config:{},dimension:{order:{type:"O",name:"order",priority:1},value:{type:"R",name:"value",priority:2},name:{type:"N",name:"name"}},init:function(){var e,t;this.tint=e=new a.utils.tint;this.g={view:r.select(this.layout.getGroup("view")),axis:r.select(this.layout.getGroup("axis"))};this.scale=t={};this.axisBottom=r.axisBottom();return this.legend=new a.utils.legend({layout:this.layout,name:"legend",root:this.root,shape:function(t){return r.select(this).attr("fill",e.get(t.key))}})},parse:function(){this.data.map(function(t){return t.value=t.value.map(function(t){if(isNaN(t)){return 0}else{return+t}})});return this.names=Array.from(new Set(this.data.map(function(t){return t.name})))},resize:function(){var t,a,e,n,i=this;this.layout.getNode("legend").style.width=!(((t=this.cfg).legend||(t.legend={})).enabled!=null)||this.cfg.legend.enabled?"":"0";this.layout.update(false);this.maxPerGroup=this.binding.height.map(function(t,e){return Math.max.apply(Math,i.data.map(function(t){return t.height[e]}))});this.order=this.data.map(function(t,e){return{key:t._idx,idx:e,name:t.order}});this.order.sort(function(t,e){if(e.name>t.name){return 1}else if(e.name<t.name){return-1}else{return 0}});this.tint.set(this.cfg.palette);this.legend.data(function(){var t,e,n=[];for(t=0,e=this.names.length;t<e;++t){a=t;n.push({key:a,text:this.names[a]})}return n}.call(this));this.layout.update(false);e=Math.max(this.data.map(function(t){return t.value}));n=this.layout.getBox("view");return t=this.scale,t.y=r.scaleLinear().domain([0,e]).range([n.width,0]),t.x=r.scaleBand().domain(this.order.map(function(t){return t.name||t.key})).range([0,n.height]),t},render:function(){var t,n,e,a,i,r,s,o;t=this.binding,n=this.scale,e=this.range,a=this.delta,i=this.cfg,r=this.tint,s=this.data;o=this.g.view.selectAll("g.bar").data(this.data);o.exit().remove();o.enter().append("g").attr("class","bar");this.g.view.selectAll("g.bar").attr("transform",function(t,e){return"translate("+n.x(t.name)+",0)"});return this.g.axis.call(this.axisBottom).attr("font-size","")},tick:function(){}}};</script></div>
1
+ <div><div plug="layout"><div class="pdl-layout"><div data-type="layout"><div class="pdl-cell" data-name="view"></div><div class="pdl-cell" data-name="xaxis">&nbsp;</div></div><div data-type="render"></div></div></div><style type="text/css">g[data-name=xaxis]{font-size:11px}.pdl-layout>div[data-type=layout]{display:grid;grid-template-columns:1fr;grid-template-rows:1fr fit-content(2em)}</style><script type="@plotdb/block">var svgns,mod;module.exports={pkg:{name:"bar-race",version:"0.0.1",extend:{name:"@makechart/base",path:"lite/index.html"},dependencies:[],i18n:{"zh-TW":{order:"順序",value:"數值",name:"名稱"}}},init:function(t){var e,r,n,a;e=t.root,r=t.context,n=t.t,a=t.pubsub;return a.fire("init",{mod:mod({context:r,t:n})})}};svgns="http://www.w3.org/2000/svg";mod=function(t){var e,r,n,a,i,C,E,s;e=t.context,r=t.t;n=e.chart;a=n.utils,i=a.scale,C=a.format,E=a.anim.join;s=function(){var t,e,r,n,u,a,i,s,o,h,l,m,c,d,f,p,b,x,g,y,v,A,w,M,k,N,z=this;if(!this.orders||!this.orders.length){return}t=this.table,e=this.ranks,r=this.names,n=this.cfg,u=this.tint;a=n.duration||1e3;i=this.orders.length-1;s=Math.min(this.playhead/a,i);o=Math.floor(s);h=Math.min(o+1,i);l=s-o;m=function(t,e){return t+(e-t)*l};c=n.top||10;d=this.layout.getBox("view");f=d.height/c;p=n.gap||0;b=[];for(x=0,g=r.length;x<g;++x){y=x;v=m(e[o][y],e[h][y]);if(v>c){continue}b.push({name:r[y],idx:y,value:m(t[y][o],t[y][h]),rank:v})}A=Math.max.apply(Math,[0].concat(b.map(function(t){return t.value})))||1;w=C.from(n.label.format||".3s");this.scale.x.domain([0,A]).range([0,d.width]);M=this.scale.x.ticks(Math.max(2,Math.floor(d.width/80)));this.xaxis.config(n.xaxis);this.xaxis.ticks(M);this.xaxis.scale(this.scale.x);this.xaxis.render();k=E({root:this.g.bars,tag:"g",cls:"bar",data:b,key:function(t){return t.name}});k.enter.map(function(t){var e,r,n;e=t.appendChild(document.createElementNS(svgns,"rect"));e.setAttribute("class","data");r=t.appendChild(document.createElementNS(svgns,"text"));r.setAttribute("class","name");r.setAttribute("text-anchor","end");r.setAttribute("dominant-baseline","central");r.setAttribute("fill","#fff");n=t.appendChild(document.createElementNS(svgns,"text"));n.setAttribute("class","value");n.setAttribute("dominant-baseline","central");n.setAttribute("fill","currentColor");return n});k.nodes.map(function(t){var e,r,n,a,i,s,o;e=t.__data__;r=Math.max(0,z.scale.x(e.value));n=Math.max(1,f-p);t.setAttribute("transform","translate(0,"+e.rank*f+")");t.setAttribute("opacity",Math.max(0,Math.min(1,c-e.rank)));a=t.childNodes,i=a[0],s=a[1],o=a[2];i.__data__=(e._raw={name:e.name,value:e.value},e);i.setAttribute("width",r);i.setAttribute("height",n);i.setAttribute("fill",u.get(e.name));s.setAttribute("x",r-4);s.setAttribute("y",n/2);s.setAttribute("font-size",Math.min(14,n*.6));s.textContent=e.name;s.setAttribute("opacity",r>60?1:0);o.setAttribute("x",r+4);o.setAttribute("y",n/2);o.setAttribute("font-size",Math.min(12,n*.5));return o.textContent=w(e.value)});N=this.g.order;N.setAttribute("x",d.width-8);N.setAttribute("y",d.height-8);N.setAttribute("font-size",Math.min(64,d.height/5));N.textContent=this.orders[l<.5?o:h];return N};return{sample:function(){var t,n;t=["Apple","Banana","Cherry","Durian","Elderberry","Fig","Grape","Honeydew"];n=t.map(function(){return 0});return{raw:[].concat.apply([],[0,1,2,3,4,5,6,7,8,9,10,11].map(function(r){return t.map(function(t,e){n[e]+=Math.round(Math.random()*100);return{name:t,value:n[e],order:2e3+r}})})),binding:{order:{key:"order"},value:{key:"value"},name:{key:"name"}}}},config:(a=import$({xaxis:JSON.parse(JSON.stringify(n.utils.config.preset.axis))},n.utils.config.preset["default"]),a.top={type:"number",default:10,min:1,max:50,step:1,desc:{en:"how many of the top-ranked bars are shown at a time","zh-TW":"同時顯示前幾名的長條"}},a.duration={type:"number",default:1e3,min:100,max:1e4,step:100,desc:{en:"playing time of each order step ( ms )","zh-TW":"每個順序 ( 一格 ) 播放的時間 ( 毫秒 )"}},a.autoplay={type:"boolean",default:true,desc:{en:"play through the orders automatically; off holds the current frame ( the first order when loaded )","zh-TW":"自動依序播放;關掉時停在目前這一格 ( 剛載入時是第一格 )"}},a.loop={type:"boolean",default:true,desc:{en:"start over after the last order; off stops on the last one","zh-TW":"播完最後一格後從頭再播;關掉時停在最後一格"}},a.gap={type:"number",default:2,min:0,max:20,step:1,desc:{en:"space between bars ( px )","zh-TW":"長條之間的間距 ( px )"}},a.label={format:{type:"format",default:".3s",desc:{en:"number format of the values shown next to the bars, e.g. .3s ( d3-format )","zh-TW":"長條旁數值的格式,例如 .3s ( d3-format )"}}},a),dimension:{order:{type:"O",name:"order",priority:1},value:{type:"R",name:"value",priority:2},name:{type:"N",name:"name"}},init:function(){var t,e=this;this.tint=new n.utils.tint;this.g=Object.fromEntries(["view","xaxis"].map(function(t){return[t,e.layout.getGroup(t)]}));this.g.bars=this.g.view.appendChild(document.createElementNS(svgns,"g"));t=this.g.order=this.g.view.appendChild(document.createElementNS(svgns,"text"));t.setAttribute("class","order");t.setAttribute("text-anchor","end");t.setAttribute("fill","currentColor");t.setAttribute("opacity",.3);this.xaxis=new n.utils.axis({layout:this.layout,name:"xaxis",direction:"bottom"});this.scale={x:i.linear()};this.playhead=0;return this.start()},parse:function(){var e,t,r,n,a=this;e=function(t){if(isNaN(+t)){return 0}else{return+t}};t=Array.from(new Set(this.data.map(function(t){return t.order})));if(t.every(function(t){return!isNaN(+t)})){t.sort(function(t,e){return+t-+e})}else{t.sort()}this.orders=t;this.names=Array.from(new Set(this.data.map(function(t){return t.name})));r=Object.fromEntries(t.map(function(t,e){return[t,e]}));n=Object.fromEntries(this.names.map(function(t,e){return[t,e]}));this.table=this.names.map(function(){return t.map(function(){return null})});this.data.map(function(t){return a.table[n[t.name]][r[t.order]]=e(t.value)});this.table.map(function(t){var e,r,n,a=[];for(e=0,r=t.length;e<r;++e){n=e;if(!(t[n]!=null)){a.push(t[n]=n?t[n-1]:0)}}return a});return this.ranks=t.map(function(t,r){var e,n;e=function(){var t,e,r=[];for(t=0,e=this.names.length;t<e;++t){r.push(t)}return r}.call(a).sort(function(t,e){return a.table[e][r]-a.table[t][r]||t-e});n=[];e.map(function(t,e){return n[t]=e});return n})},resize:function(){this.tint.set(this.cfg.palette);return this.layout.update(false)},render:function(){return s.apply(this)},tick:function(t,e){var r,n;e==null&&(e=0);if(!this.cfg.autoplay||!this.orders||this.orders.length<2){return}r=this.cfg.duration||1e3;n=this.orders.length*r;this.playhead+=e;if(this.playhead>=n){this.playhead=this.cfg.loop?this.playhead%n:n-r}return s.apply(this)}}};function import$(t,e){var r={}.hasOwnProperty;for(var n in e)if(r.call(e,n))t[n]=e[n];return t}</script></div>
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@makechart/bar-race","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/bar-race","version":"0.0.3","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.4"}}