d3plus-network
Advanced tools
Comparing version 0.4.3 to 0.4.4
/* | ||
d3plus-network v0.4.3 | ||
d3plus-network v0.4.4 | ||
Javascript network visualizations built upon d3 modules. | ||
@@ -1019,7 +1019,7 @@ Copyright (c) 2018 D3plus - https://d3plus.org | ||
labelConfig: { | ||
fontColor: function (d) { return d.data.data.id === this$1._center ? d3plusCommon.configPrep.bind(that)(that._shapeConfig, "shape", d.key).labelConfig.fontColor(d) : d3plusColor.colorLegible(d3plusCommon.configPrep.bind(that)(that._shapeConfig, "shape", d.key).fill(d)); }, | ||
fontResize: function (d) { return d.data.data.id === this$1._center; }, | ||
fontColor: function (d) { return d.data.id === this$1._center ? d3plusCommon.configPrep.bind(that)(that._shapeConfig, "shape", d.key).labelConfig.fontColor(d) : d3plusColor.colorLegible(d3plusCommon.configPrep.bind(that)(that._shapeConfig, "shape", d.key).fill(d)); }, | ||
fontResize: function (d) { return d.data.id === this$1._center; }, | ||
padding: 0, | ||
textAnchor: function (d) { return nodeLookup[d.data.data.id].textAnchor || d3plusCommon.configPrep.bind(that)(that._shapeConfig, "shape", d.key).labelConfig.textAnchor; }, | ||
verticalAlign: function (d) { return d.data.data.id === this$1._center ? "middle" : "top"; } | ||
textAnchor: function (d) { return nodeLookup[d.data.id].textAnchor || d3plusCommon.configPrep.bind(that)(that._shapeConfig, "shape", d.key).labelConfig.textAnchor; }, | ||
verticalAlign: function (d) { return d.data.id === this$1._center ? "middle" : "top"; } | ||
}, | ||
@@ -1026,0 +1026,0 @@ rotate: function (d) { return nodeLookup[d.id].rotate || 0; }, |
/* | ||
d3plus-network v0.4.3 | ||
d3plus-network v0.4.4 | ||
Javascript network visualizations built upon d3 modules. | ||
@@ -7,2 +7,2 @@ Copyright (c) 2018 D3plus - https://d3plus.org | ||
*/ | ||
if(typeof Object.assign!=="function"){Object.defineProperty(Object,"assign",{value:function e(t){"use strict";if(t===null){throw new TypeError("Cannot convert undefined or null to object")}var n=Object(t);for(var i=1;i<arguments.length;i++){var r=arguments[i];if(r!==null){for(var s in r){if(Object.prototype.hasOwnProperty.call(r,s)){n[s]=r[s]}}}}return n},writable:true,configurable:true})}if(!Array.prototype.includes){Object.defineProperty(Array.prototype,"includes",{value:function e(t,n){var i=Object(this);var r=i.length>>>0;if(r===0)return false;var s=n|0;var o=Math.max(s>=0?s:r-Math.abs(s),0);function a(e,t){return e===t||typeof e==="number"&&typeof t==="number"&&isNaN(e)&&isNaN(t)}while(o<r){if(a(i[o],t)){return true}o++}return false}})}(function(e,t){typeof exports==="object"&&typeof module!=="undefined"?t(exports,require("d3-array"),require("d3-collection"),require("d3-scale"),require("d3-zoom"),require("d3plus-common"),require("d3plus-shape"),require("d3plus-viz"),require("d3plus-color"),require("d3-sankey")):typeof define==="function"&&define.amd?define("d3plus-network",["exports","d3-array","d3-collection","d3-scale","d3-zoom","d3plus-common","d3plus-shape","d3plus-viz","d3plus-color","d3-sankey"],t):t(e.d3plus={},e.d3Array,e.d3Collection,e.scales,e.d3Zoom,e.d3plusCommon,e.shapes,e.d3plusViz,e.d3plusColor,e.d3Sankey)})(this,function(e,j,S,D,d,I,R,s,W,t){"use strict";var n=function(O){function e(){var h=this;O.call(this);this._labelCutoff=100;this._links=[];this._noDataMessage=false;this._nodes=[];this._on["click.shape"]=function(e,t){h._tooltipClass.data([]).render();if(h._hover&&h._drawDepth>=h._groupBy.length-1){if(h._focus&&h._focus===e.id){h.active(false);h._on.mouseenter.bind(h)(e,t);h._focus=undefined;h._zoomToBounds(null)}else{h.hover(false);var n=h._nodeGroupBy&&h._nodeGroupBy[h._drawDepth](e,t)?h._nodeGroupBy[h._drawDepth](e,t):h._id(e,t),i=h._linkLookup[n],r=h._nodeLookup[n];var s=[r.id];var o=[r.x-r.r,r.x+r.r],a=[r.y-r.r,r.y+r.r];i.forEach(function(e){s.push(e.id);if(e.x-e.r<o[0]){o[0]=e.x-e.r}if(e.x+e.r>o[1]){o[1]=e.x+e.r}if(e.y-e.r<a[0]){a[0]=e.y-e.r}if(e.y+e.r>a[1]){a[1]=e.y+e.r}});h.active(function(e,t){if(e.source&&e.target){return e.source.id===r.id||e.target.id===r.id}else{return s.includes(h._ids(e,t)[h._drawDepth])}});h._focus=e.id;var u=d.zoomTransform(h._container.node());o=o.map(function(e){return e*u.k+u.x});a=a.map(function(e){return e*u.k+u.y});h._zoomToBounds([[o[0],a[0]],[o[1],a[1]]])}}};this._on["click.legend"]=function(e,t){var n=h._id(e);var i=h._ids(e);i=i[i.length-1];if(h._hover&&h._drawDepth>=h._groupBy.length-1){if(h._focus&&h._focus===n){h.active(false);h._on.mouseenter.bind(h)(e,t);h._focus=undefined;h._zoomToBounds(null)}else{h.hover(false);var r=n.map(function(e){return h._nodeLookup[e]});var s=[i];var o=[r[0].x-r[0].r,r[0].x+r[0].r],a=[r[0].y-r[0].r,r[0].y+r[0].r];r.forEach(function(e){s.push(e.id);if(e.x-e.r<o[0]){o[0]=e.x-e.r}if(e.x+e.r>o[1]){o[1]=e.x+e.r}if(e.y-e.r<a[0]){a[0]=e.y-e.r}if(e.y+e.r>a[1]){a[1]=e.y+e.r}});h.active(function(e,t){if(e.source&&e.target){return s.includes(e.source.id)&&s.includes(e.target.id)}else{var n=h._ids(e,t);return s.includes(n[n.length-1])}});h._focus=n;var u=d.zoomTransform(h._container.node());o=o.map(function(e){return e*u.k+u.x});a=a.map(function(e){return e*u.k+u.y});h._zoomToBounds([[o[0],a[0]],[o[1],a[1]]])}h._on["mousemove.legend"].bind(h)(e,t)}};this._sizeMin=5;this._sizeScale="sqrt";this._shape=I.constant("Circle");this._shapeConfig=I.assign(this._shapeConfig,{ariaLabel:function(e,t){var n=h._size?", "+h._size(e,t):"";return""+h._drawLabel(e,t)+n+"."},labelConfig:{duration:0,fontMin:1,fontResize:true,labelPadding:0,textAnchor:"middle",verticalAlign:"middle"},Path:{fill:"none",label:false,stroke:"#eee",strokeWidth:1}});this._x=I.accessor("x");this._y=I.accessor("y");this._zoom=true}if(O)e.__proto__=O;e.prototype=Object.create(O&&O.prototype);e.prototype.constructor=e;e.prototype._draw=function e(t){var r=this;O.prototype._draw.call(this,t);var n=this._height-this._margin.top-this._margin.bottom,i="translate("+this._margin.left+", "+this._margin.top+")",s=this._transition,o=this._width-this._margin.left-this._margin.right;var a=this._filteredData.reduce(function(e,t,n){e[r._id(t,n)]=t;return e},{});var u=this._nodes.reduce(function(e,t,n){e[r._nodeGroupBy?r._nodeGroupBy[r._drawDepth](t,n):r._id(t,n)]=t;return e},{});u=Array.from(new Set(Object.keys(a).concat(Object.keys(u)))).map(function(e,t){var n=a[e],i=u[e];if(i===undefined){return false}return{__d3plus__:true,data:n||i,i:t,id:e,fx:n!==undefined&&r._x(n)!==undefined?r._x(n):r._x(i),fy:n!==undefined&&r._y(n)!==undefined?r._y(n):r._y(i),node:i,r:r._size?n!==undefined&&r._size(n)!==undefined?r._size(n):r._size(i):r._sizeMin,shape:n!==undefined&&r._shape(n)!==undefined?r._shape(n):r._shape(i)}}).filter(function(e){return e});var h=j.extent(u.map(function(e){return e.fx})),d=j.extent(u.map(function(e){return e.fy}));var c=D.scaleLinear().domain(h).range([0,o]),f=D.scaleLinear().domain(d).range([0,n]);var l=(h[1]-h[0])/(d[1]-d[0]),_=o/n;if(l>_){var p=n*_/l;f.range([(n-p)/2,n-(n-p)/2])}else{var g=o*l/_;c.range([(o-g)/2,o-(o-g)/2])}u.forEach(function(e){e.x=c(e.fx);e.y=f(e.fy)});var v=j.extent(u.map(function(e){return e.r}));var y=this._sizeMax||j.min(j.merge(u.map(function(t){return u.map(function(e){return t===e?null:R.pointDistance([t.x,t.y],[e.x,e.y])})})))/2;var m=D["scale"+this._sizeScale.charAt(0).toUpperCase()+this._sizeScale.slice(1)]().domain(v).range([v[0]===v[1]?y:j.min([y/2,this._sizeMin]),y]),k=c.domain(),x=f.domain();var z=k[1]-k[0],b=x[1]-x[0];u.forEach(function(e){var t=m(e.r);if(k[0]>c.invert(e.x-t)){k[0]=c.invert(e.x-t)}if(k[1]<c.invert(e.x+t)){k[1]=c.invert(e.x+t)}if(x[0]>f.invert(e.y-t)){x[0]=f.invert(e.y-t)}if(x[1]<f.invert(e.y+t)){x[1]=f.invert(e.y+t)}});var M=k[1]-k[0],w=x[1]-x[0];y*=j.min([z/M,b/w]);m.range([v[0]===v[1]?y:j.min([y/2,this._sizeMin]),y]);c.domain(k);f.domain(x);u.forEach(function(e){e.x=c(e.fx);e.fx=e.x;e.y=f(e.fy);e.fy=e.y;e.r=m(e.r);e.width=e.r*2;e.height=e.r*2});var C=this._nodeLookup=u.reduce(function(e,t){e[t.id]=t;return e},{});var B=u.map(function(e){return e.node});var q=this._links.map(function(e){return{source:typeof e.source==="number"?u[B.indexOf(r._nodes[e.source])]:C[e.source.id],target:typeof e.target==="number"?u[B.indexOf(r._nodes[e.target])]:C[e.target.id]}});this._linkLookup=q.reduce(function(e,t){if(!e[t.source.id]){e[t.source.id]=[]}e[t.source.id].push(t.target);if(!e[t.target.id]){e[t.target.id]=[]}e[t.target.id].push(t.source);return e},{});this._container=this._select.selectAll("svg.d3plus-network").data([0]);this._container=this._container.enter().append("svg").attr("class","d3plus-network").attr("opacity",0).attr("width",o).attr("height",n).attr("x",this._margin.left).attr("y",this._margin.top).style("background-color","transparent").merge(this._container);this._container.transition(this._transition).attr("opacity",1).attr("width",o).attr("height",n).attr("x",this._margin.left).attr("y",this._margin.top);var L=this._container.selectAll("rect.d3plus-network-hitArea").data([0]);L.enter().append("rect").attr("class","d3plus-network-hitArea").merge(L).attr("width",o).attr("height",n).attr("fill","transparent").on("click",function(){if(r._focus){r.active(false);r._focus=undefined;r._zoomToBounds(null)}});this._zoomGroup=this._container.selectAll("g.d3plus-network-zoomGroup").data([0]);var A=this._zoomGroup=this._zoomGroup.enter().append("g").attr("class","d3plus-network-zoomGroup").merge(this._zoomGroup);this._shapes.push((new R.Path).config(this._shapeConfig).config(this._shapeConfig.Path).d(function(e){return"M"+e.source.x+","+e.source.y+" "+e.target.x+","+e.target.y}).data(q).select(I.elem("g.d3plus-network-links",{parent:A,transition:s,enter:{transform:i},update:{transform:i}}).node()).render());var P={label:function(e){return u.length<=r._labelCutoff||(r._hover&&r._hover(e)||r._active&&r._active(e))?r._drawLabel(e.data||e.node,e.i):false},select:I.elem("g.d3plus-network-nodes",{parent:A,transition:s,enter:{transform:i},update:{transform:i}}).node()};S.nest().key(function(e){return e.shape}).entries(u).forEach(function(e){r._shapes.push((new R[e.key]).config(I.configPrep.bind(r)(r._shapeConfig,"shape",e.key)).config(P).config(P[e.key]||{}).data(e.values).render())});return this};e.prototype.labelCutoff=function e(t){return arguments.length?(this._labelCutoff=t,this):this._labelCutoff};e.prototype.links=function e(t,n){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="links"});var r=[s.dataLoad.bind(this),t,n,"links"];if(i){this._queue[this._queue.indexOf(i)]=r}else{this._queue.push(r)}return this}return this._links};e.prototype.nodeGroupBy=function e(t){var n=this;if(!arguments.length){return this._nodeGroupBy}if(!(t instanceof Array)){t=[t]}return this._nodeGroupBy=t.map(function(e){if(typeof e==="function"){return e}else{if(!n._aggs[e]){n._aggs[e]=function(e){var t=Array.from(new Set(e));return t.length===1?t[0]:t}}return I.accessor(e)}}),this};e.prototype.nodes=function e(t,n){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="nodes"});var r=[s.dataLoad.bind(this),t,n,"nodes"];if(i){this._queue[this._queue.indexOf(i)]=r}else{this._queue.push(r)}return this}return this._nodes};e.prototype.size=function e(t){return arguments.length?(this._size=typeof t==="function"||!t?t:I.accessor(t),this):this._size};e.prototype.sizeMax=function e(t){return arguments.length?(this._sizeMax=t,this):this._sizeMax};e.prototype.sizeMin=function e(t){return arguments.length?(this._sizeMin=t,this):this._sizeMin};e.prototype.sizeScale=function e(t){return arguments.length?(this._sizeScale=t,this):this._sizeScale};e.prototype.x=function e(t){if(arguments.length){if(typeof t==="function"){this._x=t}else{this._x=I.accessor(t);if(!this._aggs[t]){this._aggs[t]=function(e){return j.mean(e)}}}return this}else{return this._x}};e.prototype.y=function e(t){if(arguments.length){if(typeof t==="function"){this._y=t}else{this._y=I.accessor(t);if(!this._aggs[t]){this._aggs[t]=function(e){return j.mean(e)}}}return this}else{return this._y}};return e}(s.Viz);var i=function(G){function e(){var u=this;G.call(this);this._labelCutoff=100;this._links=[];this._noDataMessage=false;this._nodes=[];this._on.mouseenter=function(){};this._on["mouseleave.shape"]=function(){u.hover(false)};var h=this._on["mousemove.shape"];this._on["mousemove.shape"]=function(e,t){h(e,t);if(u._focus&&u._focus===e.id){u.hover(false);u._on.mouseenter.bind(u)(e,t);u._focus=undefined}else{var n=u._nodeGroupBy&&u._nodeGroupBy[u._drawDepth](e,t)?u._nodeGroupBy[u._drawDepth](e,t):u._id(e,t),i=u._linkLookup[n],r=u._nodeLookup[n];var s=[r.id];var o=[r.x-r.r,r.x+r.r],a=[r.y-r.r,r.y+r.r];i.forEach(function(e){s.push(e.id);if(e.x-e.r<o[0]){o[0]=e.x-e.r}if(e.x+e.r>o[1]){o[1]=e.x+e.r}if(e.y-e.r<a[0]){a[0]=e.y-e.r}if(e.y+e.r>a[1]){a[1]=e.y+e.r}});u.hover(function(e,t){if(e.source&&e.target){return e.source.id===r.id||e.target.id===r.id}else{return s.includes(u._ids(e,t)[u._drawDepth])}})}};this._on["click.shape"]=function(e){u._center=e.id;u._draw()};this._sizeMin=5;this._sizeScale="sqrt";this._shape=I.constant("Circle");this._shapeConfig=I.assign(this._shapeConfig,{ariaLabel:function(e,t){var n=u._size?", "+u._size(e,t):"";return""+u._drawLabel(e,t)+n+"."},labelConfig:{duration:0,fontMin:1,fontResize:true,labelPadding:0,textAnchor:"middle",verticalAlign:"middle"},Path:{fill:"none",label:false,stroke:"#eee",strokeWidth:1}})}if(G)e.__proto__=G;e.prototype=Object.create(G&&G.prototype);e.prototype.constructor=e;e.prototype._draw=function e(t){var h=this;G.prototype._draw.call(this,t);var r=this._filteredData.reduce(function(e,t,n){e[h._id(t,n)]=t;return e},{});var d=this._nodes;if(!this._nodes.length&&this._links.length){var n=Array.from(new Set(this._links.reduce(function(e,t){return e.concat([t.source,t.target])},[])));d=n.map(function(e){return typeof e==="object"?e:{id:e}})}d=d.reduce(function(e,t,n){e[h._nodeGroupBy?h._nodeGroupBy[h._drawDepth](t,n):h._id(t,n)]=t;return e},{});d=Array.from(new Set(Object.keys(r).concat(Object.keys(d)))).map(function(e,t){var n=r[e],i=d[e];if(i===undefined){return false}return{__d3plus__:true,data:n||i,i:t,id:e,node:i,shape:n!==undefined&&h._shape(n)!==undefined?h._shape(n):h._shape(i)}}).filter(function(e){return e});var i=this._nodeLookup=d.reduce(function(e,t){e[t.id]=t;return e},{});var s=this._links.map(function(n){var e=["source","target"];return e.reduce(function(e,t){e[t]=typeof n[t]==="number"?d[n[t]]:i[n[t].id||n[t]];return e},{})});var o=s.reduce(function(e,t){if(!e[t.source.id]){e[t.source.id]=[]}e[t.source.id].push(t);if(!e[t.target.id]){e[t.target.id]=[]}e[t.target.id].push(t);return e},{});var c=this._height-this._margin.top-this._margin.bottom,a="translate("+this._margin.left+", "+this._margin.top+")",u=this._transition,f=this._width-this._margin.left-this._margin.right;var l=[],_=j.min([c,f])/2,p=_/3;var g=p,v=p*2;var y=i[this._center];y.x=f/2;y.y=c/2;y.r=this._sizeMin?j.max([this._sizeMin,g*.65]):this._sizeMax?j.min([this._sizeMax,g*.65]):g*.65;var m=[y],k=[];o[this._center].forEach(function(e){var t=e.source.id===h._center?e.target:e.source;t.edges=o[t.id].filter(function(e){return e.source.id!==h._center||e.target.id!==h._center});t.edge=e;m.push(t);k.push(t)});k.sort(function(e,t){return e.edges.length-t.edges.length});var x=[];var z=0;k.forEach(function(e){var r=e.id;e.edges=e.edges.filter(function(e){return!m.includes(e.source)&&e.target.id===r||!m.includes(e.target)&&e.source.id===r});z+=e.edges.length||1;e.edges.forEach(function(e){var t=e.source;var n=e.target;var i=n.id===r?t:n;m.push(i)})});var b=Math.PI*2;var M=0;k.forEach(function(s,e){var o=s.edges.length||1;var t=b/z*o;if(e===0){M-=t/2}var a=M+t/2-b/4;s.radians=a;s.x=f/2+g*Math.cos(a);s.y=c/2+g*Math.sin(a);M+=t;s.edges.forEach(function(e,t){var n=e.source.id===s.id?e.target:e.source;var i=b/z;var r=a-i*o/2+i/2+i*t;n.radians=r;n.x=f/2+v*Math.cos(r);n.y=c/2+v*Math.sin(r);x.push(n)})});var w=p/2;var C=p/4;var B=w/2-4;if(w/2-4<8){B=j.min([w/2,8])}var q=C/2-4;if(C/2-4<4){q=j.min([C/2,4])}if(q>p/10){q=p/10}if(q>B&&q>10){q=B*.75}if(B>q*1.5){B=q*1.5}B=Math.floor(B);q=Math.floor(q);var L;if(this._size){var A=j.extent(r,function(e){return e.size});if(A[0]===A[1]){A[0]=0}L=D.scaleLinear().domain(A).rangeRound([3,j.min([B,q])]);var P=y.size;y.r=L(P)}else{L=D.scaleLinear().domain([1,2]).rangeRound([B,q])}x.forEach(function(e){e.ring=2;var t=h._size?e.size:2;e.r=h._sizeMin?j.max([h._sizeMin,L(t)]):h._sizeMax?j.min([h._sizeMax,L(t)]):L(t)});k.forEach(function(e){e.ring=1;var t=h._size?e.size:1;e.r=h._sizeMin?j.max([h._sizeMin,L(t)]):h._sizeMax?j.min([h._sizeMax,L(t)]):L(t)});d=[y].concat(k).concat(x);k.forEach(function(u){var e=["source","target"];var n=u.edge;e.forEach(function(t){n[t]=d.find(function(e){return e.id===n[t].id})});l.push(n);o[u.id].forEach(function(i){var t=i.source.id===u.id?i.target:i.source;if(t.id!==y.id){var r=x.find(function(e){return e.id===t.id});if(!r){r=k.find(function(e){return e.id===t.id})}if(r){i.spline=true;var s=f/2;var o=c/2;var a=g+(v-g)*.5;var e=["source","target"];e.forEach(function(t,e){i[t+"X"]=i[t].x+Math.cos(i[t].ring===2?i[t].radians+Math.PI:i[t].radians)*i[t].r;i[t+"Y"]=i[t].y+Math.sin(i[t].ring===2?i[t].radians+Math.PI:i[t].radians)*i[t].r;i[t+"BisectX"]=s+a*Math.cos(i[t].radians);i[t+"BisectY"]=o+a*Math.sin(i[t].radians);i[t]=d.find(function(e){return e.id===i[t].id});if(i[t].edges===undefined){i[t].edges={}}var n=e===0?i.target.id:i.source.id;if(i[t].id===u.id){i[t].edges[n]={angle:u.radians+Math.PI,radius:p/2}}else{i[t].edges[n]={angle:r.radians,radius:p/2}}});l.push(i)}}})});d.forEach(function(e){if(e.id!==h._center){var t=h._shapeConfig.labelConfig.fontSize&&h._shapeConfig.labelConfig.fontSize(e)||11;var n=t*1.4;var i=n*2;var r=5;var s=p-e.r;var o=e.radians*(180/Math.PI);var a=e.r+r;var u="start";if(o<-90||o>90){a=-e.r-s-r;u="end";o+=180}e.labelBounds={x:a,y:-n/2,width:s,height:i};e.rotate=o;e.textAnchor=u}else{e.labelBounds={x:-g/2,y:-g/2,width:g,height:g}}});this._linkLookup=s.reduce(function(e,t){if(!e[t.source.id]){e[t.source.id]=[]}e[t.source.id].push(t.target);if(!e[t.target.id]){e[t.target.id]=[]}e[t.target.id].push(t.source);return e},{});this._shapes.push((new R.Path).config(I.configPrep.bind(this)(this._shapeConfig,"edge","Path")).id(function(e){return e.source.id+"_"+e.target.id}).d(function(e){return e.spline?"M"+e.sourceX+","+e.sourceY+"C"+e.sourceBisectX+","+e.sourceBisectY+" "+e.targetBisectX+","+e.targetBisectY+" "+e.targetX+","+e.targetY:"M"+e.source.x+","+e.source.y+" "+e.target.x+","+e.target.y}).data(l).select(I.elem("g.d3plus-rings-links",{parent:this._select,transition:u,enter:{transform:a},update:{transform:a}}).node()).render());var O=this;var E={label:function(e){return d.length<=h._labelCutoff||(h._hover&&h._hover(e)||h._active&&h._active(e))?h._drawLabel(e.data||e.node,e.i):false},labelBounds:function(e){return e.labelBounds},labelConfig:{fontColor:function(e){return e.data.data.id===h._center?I.configPrep.bind(O)(O._shapeConfig,"shape",e.key).labelConfig.fontColor(e):W.colorLegible(I.configPrep.bind(O)(O._shapeConfig,"shape",e.key).fill(e))},fontResize:function(e){return e.data.data.id===h._center},padding:0,textAnchor:function(e){return i[e.data.data.id].textAnchor||I.configPrep.bind(O)(O._shapeConfig,"shape",e.key).labelConfig.textAnchor},verticalAlign:function(e){return e.data.data.id===h._center?"middle":"top"}},rotate:function(e){return i[e.id].rotate||0},select:I.elem("g.d3plus-rings-nodes",{parent:this._select,transition:u,enter:{transform:a},update:{transform:a}}).node()};S.nest().key(function(e){return e.shape}).entries(d).forEach(function(e){h._shapes.push((new R[e.key]).config(I.configPrep.bind(h)(h._shapeConfig,"shape",e.key)).config(E).data(e.values).render())});return this};e.prototype.center=function e(t){return arguments.length?(this._center=t,this):this._center};e.prototype.hover=function e(t){this._hover=t;this._shapes.forEach(function(e){return e.hover(t)});if(this._legend){this._legendClass.hover(t)}return this};e.prototype.links=function e(t,n){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="links"});var r=[s.dataLoad.bind(this),t,n,"links"];if(i){this._queue[this._queue.indexOf(i)]=r}else{this._queue.push(r)}return this}return this._links};e.prototype.nodeGroupBy=function e(t){var n=this;if(!arguments.length){return this._nodeGroupBy}if(!(t instanceof Array)){t=[t]}return this._nodeGroupBy=t.map(function(e){if(typeof e==="function"){return e}else{if(!n._aggs[e]){n._aggs[e]=function(e){var t=Array.from(new Set(e));return t.length===1?t[0]:t}}return I.accessor(e)}}),this};e.prototype.nodes=function e(t,n){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="nodes"});var r=[s.dataLoad.bind(this),t,n,"nodes"];if(i){this._queue[this._queue.indexOf(i)]=r}else{this._queue.push(r)}return this}return this._nodes};e.prototype.size=function e(t){return arguments.length?(this._size=typeof t==="function"||!t?t:I.accessor(t),this):this._size};e.prototype.sizeMax=function e(t){return arguments.length?(this._sizeMax=t,this):this._sizeMax};e.prototype.sizeMin=function e(t){return arguments.length?(this._sizeMin=t,this):this._sizeMin};e.prototype.sizeScale=function e(t){return arguments.length?(this._sizeScale=t,this):this._sizeScale};return e}(s.Viz);var r={center:t.sankeyCenter,justify:t.sankeyJustify,left:t.sankeyLeft,right:t.sankeyRight};var o=function(h){function e(){var a=this;h.call(this);this._nodeId=I.accessor("id");this._links=I.accessor("links");this._noDataMessage=false;this._nodes=I.accessor("nodes");this._nodeAlign=r.justify;this._nodeWidth=30;this._on.mouseenter=function(){};this._on["mouseleave.shape"]=function(){a.hover(false)};var u=this._on["mousemove.shape"];this._on["mousemove.shape"]=function(e,t){u(e,t);if(a._focus&&a._focus===e.id){a.hover(false);a._on.mouseenter.bind(a)(e,t);a._focus=undefined}else{var n=a._nodeId(e,t),i=a._nodeLookup[n],r=Object.keys(a._nodeLookup).reduce(function(e,t){e[a._nodeLookup[t]]=!isNaN(t)?parseInt(t,10):t;return e},{});var s=a._linkLookup[i];var o=[n];s.forEach(function(e){o.push(r[e])});a.hover(function(e,t){if(e.source&&e.target){return e.source.id===n||e.target.id===n}else{return o.includes(a._nodeId(e,t))}})}};this._path=t.sankeyLinkHorizontal();this._sankey=t.sankey();this._shape=I.constant("Rect");this._shapeConfig=I.assign(this._shapeConfig,{Path:{fill:"none",hoverStyle:{"stroke-width":function(e){return Math.max(1,Math.abs(e.source.y1-e.source.y0)*(e.value/e.source.value)-2)}},label:false,stroke:"#DBDBDB",strokeOpacity:.5,strokeWidth:function(e){return Math.max(1,Math.abs(e.source.y1-e.source.y0)*(e.value/e.source.value)-2)}},Rect:{}});this._value=I.constant(1)}if(h)e.__proto__=h;e.prototype=Object.create(h&&h.prototype);e.prototype.constructor=e;e.prototype._draw=function e(t){var r=this;h.prototype._draw.call(this,t);var n=this._height-this._margin.top-this._margin.bottom,i=this._width-this._margin.left-this._margin.right;var s=this._nodes.map(function(e,t){return{__d3plus__:true,data:e,i:t,id:r._nodeId(e,t),node:e,shape:"Rect"}});var o=this._nodeLookup=s.reduce(function(e,t,n){e[t.id]=n;return e},{});var a=this._links.map(function(n,e){var t=["source","target"];var i=t.reduce(function(e,t){e[t]=typeof n[t]==="number"?o[n[t]]:o[n[t]];return e},{});return{source:i.source,target:i.target,value:r._value(n,e)}});this._linkLookup=a.reduce(function(e,t){if(!e[t.source]){e[t.source]=[]}e[t.source].push(t.target);if(!e[t.target]){e[t.target]=[]}e[t.target].push(t.source);return e},{});var u="translate("+this._margin.left+", "+this._margin.top+")";this._sankey.nodeAlign(this._nodeAlign).nodeWidth(this._nodeWidth).nodes(s).links(a).size([i,n])();this._shapes.push((new R.Path).config(this._shapeConfig.Path).data(a).d(this._path).select(I.elem("g.d3plus-Links",{parent:this._select,enter:{transform:u},update:{transform:u}}).node()).render());S.nest().key(function(e){return e.shape}).entries(s).forEach(function(e){r._shapes.push((new R[e.key]).data(e.values).height(function(e){return e.y1-e.y0}).width(function(e){return e.x1-e.x0}).x(function(e){return(e.x1+e.x0)/2}).y(function(e){return(e.y1+e.y0)/2}).select(I.elem("g.d3plus-sankey-nodes",{parent:r._select,enter:{transform:u},update:{transform:u}}).node()).config(I.configPrep.bind(r)(r._shapeConfig,"shape",e.key)).render())});return this};e.prototype.hover=function e(t){this._hover=t;this._shapes.forEach(function(e){return e.hover(t)});if(this._legend){this._legendClass.hover(t)}return this};e.prototype.links=function e(t,n){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="links"});var r=[s.dataLoad.bind(this),t,n,"links"];if(i){this._queue[this._queue.indexOf(i)]=r}else{this._queue.push(r)}return this}return this._links};e.prototype.nodeAlign=function e(t){return arguments.length?(this._nodeAlign=typeof t==="function"?t:r[t],this):this._nodeAlign};e.prototype.nodeId=function e(t){return arguments.length?(this._nodeId=typeof t==="function"?t:I.accessor(t),this):this._nodeId};e.prototype.nodes=function e(t,n){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="nodes"});var r=[s.dataLoad.bind(this),t,n,"nodes"];if(i){this._queue[this._queue.indexOf(i)]=r}else{this._queue.push(r)}return this}return this._nodes};e.prototype.nodeWidth=function e(t){return arguments.length?(this._nodeWidth=t,this):this._nodeWidth};e.prototype.value=function e(t){return arguments.length?(this._value=typeof t==="function"?t:I.accessor(t),this):this._value};return e}(s.Viz);e.Network=n;e.Rings=i;e.Sankey=o;Object.defineProperty(e,"__esModule",{value:true})}); | ||
if(typeof Object.assign!=="function"){Object.defineProperty(Object,"assign",{value:function e(t){"use strict";if(t===null){throw new TypeError("Cannot convert undefined or null to object")}var n=Object(t);for(var i=1;i<arguments.length;i++){var r=arguments[i];if(r!==null){for(var s in r){if(Object.prototype.hasOwnProperty.call(r,s)){n[s]=r[s]}}}}return n},writable:true,configurable:true})}if(!Array.prototype.includes){Object.defineProperty(Array.prototype,"includes",{value:function e(t,n){var i=Object(this);var r=i.length>>>0;if(r===0)return false;var s=n|0;var o=Math.max(s>=0?s:r-Math.abs(s),0);function a(e,t){return e===t||typeof e==="number"&&typeof t==="number"&&isNaN(e)&&isNaN(t)}while(o<r){if(a(i[o],t)){return true}o++}return false}})}(function(e,t){typeof exports==="object"&&typeof module!=="undefined"?t(exports,require("d3-array"),require("d3-collection"),require("d3-scale"),require("d3-zoom"),require("d3plus-common"),require("d3plus-shape"),require("d3plus-viz"),require("d3plus-color"),require("d3-sankey")):typeof define==="function"&&define.amd?define("d3plus-network",["exports","d3-array","d3-collection","d3-scale","d3-zoom","d3plus-common","d3plus-shape","d3plus-viz","d3plus-color","d3-sankey"],t):t(e.d3plus={},e.d3Array,e.d3Collection,e.scales,e.d3Zoom,e.d3plusCommon,e.shapes,e.d3plusViz,e.d3plusColor,e.d3Sankey)})(this,function(e,j,S,D,d,I,R,s,W,t){"use strict";var n=function(O){function e(){var h=this;O.call(this);this._labelCutoff=100;this._links=[];this._noDataMessage=false;this._nodes=[];this._on["click.shape"]=function(e,t){h._tooltipClass.data([]).render();if(h._hover&&h._drawDepth>=h._groupBy.length-1){if(h._focus&&h._focus===e.id){h.active(false);h._on.mouseenter.bind(h)(e,t);h._focus=undefined;h._zoomToBounds(null)}else{h.hover(false);var n=h._nodeGroupBy&&h._nodeGroupBy[h._drawDepth](e,t)?h._nodeGroupBy[h._drawDepth](e,t):h._id(e,t),i=h._linkLookup[n],r=h._nodeLookup[n];var s=[r.id];var o=[r.x-r.r,r.x+r.r],a=[r.y-r.r,r.y+r.r];i.forEach(function(e){s.push(e.id);if(e.x-e.r<o[0]){o[0]=e.x-e.r}if(e.x+e.r>o[1]){o[1]=e.x+e.r}if(e.y-e.r<a[0]){a[0]=e.y-e.r}if(e.y+e.r>a[1]){a[1]=e.y+e.r}});h.active(function(e,t){if(e.source&&e.target){return e.source.id===r.id||e.target.id===r.id}else{return s.includes(h._ids(e,t)[h._drawDepth])}});h._focus=e.id;var u=d.zoomTransform(h._container.node());o=o.map(function(e){return e*u.k+u.x});a=a.map(function(e){return e*u.k+u.y});h._zoomToBounds([[o[0],a[0]],[o[1],a[1]]])}}};this._on["click.legend"]=function(e,t){var n=h._id(e);var i=h._ids(e);i=i[i.length-1];if(h._hover&&h._drawDepth>=h._groupBy.length-1){if(h._focus&&h._focus===n){h.active(false);h._on.mouseenter.bind(h)(e,t);h._focus=undefined;h._zoomToBounds(null)}else{h.hover(false);var r=n.map(function(e){return h._nodeLookup[e]});var s=[i];var o=[r[0].x-r[0].r,r[0].x+r[0].r],a=[r[0].y-r[0].r,r[0].y+r[0].r];r.forEach(function(e){s.push(e.id);if(e.x-e.r<o[0]){o[0]=e.x-e.r}if(e.x+e.r>o[1]){o[1]=e.x+e.r}if(e.y-e.r<a[0]){a[0]=e.y-e.r}if(e.y+e.r>a[1]){a[1]=e.y+e.r}});h.active(function(e,t){if(e.source&&e.target){return s.includes(e.source.id)&&s.includes(e.target.id)}else{var n=h._ids(e,t);return s.includes(n[n.length-1])}});h._focus=n;var u=d.zoomTransform(h._container.node());o=o.map(function(e){return e*u.k+u.x});a=a.map(function(e){return e*u.k+u.y});h._zoomToBounds([[o[0],a[0]],[o[1],a[1]]])}h._on["mousemove.legend"].bind(h)(e,t)}};this._sizeMin=5;this._sizeScale="sqrt";this._shape=I.constant("Circle");this._shapeConfig=I.assign(this._shapeConfig,{ariaLabel:function(e,t){var n=h._size?", "+h._size(e,t):"";return""+h._drawLabel(e,t)+n+"."},labelConfig:{duration:0,fontMin:1,fontResize:true,labelPadding:0,textAnchor:"middle",verticalAlign:"middle"},Path:{fill:"none",label:false,stroke:"#eee",strokeWidth:1}});this._x=I.accessor("x");this._y=I.accessor("y");this._zoom=true}if(O)e.__proto__=O;e.prototype=Object.create(O&&O.prototype);e.prototype.constructor=e;e.prototype._draw=function e(t){var r=this;O.prototype._draw.call(this,t);var n=this._height-this._margin.top-this._margin.bottom,i="translate("+this._margin.left+", "+this._margin.top+")",s=this._transition,o=this._width-this._margin.left-this._margin.right;var a=this._filteredData.reduce(function(e,t,n){e[r._id(t,n)]=t;return e},{});var u=this._nodes.reduce(function(e,t,n){e[r._nodeGroupBy?r._nodeGroupBy[r._drawDepth](t,n):r._id(t,n)]=t;return e},{});u=Array.from(new Set(Object.keys(a).concat(Object.keys(u)))).map(function(e,t){var n=a[e],i=u[e];if(i===undefined){return false}return{__d3plus__:true,data:n||i,i:t,id:e,fx:n!==undefined&&r._x(n)!==undefined?r._x(n):r._x(i),fy:n!==undefined&&r._y(n)!==undefined?r._y(n):r._y(i),node:i,r:r._size?n!==undefined&&r._size(n)!==undefined?r._size(n):r._size(i):r._sizeMin,shape:n!==undefined&&r._shape(n)!==undefined?r._shape(n):r._shape(i)}}).filter(function(e){return e});var h=j.extent(u.map(function(e){return e.fx})),d=j.extent(u.map(function(e){return e.fy}));var c=D.scaleLinear().domain(h).range([0,o]),f=D.scaleLinear().domain(d).range([0,n]);var l=(h[1]-h[0])/(d[1]-d[0]),_=o/n;if(l>_){var p=n*_/l;f.range([(n-p)/2,n-(n-p)/2])}else{var g=o*l/_;c.range([(o-g)/2,o-(o-g)/2])}u.forEach(function(e){e.x=c(e.fx);e.y=f(e.fy)});var v=j.extent(u.map(function(e){return e.r}));var y=this._sizeMax||j.min(j.merge(u.map(function(t){return u.map(function(e){return t===e?null:R.pointDistance([t.x,t.y],[e.x,e.y])})})))/2;var m=D["scale"+this._sizeScale.charAt(0).toUpperCase()+this._sizeScale.slice(1)]().domain(v).range([v[0]===v[1]?y:j.min([y/2,this._sizeMin]),y]),k=c.domain(),x=f.domain();var z=k[1]-k[0],b=x[1]-x[0];u.forEach(function(e){var t=m(e.r);if(k[0]>c.invert(e.x-t)){k[0]=c.invert(e.x-t)}if(k[1]<c.invert(e.x+t)){k[1]=c.invert(e.x+t)}if(x[0]>f.invert(e.y-t)){x[0]=f.invert(e.y-t)}if(x[1]<f.invert(e.y+t)){x[1]=f.invert(e.y+t)}});var M=k[1]-k[0],w=x[1]-x[0];y*=j.min([z/M,b/w]);m.range([v[0]===v[1]?y:j.min([y/2,this._sizeMin]),y]);c.domain(k);f.domain(x);u.forEach(function(e){e.x=c(e.fx);e.fx=e.x;e.y=f(e.fy);e.fy=e.y;e.r=m(e.r);e.width=e.r*2;e.height=e.r*2});var C=this._nodeLookup=u.reduce(function(e,t){e[t.id]=t;return e},{});var B=u.map(function(e){return e.node});var q=this._links.map(function(e){return{source:typeof e.source==="number"?u[B.indexOf(r._nodes[e.source])]:C[e.source.id],target:typeof e.target==="number"?u[B.indexOf(r._nodes[e.target])]:C[e.target.id]}});this._linkLookup=q.reduce(function(e,t){if(!e[t.source.id]){e[t.source.id]=[]}e[t.source.id].push(t.target);if(!e[t.target.id]){e[t.target.id]=[]}e[t.target.id].push(t.source);return e},{});this._container=this._select.selectAll("svg.d3plus-network").data([0]);this._container=this._container.enter().append("svg").attr("class","d3plus-network").attr("opacity",0).attr("width",o).attr("height",n).attr("x",this._margin.left).attr("y",this._margin.top).style("background-color","transparent").merge(this._container);this._container.transition(this._transition).attr("opacity",1).attr("width",o).attr("height",n).attr("x",this._margin.left).attr("y",this._margin.top);var L=this._container.selectAll("rect.d3plus-network-hitArea").data([0]);L.enter().append("rect").attr("class","d3plus-network-hitArea").merge(L).attr("width",o).attr("height",n).attr("fill","transparent").on("click",function(){if(r._focus){r.active(false);r._focus=undefined;r._zoomToBounds(null)}});this._zoomGroup=this._container.selectAll("g.d3plus-network-zoomGroup").data([0]);var A=this._zoomGroup=this._zoomGroup.enter().append("g").attr("class","d3plus-network-zoomGroup").merge(this._zoomGroup);this._shapes.push((new R.Path).config(this._shapeConfig).config(this._shapeConfig.Path).d(function(e){return"M"+e.source.x+","+e.source.y+" "+e.target.x+","+e.target.y}).data(q).select(I.elem("g.d3plus-network-links",{parent:A,transition:s,enter:{transform:i},update:{transform:i}}).node()).render());var P={label:function(e){return u.length<=r._labelCutoff||(r._hover&&r._hover(e)||r._active&&r._active(e))?r._drawLabel(e.data||e.node,e.i):false},select:I.elem("g.d3plus-network-nodes",{parent:A,transition:s,enter:{transform:i},update:{transform:i}}).node()};S.nest().key(function(e){return e.shape}).entries(u).forEach(function(e){r._shapes.push((new R[e.key]).config(I.configPrep.bind(r)(r._shapeConfig,"shape",e.key)).config(P).config(P[e.key]||{}).data(e.values).render())});return this};e.prototype.labelCutoff=function e(t){return arguments.length?(this._labelCutoff=t,this):this._labelCutoff};e.prototype.links=function e(t,n){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="links"});var r=[s.dataLoad.bind(this),t,n,"links"];if(i){this._queue[this._queue.indexOf(i)]=r}else{this._queue.push(r)}return this}return this._links};e.prototype.nodeGroupBy=function e(t){var n=this;if(!arguments.length){return this._nodeGroupBy}if(!(t instanceof Array)){t=[t]}return this._nodeGroupBy=t.map(function(e){if(typeof e==="function"){return e}else{if(!n._aggs[e]){n._aggs[e]=function(e){var t=Array.from(new Set(e));return t.length===1?t[0]:t}}return I.accessor(e)}}),this};e.prototype.nodes=function e(t,n){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="nodes"});var r=[s.dataLoad.bind(this),t,n,"nodes"];if(i){this._queue[this._queue.indexOf(i)]=r}else{this._queue.push(r)}return this}return this._nodes};e.prototype.size=function e(t){return arguments.length?(this._size=typeof t==="function"||!t?t:I.accessor(t),this):this._size};e.prototype.sizeMax=function e(t){return arguments.length?(this._sizeMax=t,this):this._sizeMax};e.prototype.sizeMin=function e(t){return arguments.length?(this._sizeMin=t,this):this._sizeMin};e.prototype.sizeScale=function e(t){return arguments.length?(this._sizeScale=t,this):this._sizeScale};e.prototype.x=function e(t){if(arguments.length){if(typeof t==="function"){this._x=t}else{this._x=I.accessor(t);if(!this._aggs[t]){this._aggs[t]=function(e){return j.mean(e)}}}return this}else{return this._x}};e.prototype.y=function e(t){if(arguments.length){if(typeof t==="function"){this._y=t}else{this._y=I.accessor(t);if(!this._aggs[t]){this._aggs[t]=function(e){return j.mean(e)}}}return this}else{return this._y}};return e}(s.Viz);var i=function(G){function e(){var u=this;G.call(this);this._labelCutoff=100;this._links=[];this._noDataMessage=false;this._nodes=[];this._on.mouseenter=function(){};this._on["mouseleave.shape"]=function(){u.hover(false)};var h=this._on["mousemove.shape"];this._on["mousemove.shape"]=function(e,t){h(e,t);if(u._focus&&u._focus===e.id){u.hover(false);u._on.mouseenter.bind(u)(e,t);u._focus=undefined}else{var n=u._nodeGroupBy&&u._nodeGroupBy[u._drawDepth](e,t)?u._nodeGroupBy[u._drawDepth](e,t):u._id(e,t),i=u._linkLookup[n],r=u._nodeLookup[n];var s=[r.id];var o=[r.x-r.r,r.x+r.r],a=[r.y-r.r,r.y+r.r];i.forEach(function(e){s.push(e.id);if(e.x-e.r<o[0]){o[0]=e.x-e.r}if(e.x+e.r>o[1]){o[1]=e.x+e.r}if(e.y-e.r<a[0]){a[0]=e.y-e.r}if(e.y+e.r>a[1]){a[1]=e.y+e.r}});u.hover(function(e,t){if(e.source&&e.target){return e.source.id===r.id||e.target.id===r.id}else{return s.includes(u._ids(e,t)[u._drawDepth])}})}};this._on["click.shape"]=function(e){u._center=e.id;u._draw()};this._sizeMin=5;this._sizeScale="sqrt";this._shape=I.constant("Circle");this._shapeConfig=I.assign(this._shapeConfig,{ariaLabel:function(e,t){var n=u._size?", "+u._size(e,t):"";return""+u._drawLabel(e,t)+n+"."},labelConfig:{duration:0,fontMin:1,fontResize:true,labelPadding:0,textAnchor:"middle",verticalAlign:"middle"},Path:{fill:"none",label:false,stroke:"#eee",strokeWidth:1}})}if(G)e.__proto__=G;e.prototype=Object.create(G&&G.prototype);e.prototype.constructor=e;e.prototype._draw=function e(t){var h=this;G.prototype._draw.call(this,t);var r=this._filteredData.reduce(function(e,t,n){e[h._id(t,n)]=t;return e},{});var d=this._nodes;if(!this._nodes.length&&this._links.length){var n=Array.from(new Set(this._links.reduce(function(e,t){return e.concat([t.source,t.target])},[])));d=n.map(function(e){return typeof e==="object"?e:{id:e}})}d=d.reduce(function(e,t,n){e[h._nodeGroupBy?h._nodeGroupBy[h._drawDepth](t,n):h._id(t,n)]=t;return e},{});d=Array.from(new Set(Object.keys(r).concat(Object.keys(d)))).map(function(e,t){var n=r[e],i=d[e];if(i===undefined){return false}return{__d3plus__:true,data:n||i,i:t,id:e,node:i,shape:n!==undefined&&h._shape(n)!==undefined?h._shape(n):h._shape(i)}}).filter(function(e){return e});var i=this._nodeLookup=d.reduce(function(e,t){e[t.id]=t;return e},{});var s=this._links.map(function(n){var e=["source","target"];return e.reduce(function(e,t){e[t]=typeof n[t]==="number"?d[n[t]]:i[n[t].id||n[t]];return e},{})});var o=s.reduce(function(e,t){if(!e[t.source.id]){e[t.source.id]=[]}e[t.source.id].push(t);if(!e[t.target.id]){e[t.target.id]=[]}e[t.target.id].push(t);return e},{});var c=this._height-this._margin.top-this._margin.bottom,a="translate("+this._margin.left+", "+this._margin.top+")",u=this._transition,f=this._width-this._margin.left-this._margin.right;var l=[],_=j.min([c,f])/2,p=_/3;var g=p,v=p*2;var y=i[this._center];y.x=f/2;y.y=c/2;y.r=this._sizeMin?j.max([this._sizeMin,g*.65]):this._sizeMax?j.min([this._sizeMax,g*.65]):g*.65;var m=[y],k=[];o[this._center].forEach(function(e){var t=e.source.id===h._center?e.target:e.source;t.edges=o[t.id].filter(function(e){return e.source.id!==h._center||e.target.id!==h._center});t.edge=e;m.push(t);k.push(t)});k.sort(function(e,t){return e.edges.length-t.edges.length});var x=[];var z=0;k.forEach(function(e){var r=e.id;e.edges=e.edges.filter(function(e){return!m.includes(e.source)&&e.target.id===r||!m.includes(e.target)&&e.source.id===r});z+=e.edges.length||1;e.edges.forEach(function(e){var t=e.source;var n=e.target;var i=n.id===r?t:n;m.push(i)})});var b=Math.PI*2;var M=0;k.forEach(function(s,e){var o=s.edges.length||1;var t=b/z*o;if(e===0){M-=t/2}var a=M+t/2-b/4;s.radians=a;s.x=f/2+g*Math.cos(a);s.y=c/2+g*Math.sin(a);M+=t;s.edges.forEach(function(e,t){var n=e.source.id===s.id?e.target:e.source;var i=b/z;var r=a-i*o/2+i/2+i*t;n.radians=r;n.x=f/2+v*Math.cos(r);n.y=c/2+v*Math.sin(r);x.push(n)})});var w=p/2;var C=p/4;var B=w/2-4;if(w/2-4<8){B=j.min([w/2,8])}var q=C/2-4;if(C/2-4<4){q=j.min([C/2,4])}if(q>p/10){q=p/10}if(q>B&&q>10){q=B*.75}if(B>q*1.5){B=q*1.5}B=Math.floor(B);q=Math.floor(q);var L;if(this._size){var A=j.extent(r,function(e){return e.size});if(A[0]===A[1]){A[0]=0}L=D.scaleLinear().domain(A).rangeRound([3,j.min([B,q])]);var P=y.size;y.r=L(P)}else{L=D.scaleLinear().domain([1,2]).rangeRound([B,q])}x.forEach(function(e){e.ring=2;var t=h._size?e.size:2;e.r=h._sizeMin?j.max([h._sizeMin,L(t)]):h._sizeMax?j.min([h._sizeMax,L(t)]):L(t)});k.forEach(function(e){e.ring=1;var t=h._size?e.size:1;e.r=h._sizeMin?j.max([h._sizeMin,L(t)]):h._sizeMax?j.min([h._sizeMax,L(t)]):L(t)});d=[y].concat(k).concat(x);k.forEach(function(u){var e=["source","target"];var n=u.edge;e.forEach(function(t){n[t]=d.find(function(e){return e.id===n[t].id})});l.push(n);o[u.id].forEach(function(i){var t=i.source.id===u.id?i.target:i.source;if(t.id!==y.id){var r=x.find(function(e){return e.id===t.id});if(!r){r=k.find(function(e){return e.id===t.id})}if(r){i.spline=true;var s=f/2;var o=c/2;var a=g+(v-g)*.5;var e=["source","target"];e.forEach(function(t,e){i[t+"X"]=i[t].x+Math.cos(i[t].ring===2?i[t].radians+Math.PI:i[t].radians)*i[t].r;i[t+"Y"]=i[t].y+Math.sin(i[t].ring===2?i[t].radians+Math.PI:i[t].radians)*i[t].r;i[t+"BisectX"]=s+a*Math.cos(i[t].radians);i[t+"BisectY"]=o+a*Math.sin(i[t].radians);i[t]=d.find(function(e){return e.id===i[t].id});if(i[t].edges===undefined){i[t].edges={}}var n=e===0?i.target.id:i.source.id;if(i[t].id===u.id){i[t].edges[n]={angle:u.radians+Math.PI,radius:p/2}}else{i[t].edges[n]={angle:r.radians,radius:p/2}}});l.push(i)}}})});d.forEach(function(e){if(e.id!==h._center){var t=h._shapeConfig.labelConfig.fontSize&&h._shapeConfig.labelConfig.fontSize(e)||11;var n=t*1.4;var i=n*2;var r=5;var s=p-e.r;var o=e.radians*(180/Math.PI);var a=e.r+r;var u="start";if(o<-90||o>90){a=-e.r-s-r;u="end";o+=180}e.labelBounds={x:a,y:-n/2,width:s,height:i};e.rotate=o;e.textAnchor=u}else{e.labelBounds={x:-g/2,y:-g/2,width:g,height:g}}});this._linkLookup=s.reduce(function(e,t){if(!e[t.source.id]){e[t.source.id]=[]}e[t.source.id].push(t.target);if(!e[t.target.id]){e[t.target.id]=[]}e[t.target.id].push(t.source);return e},{});this._shapes.push((new R.Path).config(I.configPrep.bind(this)(this._shapeConfig,"edge","Path")).id(function(e){return e.source.id+"_"+e.target.id}).d(function(e){return e.spline?"M"+e.sourceX+","+e.sourceY+"C"+e.sourceBisectX+","+e.sourceBisectY+" "+e.targetBisectX+","+e.targetBisectY+" "+e.targetX+","+e.targetY:"M"+e.source.x+","+e.source.y+" "+e.target.x+","+e.target.y}).data(l).select(I.elem("g.d3plus-rings-links",{parent:this._select,transition:u,enter:{transform:a},update:{transform:a}}).node()).render());var O=this;var E={label:function(e){return d.length<=h._labelCutoff||(h._hover&&h._hover(e)||h._active&&h._active(e))?h._drawLabel(e.data||e.node,e.i):false},labelBounds:function(e){return e.labelBounds},labelConfig:{fontColor:function(e){return e.data.id===h._center?I.configPrep.bind(O)(O._shapeConfig,"shape",e.key).labelConfig.fontColor(e):W.colorLegible(I.configPrep.bind(O)(O._shapeConfig,"shape",e.key).fill(e))},fontResize:function(e){return e.data.id===h._center},padding:0,textAnchor:function(e){return i[e.data.id].textAnchor||I.configPrep.bind(O)(O._shapeConfig,"shape",e.key).labelConfig.textAnchor},verticalAlign:function(e){return e.data.id===h._center?"middle":"top"}},rotate:function(e){return i[e.id].rotate||0},select:I.elem("g.d3plus-rings-nodes",{parent:this._select,transition:u,enter:{transform:a},update:{transform:a}}).node()};S.nest().key(function(e){return e.shape}).entries(d).forEach(function(e){h._shapes.push((new R[e.key]).config(I.configPrep.bind(h)(h._shapeConfig,"shape",e.key)).config(E).data(e.values).render())});return this};e.prototype.center=function e(t){return arguments.length?(this._center=t,this):this._center};e.prototype.hover=function e(t){this._hover=t;this._shapes.forEach(function(e){return e.hover(t)});if(this._legend){this._legendClass.hover(t)}return this};e.prototype.links=function e(t,n){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="links"});var r=[s.dataLoad.bind(this),t,n,"links"];if(i){this._queue[this._queue.indexOf(i)]=r}else{this._queue.push(r)}return this}return this._links};e.prototype.nodeGroupBy=function e(t){var n=this;if(!arguments.length){return this._nodeGroupBy}if(!(t instanceof Array)){t=[t]}return this._nodeGroupBy=t.map(function(e){if(typeof e==="function"){return e}else{if(!n._aggs[e]){n._aggs[e]=function(e){var t=Array.from(new Set(e));return t.length===1?t[0]:t}}return I.accessor(e)}}),this};e.prototype.nodes=function e(t,n){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="nodes"});var r=[s.dataLoad.bind(this),t,n,"nodes"];if(i){this._queue[this._queue.indexOf(i)]=r}else{this._queue.push(r)}return this}return this._nodes};e.prototype.size=function e(t){return arguments.length?(this._size=typeof t==="function"||!t?t:I.accessor(t),this):this._size};e.prototype.sizeMax=function e(t){return arguments.length?(this._sizeMax=t,this):this._sizeMax};e.prototype.sizeMin=function e(t){return arguments.length?(this._sizeMin=t,this):this._sizeMin};e.prototype.sizeScale=function e(t){return arguments.length?(this._sizeScale=t,this):this._sizeScale};return e}(s.Viz);var r={center:t.sankeyCenter,justify:t.sankeyJustify,left:t.sankeyLeft,right:t.sankeyRight};var o=function(h){function e(){var a=this;h.call(this);this._nodeId=I.accessor("id");this._links=I.accessor("links");this._noDataMessage=false;this._nodes=I.accessor("nodes");this._nodeAlign=r.justify;this._nodeWidth=30;this._on.mouseenter=function(){};this._on["mouseleave.shape"]=function(){a.hover(false)};var u=this._on["mousemove.shape"];this._on["mousemove.shape"]=function(e,t){u(e,t);if(a._focus&&a._focus===e.id){a.hover(false);a._on.mouseenter.bind(a)(e,t);a._focus=undefined}else{var n=a._nodeId(e,t),i=a._nodeLookup[n],r=Object.keys(a._nodeLookup).reduce(function(e,t){e[a._nodeLookup[t]]=!isNaN(t)?parseInt(t,10):t;return e},{});var s=a._linkLookup[i];var o=[n];s.forEach(function(e){o.push(r[e])});a.hover(function(e,t){if(e.source&&e.target){return e.source.id===n||e.target.id===n}else{return o.includes(a._nodeId(e,t))}})}};this._path=t.sankeyLinkHorizontal();this._sankey=t.sankey();this._shape=I.constant("Rect");this._shapeConfig=I.assign(this._shapeConfig,{Path:{fill:"none",hoverStyle:{"stroke-width":function(e){return Math.max(1,Math.abs(e.source.y1-e.source.y0)*(e.value/e.source.value)-2)}},label:false,stroke:"#DBDBDB",strokeOpacity:.5,strokeWidth:function(e){return Math.max(1,Math.abs(e.source.y1-e.source.y0)*(e.value/e.source.value)-2)}},Rect:{}});this._value=I.constant(1)}if(h)e.__proto__=h;e.prototype=Object.create(h&&h.prototype);e.prototype.constructor=e;e.prototype._draw=function e(t){var r=this;h.prototype._draw.call(this,t);var n=this._height-this._margin.top-this._margin.bottom,i=this._width-this._margin.left-this._margin.right;var s=this._nodes.map(function(e,t){return{__d3plus__:true,data:e,i:t,id:r._nodeId(e,t),node:e,shape:"Rect"}});var o=this._nodeLookup=s.reduce(function(e,t,n){e[t.id]=n;return e},{});var a=this._links.map(function(n,e){var t=["source","target"];var i=t.reduce(function(e,t){e[t]=typeof n[t]==="number"?o[n[t]]:o[n[t]];return e},{});return{source:i.source,target:i.target,value:r._value(n,e)}});this._linkLookup=a.reduce(function(e,t){if(!e[t.source]){e[t.source]=[]}e[t.source].push(t.target);if(!e[t.target]){e[t.target]=[]}e[t.target].push(t.source);return e},{});var u="translate("+this._margin.left+", "+this._margin.top+")";this._sankey.nodeAlign(this._nodeAlign).nodeWidth(this._nodeWidth).nodes(s).links(a).size([i,n])();this._shapes.push((new R.Path).config(this._shapeConfig.Path).data(a).d(this._path).select(I.elem("g.d3plus-Links",{parent:this._select,enter:{transform:u},update:{transform:u}}).node()).render());S.nest().key(function(e){return e.shape}).entries(s).forEach(function(e){r._shapes.push((new R[e.key]).data(e.values).height(function(e){return e.y1-e.y0}).width(function(e){return e.x1-e.x0}).x(function(e){return(e.x1+e.x0)/2}).y(function(e){return(e.y1+e.y0)/2}).select(I.elem("g.d3plus-sankey-nodes",{parent:r._select,enter:{transform:u},update:{transform:u}}).node()).config(I.configPrep.bind(r)(r._shapeConfig,"shape",e.key)).render())});return this};e.prototype.hover=function e(t){this._hover=t;this._shapes.forEach(function(e){return e.hover(t)});if(this._legend){this._legendClass.hover(t)}return this};e.prototype.links=function e(t,n){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="links"});var r=[s.dataLoad.bind(this),t,n,"links"];if(i){this._queue[this._queue.indexOf(i)]=r}else{this._queue.push(r)}return this}return this._links};e.prototype.nodeAlign=function e(t){return arguments.length?(this._nodeAlign=typeof t==="function"?t:r[t],this):this._nodeAlign};e.prototype.nodeId=function e(t){return arguments.length?(this._nodeId=typeof t==="function"?t:I.accessor(t),this):this._nodeId};e.prototype.nodes=function e(t,n){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="nodes"});var r=[s.dataLoad.bind(this),t,n,"nodes"];if(i){this._queue[this._queue.indexOf(i)]=r}else{this._queue.push(r)}return this}return this._nodes};e.prototype.nodeWidth=function e(t){return arguments.length?(this._nodeWidth=t,this):this._nodeWidth};e.prototype.value=function e(t){return arguments.length?(this._value=typeof t==="function"?t:I.accessor(t),this):this._value};return e}(s.Viz);e.Network=n;e.Rings=i;e.Sankey=o;Object.defineProperty(e,"__esModule",{value:true})}); |
@@ -437,7 +437,7 @@ /** | ||
labelConfig: { | ||
fontColor: function (d) { return d.data.data.id === this$1._center ? configPrep.bind(that)(that._shapeConfig, "shape", d.key).labelConfig.fontColor(d) : colorLegible(configPrep.bind(that)(that._shapeConfig, "shape", d.key).fill(d)); }, | ||
fontResize: function (d) { return d.data.data.id === this$1._center; }, | ||
fontColor: function (d) { return d.data.id === this$1._center ? configPrep.bind(that)(that._shapeConfig, "shape", d.key).labelConfig.fontColor(d) : colorLegible(configPrep.bind(that)(that._shapeConfig, "shape", d.key).fill(d)); }, | ||
fontResize: function (d) { return d.data.id === this$1._center; }, | ||
padding: 0, | ||
textAnchor: function (d) { return nodeLookup[d.data.data.id].textAnchor || configPrep.bind(that)(that._shapeConfig, "shape", d.key).labelConfig.textAnchor; }, | ||
verticalAlign: function (d) { return d.data.data.id === this$1._center ? "middle" : "top"; } | ||
textAnchor: function (d) { return nodeLookup[d.data.id].textAnchor || configPrep.bind(that)(that._shapeConfig, "shape", d.key).labelConfig.textAnchor; }, | ||
verticalAlign: function (d) { return d.data.id === this$1._center ? "middle" : "top"; } | ||
}, | ||
@@ -444,0 +444,0 @@ rotate: function (d) { return nodeLookup[d.id].rotate || 0; }, |
{ | ||
"name": "d3plus-network", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "Javascript network visualizations built upon d3 modules.", | ||
@@ -31,3 +31,3 @@ "main": "build/d3plus-network.js", | ||
"d3plus-common": "^0.6.35", | ||
"d3plus-shape": "^0.14.11", | ||
"d3plus-shape": "^0.16.0", | ||
"d3plus-viz": "^0.11.14" | ||
@@ -34,0 +34,0 @@ }, |
@@ -64,3 +64,3 @@ # d3plus-network | ||
* [Simple Sankey Diagram](http://d3plus.org/examples/d3plus-network/sankey-diagram/)<sup> ***New***</sup> | ||
* [Simple Sankey Diagram](http://d3plus.org/examples/d3plus-network/sankey-diagram/) | ||
* [Simple Rings](http://d3plus.org/examples/d3plus-network/simple-rings/) | ||
@@ -423,2 +423,2 @@ | ||
###### <sub>Documentation generated on Tue, 03 Jul 2018 18:19:56 GMT</sub> | ||
###### <sub>Documentation generated on Wed, 15 Aug 2018 14:55:02 GMT</sub> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
352301
2463
- Removedd3plus-shape@0.14.11(transitive)
Updatedd3plus-shape@^0.16.0