@makechart/venn 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 +7 -0
- package/index.html +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v0.0.2
|
|
4
|
+
|
|
5
|
+
- fix: page hangs when the chart is removed or hidden in dot style. the view box is 0, so the dot grid step became 0
|
|
6
|
+
and the loop filling the grid never ended. skip layout when the view has no size, and bail out on a non-positive step
|
|
7
|
+
- stop the idle dot animation on `destroy`
|
|
8
|
+
|
|
9
|
+
|
|
3
10
|
## v0.0.1
|
|
4
11
|
|
|
5
12
|
- init release: venn / euler diagram
|
package/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<div><style type="text/css">.pdl-layout>div[data-type=layout]{display:grid;grid-template-columns:1fr fit-content(10em);grid-template-rows:1fr}.pdl-layout>div[data-type=layout]>.pdl-cell[data-name=legend]{grid-column:2;grid-row:1;padding-left:1em}.pdl-layout.legend-bottom>div[data-type=layout]{grid-template-columns:1fr;grid-template-rows:1fr fit-content(3em)}.pdl-layout.legend-bottom>div[data-type=layout] .pdl-cell[data-name=legend]{padding-top:1em;padding-left:0;grid-column:1;grid-row:2}text.venn-text{pointer-events:none}</style><script type="@plotdb/block">var svgns,maxSets,popcount,hash,lens,distanceFor,splitSets,build,project,pairOf,arrange,analyze,span,fitScale,shapes,mod;module.exports={pkg:{name:"venn",version:"0.0.1",extend:{name:"@makechart/base",path:"lite/index.html"},dependencies:[],i18n:{en:{only:"$1 only",both:"both",all:"all",total:"$1 total"},"zh-TW":{only:"僅 $1",both:"兩者皆是",all:"全部皆是",total:"共 $1",sets:"集合",size:"數量",label:"標籤"}}},init:function(t){var e,n,r,i;e=t.root,n=t.context,r=t.t,i=t.pubsub;return i.fire("init",{mod:mod({context:n,t:r})})}};svgns="http://www.w3.org/2000/svg";maxSets=24;popcount=function(t){var e;e=0;while(t){t=t&t-1;e++}return e};hash=function(t){var e;e=Math.sin(t*12.9898+78.233)*43758.5453;return e-Math.floor(e)};lens=function(t,e,n){var r,i,a;if(n>=t+e){return 0}if(n<=Math.abs(t-e)){return Math.PI*Math.min(t,e)*Math.min(t,e)}r=t*t*Math.acos((n*n+t*t-e*e)/(2*n*t));i=e*e*Math.acos((n*n+e*e-t*t)/(2*n*e));a=.5*Math.sqrt((t+e-n)*(n+t-e)*(n-t+e)*(n+t+e));return r+i-a};distanceFor=function(t,e,n){var r,i,a,o,s,l;r=[Math.abs(t-e),t+e],i=r[0],a=r[1];if(n<=0){return a+Math.min(t,e)*.15}if(n>=lens(t,e,i)){return i}for(o=0;o<60;++o){s=o;l=(i+a)/2;if(lens(t,e,l)>n){i=l}else{a=l}}return(i+a)/2};splitSets=function(t,e){var n,r,i,a,o,s,l;if(!(t!=null)){return[]}n=(t+"").trim();if(!n){return[]}r=e?n.split(e):n.split(/\s*(?:&|∩|\||\+|,|、)\s*/);i=[];for(a=0,s=(o=r.map(u)).length;a<s;++a){l=o[a];if(l&&!in$(l,i)){i.push(l)}}return i;function u(t){return t.trim()}};build=function(t,e){var n,r,i,a,o,s,l,u,c,h,f,p,d,m,g,y,b,v,x,M;e==null&&(e={});n=[];r={};i={};a={};for(o=0,s=t.length;o<s;++o){l=t[o];if(!l.names.length||isNaN(l.size)){continue}if(l.names.some(_)&&n.length+l.names.filter(k).length>maxSets){continue}u=0;for(c=0,f=(h=l.names).length;c<f;++c){p=h[c];if(!(r[p]!=null)){r[p]=n.length;n.push(p)}u=u|1<<r[p]}i[u]=(i[u]||0)+l.size;if(l.label){a[u]=l.label}}m=[];for(g in i){m.push(+g)}d=m;y={};for(o=0,s=d.length;o<s;++o){u=d[o];if(!e.inclusive){y[u]=(h=i[u])>0?h:0}else{b=0;for(c=0,f=d.length;c<f;++c){v=d[c];if((v&u)===u){b+=((popcount(v)-popcount(u))%2?-1:1)*i[v]}}y[u]=b>0?b:0}}x={};n.map(function(t,n){return x[t]=d.reduce(function(t,e){return t+(e&1<<n?y[e]:0)},0)});M={};n.map(function(t,e){if(a[1<<e]){return M[t]=a[1<<e]}});return{names:n,exc:y,labels:a,totals:x,setLabels:M};function _(t){return!(r[t]!=null)}function k(t){return!(r[t]!=null)}};project=function(e,t){var n,r,i,a,o,s,l,u,c,h,f,p,d,m,g,y;n=e.names.filter(t);r=e.names.map(function(t){return n.indexOf(t)});i={};for(a in o=e.exc){s=o[a];l=+a;u=0;for(c=0,h=e.names.length;c<h;++c){f=c;if(l&1<<f&&r[f]>=0){u=u|1<<r[f]}}if(!u){continue}p=i[u]||(i[u]={mask:u,value:0,label:""});p.value+=s;if(popcount(u)===popcount(l)&&popcount(l)>1&&e.labels[l]){p.label=e.labels[l]}}d=n.map(function(t){return{name:t,label:e.setLabels[t]||t,total:0}});m=[];for(a in i){s=i[a];m.push(s)}i=m;for(c=0,g=i.length;c<g;++c){p=i[c];p.names=n.filter(b);p.key=p.names.slice().sort().join(" & ");for(y=0,h=n.length;y<h;++y){f=y;if(p.mask&1<<f){d[f].total+=p.value}}}return{sets:d,regions:i,total:i.reduce(function(t,e){return t+e.value},0)};function b(t,e){return p.mask&1<<e}};pairOf=function(t,e,n){var r;r=1<<e|1<<n;return t.regions.reduce(function(t,e){return t+((e.mask&r)===r?e.value:0)},0)};arrange=function(i,t){var p,e,n,r,a,o,s,l,u,c,h,f,d,m,g,y,b,v,x;p=i.sets.length;if(!p){return[]}e=function(t,e,n){var r,i,a,o,s,l,u,c,h,f;r=function(n){return e.reduce(function(t,e){return t+2*Math.asin(Math.min(1,e/(2*n)))},0)};i=Math.max.apply(Math,e)/2;a=e.reduce(function(t,e){return t+e},0);if(r(i)<=2*Math.PI){o=i}else{for(s=0;s<60;++s){l=s;o=(i+a)/2;if(r(o)>2*Math.PI){i=o}else{a=o}}o=(i+a)/2}u=2*Math.PI/(r(o)||1);c=[];h=-Math.PI/2;for(s=0,f=p;s<f;++s){l=s;c[n[l]]={x:o*Math.cos(h),y:o*Math.sin(h),r:t[n[l]]};h+=2*Math.asin(Math.min(1,e[l]/(2*o)))*u}return c};if(t==="venn"){if(p===1){return[{x:0,y:0,r:1}]}if(p===2){return[{x:-.5,y:0,r:1},{x:.5,y:0,r:1}]}if(p===3){n=1/Math.sqrt(3);return[-150,-30,90].map(function(t){return{x:n*Math.cos(t*Math.PI/180),y:n*Math.sin(t*Math.PI/180),r:1}})}r=Math.min(1.7,Math.max(1.3,1.05/Math.cos(Math.PI/p)));return e(function(){var t,e,n=[];for(t=0,e=p;t<e;++t){n.push(t)}return n}().map(function(){return 1}),function(){var t,e,n=[];for(t=0,e=p;t<e;++t){n.push(t)}return n}().map(function(){return r}),function(){var t,e,n=[];for(t=0,e=p;t<e;++t){n.push(t)}return n}())}a=i.sets.map(function(t){var e;return Math.sqrt(((e=t.total)>0?e:0)/Math.PI)});o=Math.max.apply(Math,a)||1;a=a.map(function(t){var e;return t>(e=o*.02)?t:e});if(p===1){return[{x:0,y:0,r:a[0]}]}if(p===2){r=distanceFor(a[0],a[1],pairOf(i,0,1));return[{x:0,y:0,r:a[0]},{x:r,y:0,r:a[1]}]}if(p===3){s=(l=distanceFor(a[0],a[1],pairOf(i,0,1)))>1e-6?l:1e-6;u=distanceFor(a[0],a[2],pairOf(i,0,2));c=distanceFor(a[1],a[2],pairOf(i,1,2));h=(s*s+u*u-c*c)/(2*s);f=Math.sqrt((l=u*u-h*h)>0?l:0);return[{x:0,y:0,r:a[0]},{x:s,y:0,r:a[1]},{x:h,y:f,r:a[2]}]}d=[0];while(d.length<p){m=d[d.length-1];g=-1;y=-1;for(b=0;b<p;++b){v=b;if(in$(v,d)||pairOf(i,m,v)<=y){continue}y=pairOf(i,m,v);g=v}d.push(g)}x=function(){var t,e,n=[];for(t=0,e=p;t<e;++t){n.push(t)}return n}().map(function(t){var e,n,r;e=[d[t],d[(t+1)%p]],n=e[0],r=e[1];return distanceFor(a[n],a[r],pairOf(i,n,r))});return e(a,x,d)};analyze=function(t,e){var n,r,i,a,o,s,l,u,c,h,f,p,d,m,g,y,b,v,x,M,_,k,w;e==null&&(e=160);if(!t.length){return{}}n=Math.min.apply(Math,t.map(function(t){return t.x-t.r}));r=Math.max.apply(Math,t.map(function(t){return t.x+t.r}));i=Math.min.apply(Math,t.map(function(t){return t.y-t.r}));a=Math.max.apply(Math,t.map(function(t){return t.y+t.r}));o=Math.max(r-n,a-i)/e||1;s={};for(l=0,u=Math.ceil((a-i)/o);l<u;++l){c=l;h=i+(c+.5)*o;for(f=0,p=Math.ceil((r-n)/o);f<p;++f){d=f;m=n+(d+.5)*o;g=0;y=Infinity;for(b=0,v=t.length;b<v;++b){x=b;M=t[b];_=Math.sqrt((m-M.x)*(m-M.x)+(h-M.y)*(h-M.y));if(_<M.r){g=g|1<<x}y=y<(k=Math.abs(_-M.r))?y:k}if(!g){continue}w=s[g]||(s[g]={count:0,best:-1});w.count++;if(y>w.best){w.best=y;w.x=m;w.y=h}}}for(x in s){w=s[x];w.area=w.count*o*o}return s};span=function(t,e){var n,r;if(!t.length){return[0,0]}n=Math.min.apply(Math,t.map(function(t){return e*t[0]+t[1]}));r=Math.max.apply(Math,t.map(function(t){return e*t[2]+t[3]}));return[n,r]};fitScale=function(o,s,l){var t,e,n,r,i,a,u;if(!o.ix.length){return 1}t=function(t){var e,n,r,i,a;e=span(o.ix,t),n=e[0],r=e[1];e=span(o.iy,t),i=e[0],a=e[1];return r-n<=s&&a-i<=l};e=[0,1],n=e[0],r=e[1];while(t(r)&&r<1e9){r=r*2}for(i=0;i<50;++i){a=i;u=(n+r)/2;if(t(u)){n=u}else{r=u}}return n>1e-6?n:1e-6};shapes={person:"M36 16a14 14 0 1 0 28 0a14 14 0 1 0 -28 0Z M50 34C64 34 74 42 74 56L74 70Q74 74 70 74L64 74L64 94Q64 98 60 98L40 98Q36 98 36 94L36 74L30 74Q26 74 26 70L26 56C26 42 36 34 50 34Z",bug:["M40 22a10 10 0 1 0 20 0a10 10 0 1 0 -20 0Z","M50 30C68 30 78 46 78 62C78 82 66 96 50 96C34 96 22 82 22 62C22 46 32 30 50 30Z","M24 48L8 40L10 36L27 44Z M22 62L6 62L6 58L22 58Z M24 76L8 86L6 82L26 72Z","M76 48L92 40L90 36L73 44Z M78 62L94 62L94 58L78 58Z M76 76L92 86L94 82L74 72Z","M44 14L36 2L39 0L47 12Z M56 14L64 2L61 0L53 12Z"].join(" ")};mod=function(t){var e,i,s,n,P,r,S,C,Y,a,j,H;e=t.context,i=t.t;s=e.chart;n=s.utils,P=n.format,r=n.anim,S=r.join,C=r.interpolate;Y=function(t,e,n){var r;r=i(t);if(!(typeof r==="string"&&r.indexOf("$1")>=0)){r=n}return r.replace("$1",e)};a=function(t,e){var n;n=i(t);if(typeof n==="string"&&n&&n!==t){return n}else{return e}};j=function(t){var e,n,r,i;if(!t.length){return"#999"}e=t[0];for(n=1,r=t.length;n<r;++n){i=n;e=C(e,t[i])(1/(i+1))}return e};H=function(t,e){if(t.label){return t.label}if(t.names.length===1){return e===1?"":Y("only",t.names[0],"$1 only")}if(t.names.length===e){return e===2?a("both","both"):a("all","all")}return t.names.join(" & ")};return{sample:function(){return{raw:[{sets:"Trial users",size:580},{sets:"Paying users",size:463},{sets:"Trial users & Paying users",size:168}],binding:{sets:{key:"sets"},size:{key:"size"}}}},config:(n=import$({legend:import$({},s.utils.config.preset.legend),tip:JSON.parse(JSON.stringify(s.utils.config.preset.tip))},s.utils.config.preset["default"]),n.layout={type:"choice",values:["euler","venn"],default:"euler",desc:{en:"euler: circle areas follow the values and overlaps follow the shared amounts; venn: equal circles that show every overlap","zh-TW":"euler:圓的面積依數值,重疊的大小依交集的數量;venn:大小相同的圓,畫出所有交集"}},n.value={type:"choice",values:["inclusive","exclusive"],default:"inclusive",desc:{en:"what a row's value means. inclusive: A is everyone in A and A & B everyone in both; exclusive: A is only those in A alone","zh-TW":"每列數值的意義。inclusive:A 是 A 的全部、A & B 是交集的全部;exclusive:A 只算只屬於 A 的"}},n.separator={type:"text",default:"",desc:{en:"character between set names in a combination, e.g. A&B; empty accepts & ∩ | + , and 、","zh-TW":"組合裡集合名稱之間的分隔字元,例如 A&B;空白表示 & ∩ | + , 、 都可以"}},n.style={type:"choice",values:["area","dot"],default:"area",desc:{en:"area: filled circles; dot: circles made of small dots, each dot a fixed amount","zh-TW":"area:填色的圓;dot:由小點組成的圓,每點代表固定的數量"}},n.circle={opacity:{type:"number",default:.3,min:0,max:1,step:.01,desc:{en:"fill opacity of the circles; overlaps get darker as fills stack","zh-TW":"圓的填色透明度;重疊處因疊色而變深"}},stroke:{type:"number",default:2.5,min:0,max:20,step:.5,desc:{en:"outline width of the circles ( px ); 0 for none","zh-TW":"圓的外框粗細 ( px );0 表示不畫"}}},n.label={set:{enabled:{type:"boolean",default:true,desc:{en:"show each set's name next to its circle","zh-TW":"在圓旁邊標出集合名稱"}},total:{type:"boolean",default:true,desc:{en:"show each set's total under its name","zh-TW":"在集合名稱下方標出該集合的總數"}}},value:{enabled:{type:"boolean",default:true,desc:{en:"show the amount in each region","zh-TW":"在每個區域標出數量"}},format:{type:"format",default:",",desc:{en:"number format of the amounts, e.g. , or .3s ( d3-format )","zh-TW":"數量的格式,例如 , 或 .3s ( d3-format )"}},percent:{type:"boolean",default:false,desc:{en:"also show each region's share of everyone","zh-TW":"同時標出每個區域佔全體的比例"}}},region:{enabled:{type:"boolean",default:true,desc:{en:"name each region under its amount, e.g. A only or both","zh-TW":"在數量下方標出區域名稱,例如「僅 A」或「兩者皆是」"}}}},n.dot={shape:{type:"choice",values:["circle","square","person","bug"],default:"circle",desc:{en:"shape of each dot","zh-TW":"每個點的形狀"}},unit:{type:"number",default:0,min:0,max:1e9,step:.01,desc:{en:"amount each dot stands for; 0 picks a round number automatically","zh-TW":"每個點代表的數量;0 表示自動挑一個整齊的數"}},count:{type:"number",default:300,min:10,max:3e3,step:10,desc:{en:"about how many dots to draw when the unit is automatic","zh-TW":"自動決定單位時,大約要畫幾個點"}},size:{type:"number",default:.75,min:.1,max:1.5,step:.05,desc:{en:"dot size relative to the space between dots","zh-TW":"點的大小,相對於點與點的間距"}},motion:{type:"choice",values:["none","jiggle","wander"],default:"jiggle",desc:{en:"idle movement of the dots: none, a small jiggle, or wandering around","zh-TW":"點平常的動態:不動、輕微抖動、或四處走動"}},speed:{type:"number",default:1,min:.1,max:5,step:.1,desc:{en:"speed of the idle movement","zh-TW":"平常動態的速度"}},outline:{type:"boolean",default:true,desc:{en:"keep the circle outlines in dot style","zh-TW":"dot 樣式下保留圓的外框"}}},n),tabinfo:(n=s.utils.config.tabinfo({legend:"legend",tip:"tip"}),n.circle={desc:{en:"fill and outline of the circles","zh-TW":"圓的填色與外框"}},n.label={desc:{en:"text on the chart: set names, amounts and region names","zh-TW":"圖上的文字:集合名稱、數量與區域名稱"}},n["label/set"]={desc:{en:"set names and totals next to the circles","zh-TW":"圓旁邊的集合名稱與總數"}},n["label/value"]={desc:{en:"the amount in each region","zh-TW":"每個區域的數量"}},n["label/region"]={desc:{en:"region names such as A only or both","zh-TW":"區域名稱,例如「僅 A」、「兩者皆是」"}},n.dot={desc:{en:"dot style: what each dot looks like, how much it stands for and how it moves","zh-TW":"dot 樣式:點的樣子、代表的數量與動態"}},n),dimension:{sets:{type:"NC",name:"sets",priority:1},size:{type:"R",name:"size",priority:2},label:{type:"NC",name:"label",passive:true}},init:function(){var e,t,n,r,i,a,o=this;this.tint=e=new s.utils.tint;this.g={view:this.layout.getGroup("view"),legend:this.layout.getGroup("legend")};for(t=0,r=(n=["fill","bubble","outline","dot","rlabel","slabel"]).length;t<r;++t){i=n[t];a=document.createElementNS(svgns,"g");a.setAttribute("class",i);this.g[i]=this.g.view.appendChild(a)}this.legend=new s.utils.legend({layout:this.layout,name:"legend",root:this.root,shape:function(t){return this.setAttribute("fill",e.get(t.key))}});this.legend.on("select",function(){o.bind();o.resize();return o.render()});this._canvas=document.createElement("canvas").getContext("2d");this._dots=new Map;this._dotId=0;return this.tip=new s.utils.tip({root:this.root,accessor:function(t){var e,n,r,i,a;e=t.evt;if(!(o.geo&&e.clientX!=null)){return null}n=o.layout.getNode("view").getBoundingClientRect();r=o.mod.hit.call(o,e.clientX-n.x,e.clientY-n.y);if(!r){return null}i=P.from(o.cfg.tip.format||",");a=o.geo.total||1;return{name:r.text||r.names.join(" & "),group:r.text&&r.names.length>1?r.names.join(" ∩ "):"",value:i(r.value),valueAlt:"("+(r.value*100/a).toFixed(1)+"%)"}},range:function(){return o.layout.getNode("view").getBoundingClientRect()}})},destroy:function(){if(this.tip){return this.tip.destroy()}},filterDims:function(){return[]},interactions:function(){return{}},hit:function(t,e){var n,r,i,a,o,s,l;if(!this.geo){return null}for(n=0,i=(r=this.geo.bubbles).length;n<i;++n){a=r[n];if((t-a.x)*(t-a.x)+(e-a.y)*(e-a.y)<=a.r*a.r){return a.region}}o=0;for(n=0,i=(r=this.geo.circles).length;n<i;++n){s=n;l=r[n];if((t-l.x)*(t-l.x)+(e-l.y)*(e-l.y)<=l.r*l.r){o=o|1<<s}}if(!o){return null}return this.geo.byMask[o]||null},parse:function(){var e,n,r,i,t,a,o,s,l,u,c,h,f=this;this.tint.reset();if(this.cfg.palette){this.tint.set(this.cfg.palette)}e=this.cfg.separator||"";n={inclusive:this.cfg.value!=="exclusive"};r=!!this.binding.size;i=function(t){return t.map(function(t){return{names:splitSets(t.sets,e),size:r?+t.size:1,label:t.label!=null?(t.label+"").trim():""}})};this._model=build(i(this.data),n);this._models=this.frame.active()&&this._frames?this._frames.list.map(function(t){return build(i(f._parseRows(t.raw)),n)}):[this._model];this._names=[];this._setLabel={};for(t=0,o=(a=this._models).length;t<o;++t){s=a[t];for(l=0,c=(u=s.names).length;l<c;++l){h=u[l];if(!in$(h,this._names)){this._names.push(h)}if(s.setLabels[h]){this._setLabel[h]=s.setLabels[h]}}}this._names.map(function(t){return f.tint.get(t)});this._allTotal=Math.max.apply(Math,this._models.map(function(n){var r,i;return function(){var t,e=[];for(r in t=n.exc){i=t[r];e.push(i)}return e}().reduce(function(t,e){return t+e},0)}))||0;return this._fcache=null},resize:function(){var t,e,Z,F,n,B,w,E,r,Q,R,J,G,V,X,D,i,U,a,o,s,A,l,u,z,c,L,T,W,h,f,S,C,p,d,m,g,q,y,$,b,v,x,I,M,_,N,k=this;this.root.querySelector(".pdl-layout").classList.toggle("legend-bottom",this.cfg.legend.position==="bottom");this.legend.config(this.cfg.legend);this.legend.data(this._names.map(function(t){return{key:t,text:k._setLabel[t]||t,value:k._model.totals[t]||0}}));this.layout.update(false);t=this.layout.getBox("view");e=[t.width,t.height],Z=e[0],F=e[1];n=window.getComputedStyle(this.root);B=parseFloat(n.fontSize)||14;w=n.fontFamily||"sans-serif";E=function(t,e,n){k._canvas.font=(n?"bold ":"")+""+e+"px "+w;return k._canvas.measureText(t||"").width};r=this.cfg.label||{};Q=P.from((r.value||{}).format||",");R=!!(r.set||{}).enabled;J=R&&!!(r.set||{}).total;G=B*1.2;V=B*.9;X=B*1.4;D=this.cfg.layout||"euler";i=this.legend;U=function(t){return!i.enabled()||i.isSelected(t)};a=function(t){var x,e,M,n,r,i,a,o,s,l,u,c,h,f,p,_,k,d,m,g,y,b,v,w,A,z,L,T,W,S,C,q,$,I,N;x=project(t,U);e=arrange(x,D);M=e.length;n=analyze(e);r={};for(i=0,o=(a=x.regions).length;i<o;++i){s=a[i];l=n[s.mask];s.geo=l&&l.count>=3?l:null;r[s.mask]=s}for(u in n){l=n[u];if(r[u]||l.count<3){continue}c=x.sets.map(O).filter(P);s={mask:+u,value:0,label:"",names:c,key:c.slice().sort().join(" & "),geo:l,empty:true};x.regions.push(s);r[u]=s}x.regions.map(function(t){return t.text=H(t,M)});h=Math.max.apply(Math,x.regions.map(function(t){return t.value}).concat([0]))||1;f=e.reduce(function(t,e){return t+e.r},0)/(M||1)||1;p=x.regions.filter(function(t){return!t.geo&&t.value>0}).map(function(t){var e;return{region:t,r:D==="venn"?(e=.55*Math.sqrt(t.value/h))>.18?e:.18:Math.sqrt(t.value/Math.PI)}}).sort(function(t,e){return e.r-t.r});_=e.reduce(function(t,e){return t+e.x},0)/(M||1);k=e.reduce(function(t,e){return t+e.y},0)/(M||1);d=f*.12;m=fitScale({ix:e.map(function(t){return[t.x-t.r,0,t.x+t.r,0]}),iy:e.map(function(t){return[t.y-t.r,0,t.y+t.r,0]})},Z,F);g=function(t,e,n,r,i){var a,o;a=Math.max(e-t.x,0,t.x-r);o=Math.max(n-t.y,0,t.y-i);return Math.sqrt(a*a+o*o)};y=[];for(i=0,o=p.length;i<o;++i){b=p[i];v=E(b.region.text,B*.85)/2/m;w=B*1.4/m;for(A=0;A<6e3;++A){z=A;L=z*.35;T=z*f*.004;a=[_+T*Math.cos(L),k+T*Math.sin(L)],W=a[0],S=a[1];C=j;if(e.every(C)&&y.every(C)){break}}b.x=W;b.y=S;y.push(b)}q=[];$=[];I=e.map(function(t,e){var n,r,i,a,o,s,l,u,c,h,f,p,d,m,g,y,b,v;n=x.sets[e];r=[t.x-_,t.y-k],i=r[0],a=r[1];o=Math.sqrt(i*i+a*a);r=o>1e-9?[i/o,a/o]:[0,0],s=r[0],l=r[1];r=M<=2?[s*.55,l-1]:o>1e-9?[s,l-.35]:[0,-1],u=r[0],c=r[1];h=Math.sqrt(u*u+c*c)||1;r=[u/h,c/h],u=r[0],c=r[1];f=u>.6?"start":u<-.6?"end":"middle";p=Math.max(E(n.label,G,true),J?E(Y("total",Q(n.total),"$1 total"),V):0);d=G+(J?V*1.3:0);m=c<-.3?"above":c>.3?"below":"side";g=f==="start"?[0,p]:f==="end"?[-p,0]:[-p/2,p/2];y=m==="above"?[-d,0]:m==="below"?[0,d]:[-G,d-G];q.push([t.x-t.r,0,t.x+t.r,0]);$.push([t.y-t.r,0,t.y+t.r,0]);if(R&&n.label){r=[t.x+u*t.r,t.y+c*t.r],b=r[0],v=r[1];q.push([b,u*X+g[0],b,u*X+g[1]]);$.push([v,c*X+y[0],v,c*X+y[1]])}return{name:n.name,label:n.label,total:n.total,x:t.x,y:t.y,r:t.r,dx:u,dy:c,anchor:f,pos:m}});for(i=0,o=p.length;i<o;++i){b=p[i];q.push([b.x-b.r,0,b.x+b.r,0]);N=E(b.region.text,B*.85)/2;q.push([b.x,-N,b.x,N]);$.push([b.y-b.r,0,b.y+b.r,B*2.4])}return{p:x,sets:I,bubbles:p,byMask:r,ix:q,iy:$};function O(t){return t.name}function P(t,e){return+u&1<<e}function j(t){return Math.sqrt((W-t.x)*(W-t.x)+(S-t.y)*(S-t.y))>=t.r+b.r+d&&g(t,W-v,S+b.r,W+v,S+b.r+w)>=t.r+d*.5}};o=a(this._model);s=JSON.stringify([this._names.filter(U),D,this.cfg.value,B,Z,F,r]);if(!(this._fcache&&this._fcache.sig===s)){A=this._models.length>1?this._models.map(a):[o];this._fcache={sig:s,scale:Math.min.apply(Math,A.map(function(t){return fitScale(t,Z,F)}))}}l=this._fcache.scale;e=span(o.ix,l),u=e[0],z=e[1];e=span(o.iy,l),c=e[0],L=e[1];T=(Z-(z-u))/2-u;W=(F-(L-c))/2-c;h=function(t){return T+l*t};f=function(t){return W+l*t};S=function(t){return j(t.map(function(t){return k.tint.get(t)}))};C=o.sets.map(function(t){var e,n,r;e=[h(t.x+t.dx*t.r),f(t.y+t.dy*t.r)],n=e[0],r=e[1];return t.x=h(t.x),t.y=f(t.y),t.r=l*t.r,t.color=k.tint.get(t.name),t.ex=n,t.ey=r,t.lx=n+t.dx*X,t.ly=r+t.dy*X,t});p=o.bubbles.map(function(t){return t.x=h(t.x),t.y=f(t.y),t.r=l*t.r,t});d=B*1.9;m=B*.95;g=o.p.total||1;q=[];for(y=0,$=(e=o.p.regions).length;y<$;++y){b=e[y];b.color=S(b.names);v=p.find(O);if(b.geo){b.x=h(b.geo.x);b.y=f(b.geo.y);b.dist=l*b.geo.best;b.area=l*l*b.geo.area}else if(v){b.x=v.x;b.y=v.y;b.dist=v.r;b.area=Math.PI*v.r*v.r;b.bubble=v}else{continue}if(b.value<=0&&!(D==="venn"&&b.geo)){continue}x=Q(b.value)+((r.value||{}).percent?" ("+Math.round(b.value*100/g)+"%)":"");I=Math.min(1,b.dist*2/(E(x,d,true)||1),b.dist/(d*.55));M=d*I;_=!!(r.value||{}).enabled&&M>=B*.75;N=!!(r.region||{}).enabled&&!!b.text&&(b.bubble?true:_&&b.dist>=M*.6+m*1.2&&E(b.text,m)<=b.dist*2.2);if(b.bubble&&!_){x=""}q.push({key:b.key,x:b.x,y:b.y,value:b.value,vt:x,vsize:M,showV:_,lt:b.text,lsize:m,showL:N,bubble:!!b.bubble,r:b.dist||0,percent:!!(r.value||{}).percent,total:g})}this.geo={circles:C,bubbles:p,labels:q,total:o.p.total,regions:o.p.regions,byMask:o.byMask,fs:B,ts:G,us:V,showSet:R,showTotal:J,fmt:Q};if(this.cfg.style==="dot"){return this.mod.dotLayout.call(this,this._allTotal)}else{return this.dots=[]}function O(t){return t.region===b}},dotLayout:function(t){var e,n,r,i,a,o,s,l,u,c,h,f,p,d,m,g,y,O,b,v,x,M,_,k,w,A,P,j,z,L,T,W,S,C,q,Z,$,I,N,F;e=this.cfg.dot||{};n=+e.unit;if(!(n>0)){r=(t||1)/(e.count||300);i=Math.pow(10,Math.floor(Math.log10(r)));n=[1,2,2.5,5,10].map(function(t){return t*i}).find(function(t){return t>=r})||r}n=n>(a=t/5e3)?n:a;a=this.geo,o=a.circles,s=a.bubbles;l=this.geo.regions.filter(function(t){return t.value>0&&(t.geo||t.bubble)});l.map(function(t){return t.k=Math.round(t.value/n)});l=l.filter(function(t){return t.k>0});if(!l.length){this.dots=[];return this._dots=new Map}u={};l.map(function(t){if(!t.bubble){return u[t.mask]=t}});c=Math.min.apply(Math,l.map(function(t){return Math.sqrt(t.area*.8/(t.k*.866))}));h=this.layout.getBox("view");c=c<(a=Math.min(h.width,h.height)/4)?c:a;f=o.map(function(t){return[t.x,t.y,t.r]}).concat(s.map(function(t){return[t.x,t.y,t.r]}));p=Math.min.apply(Math,f.map(function(t){return t[0]-t[2]}));d=Math.max.apply(Math,f.map(function(t){return t[0]+t[2]}));m=Math.min.apply(Math,f.map(function(t){return t[1]-t[2]}));g=Math.max.apply(Math,f.map(function(t){return t[1]+t[2]}));for(y=0;y<16;++y){O=y;b={};v=c*.5;x=c*.866;for(M=0,_=Math.ceil((g-m)/x);M<=_;++M){k=M;w=m+k*x;for(A=0,P=Math.ceil((d-p)/c);A<=P;++A){j=A;z=p+j*c+(k%2?c/2:0);L=null;for(T=0,W=s.length;T<W;++T){S=s[T];if(Math.sqrt((z-S.x)*(z-S.x)+(w-S.y)*(w-S.y))<=S.r-v){L=S.region}}if(!L){C=0;q=Infinity;for(T=0,W=o.length;T<W;++T){Z=T;$=o[T];I=Math.sqrt((z-$.x)*(z-$.x)+(w-$.y)*(w-$.y));if(I<$.r){C=C|1<<Z}q=q<(a=Math.abs(I-$.r))?q:a}if(C&&q>=v){L=u[C]}}if(L){(b[L.key]||(b[L.key]=[])).push([z,w])}}}if(l.every(B)){break}c=c*.93}for(y=0,W=l.length;y<W;++y){L=l[y];N=b[L.key]||[];N.sort(E);L.pts=N;L.k=(a=L.k)<(F=N.length)?a:F}this._dotStep=c;this._dotUnit=n;return this.dots=this.mod.dotAssign.call(this,l);function B(t){return(b[t.key]||[]).length>=t.k}function E(t,e){return Math.pow(t[0]-L.x,2)+Math.pow(t[1]-L.y,2)-(Math.pow(e[0]-L.x,2)+Math.pow(e[1]-L.y,2))}},dotAssign:function(t){var e,n,r,i,a,o,s,l,u,c,h,f,p,d,m,g,y,b,v,x,M,_,k,w,A,z,L,T,W,S,C,q,$=this;e={};this._dots.forEach(function(t){return(e[t.key]||(e[t.key]=[])).push(t)});n=[];r=t.map(function(t){return t.key});for(i in e){a=e[i];if(!in$(i,r)){n=n.concat(a)}}for(o=0,s=t.length;o<s;++o){l=t[o];a=(e[l.key]||[]).sort(I);l._keep=a.slice(0,l.k);n=n.concat(a.slice(l.k));l._in=[]}u=function(t,e){var n;n=t.filter(function(t){return in$(t,e)}).length;return n/(t.length+e.length-n||1)};for(o=0,s=(c=t.slice().sort(N)).length;o<s;++o){l=c[o];h=l.k-l._keep.length;if(h<=0||!n.length){continue}n.map(O);n.sort(P);l._in=n.splice(0,h)}f=[];for(o=0,s=t.length;o<s;++o){l=t[o];for(p=0,d=(c=l._keep).length;p<d;++p){m=p;g=c[p];g.slot=m}b=[];for(p=l._keep.length,v=l.k;p<v;++p){x=p;b.push(x)}y=b;for(p=0,d=(c=l._in).length;p<d;++p){g=c[p];if(!y.length){break}M=0;if(y.length*l._in.length<2e5){_=Infinity;for(k=0,w=y.length;k<w;++k){m=k;A=y[k];z=l.pts[A],L=z[0],T=z[1];W=(L-g.x)*(L-g.x)+(T-g.y)*(T-g.y);if(W<_){z=[W,m],_=z[0],M=z[1]}}}g.slot=y.splice(M,1)[0];g.moved=true}S=y.map(j);for(p=0,d=(c=l._keep.concat(l._in,S)).length;p<d;++p){g=c[p];if(!(g.slot!=null)){continue}z=l.pts[g.slot],C=z[0],q=z[1];g.key=l.key;g.names=l.names;g.x=C;g.y=q;g.color=l.color;f.push(g)}}this._dots=new Map(f.map(function(t){return[t.id,t]}));return f;function I(t,e){return t.slot-e.slot}function N(t,e){return e.k-e._keep.length-(t.k-t._keep.length)}function O(t){return t._sim=u(t.names,l.names)}function P(t,e){return e._sim-t._sim||t.id-e.id}function j(t){return{id:$._dotId++,slot:t,fresh:true}}},render:function(){var y,n,b,i,a,t,o,r,v,l,x,e,s,u,c,h,f,p,d,m,g,M,_,k,w,A=this;y=this.geo,n=this.cfg;if(!y){return}b=function(t,e,n){return A.anim.tween(t,e,n)};i=n.style==="dot";a=(t=(n.circle||{}).opacity)!=null?t:.3;o=(t=(n.circle||{}).stroke)!=null?t:2.5;r=i?n.background&&n.background!=="transparent"?n.background:"#fff":null;v=n.color||"currentColor";l=function(t,e,n){var r;r=document.createElementNS(svgns,e);if(n){r.setAttribute("class",n)}return t.appendChild(r)};x=function(t,e,n){t.setAttribute("font-size",e);t.setAttribute("font-weight",n?"bold":"normal");if(r){t.setAttribute("stroke",r);t.setAttribute("stroke-width",3);t.setAttribute("stroke-opacity",.85);t.setAttribute("stroke-linejoin","round");return t.setAttribute("paint-order","stroke")}else{return t.removeAttribute("stroke")}};for(e=0,s=(t=[[this.g.fill,false],[this.g.outline,true]]).length;e<s;++e){u=t[e],c=u[0],h=u[1];f=S({root:c,tag:"circle",cls:"set",data:y.circles,key:z});f.exit.map(L);f.enter.map(T);f.nodes.map(W)}p=S({root:this.g.bubble,tag:"circle",cls:"bubble",data:y.bubbles,key:function(t){return t.region.key}});p.exit.map(function(t){return b(t,{r:0},{remove:true})});p.enter.map(function(t){var e;e=t.__data__;t.setAttribute("cx",e.x);t.setAttribute("cy",e.y);t.setAttribute("r",0);return t.setAttribute("stroke-dasharray","4 3")});p.nodes.map(function(t){var e,n,r;e=t.__data__;n=e.region.color;return b(t,{cx:e.x,cy:e.y,r:e.r,fill:n,stroke:n,"fill-opacity":i?a*.25:(r=a*1.4)<1?r:1,"stroke-width":(r=o*.6)>1?r:1})});d=n.dot.shape||"circle";m=(this._dotStep||0)*(n.dot.size||.75)/2;g=S({root:this.g.dot,tag:"g",cls:"dot",data:i?this.dots:[],key:function(t){return t.id}});g.exit.map(function(t){return b(t,{opacity:0},{duration:250,remove:true})});g.enter.map(function(t){var e;e=t.__data__;t.setAttribute("transform","translate("+e.x+","+e.y+")");t.setAttribute("opacity",0);return l(t,"g","wig")});M=d+":"+m;g.nodes.map(function(t){var e,n,r,i;e=t.__data__;n=t.firstChild;if(n._sig!==M){n._sig=M;n.textContent="";if(d==="circle"){r=l(n,"circle");r.setAttribute("r",m)}else if(d==="square"){r=l(n,"rect");r.setAttribute("x",-m*.9);r.setAttribute("y",-m*.9);r.setAttribute("width",m*1.8);r.setAttribute("height",m*1.8)}else{r=l(n,"path");r.setAttribute("d",shapes[d])||shapes.person;r.setAttribute("transform","scale("+m*2.3/100+") translate(-50,-50)")}r.setAttribute("fill",e.color)}b(n.firstChild,{fill:e.color});i=e.moved?{duration:800,delay:hash(e.id)*450}:{};b(t,{transform:"translate("+e.x+","+e.y+")",opacity:1},i);return e.moved=e.fresh=false});this._wigs=Array.from(this.g.dot.querySelectorAll(":scope > g.dot > g.wig"));if(i&&n.dot.motion!=="none"&&this._wigs.length){this.start()}else{this.stop();this._wigs.map(function(t){return t.removeAttribute("transform")})}_=y.fmt;k=S({root:this.g.rlabel,tag:"g",cls:"rl",data:y.labels,key:function(t){return t.key}});k.exit.map(function(t){return b(t,{opacity:0},{duration:200,remove:true})});k.enter.map(function(t){var e,n,r,i,a,o,s=[];e=t.__data__;t.setAttribute("transform","translate("+e.x+","+e.y+")");t.setAttribute("opacity",0);for(n=0,i=(r=["v","l"]).length;n<i;++n){a=r[n];o=l(t,"text","venn-text "+a);o.setAttribute("text-anchor","middle");s.push(o.setAttribute("dominant-baseline","central"))}return s});k.nodes.map(function(t){var e,n,r,i,a,o,s,l;e=t.__data__;n=[t.childNodes[0],t.childNodes[1]],r=n[0],i=n[1];x(r,e.vsize,true);x(i,e.lsize,false);r.setAttribute("fill",v);i.setAttribute("fill",v);i.setAttribute("fill-opacity",.75);r.style.display=e.showV&&e.vt?"":"none";i.style.display=e.showL?"":"none";i.textContent=e.lt;if(e.bubble){r.setAttribute("y",0);i.setAttribute("y",e.r+e.lsize*.9);if(!e.vt){i.textContent=e.lt+" "+_(e.value)}}else{r.setAttribute("y",e.showL?-e.lsize*.6:0);i.setAttribute("y",e.vsize*.5+e.lsize*.45)}a=t._v!=null?t._v:e.value;o=e.value;t._v=o;s=function(t){if(e.percent){return" ("+Math.round(t*100/e.total)+"%)"}else{return""}};r.textContent=e.vt;if(a!==o&&e.vt){l=a%1===0&&o%1===0;b(r,{"data-v":function(t){var e;e=a+(o-a)*t;r.textContent=_(l?Math.round(e):e)+s(e);return e}})}return b(t,{transform:"translate("+e.x+","+e.y+")",opacity:1})});w=S({root:this.g.slabel,tag:"g",cls:"sl",data:y.showSet?y.circles.filter(function(t){return t.label}):[],key:function(t){return t.name}});w.exit.map(function(t){return b(t,{opacity:0},{duration:200,remove:true})});w.enter.map(function(t){var e,n,r,i,a,o=[];t.setAttribute("opacity",0);e=l(t,"line","leader");e.setAttribute("stroke-dasharray","3 3");e.setAttribute("stroke-width",1.5);for(n=0,i=(r=["title","total"]).length;n<i;++n){a=r[n];o.push(l(t,"text","venn-text "+a))}return o});w.nodes.map(function(t){var e,n,r,i,a,o,s,l,u,c,h,f,p,d,m,g;e=t.__data__;n=[t.childNodes[0],t.childNodes[1],t.childNodes[2]],r=n[0],i=n[1],a=n[2];o=y.ts;s=y.us;n=e.pos==="above"?y.showTotal?[-s*1.3-o*.25,-s*.25]:[-o*.25,0]:e.pos==="below"?[o*.85,o*.85+s*1.3]:[-o*.15,s*1.1],l=n[0],u=n[1];for(c=0,h=(n=[[i,l],[a,u]]).length;c<h;++c){f=n[c],p=f[0],d=f[1];p.setAttribute("text-anchor",e.anchor);p.setAttribute("y",d)}x(i,o,true);x(a,s,false);i.setAttribute("fill",C(e.color,"#000")(.25));a.setAttribute("fill",v);a.setAttribute("fill-opacity",.55);i.textContent=e.label;a.textContent=Y("total",y.fmt(e.total),"$1 total");a.style.display=y.showTotal?"":"none";r.setAttribute("stroke",v);r.setAttribute("stroke-opacity",.3);n=[e.dx,e.dy],m=n[0],g=n[1];b(r,{x1:e.ex-e.lx+m*2,y1:e.ey-e.ly+g*2,x2:-m*4,y2:-g*4});return b(t,{transform:"translate("+e.lx+","+e.ly+")",opacity:1})});return this.legend.render();function z(t){return t.name}function L(t){return b(t,{r:0},{remove:true})}function T(t){var e;e=t.__data__;t.setAttribute("cx",e.x);t.setAttribute("cy",e.y);t.setAttribute("r",0);t.setAttribute("fill",h?"none":e.color);if(h){return t.setAttribute("stroke",e.color)}}function W(t){var e;e=t.__data__;if(h){return b(t,{cx:e.x,cy:e.y,r:e.r,stroke:e.color,"stroke-width":i&&!n.dot.outline?0:o,"stroke-opacity":i?.6:1})}else{return b(t,{cx:e.x,cy:e.y,r:e.r,fill:e.color,"fill-opacity":i?a*.25:a})}}},tick:function(t){var e,n,r,i,a,o,s,l,u,c,h,f,p,d,m,g,y,b,v,x,M,_,k,w,A,z,L=[];if(!(this._wigs&&this._wigs.length)||this.cfg.style!=="dot"){return}e=this.cfg.dot.motion;if(e==="none"){return}n=e==="wander";r=(this._dotStep||0)*(n?.45:.1);i=(this.cfg.dot.speed||1)*.001*(n?.8:4);a=n&&this.cfg.dot.shape==="bug";o=t*i;for(s=0,u=(l=this._wigs).length;s<u;++s){c=l[s];h=c.parentNode.__data__;if(!h){continue}f=h._h||(h._h=[0,1,2,3,4,5,6,7].map(T));p=[.6+f[0]*.8,1.2+f[1],.6+f[2]*.8,1.2+f[3]],d=p[0],m=p[1],g=p[2],y=p[3];p=[f[4]*6.283,f[5]*6.283,f[6]*6.283,f[7]*6.283],b=p[0],v=p[1],x=p[2],M=p[3];_=r*(.7*Math.sin(o*d+b)+.3*Math.sin(o*m+v));k=r*(.7*Math.cos(o*g+x)+.3*Math.sin(o*y+M));w="translate("+_+","+k+")";if(a){A=.7*d*Math.cos(o*d+b)+.3*m*Math.cos(o*m+v);z=-.7*g*Math.sin(o*g+x)+.3*y*Math.cos(o*y+M);w+=" rotate("+(Math.atan2(z,A)*180/Math.PI+90)+")"}L.push(c.setAttribute("transform",w))}return L;function T(t){return hash(h.id*8+t)}}}};function in$(t,e){var n=-1,r=e.length>>>0;while(++n<r)if(t===e[n])return true;return false}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 plug="layout"><div class="pdl-layout"><div data-type="layout"><div class="pdl-cell" data-name="view"></div><div class="pdl-cell" data-name="legend"> </div></div><div data-type="render"></div></div></div></div>
|
|
1
|
+
<div><style type="text/css">.pdl-layout>div[data-type=layout]{display:grid;grid-template-columns:1fr fit-content(10em);grid-template-rows:1fr}.pdl-layout>div[data-type=layout]>.pdl-cell[data-name=legend]{grid-column:2;grid-row:1;padding-left:1em}.pdl-layout.legend-bottom>div[data-type=layout]{grid-template-columns:1fr;grid-template-rows:1fr fit-content(3em)}.pdl-layout.legend-bottom>div[data-type=layout] .pdl-cell[data-name=legend]{padding-top:1em;padding-left:0;grid-column:1;grid-row:2}text.venn-text{pointer-events:none}</style><script type="@plotdb/block">var svgns,maxSets,popcount,hash,lens,distanceFor,splitSets,build,project,pairOf,arrange,analyze,span,fitScale,shapes,mod;module.exports={pkg:{name:"venn",version:"0.0.1",extend:{name:"@makechart/base",path:"lite/index.html"},dependencies:[],i18n:{en:{only:"$1 only",both:"both",all:"all",total:"$1 total"},"zh-TW":{only:"僅 $1",both:"兩者皆是",all:"全部皆是",total:"共 $1",sets:"集合",size:"數量",label:"標籤"}}},init:function(t){var e,n,r,i;e=t.root,n=t.context,r=t.t,i=t.pubsub;return i.fire("init",{mod:mod({context:n,t:r})})}};svgns="http://www.w3.org/2000/svg";maxSets=24;popcount=function(t){var e;e=0;while(t){t=t&t-1;e++}return e};hash=function(t){var e;e=Math.sin(t*12.9898+78.233)*43758.5453;return e-Math.floor(e)};lens=function(t,e,n){var r,i,a;if(n>=t+e){return 0}if(n<=Math.abs(t-e)){return Math.PI*Math.min(t,e)*Math.min(t,e)}r=t*t*Math.acos((n*n+t*t-e*e)/(2*n*t));i=e*e*Math.acos((n*n+e*e-t*t)/(2*n*e));a=.5*Math.sqrt((t+e-n)*(n+t-e)*(n-t+e)*(n+t+e));return r+i-a};distanceFor=function(t,e,n){var r,i,a,o,s,l;r=[Math.abs(t-e),t+e],i=r[0],a=r[1];if(n<=0){return a+Math.min(t,e)*.15}if(n>=lens(t,e,i)){return i}for(o=0;o<60;++o){s=o;l=(i+a)/2;if(lens(t,e,l)>n){i=l}else{a=l}}return(i+a)/2};splitSets=function(t,e){var n,r,i,a,o,s,l;if(!(t!=null)){return[]}n=(t+"").trim();if(!n){return[]}r=e?n.split(e):n.split(/\s*(?:&|∩|\||\+|,|、)\s*/);i=[];for(a=0,s=(o=r.map(u)).length;a<s;++a){l=o[a];if(l&&!in$(l,i)){i.push(l)}}return i;function u(t){return t.trim()}};build=function(t,e){var n,r,i,a,o,s,l,u,c,h,f,p,d,m,g,y,b,v,x,M;e==null&&(e={});n=[];r={};i={};a={};for(o=0,s=t.length;o<s;++o){l=t[o];if(!l.names.length||isNaN(l.size)){continue}if(l.names.some(_)&&n.length+l.names.filter(k).length>maxSets){continue}u=0;for(c=0,f=(h=l.names).length;c<f;++c){p=h[c];if(!(r[p]!=null)){r[p]=n.length;n.push(p)}u=u|1<<r[p]}i[u]=(i[u]||0)+l.size;if(l.label){a[u]=l.label}}m=[];for(g in i){m.push(+g)}d=m;y={};for(o=0,s=d.length;o<s;++o){u=d[o];if(!e.inclusive){y[u]=(h=i[u])>0?h:0}else{b=0;for(c=0,f=d.length;c<f;++c){v=d[c];if((v&u)===u){b+=((popcount(v)-popcount(u))%2?-1:1)*i[v]}}y[u]=b>0?b:0}}x={};n.map(function(t,n){return x[t]=d.reduce(function(t,e){return t+(e&1<<n?y[e]:0)},0)});M={};n.map(function(t,e){if(a[1<<e]){return M[t]=a[1<<e]}});return{names:n,exc:y,labels:a,totals:x,setLabels:M};function _(t){return!(r[t]!=null)}function k(t){return!(r[t]!=null)}};project=function(e,t){var n,r,i,a,o,s,l,u,c,h,f,p,d,m,g,y;n=e.names.filter(t);r=e.names.map(function(t){return n.indexOf(t)});i={};for(a in o=e.exc){s=o[a];l=+a;u=0;for(c=0,h=e.names.length;c<h;++c){f=c;if(l&1<<f&&r[f]>=0){u=u|1<<r[f]}}if(!u){continue}p=i[u]||(i[u]={mask:u,value:0,label:""});p.value+=s;if(popcount(u)===popcount(l)&&popcount(l)>1&&e.labels[l]){p.label=e.labels[l]}}d=n.map(function(t){return{name:t,label:e.setLabels[t]||t,total:0}});m=[];for(a in i){s=i[a];m.push(s)}i=m;for(c=0,g=i.length;c<g;++c){p=i[c];p.names=n.filter(b);p.key=p.names.slice().sort().join(" & ");for(y=0,h=n.length;y<h;++y){f=y;if(p.mask&1<<f){d[f].total+=p.value}}}return{sets:d,regions:i,total:i.reduce(function(t,e){return t+e.value},0)};function b(t,e){return p.mask&1<<e}};pairOf=function(t,e,n){var r;r=1<<e|1<<n;return t.regions.reduce(function(t,e){return t+((e.mask&r)===r?e.value:0)},0)};arrange=function(i,t){var p,e,n,r,a,o,s,l,u,c,h,f,d,m,g,y,b,v,x;p=i.sets.length;if(!p){return[]}e=function(t,e,n){var r,i,a,o,s,l,u,c,h,f;r=function(n){return e.reduce(function(t,e){return t+2*Math.asin(Math.min(1,e/(2*n)))},0)};i=Math.max.apply(Math,e)/2;a=e.reduce(function(t,e){return t+e},0);if(r(i)<=2*Math.PI){o=i}else{for(s=0;s<60;++s){l=s;o=(i+a)/2;if(r(o)>2*Math.PI){i=o}else{a=o}}o=(i+a)/2}u=2*Math.PI/(r(o)||1);c=[];h=-Math.PI/2;for(s=0,f=p;s<f;++s){l=s;c[n[l]]={x:o*Math.cos(h),y:o*Math.sin(h),r:t[n[l]]};h+=2*Math.asin(Math.min(1,e[l]/(2*o)))*u}return c};if(t==="venn"){if(p===1){return[{x:0,y:0,r:1}]}if(p===2){return[{x:-.5,y:0,r:1},{x:.5,y:0,r:1}]}if(p===3){n=1/Math.sqrt(3);return[-150,-30,90].map(function(t){return{x:n*Math.cos(t*Math.PI/180),y:n*Math.sin(t*Math.PI/180),r:1}})}r=Math.min(1.7,Math.max(1.3,1.05/Math.cos(Math.PI/p)));return e(function(){var t,e,n=[];for(t=0,e=p;t<e;++t){n.push(t)}return n}().map(function(){return 1}),function(){var t,e,n=[];for(t=0,e=p;t<e;++t){n.push(t)}return n}().map(function(){return r}),function(){var t,e,n=[];for(t=0,e=p;t<e;++t){n.push(t)}return n}())}a=i.sets.map(function(t){var e;return Math.sqrt(((e=t.total)>0?e:0)/Math.PI)});o=Math.max.apply(Math,a)||1;a=a.map(function(t){var e;return t>(e=o*.02)?t:e});if(p===1){return[{x:0,y:0,r:a[0]}]}if(p===2){r=distanceFor(a[0],a[1],pairOf(i,0,1));return[{x:0,y:0,r:a[0]},{x:r,y:0,r:a[1]}]}if(p===3){s=(l=distanceFor(a[0],a[1],pairOf(i,0,1)))>1e-6?l:1e-6;u=distanceFor(a[0],a[2],pairOf(i,0,2));c=distanceFor(a[1],a[2],pairOf(i,1,2));h=(s*s+u*u-c*c)/(2*s);f=Math.sqrt((l=u*u-h*h)>0?l:0);return[{x:0,y:0,r:a[0]},{x:s,y:0,r:a[1]},{x:h,y:f,r:a[2]}]}d=[0];while(d.length<p){m=d[d.length-1];g=-1;y=-1;for(b=0;b<p;++b){v=b;if(in$(v,d)||pairOf(i,m,v)<=y){continue}y=pairOf(i,m,v);g=v}d.push(g)}x=function(){var t,e,n=[];for(t=0,e=p;t<e;++t){n.push(t)}return n}().map(function(t){var e,n,r;e=[d[t],d[(t+1)%p]],n=e[0],r=e[1];return distanceFor(a[n],a[r],pairOf(i,n,r))});return e(a,x,d)};analyze=function(t,e){var n,r,i,a,o,s,l,u,c,h,f,p,d,m,g,y,b,v,x,M,_,k,w;e==null&&(e=160);if(!t.length){return{}}n=Math.min.apply(Math,t.map(function(t){return t.x-t.r}));r=Math.max.apply(Math,t.map(function(t){return t.x+t.r}));i=Math.min.apply(Math,t.map(function(t){return t.y-t.r}));a=Math.max.apply(Math,t.map(function(t){return t.y+t.r}));o=Math.max(r-n,a-i)/e||1;s={};for(l=0,u=Math.ceil((a-i)/o);l<u;++l){c=l;h=i+(c+.5)*o;for(f=0,p=Math.ceil((r-n)/o);f<p;++f){d=f;m=n+(d+.5)*o;g=0;y=Infinity;for(b=0,v=t.length;b<v;++b){x=b;M=t[b];_=Math.sqrt((m-M.x)*(m-M.x)+(h-M.y)*(h-M.y));if(_<M.r){g=g|1<<x}y=y<(k=Math.abs(_-M.r))?y:k}if(!g){continue}w=s[g]||(s[g]={count:0,best:-1});w.count++;if(y>w.best){w.best=y;w.x=m;w.y=h}}}for(x in s){w=s[x];w.area=w.count*o*o}return s};span=function(t,e){var n,r;if(!t.length){return[0,0]}n=Math.min.apply(Math,t.map(function(t){return e*t[0]+t[1]}));r=Math.max.apply(Math,t.map(function(t){return e*t[2]+t[3]}));return[n,r]};fitScale=function(o,s,l){var t,e,n,r,i,a,u;if(!o.ix.length){return 1}t=function(t){var e,n,r,i,a;e=span(o.ix,t),n=e[0],r=e[1];e=span(o.iy,t),i=e[0],a=e[1];return r-n<=s&&a-i<=l};e=[0,1],n=e[0],r=e[1];while(t(r)&&r<1e9){r=r*2}for(i=0;i<50;++i){a=i;u=(n+r)/2;if(t(u)){n=u}else{r=u}}return n>1e-6?n:1e-6};shapes={person:"M36 16a14 14 0 1 0 28 0a14 14 0 1 0 -28 0Z M50 34C64 34 74 42 74 56L74 70Q74 74 70 74L64 74L64 94Q64 98 60 98L40 98Q36 98 36 94L36 74L30 74Q26 74 26 70L26 56C26 42 36 34 50 34Z",bug:["M40 22a10 10 0 1 0 20 0a10 10 0 1 0 -20 0Z","M50 30C68 30 78 46 78 62C78 82 66 96 50 96C34 96 22 82 22 62C22 46 32 30 50 30Z","M24 48L8 40L10 36L27 44Z M22 62L6 62L6 58L22 58Z M24 76L8 86L6 82L26 72Z","M76 48L92 40L90 36L73 44Z M78 62L94 62L94 58L78 58Z M76 76L92 86L94 82L74 72Z","M44 14L36 2L39 0L47 12Z M56 14L64 2L61 0L53 12Z"].join(" ")};mod=function(t){var e,i,s,n,P,r,S,C,Y,a,j,H;e=t.context,i=t.t;s=e.chart;n=s.utils,P=n.format,r=n.anim,S=r.join,C=r.interpolate;Y=function(t,e,n){var r;r=i(t);if(!(typeof r==="string"&&r.indexOf("$1")>=0)){r=n}return r.replace("$1",e)};a=function(t,e){var n;n=i(t);if(typeof n==="string"&&n&&n!==t){return n}else{return e}};j=function(t){var e,n,r,i;if(!t.length){return"#999"}e=t[0];for(n=1,r=t.length;n<r;++n){i=n;e=C(e,t[i])(1/(i+1))}return e};H=function(t,e){if(t.label){return t.label}if(t.names.length===1){return e===1?"":Y("only",t.names[0],"$1 only")}if(t.names.length===e){return e===2?a("both","both"):a("all","all")}return t.names.join(" & ")};return{sample:function(){return{raw:[{sets:"Trial users",size:580},{sets:"Paying users",size:463},{sets:"Trial users & Paying users",size:168}],binding:{sets:{key:"sets"},size:{key:"size"}}}},config:(n=import$({legend:import$({},s.utils.config.preset.legend),tip:JSON.parse(JSON.stringify(s.utils.config.preset.tip))},s.utils.config.preset["default"]),n.layout={type:"choice",values:["euler","venn"],default:"euler",desc:{en:"euler: circle areas follow the values and overlaps follow the shared amounts; venn: equal circles that show every overlap","zh-TW":"euler:圓的面積依數值,重疊的大小依交集的數量;venn:大小相同的圓,畫出所有交集"}},n.value={type:"choice",values:["inclusive","exclusive"],default:"inclusive",desc:{en:"what a row's value means. inclusive: A is everyone in A and A & B everyone in both; exclusive: A is only those in A alone","zh-TW":"每列數值的意義。inclusive:A 是 A 的全部、A & B 是交集的全部;exclusive:A 只算只屬於 A 的"}},n.separator={type:"text",default:"",desc:{en:"character between set names in a combination, e.g. A&B; empty accepts & ∩ | + , and 、","zh-TW":"組合裡集合名稱之間的分隔字元,例如 A&B;空白表示 & ∩ | + , 、 都可以"}},n.style={type:"choice",values:["area","dot"],default:"area",desc:{en:"area: filled circles; dot: circles made of small dots, each dot a fixed amount","zh-TW":"area:填色的圓;dot:由小點組成的圓,每點代表固定的數量"}},n.circle={opacity:{type:"number",default:.3,min:0,max:1,step:.01,desc:{en:"fill opacity of the circles; overlaps get darker as fills stack","zh-TW":"圓的填色透明度;重疊處因疊色而變深"}},stroke:{type:"number",default:2.5,min:0,max:20,step:.5,desc:{en:"outline width of the circles ( px ); 0 for none","zh-TW":"圓的外框粗細 ( px );0 表示不畫"}}},n.label={set:{enabled:{type:"boolean",default:true,desc:{en:"show each set's name next to its circle","zh-TW":"在圓旁邊標出集合名稱"}},total:{type:"boolean",default:true,desc:{en:"show each set's total under its name","zh-TW":"在集合名稱下方標出該集合的總數"}}},value:{enabled:{type:"boolean",default:true,desc:{en:"show the amount in each region","zh-TW":"在每個區域標出數量"}},format:{type:"format",default:",",desc:{en:"number format of the amounts, e.g. , or .3s ( d3-format )","zh-TW":"數量的格式,例如 , 或 .3s ( d3-format )"}},percent:{type:"boolean",default:false,desc:{en:"also show each region's share of everyone","zh-TW":"同時標出每個區域佔全體的比例"}}},region:{enabled:{type:"boolean",default:true,desc:{en:"name each region under its amount, e.g. A only or both","zh-TW":"在數量下方標出區域名稱,例如「僅 A」或「兩者皆是」"}}}},n.dot={shape:{type:"choice",values:["circle","square","person","bug"],default:"circle",desc:{en:"shape of each dot","zh-TW":"每個點的形狀"}},unit:{type:"number",default:0,min:0,max:1e9,step:.01,desc:{en:"amount each dot stands for; 0 picks a round number automatically","zh-TW":"每個點代表的數量;0 表示自動挑一個整齊的數"}},count:{type:"number",default:300,min:10,max:3e3,step:10,desc:{en:"about how many dots to draw when the unit is automatic","zh-TW":"自動決定單位時,大約要畫幾個點"}},size:{type:"number",default:.75,min:.1,max:1.5,step:.05,desc:{en:"dot size relative to the space between dots","zh-TW":"點的大小,相對於點與點的間距"}},motion:{type:"choice",values:["none","jiggle","wander"],default:"jiggle",desc:{en:"idle movement of the dots: none, a small jiggle, or wandering around","zh-TW":"點平常的動態:不動、輕微抖動、或四處走動"}},speed:{type:"number",default:1,min:.1,max:5,step:.1,desc:{en:"speed of the idle movement","zh-TW":"平常動態的速度"}},outline:{type:"boolean",default:true,desc:{en:"keep the circle outlines in dot style","zh-TW":"dot 樣式下保留圓的外框"}}},n),tabinfo:(n=s.utils.config.tabinfo({legend:"legend",tip:"tip"}),n.circle={desc:{en:"fill and outline of the circles","zh-TW":"圓的填色與外框"}},n.label={desc:{en:"text on the chart: set names, amounts and region names","zh-TW":"圖上的文字:集合名稱、數量與區域名稱"}},n["label/set"]={desc:{en:"set names and totals next to the circles","zh-TW":"圓旁邊的集合名稱與總數"}},n["label/value"]={desc:{en:"the amount in each region","zh-TW":"每個區域的數量"}},n["label/region"]={desc:{en:"region names such as A only or both","zh-TW":"區域名稱,例如「僅 A」、「兩者皆是」"}},n.dot={desc:{en:"dot style: what each dot looks like, how much it stands for and how it moves","zh-TW":"dot 樣式:點的樣子、代表的數量與動態"}},n),dimension:{sets:{type:"NC",name:"sets",priority:1},size:{type:"R",name:"size",priority:2},label:{type:"NC",name:"label",passive:true}},init:function(){var e,t,n,r,i,a,o=this;this.tint=e=new s.utils.tint;this.g={view:this.layout.getGroup("view"),legend:this.layout.getGroup("legend")};for(t=0,r=(n=["fill","bubble","outline","dot","rlabel","slabel"]).length;t<r;++t){i=n[t];a=document.createElementNS(svgns,"g");a.setAttribute("class",i);this.g[i]=this.g.view.appendChild(a)}this.legend=new s.utils.legend({layout:this.layout,name:"legend",root:this.root,shape:function(t){return this.setAttribute("fill",e.get(t.key))}});this.legend.on("select",function(){o.bind();o.resize();return o.render()});this._canvas=document.createElement("canvas").getContext("2d");this._dots=new Map;this._dotId=0;return this.tip=new s.utils.tip({root:this.root,accessor:function(t){var e,n,r,i,a;e=t.evt;if(!(o.geo&&e.clientX!=null)){return null}n=o.layout.getNode("view").getBoundingClientRect();r=o.mod.hit.call(o,e.clientX-n.x,e.clientY-n.y);if(!r){return null}i=P.from(o.cfg.tip.format||",");a=o.geo.total||1;return{name:r.text||r.names.join(" & "),group:r.text&&r.names.length>1?r.names.join(" ∩ "):"",value:i(r.value),valueAlt:"("+(r.value*100/a).toFixed(1)+"%)"}},range:function(){return o.layout.getNode("view").getBoundingClientRect()}})},destroy:function(){this.stop();if(this.tip){return this.tip.destroy()}},filterDims:function(){return[]},interactions:function(){return{}},hit:function(t,e){var n,r,i,a,o,s,l;if(!this.geo){return null}for(n=0,i=(r=this.geo.bubbles).length;n<i;++n){a=r[n];if((t-a.x)*(t-a.x)+(e-a.y)*(e-a.y)<=a.r*a.r){return a.region}}o=0;for(n=0,i=(r=this.geo.circles).length;n<i;++n){s=n;l=r[n];if((t-l.x)*(t-l.x)+(e-l.y)*(e-l.y)<=l.r*l.r){o=o|1<<s}}if(!o){return null}return this.geo.byMask[o]||null},parse:function(){var e,n,r,i,t,a,o,s,l,u,c,h,f=this;this.tint.reset();if(this.cfg.palette){this.tint.set(this.cfg.palette)}e=this.cfg.separator||"";n={inclusive:this.cfg.value!=="exclusive"};r=!!this.binding.size;i=function(t){return t.map(function(t){return{names:splitSets(t.sets,e),size:r?+t.size:1,label:t.label!=null?(t.label+"").trim():""}})};this._model=build(i(this.data),n);this._models=this.frame.active()&&this._frames?this._frames.list.map(function(t){return build(i(f._parseRows(t.raw)),n)}):[this._model];this._names=[];this._setLabel={};for(t=0,o=(a=this._models).length;t<o;++t){s=a[t];for(l=0,c=(u=s.names).length;l<c;++l){h=u[l];if(!in$(h,this._names)){this._names.push(h)}if(s.setLabels[h]){this._setLabel[h]=s.setLabels[h]}}}this._names.map(function(t){return f.tint.get(t)});this._allTotal=Math.max.apply(Math,this._models.map(function(n){var r,i;return function(){var t,e=[];for(r in t=n.exc){i=t[r];e.push(i)}return e}().reduce(function(t,e){return t+e},0)}))||0;return this._fcache=null},resize:function(){var t,e,Z,F,n,B,w,E,r,Q,R,J,G,V,X,D,i,U,a,o,s,A,l,u,z,c,L,T,W,h,f,S,C,p,d,m,g,q,y,$,b,v,x,I,M,_,N,k=this;this.root.querySelector(".pdl-layout").classList.toggle("legend-bottom",this.cfg.legend.position==="bottom");this.legend.config(this.cfg.legend);this.legend.data(this._names.map(function(t){return{key:t,text:k._setLabel[t]||t,value:k._model.totals[t]||0}}));this.layout.update(false);t=this.layout.getBox("view");e=[t.width,t.height],Z=e[0],F=e[1];if(!(Z>0&&F>0)){return}n=window.getComputedStyle(this.root);B=parseFloat(n.fontSize)||14;w=n.fontFamily||"sans-serif";E=function(t,e,n){k._canvas.font=(n?"bold ":"")+""+e+"px "+w;return k._canvas.measureText(t||"").width};r=this.cfg.label||{};Q=P.from((r.value||{}).format||",");R=!!(r.set||{}).enabled;J=R&&!!(r.set||{}).total;G=B*1.2;V=B*.9;X=B*1.4;D=this.cfg.layout||"euler";i=this.legend;U=function(t){return!i.enabled()||i.isSelected(t)};a=function(t){var x,e,M,n,r,i,a,o,s,l,u,c,h,f,p,_,k,d,m,g,y,b,v,w,A,z,L,T,W,S,C,q,$,I,N;x=project(t,U);e=arrange(x,D);M=e.length;n=analyze(e);r={};for(i=0,o=(a=x.regions).length;i<o;++i){s=a[i];l=n[s.mask];s.geo=l&&l.count>=3?l:null;r[s.mask]=s}for(u in n){l=n[u];if(r[u]||l.count<3){continue}c=x.sets.map(O).filter(P);s={mask:+u,value:0,label:"",names:c,key:c.slice().sort().join(" & "),geo:l,empty:true};x.regions.push(s);r[u]=s}x.regions.map(function(t){return t.text=H(t,M)});h=Math.max.apply(Math,x.regions.map(function(t){return t.value}).concat([0]))||1;f=e.reduce(function(t,e){return t+e.r},0)/(M||1)||1;p=x.regions.filter(function(t){return!t.geo&&t.value>0}).map(function(t){var e;return{region:t,r:D==="venn"?(e=.55*Math.sqrt(t.value/h))>.18?e:.18:Math.sqrt(t.value/Math.PI)}}).sort(function(t,e){return e.r-t.r});_=e.reduce(function(t,e){return t+e.x},0)/(M||1);k=e.reduce(function(t,e){return t+e.y},0)/(M||1);d=f*.12;m=fitScale({ix:e.map(function(t){return[t.x-t.r,0,t.x+t.r,0]}),iy:e.map(function(t){return[t.y-t.r,0,t.y+t.r,0]})},Z,F);g=function(t,e,n,r,i){var a,o;a=Math.max(e-t.x,0,t.x-r);o=Math.max(n-t.y,0,t.y-i);return Math.sqrt(a*a+o*o)};y=[];for(i=0,o=p.length;i<o;++i){b=p[i];v=E(b.region.text,B*.85)/2/m;w=B*1.4/m;for(A=0;A<6e3;++A){z=A;L=z*.35;T=z*f*.004;a=[_+T*Math.cos(L),k+T*Math.sin(L)],W=a[0],S=a[1];C=j;if(e.every(C)&&y.every(C)){break}}b.x=W;b.y=S;y.push(b)}q=[];$=[];I=e.map(function(t,e){var n,r,i,a,o,s,l,u,c,h,f,p,d,m,g,y,b,v;n=x.sets[e];r=[t.x-_,t.y-k],i=r[0],a=r[1];o=Math.sqrt(i*i+a*a);r=o>1e-9?[i/o,a/o]:[0,0],s=r[0],l=r[1];r=M<=2?[s*.55,l-1]:o>1e-9?[s,l-.35]:[0,-1],u=r[0],c=r[1];h=Math.sqrt(u*u+c*c)||1;r=[u/h,c/h],u=r[0],c=r[1];f=u>.6?"start":u<-.6?"end":"middle";p=Math.max(E(n.label,G,true),J?E(Y("total",Q(n.total),"$1 total"),V):0);d=G+(J?V*1.3:0);m=c<-.3?"above":c>.3?"below":"side";g=f==="start"?[0,p]:f==="end"?[-p,0]:[-p/2,p/2];y=m==="above"?[-d,0]:m==="below"?[0,d]:[-G,d-G];q.push([t.x-t.r,0,t.x+t.r,0]);$.push([t.y-t.r,0,t.y+t.r,0]);if(R&&n.label){r=[t.x+u*t.r,t.y+c*t.r],b=r[0],v=r[1];q.push([b,u*X+g[0],b,u*X+g[1]]);$.push([v,c*X+y[0],v,c*X+y[1]])}return{name:n.name,label:n.label,total:n.total,x:t.x,y:t.y,r:t.r,dx:u,dy:c,anchor:f,pos:m}});for(i=0,o=p.length;i<o;++i){b=p[i];q.push([b.x-b.r,0,b.x+b.r,0]);N=E(b.region.text,B*.85)/2;q.push([b.x,-N,b.x,N]);$.push([b.y-b.r,0,b.y+b.r,B*2.4])}return{p:x,sets:I,bubbles:p,byMask:r,ix:q,iy:$};function O(t){return t.name}function P(t,e){return+u&1<<e}function j(t){return Math.sqrt((W-t.x)*(W-t.x)+(S-t.y)*(S-t.y))>=t.r+b.r+d&&g(t,W-v,S+b.r,W+v,S+b.r+w)>=t.r+d*.5}};o=a(this._model);s=JSON.stringify([this._names.filter(U),D,this.cfg.value,B,Z,F,r]);if(!(this._fcache&&this._fcache.sig===s)){A=this._models.length>1?this._models.map(a):[o];this._fcache={sig:s,scale:Math.min.apply(Math,A.map(function(t){return fitScale(t,Z,F)}))}}l=this._fcache.scale;e=span(o.ix,l),u=e[0],z=e[1];e=span(o.iy,l),c=e[0],L=e[1];T=(Z-(z-u))/2-u;W=(F-(L-c))/2-c;h=function(t){return T+l*t};f=function(t){return W+l*t};S=function(t){return j(t.map(function(t){return k.tint.get(t)}))};C=o.sets.map(function(t){var e,n,r;e=[h(t.x+t.dx*t.r),f(t.y+t.dy*t.r)],n=e[0],r=e[1];return t.x=h(t.x),t.y=f(t.y),t.r=l*t.r,t.color=k.tint.get(t.name),t.ex=n,t.ey=r,t.lx=n+t.dx*X,t.ly=r+t.dy*X,t});p=o.bubbles.map(function(t){return t.x=h(t.x),t.y=f(t.y),t.r=l*t.r,t});d=B*1.9;m=B*.95;g=o.p.total||1;q=[];for(y=0,$=(e=o.p.regions).length;y<$;++y){b=e[y];b.color=S(b.names);v=p.find(O);if(b.geo){b.x=h(b.geo.x);b.y=f(b.geo.y);b.dist=l*b.geo.best;b.area=l*l*b.geo.area}else if(v){b.x=v.x;b.y=v.y;b.dist=v.r;b.area=Math.PI*v.r*v.r;b.bubble=v}else{continue}if(b.value<=0&&!(D==="venn"&&b.geo)){continue}x=Q(b.value)+((r.value||{}).percent?" ("+Math.round(b.value*100/g)+"%)":"");I=Math.min(1,b.dist*2/(E(x,d,true)||1),b.dist/(d*.55));M=d*I;_=!!(r.value||{}).enabled&&M>=B*.75;N=!!(r.region||{}).enabled&&!!b.text&&(b.bubble?true:_&&b.dist>=M*.6+m*1.2&&E(b.text,m)<=b.dist*2.2);if(b.bubble&&!_){x=""}q.push({key:b.key,x:b.x,y:b.y,value:b.value,vt:x,vsize:M,showV:_,lt:b.text,lsize:m,showL:N,bubble:!!b.bubble,r:b.dist||0,percent:!!(r.value||{}).percent,total:g})}this.geo={circles:C,bubbles:p,labels:q,total:o.p.total,regions:o.p.regions,byMask:o.byMask,fs:B,ts:G,us:V,showSet:R,showTotal:J,fmt:Q};if(this.cfg.style==="dot"){return this.mod.dotLayout.call(this,this._allTotal)}else{return this.dots=[]}function O(t){return t.region===b}},dotLayout:function(t){var e,n,r,i,a,o,s,l,u,c,h,f,p,d,m,g,y,O,b,v,x,M,_,k,w,A,P,j,z,L,T,W,S,C,q,Z,$,I,N,F;e=this.cfg.dot||{};n=+e.unit;if(!(n>0)){r=(t||1)/(e.count||300);i=Math.pow(10,Math.floor(Math.log10(r)));n=[1,2,2.5,5,10].map(function(t){return t*i}).find(function(t){return t>=r})||r}n=n>(a=t/5e3)?n:a;a=this.geo,o=a.circles,s=a.bubbles;l=this.geo.regions.filter(function(t){return t.value>0&&(t.geo||t.bubble)});l.map(function(t){return t.k=Math.round(t.value/n)});l=l.filter(function(t){return t.k>0});if(!l.length){this.dots=[];return this._dots=new Map}u={};l.map(function(t){if(!t.bubble){return u[t.mask]=t}});c=Math.min.apply(Math,l.map(function(t){return Math.sqrt(t.area*.8/(t.k*.866))}));h=this.layout.getBox("view");c=c<(a=Math.min(h.width,h.height)/4)?c:a;if(!(c>0&&isFinite(c))){this.dots=[];return this._dots=new Map}f=o.map(function(t){return[t.x,t.y,t.r]}).concat(s.map(function(t){return[t.x,t.y,t.r]}));p=Math.min.apply(Math,f.map(function(t){return t[0]-t[2]}));d=Math.max.apply(Math,f.map(function(t){return t[0]+t[2]}));m=Math.min.apply(Math,f.map(function(t){return t[1]-t[2]}));g=Math.max.apply(Math,f.map(function(t){return t[1]+t[2]}));for(y=0;y<16;++y){O=y;b={};v=c*.5;x=c*.866;for(M=0,_=Math.ceil((g-m)/x);M<=_;++M){k=M;w=m+k*x;for(A=0,P=Math.ceil((d-p)/c);A<=P;++A){j=A;z=p+j*c+(k%2?c/2:0);L=null;for(T=0,W=s.length;T<W;++T){S=s[T];if(Math.sqrt((z-S.x)*(z-S.x)+(w-S.y)*(w-S.y))<=S.r-v){L=S.region}}if(!L){C=0;q=Infinity;for(T=0,W=o.length;T<W;++T){Z=T;$=o[T];I=Math.sqrt((z-$.x)*(z-$.x)+(w-$.y)*(w-$.y));if(I<$.r){C=C|1<<Z}q=q<(a=Math.abs(I-$.r))?q:a}if(C&&q>=v){L=u[C]}}if(L){(b[L.key]||(b[L.key]=[])).push([z,w])}}}if(l.every(B)){break}c=c*.93}for(y=0,W=l.length;y<W;++y){L=l[y];N=b[L.key]||[];N.sort(E);L.pts=N;L.k=(a=L.k)<(F=N.length)?a:F}this._dotStep=c;this._dotUnit=n;return this.dots=this.mod.dotAssign.call(this,l);function B(t){return(b[t.key]||[]).length>=t.k}function E(t,e){return Math.pow(t[0]-L.x,2)+Math.pow(t[1]-L.y,2)-(Math.pow(e[0]-L.x,2)+Math.pow(e[1]-L.y,2))}},dotAssign:function(t){var e,n,r,i,a,o,s,l,u,c,h,f,p,d,m,g,y,b,v,x,M,_,k,w,A,z,L,T,W,S,C,q,$=this;e={};this._dots.forEach(function(t){return(e[t.key]||(e[t.key]=[])).push(t)});n=[];r=t.map(function(t){return t.key});for(i in e){a=e[i];if(!in$(i,r)){n=n.concat(a)}}for(o=0,s=t.length;o<s;++o){l=t[o];a=(e[l.key]||[]).sort(I);l._keep=a.slice(0,l.k);n=n.concat(a.slice(l.k));l._in=[]}u=function(t,e){var n;n=t.filter(function(t){return in$(t,e)}).length;return n/(t.length+e.length-n||1)};for(o=0,s=(c=t.slice().sort(N)).length;o<s;++o){l=c[o];h=l.k-l._keep.length;if(h<=0||!n.length){continue}n.map(O);n.sort(P);l._in=n.splice(0,h)}f=[];for(o=0,s=t.length;o<s;++o){l=t[o];for(p=0,d=(c=l._keep).length;p<d;++p){m=p;g=c[p];g.slot=m}b=[];for(p=l._keep.length,v=l.k;p<v;++p){x=p;b.push(x)}y=b;for(p=0,d=(c=l._in).length;p<d;++p){g=c[p];if(!y.length){break}M=0;if(y.length*l._in.length<2e5){_=Infinity;for(k=0,w=y.length;k<w;++k){m=k;A=y[k];z=l.pts[A],L=z[0],T=z[1];W=(L-g.x)*(L-g.x)+(T-g.y)*(T-g.y);if(W<_){z=[W,m],_=z[0],M=z[1]}}}g.slot=y.splice(M,1)[0];g.moved=true}S=y.map(j);for(p=0,d=(c=l._keep.concat(l._in,S)).length;p<d;++p){g=c[p];if(!(g.slot!=null)){continue}z=l.pts[g.slot],C=z[0],q=z[1];g.key=l.key;g.names=l.names;g.x=C;g.y=q;g.color=l.color;f.push(g)}}this._dots=new Map(f.map(function(t){return[t.id,t]}));return f;function I(t,e){return t.slot-e.slot}function N(t,e){return e.k-e._keep.length-(t.k-t._keep.length)}function O(t){return t._sim=u(t.names,l.names)}function P(t,e){return e._sim-t._sim||t.id-e.id}function j(t){return{id:$._dotId++,slot:t,fresh:true}}},render:function(){var y,n,b,i,a,t,o,r,v,l,x,e,s,u,c,h,f,p,d,m,g,M,_,k,w,A=this;y=this.geo,n=this.cfg;if(!y){return}b=function(t,e,n){return A.anim.tween(t,e,n)};i=n.style==="dot";a=(t=(n.circle||{}).opacity)!=null?t:.3;o=(t=(n.circle||{}).stroke)!=null?t:2.5;r=i?n.background&&n.background!=="transparent"?n.background:"#fff":null;v=n.color||"currentColor";l=function(t,e,n){var r;r=document.createElementNS(svgns,e);if(n){r.setAttribute("class",n)}return t.appendChild(r)};x=function(t,e,n){t.setAttribute("font-size",e);t.setAttribute("font-weight",n?"bold":"normal");if(r){t.setAttribute("stroke",r);t.setAttribute("stroke-width",3);t.setAttribute("stroke-opacity",.85);t.setAttribute("stroke-linejoin","round");return t.setAttribute("paint-order","stroke")}else{return t.removeAttribute("stroke")}};for(e=0,s=(t=[[this.g.fill,false],[this.g.outline,true]]).length;e<s;++e){u=t[e],c=u[0],h=u[1];f=S({root:c,tag:"circle",cls:"set",data:y.circles,key:z});f.exit.map(L);f.enter.map(T);f.nodes.map(W)}p=S({root:this.g.bubble,tag:"circle",cls:"bubble",data:y.bubbles,key:function(t){return t.region.key}});p.exit.map(function(t){return b(t,{r:0},{remove:true})});p.enter.map(function(t){var e;e=t.__data__;t.setAttribute("cx",e.x);t.setAttribute("cy",e.y);t.setAttribute("r",0);return t.setAttribute("stroke-dasharray","4 3")});p.nodes.map(function(t){var e,n,r;e=t.__data__;n=e.region.color;return b(t,{cx:e.x,cy:e.y,r:e.r,fill:n,stroke:n,"fill-opacity":i?a*.25:(r=a*1.4)<1?r:1,"stroke-width":(r=o*.6)>1?r:1})});d=n.dot.shape||"circle";m=(this._dotStep||0)*(n.dot.size||.75)/2;g=S({root:this.g.dot,tag:"g",cls:"dot",data:i?this.dots:[],key:function(t){return t.id}});g.exit.map(function(t){return b(t,{opacity:0},{duration:250,remove:true})});g.enter.map(function(t){var e;e=t.__data__;t.setAttribute("transform","translate("+e.x+","+e.y+")");t.setAttribute("opacity",0);return l(t,"g","wig")});M=d+":"+m;g.nodes.map(function(t){var e,n,r,i;e=t.__data__;n=t.firstChild;if(n._sig!==M){n._sig=M;n.textContent="";if(d==="circle"){r=l(n,"circle");r.setAttribute("r",m)}else if(d==="square"){r=l(n,"rect");r.setAttribute("x",-m*.9);r.setAttribute("y",-m*.9);r.setAttribute("width",m*1.8);r.setAttribute("height",m*1.8)}else{r=l(n,"path");r.setAttribute("d",shapes[d])||shapes.person;r.setAttribute("transform","scale("+m*2.3/100+") translate(-50,-50)")}r.setAttribute("fill",e.color)}b(n.firstChild,{fill:e.color});i=e.moved?{duration:800,delay:hash(e.id)*450}:{};b(t,{transform:"translate("+e.x+","+e.y+")",opacity:1},i);return e.moved=e.fresh=false});this._wigs=Array.from(this.g.dot.querySelectorAll(":scope > g.dot > g.wig"));if(i&&n.dot.motion!=="none"&&this._wigs.length){this.start()}else{this.stop();this._wigs.map(function(t){return t.removeAttribute("transform")})}_=y.fmt;k=S({root:this.g.rlabel,tag:"g",cls:"rl",data:y.labels,key:function(t){return t.key}});k.exit.map(function(t){return b(t,{opacity:0},{duration:200,remove:true})});k.enter.map(function(t){var e,n,r,i,a,o,s=[];e=t.__data__;t.setAttribute("transform","translate("+e.x+","+e.y+")");t.setAttribute("opacity",0);for(n=0,i=(r=["v","l"]).length;n<i;++n){a=r[n];o=l(t,"text","venn-text "+a);o.setAttribute("text-anchor","middle");s.push(o.setAttribute("dominant-baseline","central"))}return s});k.nodes.map(function(t){var e,n,r,i,a,o,s,l;e=t.__data__;n=[t.childNodes[0],t.childNodes[1]],r=n[0],i=n[1];x(r,e.vsize,true);x(i,e.lsize,false);r.setAttribute("fill",v);i.setAttribute("fill",v);i.setAttribute("fill-opacity",.75);r.style.display=e.showV&&e.vt?"":"none";i.style.display=e.showL?"":"none";i.textContent=e.lt;if(e.bubble){r.setAttribute("y",0);i.setAttribute("y",e.r+e.lsize*.9);if(!e.vt){i.textContent=e.lt+" "+_(e.value)}}else{r.setAttribute("y",e.showL?-e.lsize*.6:0);i.setAttribute("y",e.vsize*.5+e.lsize*.45)}a=t._v!=null?t._v:e.value;o=e.value;t._v=o;s=function(t){if(e.percent){return" ("+Math.round(t*100/e.total)+"%)"}else{return""}};r.textContent=e.vt;if(a!==o&&e.vt){l=a%1===0&&o%1===0;b(r,{"data-v":function(t){var e;e=a+(o-a)*t;r.textContent=_(l?Math.round(e):e)+s(e);return e}})}return b(t,{transform:"translate("+e.x+","+e.y+")",opacity:1})});w=S({root:this.g.slabel,tag:"g",cls:"sl",data:y.showSet?y.circles.filter(function(t){return t.label}):[],key:function(t){return t.name}});w.exit.map(function(t){return b(t,{opacity:0},{duration:200,remove:true})});w.enter.map(function(t){var e,n,r,i,a,o=[];t.setAttribute("opacity",0);e=l(t,"line","leader");e.setAttribute("stroke-dasharray","3 3");e.setAttribute("stroke-width",1.5);for(n=0,i=(r=["title","total"]).length;n<i;++n){a=r[n];o.push(l(t,"text","venn-text "+a))}return o});w.nodes.map(function(t){var e,n,r,i,a,o,s,l,u,c,h,f,p,d,m,g;e=t.__data__;n=[t.childNodes[0],t.childNodes[1],t.childNodes[2]],r=n[0],i=n[1],a=n[2];o=y.ts;s=y.us;n=e.pos==="above"?y.showTotal?[-s*1.3-o*.25,-s*.25]:[-o*.25,0]:e.pos==="below"?[o*.85,o*.85+s*1.3]:[-o*.15,s*1.1],l=n[0],u=n[1];for(c=0,h=(n=[[i,l],[a,u]]).length;c<h;++c){f=n[c],p=f[0],d=f[1];p.setAttribute("text-anchor",e.anchor);p.setAttribute("y",d)}x(i,o,true);x(a,s,false);i.setAttribute("fill",C(e.color,"#000")(.25));a.setAttribute("fill",v);a.setAttribute("fill-opacity",.55);i.textContent=e.label;a.textContent=Y("total",y.fmt(e.total),"$1 total");a.style.display=y.showTotal?"":"none";r.setAttribute("stroke",v);r.setAttribute("stroke-opacity",.3);n=[e.dx,e.dy],m=n[0],g=n[1];b(r,{x1:e.ex-e.lx+m*2,y1:e.ey-e.ly+g*2,x2:-m*4,y2:-g*4});return b(t,{transform:"translate("+e.lx+","+e.ly+")",opacity:1})});return this.legend.render();function z(t){return t.name}function L(t){return b(t,{r:0},{remove:true})}function T(t){var e;e=t.__data__;t.setAttribute("cx",e.x);t.setAttribute("cy",e.y);t.setAttribute("r",0);t.setAttribute("fill",h?"none":e.color);if(h){return t.setAttribute("stroke",e.color)}}function W(t){var e;e=t.__data__;if(h){return b(t,{cx:e.x,cy:e.y,r:e.r,stroke:e.color,"stroke-width":i&&!n.dot.outline?0:o,"stroke-opacity":i?.6:1})}else{return b(t,{cx:e.x,cy:e.y,r:e.r,fill:e.color,"fill-opacity":i?a*.25:a})}}},tick:function(t){var e,n,r,i,a,o,s,l,u,c,h,f,p,d,m,g,y,b,v,x,M,_,k,w,A,z,L=[];if(!(this._wigs&&this._wigs.length)||this.cfg.style!=="dot"){return}e=this.cfg.dot.motion;if(e==="none"){return}n=e==="wander";r=(this._dotStep||0)*(n?.45:.1);i=(this.cfg.dot.speed||1)*.001*(n?.8:4);a=n&&this.cfg.dot.shape==="bug";o=t*i;for(s=0,u=(l=this._wigs).length;s<u;++s){c=l[s];h=c.parentNode.__data__;if(!h){continue}f=h._h||(h._h=[0,1,2,3,4,5,6,7].map(T));p=[.6+f[0]*.8,1.2+f[1],.6+f[2]*.8,1.2+f[3]],d=p[0],m=p[1],g=p[2],y=p[3];p=[f[4]*6.283,f[5]*6.283,f[6]*6.283,f[7]*6.283],b=p[0],v=p[1],x=p[2],M=p[3];_=r*(.7*Math.sin(o*d+b)+.3*Math.sin(o*m+v));k=r*(.7*Math.cos(o*g+x)+.3*Math.sin(o*y+M));w="translate("+_+","+k+")";if(a){A=.7*d*Math.cos(o*d+b)+.3*m*Math.cos(o*m+v);z=-.7*g*Math.sin(o*g+x)+.3*y*Math.cos(o*y+M);w+=" rotate("+(Math.atan2(z,A)*180/Math.PI+90)+")"}L.push(c.setAttribute("transform",w))}return L;function T(t){return hash(h.id*8+t)}}}};function in$(t,e){var n=-1,r=e.length>>>0;while(++n<r)if(t===e[n])return true;return false}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 plug="layout"><div class="pdl-layout"><div data-type="layout"><div class="pdl-cell" data-name="view"></div><div class="pdl-cell" data-name="legend"> </div></div><div data-type="render"></div></div></div></div>
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@makechart/venn","version":"0.0.
|
|
1
|
+
{"name":"@makechart/venn","version":"0.0.2","description":"","scripts":{"build":"./build","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.8"}}
|