d3plus-network
Advanced tools
Comparing version 0.5.2 to 0.5.3
/* | ||
d3plus-network v0.5.2 | ||
d3plus-network v0.5.3 | ||
Javascript network visualizations built upon d3 modules. | ||
@@ -66,2 +66,143 @@ Copyright (c) 2019 D3plus - https://d3plus.org | ||
if (!String.prototype.includes) { | ||
Object.defineProperty(String.prototype, 'includes', { | ||
value: function(search, start) { | ||
if (typeof start !== 'number') { | ||
start = 0 | ||
} | ||
if (start + search.length > this.length) { | ||
return false | ||
} else { | ||
return this.indexOf(search, start) !== -1 | ||
} | ||
} | ||
}) | ||
} | ||
if (!Array.prototype.find) { | ||
Object.defineProperty(Array.prototype, 'find', { | ||
value: function(predicate) { | ||
// 1. Let O be ? ToObject(this value). | ||
if (this == null) { | ||
throw new TypeError('"this" is null or not defined'); | ||
} | ||
var o = Object(this); | ||
// 2. Let len be ? ToLength(? Get(O, "length")). | ||
var len = o.length >>> 0; | ||
// 3. If IsCallable(predicate) is false, throw a TypeError exception. | ||
if (typeof predicate !== 'function') { | ||
throw new TypeError('predicate must be a function'); | ||
} | ||
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined. | ||
var thisArg = arguments[1]; | ||
// 5. Let k be 0. | ||
var k = 0; | ||
// 6. Repeat, while k < len | ||
while (k < len) { | ||
// a. Let Pk be ! ToString(k). | ||
// b. Let kValue be ? Get(O, Pk). | ||
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). | ||
// d. If testResult is true, return kValue. | ||
var kValue = o[k]; | ||
if (predicate.call(thisArg, kValue, k, o)) { | ||
return kValue; | ||
} | ||
// e. Increase k by 1. | ||
k++; | ||
} | ||
// 7. Return undefined. | ||
return undefined; | ||
}, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} | ||
if (!String.prototype.startsWith) { | ||
Object.defineProperty(String.prototype, 'startsWith', { | ||
value: function(search, pos) { | ||
pos = !pos || pos < 0 ? 0 : +pos; | ||
return this.substring(pos, pos + search.length) === search; | ||
} | ||
}); | ||
} | ||
if (typeof window !== "undefined") { | ||
(function () { | ||
var serializeXML = function (node, output) { | ||
var nodeType = node.nodeType; | ||
if (nodeType === 3) { | ||
output.push(node.textContent.replace(/&/, '&').replace(/</, '<').replace('>', '>')); | ||
} else if (nodeType === 1) { | ||
output.push('<', node.tagName); | ||
if (node.hasAttributes()) { | ||
[].forEach.call(node.attributes, function(attrNode){ | ||
output.push(' ', attrNode.item.name, '=\'', attrNode.item.value, '\''); | ||
}) | ||
} | ||
if (node.hasChildNodes()) { | ||
output.push('>'); | ||
[].forEach.call(node.childNodes, function(childNode){ | ||
serializeXML(childNode, output); | ||
}) | ||
output.push('</', node.tagName, '>'); | ||
} else { | ||
output.push('/>'); | ||
} | ||
} else if (nodeType == 8) { | ||
output.push('<!--', node.nodeValue, '-->'); | ||
} | ||
} | ||
Object.defineProperty(SVGElement.prototype, 'innerHTML', { | ||
get: function () { | ||
var output = []; | ||
var childNode = this.firstChild; | ||
while (childNode) { | ||
serializeXML(childNode, output); | ||
childNode = childNode.nextSibling; | ||
} | ||
return output.join(''); | ||
}, | ||
set: function (markupText) { | ||
while (this.firstChild) { | ||
this.removeChild(this.firstChild); | ||
} | ||
try { | ||
var dXML = new DOMParser(); | ||
dXML.async = false; | ||
var sXML = '<svg xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\'>' + markupText + '</svg>'; | ||
var svgDocElement = dXML.parseFromString(sXML, 'text/xml').documentElement; | ||
var childNode = svgDocElement.firstChild; | ||
while (childNode) { | ||
this.appendChild(this.ownerDocument.importNode(childNode, true)); | ||
childNode = childNode.nextSibling; | ||
} | ||
} catch (e) {}; | ||
} | ||
}); | ||
Object.defineProperty(SVGElement.prototype, 'innerSVG', { | ||
get: function () { | ||
return this.innerHTML; | ||
}, | ||
set: function (markup) { | ||
this.innerHTML = markup; | ||
} | ||
}); | ||
})(); | ||
} | ||
(function (global, factory) { | ||
@@ -83,3 +224,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(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')) : | ||
*/ | ||
var Network = (function (Viz) { | ||
var Network = /*@__PURE__*/(function (Viz) { | ||
function Network() { | ||
@@ -604,3 +745,3 @@ var this$1 = this; | ||
*/ | ||
var Rings = (function (Viz) { | ||
var Rings = /*@__PURE__*/(function (Viz) { | ||
function Rings() { | ||
@@ -1022,7 +1163,7 @@ var this$1 = this; | ||
labelConfig: { | ||
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; }, | ||
fontColor: function (d) { return d.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.id === this$1._center; }, | ||
padding: 0, | ||
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"; } | ||
textAnchor: function (d) { return nodeLookup[d.id].textAnchor || d3plusCommon.configPrep.bind(that)(that._shapeConfig, "shape", d.key).labelConfig.textAnchor; }, | ||
verticalAlign: function (d) { return d.id === this$1._center ? "middle" : "top"; } | ||
}, | ||
@@ -1198,3 +1339,3 @@ rotate: function (d) { return nodeLookup[d.id].rotate || 0; }, | ||
*/ | ||
var Sankey = (function (Viz) { | ||
var Sankey = /*@__PURE__*/(function (Viz) { | ||
function Sankey() { | ||
@@ -1201,0 +1342,0 @@ var this$1 = this; |
/* | ||
d3plus-network v0.5.2 | ||
d3plus-network v0.5.3 | ||
Javascript network visualizations built upon d3 modules. | ||
@@ -7,2 +7,2 @@ Copyright (c) 2019 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 _=(h[1]-h[0])/(d[1]-d[0]),l=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 P=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:P,transition:s,enter:{transform:i},update:{transform:i}}).node()).render());var A={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:P,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(A).config(A[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=l/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 P=j.extent(r,function(e){return e.size});if(P[0]===P[1]){P[0]=0}L=D.scaleLinear().domain(P).rangeRound([3,j.min([B,q])]);var A=y.size;y.r=L(A)}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})});_.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}}});_.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(_).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._nodePadding=8;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).nodePadding(this._nodePadding).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.nodePadding=function e(t){return arguments.length?(this._nodePadding=t,this):this._nodePadding};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 o in r){if(Object.prototype.hasOwnProperty.call(r,o)){n[o]=r[o]}}}}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 o=n|0;var s=Math.max(o>=0?o:r-Math.abs(o),0);function a(e,t){return e===t||typeof e==="number"&&typeof t==="number"&&isNaN(e)&&isNaN(t)}while(s<r){if(a(i[s],t)){return true}s++}return false}})}if(!String.prototype.includes){Object.defineProperty(String.prototype,"includes",{value:function(e,t){if(typeof t!=="number"){t=0}if(t+e.length>this.length){return false}else{return this.indexOf(e,t)!==-1}}})}if(!Array.prototype.find){Object.defineProperty(Array.prototype,"find",{value:function(e){if(this==null){throw new TypeError('"this" is null or not defined')}var t=Object(this);var n=t.length>>>0;if(typeof e!=="function"){throw new TypeError("predicate must be a function")}var i=arguments[1];var r=0;while(r<n){var o=t[r];if(e.call(i,o,r,t)){return o}r++}return undefined},configurable:true,writable:true})}if(!String.prototype.startsWith){Object.defineProperty(String.prototype,"startsWith",{value:function(e,t){t=!t||t<0?0:+t;return this.substring(t,t+e.length)===e}})}if(typeof window!=="undefined"){(function(){var i=function(e,t){var n=e.nodeType;if(n===3){t.push(e.textContent.replace(/&/,"&").replace(/</,"<").replace(">",">"))}else if(n===1){t.push("<",e.tagName);if(e.hasAttributes()){[].forEach.call(e.attributes,function(e){t.push(" ",e.item.name,"='",e.item.value,"'")})}if(e.hasChildNodes()){t.push(">");[].forEach.call(e.childNodes,function(e){i(e,t)});t.push("</",e.tagName,">")}else{t.push("/>")}}else if(n==8){t.push("\x3c!--",e.nodeValue,"--\x3e")}};Object.defineProperty(SVGElement.prototype,"innerHTML",{get:function(){var e=[];var t=this.firstChild;while(t){i(t,e);t=t.nextSibling}return e.join("")},set:function(e){while(this.firstChild){this.removeChild(this.firstChild)}try{var t=new DOMParser;t.async=false;var n="<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>"+e+"</svg>";var i=t.parseFromString(n,"text/xml").documentElement;var r=i.firstChild;while(r){this.appendChild(this.ownerDocument.importNode(r,true));r=r.nextSibling}}catch(e){}}});Object.defineProperty(SVGElement.prototype,"innerSVG",{get:function(){return this.innerHTML},set:function(e){this.innerHTML=e}})})()}(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,G,D,f,T,I,o,N,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 o=[r.id];var s=[r.x-r.r,r.x+r.r],a=[r.y-r.r,r.y+r.r];i.forEach(function(e){o.push(e.id);if(e.x-e.r<s[0]){s[0]=e.x-e.r}if(e.x+e.r>s[1]){s[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 o.includes(h._ids(e,t)[h._drawDepth])}});h._focus=e.id;var u=f.zoomTransform(h._container.node());s=s.map(function(e){return e*u.k+u.x});a=a.map(function(e){return e*u.k+u.y});h._zoomToBounds([[s[0],a[0]],[s[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 o=[i];var s=[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){o.push(e.id);if(e.x-e.r<s[0]){s[0]=e.x-e.r}if(e.x+e.r>s[1]){s[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 o.includes(e.source.id)&&o.includes(e.target.id)}else{var n=h._ids(e,t);return o.includes(n[n.length-1])}});h._focus=n;var u=f.zoomTransform(h._container.node());s=s.map(function(e){return e*u.k+u.x});a=a.map(function(e){return e*u.k+u.y});h._zoomToBounds([[s[0],a[0]],[s[1],a[1]]])}h._on["mousemove.legend"].bind(h)(e,t)}};this._sizeMin=5;this._sizeScale="sqrt";this._shape=T.constant("Circle");this._shapeConfig=T.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=T.accessor("x");this._y=T.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+")",o=this._transition,s=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})),f=j.extent(u.map(function(e){return e.fy}));var d=D.scaleLinear().domain(h).range([0,s]),c=D.scaleLinear().domain(f).range([0,n]);var l=(h[1]-h[0])/(f[1]-f[0]),p=s/n;if(l>p){var _=n*p/l;c.range([(n-_)/2,n-(n-_)/2])}else{var g=s*l/p;d.range([(s-g)/2,s-(s-g)/2])}u.forEach(function(e){e.x=d(e.fx);e.y=c(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:I.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]),x=d.domain(),k=c.domain();var b=x[1]-x[0],z=k[1]-k[0];u.forEach(function(e){var t=m(e.r);if(x[0]>d.invert(e.x-t)){x[0]=d.invert(e.x-t)}if(x[1]<d.invert(e.x+t)){x[1]=d.invert(e.x+t)}if(k[0]>c.invert(e.y-t)){k[0]=c.invert(e.y-t)}if(k[1]<c.invert(e.y+t)){k[1]=c.invert(e.y+t)}});var w=x[1]-x[0],M=k[1]-k[0];y*=j.min([b/w,z/M]);m.range([v[0]===v[1]?y:j.min([y/2,this._sizeMin]),y]);d.domain(x);c.domain(k);u.forEach(function(e){e.x=d(e.fx);e.fx=e.x;e.y=c(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 P=u.map(function(e){return e.node});var L=this._links.map(function(e){return{source:typeof e.source==="number"?u[P.indexOf(r._nodes[e.source])]:C[e.source.id],target:typeof e.target==="number"?u[P.indexOf(r._nodes[e.target])]:C[e.target.id]}});this._linkLookup=L.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",s).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",s).attr("height",n).attr("x",this._margin.left).attr("y",this._margin.top);var B=this._container.selectAll("rect.d3plus-network-hitArea").data([0]);B.enter().append("rect").attr("class","d3plus-network-hitArea").merge(B).attr("width",s).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 q=this._zoomGroup=this._zoomGroup.enter().append("g").attr("class","d3plus-network-zoomGroup").merge(this._zoomGroup);this._shapes.push((new I.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(L).select(T.elem("g.d3plus-network-links",{parent:q,transition:o,enter:{transform:i},update:{transform:i}}).node()).render());var A={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:T.elem("g.d3plus-network-nodes",{parent:q,transition:o,enter:{transform:i},update:{transform:i}}).node()};G.nest().key(function(e){return e.shape}).entries(u).forEach(function(e){r._shapes.push((new I[e.key]).config(T.configPrep.bind(r)(r._shapeConfig,"shape",e.key)).config(A).config(A[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=[o.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 T.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=[o.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:T.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=T.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=T.accessor(t);if(!this._aggs[t]){this._aggs[t]=function(e){return j.mean(e)}}}return this}else{return this._y}};return e}(o.Viz);var i=function(S){function e(){var u=this;S.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 o=[r.id];var s=[r.x-r.r,r.x+r.r],a=[r.y-r.r,r.y+r.r];i.forEach(function(e){o.push(e.id);if(e.x-e.r<s[0]){s[0]=e.x-e.r}if(e.x+e.r>s[1]){s[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 o.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=T.constant("Circle");this._shapeConfig=T.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(S)e.__proto__=S;e.prototype=Object.create(S&&S.prototype);e.prototype.constructor=e;e.prototype._draw=function e(t){var h=this;S.prototype._draw.call(this,t);var r=this._filteredData.reduce(function(e,t,n){e[h._id(t,n)]=t;return e},{});var f=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])},[])));f=n.map(function(e){return typeof e==="object"?e:{id:e}})}f=f.reduce(function(e,t,n){e[h._nodeGroupBy?h._nodeGroupBy[h._drawDepth](t,n):h._id(t,n)]=t;return e},{});f=Array.from(new Set(Object.keys(r).concat(Object.keys(f)))).map(function(e,t){var n=r[e],i=f[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=f.reduce(function(e,t){e[t.id]=t;return e},{});var o=this._links.map(function(n){var e=["source","target"];return e.reduce(function(e,t){e[t]=typeof n[t]==="number"?f[n[t]]:i[n[t].id||n[t]];return e},{})});var s=o.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 d=this._height-this._margin.top-this._margin.bottom,a="translate("+this._margin.left+", "+this._margin.top+")",u=this._transition,c=this._width-this._margin.left-this._margin.right;var l=[],p=j.min([d,c])/2,_=p/3;var g=_,v=_*2;var y=i[this._center];y.x=c/2;y.y=d/2;y.r=this._sizeMin?j.max([this._sizeMin,g*.65]):this._sizeMax?j.min([this._sizeMax,g*.65]):g*.65;var m=[y],x=[];s[this._center].forEach(function(e){var t=e.source.id===h._center?e.target:e.source;t.edges=s[t.id].filter(function(e){return e.source.id!==h._center||e.target.id!==h._center});t.edge=e;m.push(t);x.push(t)});x.sort(function(e,t){return e.edges.length-t.edges.length});var k=[];var b=0;x.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});b+=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 z=Math.PI*2;var w=0;x.forEach(function(o,e){var s=o.edges.length||1;var t=z/b*s;if(e===0){w-=t/2}var a=w+t/2-z/4;o.radians=a;o.x=c/2+g*Math.cos(a);o.y=d/2+g*Math.sin(a);w+=t;o.edges.forEach(function(e,t){var n=e.source.id===o.id?e.target:e.source;var i=z/b;var r=a-i*s/2+i/2+i*t;n.radians=r;n.x=c/2+v*Math.cos(r);n.y=d/2+v*Math.sin(r);k.push(n)})});var M=_/2;var C=_/4;var P=M/2-4;if(M/2-4<8){P=j.min([M/2,8])}var L=C/2-4;if(C/2-4<4){L=j.min([C/2,4])}if(L>_/10){L=_/10}if(L>P&&L>10){L=P*.75}if(P>L*1.5){P=L*1.5}P=Math.floor(P);L=Math.floor(L);var B;if(this._size){var q=j.extent(r,function(e){return e.size});if(q[0]===q[1]){q[0]=0}B=D.scaleLinear().domain(q).rangeRound([3,j.min([P,L])]);var A=y.size;y.r=B(A)}else{B=D.scaleLinear().domain([1,2]).rangeRound([P,L])}k.forEach(function(e){e.ring=2;var t=h._size?e.size:2;e.r=h._sizeMin?j.max([h._sizeMin,B(t)]):h._sizeMax?j.min([h._sizeMax,B(t)]):B(t)});x.forEach(function(e){e.ring=1;var t=h._size?e.size:1;e.r=h._sizeMin?j.max([h._sizeMin,B(t)]):h._sizeMax?j.min([h._sizeMax,B(t)]):B(t)});f=[y].concat(x).concat(k);x.forEach(function(u){var e=["source","target"];var n=u.edge;e.forEach(function(t){n[t]=f.find(function(e){return e.id===n[t].id})});l.push(n);s[u.id].forEach(function(i){var t=i.source.id===u.id?i.target:i.source;if(t.id!==y.id){var r=k.find(function(e){return e.id===t.id});if(!r){r=x.find(function(e){return e.id===t.id})}if(r){i.spline=true;var o=c/2;var s=d/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"]=o+a*Math.cos(i[t].radians);i[t+"BisectY"]=s+a*Math.sin(i[t].radians);i[t]=f.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:_/2}}else{i[t].edges[n]={angle:r.radians,radius:_/2}}});l.push(i)}}})});f.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 o=_-e.r;var s=e.radians*(180/Math.PI);var a=e.r+r;var u="start";if(s<-90||s>90){a=-e.r-o-r;u="end";s+=180}e.labelBounds={x:a,y:-n/2,width:o,height:i};e.rotate=s;e.textAnchor=u}else{e.labelBounds={x:-g/2,y:-g/2,width:g,height:g}}});this._linkLookup=o.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 I.Path).config(T.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(T.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 f.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.id===h._center?T.configPrep.bind(O)(O._shapeConfig,"shape",e.key).labelConfig.fontColor(e):N.colorLegible(T.configPrep.bind(O)(O._shapeConfig,"shape",e.key).fill(e))},fontResize:function(e){return e.id===h._center},padding:0,textAnchor:function(e){return i[e.id].textAnchor||T.configPrep.bind(O)(O._shapeConfig,"shape",e.key).labelConfig.textAnchor},verticalAlign:function(e){return e.id===h._center?"middle":"top"}},rotate:function(e){return i[e.id].rotate||0},select:T.elem("g.d3plus-rings-nodes",{parent:this._select,transition:u,enter:{transform:a},update:{transform:a}}).node()};G.nest().key(function(e){return e.shape}).entries(f).forEach(function(e){h._shapes.push((new I[e.key]).config(T.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=[o.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 T.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=[o.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:T.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}(o.Viz);var r={center:t.sankeyCenter,justify:t.sankeyJustify,left:t.sankeyLeft,right:t.sankeyRight};var s=function(h){function e(){var a=this;h.call(this);this._nodeId=T.accessor("id");this._links=T.accessor("links");this._noDataMessage=false;this._nodes=T.accessor("nodes");this._nodeAlign=r.justify;this._nodePadding=8;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 o=a._linkLookup[i];var s=[n];o.forEach(function(e){s.push(r[e])});a.hover(function(e,t){if(e.source&&e.target){return e.source.id===n||e.target.id===n}else{return s.includes(a._nodeId(e,t))}})}};this._path=t.sankeyLinkHorizontal();this._sankey=t.sankey();this._shape=T.constant("Rect");this._shapeConfig=T.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=T.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 o=this._nodes.map(function(e,t){return{__d3plus__:true,data:e,i:t,id:r._nodeId(e,t),node:e,shape:"Rect"}});var s=this._nodeLookup=o.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"?s[n[t]]:s[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).nodePadding(this._nodePadding).nodeWidth(this._nodeWidth).nodes(o).links(a).size([i,n])();this._shapes.push((new I.Path).config(this._shapeConfig.Path).data(a).d(this._path).select(T.elem("g.d3plus-Links",{parent:this._select,enter:{transform:u},update:{transform:u}}).node()).render());G.nest().key(function(e){return e.shape}).entries(o).forEach(function(e){r._shapes.push((new I[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(T.elem("g.d3plus-sankey-nodes",{parent:r._select,enter:{transform:u},update:{transform:u}}).node()).config(T.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=[o.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:T.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=[o.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.nodePadding=function e(t){return arguments.length?(this._nodePadding=t,this):this._nodePadding};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:T.accessor(t),this):this._value};return e}(o.Viz);e.Network=n;e.Rings=i;e.Sankey=s;Object.defineProperty(e,"__esModule",{value:true})}); |
@@ -21,3 +21,3 @@ /** | ||
*/ | ||
var Network = (function (Viz) { | ||
var Network = /*@__PURE__*/(function (Viz) { | ||
function Network() { | ||
@@ -24,0 +24,0 @@ var this$1 = this; |
@@ -20,3 +20,3 @@ /** | ||
*/ | ||
var Rings = (function (Viz) { | ||
var Rings = /*@__PURE__*/(function (Viz) { | ||
function Rings() { | ||
@@ -438,7 +438,7 @@ var this$1 = this; | ||
labelConfig: { | ||
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; }, | ||
fontColor: function (d) { return d.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.id === this$1._center; }, | ||
padding: 0, | ||
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"; } | ||
textAnchor: function (d) { return nodeLookup[d.id].textAnchor || configPrep.bind(that)(that._shapeConfig, "shape", d.key).labelConfig.textAnchor; }, | ||
verticalAlign: function (d) { return d.id === this$1._center ? "middle" : "top"; } | ||
}, | ||
@@ -445,0 +445,0 @@ rotate: function (d) { return nodeLookup[d.id].rotate || 0; }, |
@@ -32,3 +32,3 @@ /** | ||
*/ | ||
var Sankey = (function (Viz) { | ||
var Sankey = /*@__PURE__*/(function (Viz) { | ||
function Sankey() { | ||
@@ -35,0 +35,0 @@ var this$1 = this; |
{ | ||
"name": "d3plus-network", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "Javascript network visualizations built upon d3 modules.", | ||
@@ -30,5 +30,5 @@ "main": "build/d3plus-network.js", | ||
"d3-scale": "^2.1.2", | ||
"d3plus-common": "^0.6.43", | ||
"d3plus-shape": "^0.16.0", | ||
"d3plus-viz": "^0.12.3" | ||
"d3plus-common": "^0.6.45", | ||
"d3plus-shape": "^0.16.2", | ||
"d3plus-viz": "^0.12.10" | ||
}, | ||
@@ -45,3 +45,3 @@ "scripts": { | ||
"devDependencies": { | ||
"d3plus-dev": "^0.6.9" | ||
"d3plus-dev": "^0.6.18" | ||
}, | ||
@@ -48,0 +48,0 @@ "module": "es/index", |
@@ -431,2 +431,2 @@ # d3plus-network | ||
###### <sub>Documentation generated on Thu, 03 Jan 2019 22:53:59 GMT</sub> | ||
###### <sub>Documentation generated on Fri, 01 Mar 2019 17:59:26 GMT</sub> |
Sorry, the diff of this file is not supported yet
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
361488
2608
Updatedd3plus-common@^0.6.45
Updatedd3plus-shape@^0.16.2
Updatedd3plus-viz@^0.12.10