@makechart/delaunay 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,14 @@
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-delaunay` 6.0.4, loaded as a dependency instead of from a CDN
8
+ - fix `pkg.name` ( was `scatter` )
9
+ - add test cases ( `test/index.ls`, run with `npm test` via `@makechart/viewer` )
10
+
11
+
3
12
  ## v0.0.1
4
13
 
5
14
  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="axis-left"></div><div class="pdl-cell" data-name="view"></div><div class="pdl-cell"></div><div class="pdl-cell" data-name="axis-bottom"></div><div class="pdl-cell" data-name="legend"></div></div><div data-type="render"></div></div></div><style type="text/css">.pdl-layout>div[data-type=layout]{display:grid;grid-template-columns:2em 1fr;grid-template-rows:1fr 1em 3em;padding:20px 20px 0 20px}.pdl-layout>div[data-type=layout] .pdl-cell[data-name=legend]{grid-column:1/span 2;grid-row:3}</style><script type="@plotdb/block">var mod;module.exports={pkg:{name:"scatter",version:"0.0.1",extend:{name:"@makechart/base"},dependencies:[{url:"https://cdn.jsdelivr.net/npm/d3-delaunay@6/dist/d3-delaunay.min.js"}]},init:function(t){var e,n,i;e=t.root,n=t.context,i=t.pubsub;return i.fire("init",{mod:mod({context:n})})}};mod=function(t){var e,x,n,i;e=t.context;x=e.d3,n=e.chart;i=["The Glenn Miller Story","The Fifth Element","Forrest Gump","Finding Nemo","The Fly","First Blood","You Can't Take It with You","Man of the Year","From Hell","The Easy Rider","The English Patient","The Extra-Terrestial","Edward Scissorhands","Empire of the Sun","Encounters of the Third Kind","Elizabeth: The Golden Age"];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;e={x:Math.random(),y:Math.random(),name:i[Math.floor(Math.random()*i.length)]};return e}),binding:{x:{key:"x"},y:{key:"y"},name:{key:"name"}}}},config:{},dimension:{x:{type:"R",name:"x axis"},y:{type:"R",name:"y axis"},radius:{type:"R",name:"radius"},category:{type:"CN",name:"category"},name:{type:"N",name:"name"}},init:function(){var t,e=this;this.tint=t=new n.utils.tint;["view","yaxis","xaxis"].map(function(t){return(e.g||(e.g={}))[t]=x.select(e.layout.getGroup(t))});return this.path=x.select(this.svg).append("path")},parse:function(){},resize:function(){var t,e,n,i,u=this;t=[this.box.width,this.box.height],e=t[0],n=t[1];this.extent={x:x.extent(this.data.map(function(t){return t.x})),y:x.extent(this.data.map(function(t){return t.y}))};i=this.layout.getBox("view");this.scale={x:x.scaleLinear().domain(this.extent.x).range([0,i.width]),y:x.scaleLinear().domain(this.extent.y).range([0,i.height])};this.pts=this.data.map(function(t){return[u.scale.x(t.x),u.scale.y(t.y)]});this.delaunay=x.Delaunay.from(this.pts);this.voronoi=this.delaunay.voronoi([0,0,i.width,i.height]);return this.cells=this.pts.map(function(t,e){var n,i,a,r,h,s,o,d,l;n=t[0],i=t[1];a=u.voronoi.cellPolygon(e);h=r=x.polygonCentroid(a),s=h[0],o=h[1];d=-x.polygonArea(a);l=(Math.round(Math.atan2(o-i,s-n)/Math.PI*2)+4)%4;return{point:t,polygon:a,centroid:r,area:d,angle:l}})},render:function(){var n,t,e;n=this.scale;t=this.g.view.selectAll("circle.data").data(this.data);t.exit().remove();t.enter().append("circle").attr("class","data").attr("cx",function(t,e){return n.x(t.x)}).attr("cy",function(t,e){return n.y(t.y)}).attr("r",3).attr("fill","#000");e=this.g.view.selectAll("text").data(this.data);e.exit().remove();e.enter().append("text").text(function(t,e){return t.name}).attr("x",function(t,e){if(t.nb){return t.nb.x}else{return n.x(t.x)}}).attr("y",function(t,e){if(t.nb){return t.nb.y}else{return n.y(t.y)}}).attr("text-anchor","middle").attr("dominant-baseline","middle");this.g.view.selectAll("text").data(this.data).attr("x",function(t,e){if(t.nb){return t.nb.x}else{return n.x(t.x)}}).attr("y",function(t,e){if(t.nb){return t.nb.y}else{return n.y(t.y)-20}}).attr("opacity",function(t,e){if(t.nb){if(t.nb.show){return 1}else{return 0}}else{return 1}});return this.path.attr("d",this.voronoi.render()).attr("stroke","#000").attr("transform",this.g.view.node().getAttribute("transform"))},tick:function(){var t,e,n,i,a,r,h,s,o,d,l,u,x,y;t=this.scale;this.g.view.selectAll("text").each(function(t,e){return t.box=this.getBoundingClientRect()});e=this.layout.getBox("view");for(n=0,i=this.data.length;n<i;++n){a=n;r=this.data[a].box;if(!this.data[a].nb){this.data[a].nb={x:t.x(this.data[a].x),y:t.y(this.data[a].y)-20}}h=this.data[a].nb;h.width=r.width;h.height=r.height;h.show=true}for(n=20;n<200;n+=20){s=n;for(o=0,i=this.data.length;o<i;++o){a=o;for(d=0;d<a;++d){l=d;h=[this.data[a].nb,this.data[l].nb],u=h[0],x=h[1];if((u.x>=x.x&&u.x<=x.x+x.width||u.x+u.width>=x.x&&u.x+u.width<=x.x+x.width)&&(u.y>=x.y&&u.y<=x.y+x.height||u.y+u.height>=x.y&&u.y+u.height<=x.y+x.height)){r=Math.random()*Math.PI*2;y=this.data[a];h=y.nb;h.x=t.x(y.x)+Math.cos(r)*s;h.y=t.y(y.y)+Math.sin(r)*s}}}}for(n=0,i=this.data.length;n<i;++n){a=n;for(o=0;o<a;++o){l=o;h=[this.data[a].nb,this.data[l].nb],u=h[0],x=h[1];if((u.x>=x.x&&u.x<=x.x+x.width||u.x+u.width>=x.x&&u.x+u.width<=x.x+x.width)&&(u.y>=x.y&&u.y<=x.y+x.height||u.y+u.height>=x.y&&u.y+u.height<=x.y+x.height)){this.data[a].nb.show=false}}}return this.render()}}};</script></div>
1
+ <div><div plug="layout"><div class="pdl-layout"><div data-type="layout"><div class="pdl-cell" data-name="axis-left"></div><div class="pdl-cell" data-name="view"></div><div class="pdl-cell"></div><div class="pdl-cell" data-name="axis-bottom"></div><div class="pdl-cell" data-name="legend"></div></div><div data-type="render"></div></div></div><style type="text/css">.pdl-layout>div[data-type=layout]{display:grid;grid-template-columns:2em 1fr;grid-template-rows:1fr 1em 3em;padding:20px 20px 0 20px}.pdl-layout>div[data-type=layout] .pdl-cell[data-name=legend]{grid-column:1/span 2;grid-row:3}</style><script type="@plotdb/block">var mod;module.exports={pkg:{name:"delaunay",version:"0.0.1",extend:{name:"@makechart/base",path:"lite/index.html"},dependencies:[{name:"d3-delaunay",version:"6.0.4",path:"dist/d3-delaunay.min.js",async:false}]},init:function(t){var e,n,i;e=t.root,n=t.context,i=t.pubsub;return i.fire("init",{mod:mod({context:n})})}};mod=function(t){var e,a,n,i,r,h,o,s,y,x,u;e=t.context;a=e.d3,n=e.chart;i=n.utils,r=i.scale,h=i.anim.join;o="http://www.w3.org/2000/svg";s=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]}};y=function(t){var e,n,i,a,r,h,o;e=[t.length,t[t.length-1],0],n=e[0],i=e[1],a=e[2];for(r=0;r<n;++r){h=r;o=i;i=t[h];a+=o[1]*i[0]-o[0]*i[1]}return a/2};x=function(t){var e,n,i,a,r,h,o,s,u,d;e=[t.length,0,0,0,t[t.length-1]],n=e[0],i=e[1],a=e[2],r=e[3],h=e[4];for(o=0;o<n;++o){s=o;u=h;h=t[s];r+=d=u[0]*h[1]-h[0]*u[1];i+=(u[0]+h[0])*d;a+=(u[1]+h[1])*d}r*=3;return[i/r,a/r]};u=["The Glenn Miller Story","The Fifth Element","Forrest Gump","Finding Nemo","The Fly","First Blood","You Can't Take It with You","Man of the Year","From Hell","The Easy Rider","The English Patient","The Extra-Terrestial","Edward Scissorhands","Empire of the Sun","Encounters of the Third Kind","Elizabeth: The Golden Age"];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;e={x:Math.random(),y:Math.random(),name:u[Math.floor(Math.random()*u.length)]};return e}),binding:{x:{key:"x"},y:{key:"y"},name:{key:"name"}}}},config:{},dimension:{x:{type:"R",name:"x axis"},y:{type:"R",name:"y axis"},radius:{type:"R",name:"radius"},category:{type:"CN",name:"category"},name:{type:"N",name:"name"}},init:function(){var t,e=this;this.tint=t=new n.utils.tint;["view","yaxis","xaxis"].map(function(t){return(e.g||(e.g={}))[t]=e.layout.getGroup(t)});return this.path=this.svg.appendChild(document.createElementNS(o,"path"))},parse:function(){},resize:function(){var t,e,n,i,l=this;t=[this.box.width,this.box.height],e=t[0],n=t[1];this.extent={x:s(this.data.map(function(t){return t.x})),y:s(this.data.map(function(t){return t.y}))};i=this.layout.getBox("view");this.scale={x:r.linear().domain(this.extent.x).range([0,i.width]),y:r.linear().domain(this.extent.y).range([0,i.height])};this.pts=this.data.map(function(t){return[l.scale.x(t.x),l.scale.y(t.y)]});this.delaunay=a.Delaunay.from(this.pts);this.voronoi=this.delaunay.voronoi([0,0,i.width,i.height]);return this.cells=this.pts.map(function(t,e){var n,i,a,r,h,o,s,u,d;n=t[0],i=t[1];a=l.voronoi.cellPolygon(e);h=r=x(a),o=h[0],s=h[1];u=-y(a);d=(Math.round(Math.atan2(s-i,o-n)/Math.PI*2)+4)%4;return{point:t,polygon:a,centroid:r,area:u,angle:d}})},render:function(){var n,r,t,e,i;n=this.scale;r=function(t){return[t.nb?t.nb.x:n.x(t.x),t.nb?t.nb.y:n.y(t.y)]};t=h({root:this.g.view,tag:"circle",cls:"data",data:this.data});t.exit.map(function(t){return t.remove()});t.enter.map(function(t){var e;e=t.__data__;t.setAttribute("cx",n.x(e.x));t.setAttribute("cy",n.y(e.y));t.setAttribute("r",3);return t.setAttribute("fill","#000")});e=h({root:this.g.view,tag:"text",data:this.data});e.exit.map(function(t){return t.remove()});e.enter.map(function(t){var e,n,i,a;e=t.__data__;t.textContent=e.name;n=r(e),i=n[0],a=n[1];t.setAttribute("x",i);t.setAttribute("y",a);t.setAttribute("text-anchor","middle");return t.setAttribute("dominant-baseline","middle")});e.nodes.map(function(t){var e;e=t.__data__;t.setAttribute("x",e.nb?e.nb.x:n.x(e.x));t.setAttribute("y",e.nb?e.nb.y:n.y(e.y)-20);return t.setAttribute("opacity",e.nb?e.nb.show?1:0:1)});this.path.setAttribute("d",this.voronoi.render());this.path.setAttribute("stroke","#000");if((i=this.g.view.getAttribute("transform"))!=null){return this.path.setAttribute("transform",i)}else{return this.path.removeAttribute("transform")}},tick:function(){var t,e,n,i,a,r,h,o,s,u,d,l,y,x;t=this.scale;Array.from(this.g.view.querySelectorAll(":scope > text")).map(function(t){return t.__data__.box=t.getBoundingClientRect()});e=this.layout.getBox("view");for(n=0,i=this.data.length;n<i;++n){a=n;r=this.data[a].box;if(!this.data[a].nb){this.data[a].nb={x:t.x(this.data[a].x),y:t.y(this.data[a].y)-20}}h=this.data[a].nb;h.width=r.width;h.height=r.height;h.show=true}for(n=20;n<200;n+=20){o=n;for(s=0,i=this.data.length;s<i;++s){a=s;for(u=0;u<a;++u){d=u;h=[this.data[a].nb,this.data[d].nb],l=h[0],y=h[1];if((l.x>=y.x&&l.x<=y.x+y.width||l.x+l.width>=y.x&&l.x+l.width<=y.x+y.width)&&(l.y>=y.y&&l.y<=y.y+y.height||l.y+l.height>=y.y&&l.y+l.height<=y.y+y.height)){r=Math.random()*Math.PI*2;x=this.data[a];h=x.nb;h.x=t.x(x.x)+Math.cos(r)*o;h.y=t.y(x.y)+Math.sin(r)*o}}}}for(n=0,i=this.data.length;n<i;++n){a=n;for(s=0;s<a;++s){d=s;h=[this.data[a].nb,this.data[d].nb],l=h[0],y=h[1];if((l.x>=y.x&&l.x<=y.x+y.width||l.x+l.width>=y.x&&l.x+l.width<=y.x+y.width)&&(l.y>=y.y&&l.y<=y.y+y.height||l.y+l.height>=y.y&&l.y+l.height<=y.y+y.height)){this.data[a].nb.show=false}}}return this.render()}}};</script></div>
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@makechart/delaunay","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/delaunay","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"}}