d3plus-network
Advanced tools
Comparing version 0.3.1 to 0.4.0
/* | ||
d3plus-network v0.3.1 | ||
d3plus-network v0.4.0 | ||
Javascript network visualizations built upon d3 modules. | ||
@@ -67,6 +67,6 @@ Copyright (c) 2018 D3plus - https://d3plus.org | ||
(function (global, factory) { | ||
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')) : | ||
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'], factory) : | ||
(factory((global.d3plus = {}),global.d3Array,global.d3Collection,global.scales,global.d3Zoom,global.d3plusCommon,global.shapes,global.d3plusViz,global.d3plusColor)); | ||
}(this, (function (exports,d3Array,d3Collection,scales,d3Zoom,d3plusCommon,shapes,d3plusViz,d3plusColor) { 'use strict'; | ||
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')) : | ||
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'], factory) : | ||
(factory((global.d3plus = {}),global.d3Array,global.d3Collection,global.scales,global.d3Zoom,global.d3plusCommon,global.shapes,global.d3plusViz,global.d3plusColor,global.d3Sankey)); | ||
}(this, (function (exports,d3Array,d3Collection,scales,d3Zoom,d3plusCommon,shapes,d3plusViz,d3plusColor,d3Sankey) { 'use strict'; | ||
@@ -1176,4 +1176,281 @@ /** | ||
/** | ||
@external Viz | ||
@see https://github.com/d3plus/d3plus-viz#Viz | ||
*/ | ||
/** | ||
@class Sankey | ||
@extends external:Viz | ||
@desc Creates a sankey visualization based on a defined set of nodes and links. [Click here](http://d3plus.org/examples/d3plus-network/sankey-diagram/) for help getting started using the Sankey class. | ||
*/ | ||
var Sankey = (function (Viz) { | ||
function Sankey() { | ||
var this$1 = this; | ||
Viz.call(this); | ||
this._nodeId = d3plusCommon.accessor("id"); | ||
this._links = d3plusCommon.accessor("links"); | ||
this._noDataMessage = false; | ||
this._nodes = d3plusCommon.accessor("nodes"); | ||
this._nodeWidth = 30; | ||
this._on.mouseenter = function () {}; | ||
this._on["mouseleave.shape"] = function () { | ||
this$1.hover(false); | ||
}; | ||
this._on["mousemove.shape"] = function (d, i) { | ||
if (this$1._focus && this$1._focus === d.id) { | ||
this$1.hover(false); | ||
this$1._on.mouseenter.bind(this$1)(d, i); | ||
this$1._focus = undefined; | ||
} | ||
else { | ||
var id = this$1._nodeId(d, i), | ||
node = this$1._nodeLookup[id], | ||
nodeLookup = Object.keys(this$1._nodeLookup).reduce(function (all, item) { | ||
all[this$1._nodeLookup[item]] = !isNaN(item) ? parseInt(item, 10) : item; | ||
return all; | ||
}, {}); | ||
var links = this$1._linkLookup[node]; | ||
var filterIds = [id]; | ||
links.forEach(function (l) { | ||
filterIds.push(nodeLookup[l]); | ||
}); | ||
this$1.hover(function (h, x) { | ||
if (h.source && h.target) { | ||
return h.source.id === id || h.target.id === id; | ||
} | ||
else { | ||
return filterIds.includes(this$1._nodeId(h, x)); | ||
} | ||
}); | ||
} | ||
}; | ||
this._path = d3Sankey.sankeyLinkHorizontal(); | ||
this._sankey = d3Sankey.sankey(); | ||
this._shape = d3plusCommon.constant("Rect"); | ||
this._shapeConfig = d3plusCommon.assign(this._shapeConfig, { | ||
Path: { | ||
fill: "none", | ||
hoverStyle: { | ||
"stroke-width": function (d, i) { return Math.max(1, Math.abs(d.source.y1 - d.source.y0) * (this$1._value(d, i) / d.source.value) - 20); } | ||
}, | ||
label: false, | ||
stroke: "#DBDBDB", | ||
strokeOpacity: 0.2, | ||
strokeWidth: function (d, i) { return Math.max(1, Math.abs(d.source.y1 - d.source.y0) * (this$1._value(d, i) / d.source.value) - 20); } | ||
}, | ||
Rect: {} | ||
}); | ||
this._value = d3plusCommon.constant(1); | ||
} | ||
if ( Viz ) Sankey.__proto__ = Viz; | ||
Sankey.prototype = Object.create( Viz && Viz.prototype ); | ||
Sankey.prototype.constructor = Sankey; | ||
/** | ||
Extends the draw behavior of the abstract Viz class. | ||
@private | ||
*/ | ||
Sankey.prototype._draw = function _draw (callback) { | ||
var this$1 = this; | ||
Viz.prototype._draw.call(this, callback); | ||
var height = this._height - this._margin.top - this._margin.bottom, | ||
width = this._width - this._margin.left - this._margin.right; | ||
var nodes = this._nodes | ||
.map(function (id, i) { | ||
var n = id; | ||
return { | ||
__d3plus__: true, | ||
data: n, | ||
id: this$1._nodeId(id, i), | ||
node: n, | ||
shape: "Rect" | ||
}; | ||
}) | ||
.filter(function (n) { return n; }); | ||
var nodeLookup = this._nodeLookup = nodes.reduce(function (obj, d, i) { | ||
obj[d.id] = i; | ||
return obj; | ||
}, {}); | ||
var links = this._links.map(function (link, i) { | ||
var check = ["source", "target"]; | ||
var linkLookup = check.reduce(function (result, item) { | ||
result[item] = | ||
typeof link[item] === "number" | ||
? nodeLookup[link[item]] | ||
: nodeLookup[link[item]]; | ||
return result; | ||
}, {}); | ||
return { | ||
source: linkLookup.source, | ||
target: linkLookup.target, | ||
value: this$1._value(link, i) | ||
}; | ||
}); | ||
this._linkLookup = links.reduce(function (obj, d) { | ||
if (!obj[d.source]) { obj[d.source] = []; } | ||
obj[d.source].push(d.target); | ||
if (!obj[d.target]) { obj[d.target] = []; } | ||
obj[d.target].push(d.source); | ||
return obj; | ||
}, {}); | ||
var transform = "translate(" + (this._margin.left) + ", " + (this._margin.top) + ")"; | ||
this._sankey | ||
.nodeWidth(this._nodeWidth) | ||
.nodes(nodes) | ||
.links(links) | ||
.size([width, height])(); | ||
this._shapes.push( | ||
new shapes.Path() | ||
.config(this._shapeConfig.Path) | ||
.data(links) | ||
.d(this._path) | ||
.select( | ||
d3plusCommon.elem("g.d3plus-Links", { | ||
parent: this._select, | ||
enter: {transform: transform}, | ||
update: {transform: transform} | ||
}).node() | ||
) | ||
.render() | ||
); | ||
d3Collection.nest() | ||
.key(function (d) { return d.shape; }) | ||
.entries(nodes) | ||
.forEach(function (d) { | ||
this$1._shapes.push( | ||
new shapes[d.key]() | ||
.data(d.values) | ||
.height(function (d) { return d.y1 - d.y0; }) | ||
.width(function (d) { return d.x1 - d.x0; }) | ||
.x(function (d) { return (d.x1 + d.x0) / 2; }) | ||
.y(function (d) { return (d.y1 + d.y0) / 2; }) | ||
.select( | ||
d3plusCommon.elem("g.d3plus-sankey-nodes", { | ||
parent: this$1._select, | ||
enter: {transform: transform}, | ||
update: {transform: transform} | ||
}).node() | ||
) | ||
.config(d3plusCommon.configPrep.bind(this$1)(this$1._shapeConfig, "shape", d.key)) | ||
.render() | ||
); | ||
}); | ||
return this; | ||
}; | ||
/** | ||
@memberof Sankey | ||
@desc If *value* is specified, sets the hover method to the specified function and returns the current class instance. | ||
@param {Function} [*value*] | ||
@chainable | ||
*/ | ||
Sankey.prototype.hover = function hover (_) { | ||
this._hover = _; | ||
this._shapes.forEach(function (s) { return s.hover(_); }); | ||
if (this._legend) { this._legendClass.hover(_); } | ||
return this; | ||
}; | ||
/** | ||
@memberof Sankey | ||
@desc A predefined *Array* of edges that connect each object passed to the [node](#Sankey.node) method. The `source` and `target` keys in each link need to map to the nodes in one of one way: | ||
1. A *String* value matching the `id` of the node. | ||
The value passed should be an *Array* of data. An optional formatting function can be passed as a second argument to this method. This custom function will be passed the data that has been loaded, as long as there are no errors. This function should return the final links *Array*. | ||
@param {Array} *links* = [] | ||
@chainable | ||
*/ | ||
Sankey.prototype.links = function links (_, f) { | ||
if (arguments.length) { | ||
var prev = this._queue.find(function (q) { return q[3] === "links"; }); | ||
var d = [d3plusViz.dataLoad.bind(this), _, f, "links"]; | ||
if (prev) { this._queue[this._queue.indexOf(prev)] = d; } | ||
else { this._queue.push(d); } | ||
return this; | ||
} | ||
return this._links; | ||
}; | ||
/** | ||
@memberof Sankey | ||
@desc If *value* is specified, sets the node id accessor(s) to the specified array of values and returns the current class instance. If *value* is not specified, returns the current node group accessor. | ||
@param {String} [*value* = "id"] | ||
@chainable | ||
*/ | ||
Sankey.prototype.nodeId = function nodeId (_) { | ||
return arguments.length | ||
? (this._nodeId = typeof _ === "function" ? _ : d3plusCommon.accessor(_), this) | ||
: this._nodeId; | ||
}; | ||
/** | ||
@memberof Sankey | ||
@desc The list of nodes to be used for drawing the network. The value passed must be an *Array* of data. | ||
Additionally, a custom formatting function can be passed as a second argument to this method. This custom function will be passed the data that has been loaded, as long as there are no errors. This function should return the final node *Array*. | ||
@param {Array} *nodes* = [] | ||
@chainable | ||
*/ | ||
Sankey.prototype.nodes = function nodes (_, f) { | ||
if (arguments.length) { | ||
var prev = this._queue.find(function (q) { return q[3] === "nodes"; }); | ||
var d = [d3plusViz.dataLoad.bind(this), _, f, "nodes"]; | ||
if (prev) { this._queue[this._queue.indexOf(prev)] = d; } | ||
else { this._queue.push(d); } | ||
return this; | ||
} | ||
return this._nodes; | ||
}; | ||
/** | ||
@memberof Sankey | ||
@desc If *value* is specified, sets the width of the node and returns the current class instance. If *value* is not specified, returns the current nodeWidth. By default, the nodeWidth size is 30. | ||
@param {Number} [*value* = 30] | ||
@chainable | ||
*/ | ||
Sankey.prototype.nodeWidth = function nodeWidth (_) { | ||
return arguments.length ? (this._nodeWidth = _, this) : this._nodeWidth; | ||
}; | ||
/** | ||
@memberof Sankey | ||
@desc If *value* is specified, sets the width of the links and returns the current class instance. If *value* is not specified, returns the current value accessor. | ||
@param {Function|Number} *value* | ||
@example | ||
function value(d) { | ||
return d.value; | ||
} | ||
*/ | ||
Sankey.prototype.value = function value (_) { | ||
return arguments.length | ||
? (this._value = typeof _ === "function" ? _ : d3plusCommon.accessor(_), this) | ||
: this._value; | ||
}; | ||
return Sankey; | ||
}(d3plusViz.Viz)); | ||
exports.Network = Network; | ||
exports.Rings = Rings; | ||
exports.Sankey = Sankey; | ||
@@ -1180,0 +1457,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
/* | ||
d3plus-network v0.3.1 | ||
d3plus-network v0.4.0 | ||
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 r=Object(t);for(var i=1;i<arguments.length;i++){var n=arguments[i];if(n!==null){for(var o in n){if(Object.prototype.hasOwnProperty.call(n,o)){r[o]=n[o]}}}}return r},writable:true,configurable:true})}if(!Array.prototype.includes){Object.defineProperty(Array.prototype,"includes",{value:function e(t,r){var i=Object(this);var n=i.length>>>0;if(n===0)return false;var o=r|0;var s=Math.max(o>=0?o:n-Math.abs(o),0);function a(e,t){return e===t||typeof e==="number"&&typeof t==="number"&&isNaN(e)&&isNaN(t)}while(s<n){if(a(i[s],t)){return true}s++}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")):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"],t):t(e.d3plus={},e.d3Array,e.d3Collection,e.scales,e.d3Zoom,e.d3plusCommon,e.shapes,e.d3plusViz,e.d3plusColor)})(this,function(e,j,S,D,d,T,R,o,X){"use strict";var t=function(E){function e(){var f=this;E.call(this);this._labelCutoff=100;this._links=[];this._noDataMessage=false;this._nodes=[];this._on["click.shape"]=function(e,t){f._tooltipClass.data([]).render();if(f._hover&&f._drawDepth>=f._groupBy.length-1){if(f._focus&&f._focus===e.id){f.active(false);f._on.mouseenter.bind(f)(e,t);f._focus=undefined;f._zoomToBounds(null)}else{f.hover(false);var r=f._nodeGroupBy&&f._nodeGroupBy[f._drawDepth](e,t)?f._nodeGroupBy[f._drawDepth](e,t):f._id(e,t),i=f._linkLookup[r],n=f._nodeLookup[r];var o=[n.id];var s=[n.x-n.r,n.x+n.r],a=[n.y-n.r,n.y+n.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}});f.active(function(e,t){if(e.source&&e.target){return e.source.id===n.id||e.target.id===n.id}else{return o.includes(f._ids(e,t)[f._drawDepth])}});f._focus=e.id;var u=d.zoomTransform(f._container.node());s=s.map(function(e){return e*u.k+u.x});a=a.map(function(e){return e*u.k+u.y});f._zoomToBounds([[s[0],a[0]],[s[1],a[1]]])}}};this._on["click.legend"]=function(e,t){var r=f._id(e);var i=f._ids(e);i=i[i.length-1];if(f._hover&&f._drawDepth>=f._groupBy.length-1){if(f._focus&&f._focus===r){f.active(false);f._on.mouseenter.bind(f)(e,t);f._focus=undefined;f._zoomToBounds(null)}else{f.hover(false);var n=r.map(function(e){return f._nodeLookup[e]});var o=[i];var s=[n[0].x-n[0].r,n[0].x+n[0].r],a=[n[0].y-n[0].r,n[0].y+n[0].r];n.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}});f.active(function(e,t){if(e.source&&e.target){return o.includes(e.source.id)&&o.includes(e.target.id)}else{var r=f._ids(e,t);return o.includes(r[r.length-1])}});f._focus=r;var u=d.zoomTransform(f._container.node());s=s.map(function(e){return e*u.k+u.x});a=a.map(function(e){return e*u.k+u.y});f._zoomToBounds([[s[0],a[0]],[s[1],a[1]]])}f._on["mousemove.legend"].bind(f)(e,t)}};this._sizeMin=5;this._sizeScale="sqrt";this._shape=T.constant("Circle");this._shapeConfig=T.assign(this._shapeConfig,{ariaLabel:function(e,t){var r=f._size?", "+f._size(e,t):"";return""+f._drawLabel(e,t)+r+"."},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(E)e.__proto__=E;e.prototype=Object.create(E&&E.prototype);e.prototype.constructor=e;e.prototype._draw=function e(t){var n=this;E.prototype._draw.call(this,t);var r=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,r){e[n._id(t,r)]=t;return e},{});var u=this._nodes.reduce(function(e,t,r){e[n._nodeGroupBy?n._nodeGroupBy[n._drawDepth](t,r):n._id(t,r)]=t;return e},{});u=Array.from(new Set(Object.keys(a).concat(Object.keys(u)))).map(function(e,t){var r=a[e],i=u[e];if(i===undefined){return false}return{__d3plus__:true,data:r||i,i:t,id:e,fx:r!==undefined&&n._x(r)!==undefined?n._x(r):n._x(i),fy:r!==undefined&&n._y(r)!==undefined?n._y(r):n._y(i),node:i,r:n._size?r!==undefined&&n._size(r)!==undefined?n._size(r):n._size(i):n._sizeMin,shape:r!==undefined&&n._shape(r)!==undefined?n._shape(r):n._shape(i)}}).filter(function(e){return e});var f=j.extent(u.map(function(e){return e.fx})),d=j.extent(u.map(function(e){return e.fy}));var c=D.scaleLinear().domain(f).range([0,s]),h=D.scaleLinear().domain(d).range([0,r]);var l=(f[1]-f[0])/(d[1]-d[0]),_=s/r;if(l>_){var p=r*_/l;h.range([(r-p)/2,r-(r-p)/2])}else{var g=s*l/_;c.range([(s-g)/2,s-(s-g)/2])}u.forEach(function(e){e.x=c(e.fx);e.y=h(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]),x=c.domain(),z=h.domain();var b=x[1]-x[0],k=z[1]-z[0];u.forEach(function(e){var t=m(e.r);if(x[0]>c.invert(e.x-t)){x[0]=c.invert(e.x-t)}if(x[1]<c.invert(e.x+t)){x[1]=c.invert(e.x+t)}if(z[0]>h.invert(e.y-t)){z[0]=h.invert(e.y-t)}if(z[1]<h.invert(e.y+t)){z[1]=h.invert(e.y+t)}});var M=x[1]-x[0],w=z[1]-z[0];y*=j.min([b/M,k/w]);m.range([v[0]===v[1]?y:j.min([y/2,this._sizeMin]),y]);c.domain(x);h.domain(z);u.forEach(function(e){e.x=c(e.fx);e.fx=e.x;e.y=h(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(n._nodes[e.source])]:C[e.source.id],target:typeof e.target==="number"?u[B.indexOf(n._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",s).attr("height",r).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",r).attr("x",this._margin.left).attr("y",this._margin.top);var A=this._container.selectAll("rect.d3plus-network-hitArea").data([0]);A.enter().append("rect").attr("class","d3plus-network-hitArea").merge(A).attr("width",s).attr("height",r).attr("fill","transparent").on("click",function(){if(n._focus){n.active(false);n._focus=undefined;n._zoomToBounds(null)}});this._zoomGroup=this._container.selectAll("g.d3plus-network-zoomGroup").data([0]);var L=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(T.elem("g.d3plus-network-links",{parent:L,transition:o,enter:{transform:i},update:{transform:i}}).node()).render());var P={label:function(e){return u.length<=n._labelCutoff||(n._hover&&n._hover(e)||n._active&&n._active(e))?n._drawLabel(e.data||e.node,e.i):false},select:T.elem("g.d3plus-network-nodes",{parent:L,transition:o,enter:{transform:i},update:{transform:i}}).node()};S.nest().key(function(e){return e.shape}).entries(u).forEach(function(e){n._shapes.push((new R[e.key]).config(T.configPrep.bind(n)(n._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,r){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="links"});var n=[o.dataLoad.bind(this),t,r,"links"];if(i){this._queue[this._queue.indexOf(i)]=n}else{this._queue.push(n)}return this}return this._links};e.prototype.nodeGroupBy=function e(t){var r=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(!r._aggs[e]){r._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,r){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="nodes"});var n=[o.dataLoad.bind(this),t,r,"nodes"];if(i){this._queue[this._queue.indexOf(i)]=n}else{this._queue.push(n)}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 r=function(O){function e(){var u=this;O.call(this);this._labelCutoff=100;this._links=[];this._noDataMessage=false;this._nodes=[];this._on.mouseenter=function(){};this._on["mouseleave.shape"]=function(){u.hover(false)};this._on["mousemove.shape"]=function(e,t){if(u._focus&&u._focus===e.id){u.hover(false);u._on.mouseenter.bind(u)(e,t);u._focus=undefined}else{var r=u._nodeGroupBy&&u._nodeGroupBy[u._drawDepth](e,t)?u._nodeGroupBy[u._drawDepth](e,t):u._id(e,t),i=u._linkLookup[r],n=u._nodeLookup[r];var o=[n.id];var s=[n.x-n.r,n.x+n.r],a=[n.y-n.r,n.y+n.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===n.id||e.target.id===n.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 r=u._size?", "+u._size(e,t):"";return""+u._drawLabel(e,t)+r+"."},labelConfig:{duration:0,fontMin:1,fontResize:true,labelPadding:0,textAnchor:"middle",verticalAlign:"middle"},Path:{fill:"none",label:false,stroke:"#eee",strokeWidth:1}})}if(O)e.__proto__=O;e.prototype=Object.create(O&&O.prototype);e.prototype.constructor=e;e.prototype._draw=function e(t){var f=this;O.prototype._draw.call(this,t);var n=this._filteredData.reduce(function(e,t,r){e[f._id(t,r)]=t;return e},{});var d=this._nodes;if(!this._nodes.length&&this._links.length){var r=Array.from(new Set(this._links.reduce(function(e,t){return e.concat([t.source,t.target])},[])));d=r.map(function(e){return typeof e==="object"?e:{id:e}})}d=d.reduce(function(e,t,r){e[f._nodeGroupBy?f._nodeGroupBy[f._drawDepth](t,r):f._id(t,r)]=t;return e},{});d=Array.from(new Set(Object.keys(n).concat(Object.keys(d)))).map(function(e,t){var r=n[e],i=d[e];if(i===undefined){return false}return{__d3plus__:true,data:r||i,i:t,id:e,node:i,shape:r!==undefined&&f._shape(r)!==undefined?f._shape(r):f._shape(i)}}).filter(function(e){return e});var i=this._nodeLookup=d.reduce(function(e,t){e[t.id]=t;return e},{});var o=this._links.map(function(r){var e=["source","target"];return e.reduce(function(e,t){e[t]=typeof r[t]==="number"?d[r[t]]:i[r[t].id||r[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 c=this._height-this._margin.top-this._margin.bottom,a="translate("+this._margin.left+", "+this._margin.top+")",u=this._transition,h=this._width-this._margin.left-this._margin.right;var l=[],_=j.min([c,h])/2,p=_/3;var g=p,v=p*2;var y=i[this._center];y.x=h/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],x=[];s[this._center].forEach(function(e){var t=e.source.id===f._center?e.target:e.source;t.edges=s[t.id].filter(function(e){return e.source.id!==f._center||e.target.id!==f._center});t.edge=e;m.push(t);x.push(t)});x.sort(function(e,t){return e.edges.length-t.edges.length});var z=[];var b=0;x.forEach(function(e){var n=e.id;e.edges=e.edges.filter(function(e){return!m.includes(e.source)&&e.target.id===n||!m.includes(e.target)&&e.source.id===n});b+=e.edges.length||1;e.edges.forEach(function(e){var t=e.source;var r=e.target;var i=r.id===n?t:r;m.push(i)})});var k=Math.PI*2;var M=0;x.forEach(function(o,e){var s=o.edges.length||1;var t=k/b*s;if(e===0){M-=t/2}var a=M+t/2-k/4;o.radians=a;o.x=h/2+g*Math.cos(a);o.y=c/2+g*Math.sin(a);M+=t;o.edges.forEach(function(e,t){var r=e.source.id===o.id?e.target:e.source;var i=k/b;var n=a-i*s/2+i/2+i*t;r.radians=n;r.x=h/2+v*Math.cos(n);r.y=c/2+v*Math.sin(n);z.push(r)})});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 A;if(this._size){var L=j.extent(n,function(e){return e.size});if(L[0]===L[1]){L[0]=0}A=D.scaleLinear().domain(L).rangeRound([3,j.min([B,q])]);var P=y.size;y.r=A(P)}else{A=D.scaleLinear().domain([1,2]).rangeRound([B,q])}z.forEach(function(e){e.ring=2;var t=f._size?e.size:2;e.r=f._sizeMin?j.max([f._sizeMin,A(t)]):f._sizeMax?j.min([f._sizeMax,A(t)]):A(t)});x.forEach(function(e){e.ring=1;var t=f._size?e.size:1;e.r=f._sizeMin?j.max([f._sizeMin,A(t)]):f._sizeMax?j.min([f._sizeMax,A(t)]):A(t)});d=[y].concat(x).concat(z);x.forEach(function(u){var e=["source","target"];var r=u.edge;e.forEach(function(t){r[t]=d.find(function(e){return e.id===r[t].id})});l.push(r);s[u.id].forEach(function(i){var t=i.source.id===u.id?i.target:i.source;if(t.id!==y.id){var n=z.find(function(e){return e.id===t.id});if(!n){n=x.find(function(e){return e.id===t.id})}if(n){i.spline=true;var o=h/2;var s=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"]=o+a*Math.cos(i[t].radians);i[t+"BisectY"]=s+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 r=e===0?i.target.id:i.source.id;if(i[t].id===u.id){i[t].edges[r]={angle:u.radians+Math.PI,radius:p/2}}else{i[t].edges[r]={angle:n.radians,radius:p/2}}});l.push(i)}}})});d.forEach(function(e){if(e.id!==f._center){var t=f._shapeConfig.labelConfig.fontSize&&f._shapeConfig.labelConfig.fontSize(e)||11;var r=t*1.4;var i=r*2;var n=5;var o=p-e.r;var s=e.radians*(180/Math.PI);var a=e.r+n;var u="start";if(s<-90||s>90){a=-e.r-o-n;u="end";s+=180}e.labelBounds={x:a,y:-r/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 R.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 E=this;var G={label:function(e){return d.length<=f._labelCutoff||(f._hover&&f._hover(e)||f._active&&f._active(e))?f._drawLabel(e.data||e.node,e.i):false},labelBounds:function(e){return e.labelBounds},labelConfig:{fontColor:function(e){return e.data.data.id===f._center?T.configPrep.bind(E)(E._shapeConfig,"shape",e.key).labelConfig.fontColor(e):X.colorLegible(T.configPrep.bind(E)(E._shapeConfig,"shape",e.key).fill(e))},fontResize:function(e){return e.data.data.id===f._center},padding:0,textAnchor:function(e){return i[e.data.data.id].textAnchor||T.configPrep.bind(E)(E._shapeConfig,"shape",e.key).labelConfig.textAnchor},verticalAlign:function(e){return e.data.data.id===f._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()};S.nest().key(function(e){return e.shape}).entries(d).forEach(function(e){f._shapes.push((new R[e.key]).config(T.configPrep.bind(f)(f._shapeConfig,"shape",e.key)).config(G).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,r){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="links"});var n=[o.dataLoad.bind(this),t,r,"links"];if(i){this._queue[this._queue.indexOf(i)]=n}else{this._queue.push(n)}return this}return this._links};e.prototype.nodeGroupBy=function e(t){var r=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(!r._aggs[e]){r._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,r){if(arguments.length){var i=this._queue.find(function(e){return e[3]==="nodes"});var n=[o.dataLoad.bind(this),t,r,"nodes"];if(i){this._queue[this._queue.indexOf(i)]=n}else{this._queue.push(n)}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);e.Network=t;e.Rings=r;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 r=1;r<arguments.length;r++){var i=arguments[r];if(i!==null){for(var s in i){if(Object.prototype.hasOwnProperty.call(i,s)){n[s]=i[s]}}}}return n},writable:true,configurable:true})}if(!Array.prototype.includes){Object.defineProperty(Array.prototype,"includes",{value:function e(t,n){var r=Object(this);var i=r.length>>>0;if(i===0)return false;var s=n|0;var o=Math.max(s>=0?s:i-Math.abs(s),0);function a(e,t){return e===t||typeof e==="number"&&typeof t==="number"&&isNaN(e)&&isNaN(t)}while(o<i){if(a(r[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,S,j,D,d,I,R,s,W,t){"use strict";var n=function(A){function e(){var h=this;A.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),r=h._linkLookup[n],i=h._nodeLookup[n];var s=[i.id];var o=[i.x-i.r,i.x+i.r],a=[i.y-i.r,i.y+i.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 e.source.id===i.id||e.target.id===i.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 r=h._ids(e);r=r[r.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 i=n.map(function(e){return h._nodeLookup[e]});var s=[r];var o=[i[0].x-i[0].r,i[0].x+i[0].r],a=[i[0].y-i[0].r,i[0].y+i[0].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 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(A)e.__proto__=A;e.prototype=Object.create(A&&A.prototype);e.prototype.constructor=e;e.prototype._draw=function e(t){var i=this;A.prototype._draw.call(this,t);var n=this._height-this._margin.top-this._margin.bottom,r="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[i._id(t,n)]=t;return e},{});var u=this._nodes.reduce(function(e,t,n){e[i._nodeGroupBy?i._nodeGroupBy[i._drawDepth](t,n):i._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],r=u[e];if(r===undefined){return false}return{__d3plus__:true,data:n||r,i:t,id:e,fx:n!==undefined&&i._x(n)!==undefined?i._x(n):i._x(r),fy:n!==undefined&&i._y(n)!==undefined?i._y(n):i._y(r),node:r,r:i._size?n!==undefined&&i._size(n)!==undefined?i._size(n):i._size(r):i._sizeMin,shape:n!==undefined&&i._shape(n)!==undefined?i._shape(n):i._shape(r)}}).filter(function(e){return e});var h=S.extent(u.map(function(e){return e.fx})),d=S.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=S.extent(u.map(function(e){return e.r}));var y=this._sizeMax||S.min(S.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:S.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*=S.min([z/M,b/w]);m.range([v[0]===v[1]?y:S.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(i._nodes[e.source])]:C[e.source.id],target:typeof e.target==="number"?u[B.indexOf(i._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(i._focus){i.active(false);i._focus=undefined;i._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:r},update:{transform:r}}).node()).render());var O={label:function(e){return u.length<=i._labelCutoff||(i._hover&&i._hover(e)||i._active&&i._active(e))?i._drawLabel(e.data||e.node,e.i):false},select:I.elem("g.d3plus-network-nodes",{parent:P,transition:s,enter:{transform:r},update:{transform:r}}).node()};j.nest().key(function(e){return e.shape}).entries(u).forEach(function(e){i._shapes.push((new R[e.key]).config(I.configPrep.bind(i)(i._shapeConfig,"shape",e.key)).config(O).config(O[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 r=this._queue.find(function(e){return e[3]==="links"});var i=[s.dataLoad.bind(this),t,n,"links"];if(r){this._queue[this._queue.indexOf(r)]=i}else{this._queue.push(i)}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 r=this._queue.find(function(e){return e[3]==="nodes"});var i=[s.dataLoad.bind(this),t,n,"nodes"];if(r){this._queue[this._queue.indexOf(r)]=i}else{this._queue.push(i)}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 S.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 S.mean(e)}}}return this}else{return this._y}};return e}(s.Viz);var r=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)};this._on["mousemove.shape"]=function(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),r=u._linkLookup[n],i=u._nodeLookup[n];var s=[i.id];var o=[i.x-i.r,i.x+i.r],a=[i.y-i.r,i.y+i.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}});u.hover(function(e,t){if(e.source&&e.target){return e.source.id===i.id||e.target.id===i.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 i=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(i).concat(Object.keys(d)))).map(function(e,t){var n=i[e],r=d[e];if(r===undefined){return false}return{__d3plus__:true,data:n||r,i:t,id:e,node:r,shape:n!==undefined&&h._shape(n)!==undefined?h._shape(n):h._shape(r)}}).filter(function(e){return e});var r=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]]:r[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=S.min([c,f])/2,p=l/3;var g=p,v=p*2;var y=r[this._center];y.x=f/2;y.y=c/2;y.r=this._sizeMin?S.max([this._sizeMin,g*.65]):this._sizeMax?S.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 i=e.id;e.edges=e.edges.filter(function(e){return!m.includes(e.source)&&e.target.id===i||!m.includes(e.target)&&e.source.id===i});z+=e.edges.length||1;e.edges.forEach(function(e){var t=e.source;var n=e.target;var r=n.id===i?t:n;m.push(r)})});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 r=b/z;var i=a-r*o/2+r/2+r*t;n.radians=i;n.x=f/2+v*Math.cos(i);n.y=c/2+v*Math.sin(i);x.push(n)})});var w=p/2;var C=p/4;var B=w/2-4;if(w/2-4<8){B=S.min([w/2,8])}var q=C/2-4;if(C/2-4<4){q=S.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=S.extent(i,function(e){return e.size});if(P[0]===P[1]){P[0]=0}L=D.scaleLinear().domain(P).rangeRound([3,S.min([B,q])]);var O=y.size;y.r=L(O)}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?S.max([h._sizeMin,L(t)]):h._sizeMax?S.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?S.max([h._sizeMin,L(t)]):h._sizeMax?S.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(r){var t=r.source.id===u.id?r.target:r.source;if(t.id!==y.id){var i=x.find(function(e){return e.id===t.id});if(!i){i=k.find(function(e){return e.id===t.id})}if(i){r.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){r[t+"X"]=r[t].x+Math.cos(r[t].ring===2?r[t].radians+Math.PI:r[t].radians)*r[t].r;r[t+"Y"]=r[t].y+Math.sin(r[t].ring===2?r[t].radians+Math.PI:r[t].radians)*r[t].r;r[t+"BisectX"]=s+a*Math.cos(r[t].radians);r[t+"BisectY"]=o+a*Math.sin(r[t].radians);r[t]=d.find(function(e){return e.id===r[t].id});if(r[t].edges===undefined){r[t].edges={}}var n=e===0?r.target.id:r.source.id;if(r[t].id===u.id){r[t].edges[n]={angle:u.radians+Math.PI,radius:p/2}}else{r[t].edges[n]={angle:i.radians,radius:p/2}}});_.push(r)}}})});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 r=n*2;var i=5;var s=p-e.r;var o=e.radians*(180/Math.PI);var a=e.r+i;var u="start";if(o<-90||o>90){a=-e.r-s-i;u="end";o+=180}e.labelBounds={x:a,y:-n/2,width:s,height:r};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 A=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(A)(A._shapeConfig,"shape",e.key).labelConfig.fontColor(e):W.colorLegible(I.configPrep.bind(A)(A._shapeConfig,"shape",e.key).fill(e))},fontResize:function(e){return e.data.data.id===h._center},padding:0,textAnchor:function(e){return r[e.data.data.id].textAnchor||I.configPrep.bind(A)(A._shapeConfig,"shape",e.key).labelConfig.textAnchor},verticalAlign:function(e){return e.data.data.id===h._center?"middle":"top"}},rotate:function(e){return r[e.id].rotate||0},select:I.elem("g.d3plus-rings-nodes",{parent:this._select,transition:u,enter:{transform:a},update:{transform:a}}).node()};j.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 r=this._queue.find(function(e){return e[3]==="links"});var i=[s.dataLoad.bind(this),t,n,"links"];if(r){this._queue[this._queue.indexOf(r)]=i}else{this._queue.push(i)}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 r=this._queue.find(function(e){return e[3]==="nodes"});var i=[s.dataLoad.bind(this),t,n,"nodes"];if(r){this._queue[this._queue.indexOf(r)]=i}else{this._queue.push(i)}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 i=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._nodeWidth=30;this._on.mouseenter=function(){};this._on["mouseleave.shape"]=function(){a.hover(false)};this._on["mousemove.shape"]=function(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),r=a._nodeLookup[n],i=Object.keys(a._nodeLookup).reduce(function(e,t){e[a._nodeLookup[t]]=!isNaN(t)?parseInt(t,10):t;return e},{});var s=a._linkLookup[r];var o=[n];s.forEach(function(e){o.push(i[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,t){return Math.max(1,Math.abs(e.source.y1-e.source.y0)*(a._value(e,t)/e.source.value)-20)}},label:false,stroke:"#DBDBDB",strokeOpacity:.2,strokeWidth:function(e,t){return Math.max(1,Math.abs(e.source.y1-e.source.y0)*(a._value(e,t)/e.source.value)-20)}},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 i=this;h.prototype._draw.call(this,t);var n=this._height-this._margin.top-this._margin.bottom,r=this._width-this._margin.left-this._margin.right;var s=this._nodes.map(function(e,t){var n=e;return{__d3plus__:true,data:n,id:i._nodeId(e,t),node:n,shape:"Rect"}}).filter(function(e){return e});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 r=t.reduce(function(e,t){e[t]=typeof n[t]==="number"?o[n[t]]:o[n[t]];return e},{});return{source:r.source,target:r.target,value:i._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.nodeWidth(this._nodeWidth).nodes(s).links(a).size([r,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());j.nest().key(function(e){return e.shape}).entries(s).forEach(function(e){i._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:i._select,enter:{transform:u},update:{transform:u}}).node()).config(I.configPrep.bind(i)(i._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 r=this._queue.find(function(e){return e[3]==="links"});var i=[s.dataLoad.bind(this),t,n,"links"];if(r){this._queue[this._queue.indexOf(r)]=i}else{this._queue.push(i)}return this}return this._links};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 r=this._queue.find(function(e){return e[3]==="nodes"});var i=[s.dataLoad.bind(this),t,n,"nodes"];if(r){this._queue[this._queue.indexOf(r)]=i}else{this._queue.push(i)}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=r;e.Sankey=i;Object.defineProperty(e,"__esModule",{value:true})}); |
export {default as Network} from "./src/Network"; | ||
export {default as Rings} from "./src/Rings"; | ||
export {default as Sankey} from "./src/Sankey"; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "d3plus-network", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Javascript network visualizations built upon d3 modules.", | ||
@@ -28,2 +28,3 @@ "main": "build/d3plus-network.js", | ||
"d3-force": "^1.1.0", | ||
"d3-sankey": "^0.7.1", | ||
"d3-scale": "^2.0.0", | ||
@@ -30,0 +31,0 @@ "d3plus-common": "^0.6.35", |
@@ -12,3 +12,3 @@ # d3plus-network | ||
```html | ||
<script src="https://d3plus.org/js/d3plus-network.v0.3.full.min.js"></script> | ||
<script src="https://d3plus.org/js/d3plus-network.v0.4.full.min.js"></script> | ||
``` | ||
@@ -65,2 +65,3 @@ | ||
* [Simple Sankey Diagram](http://d3plus.org/examples/d3plus-network/sankey-diagram/)<sup> ***New***</sup> | ||
* [Simple Rings](http://d3plus.org/examples/d3plus-network/simple-rings/) | ||
@@ -73,2 +74,3 @@ | ||
* [Rings](#Rings) | ||
* [Sankey](#Sankey) | ||
@@ -326,4 +328,90 @@ --- | ||
<a name="Sankey"></a> | ||
#### **Sankey** [<>](https://github.com/d3plus/d3plus-network/blob/master/src/Sankey.js#L13) | ||
###### <sub>Documentation generated on Mon, 25 Jun 2018 19:30:47 GMT</sub> | ||
This is a global class, and extends all of the methods and functionality of [<code>Viz</code>](https://github.com/d3plus/d3plus-viz#Viz). | ||
* [Sankey](#Sankey) ⇐ [<code>Viz</code>](https://github.com/d3plus/d3plus-viz#Viz) | ||
* [new Sankey()](#new_Sankey_new) | ||
* [.hover([*value*])](#Sankey.hover) ↩︎ | ||
* [.links(*links*)](#Sankey.links) ↩︎ | ||
* [.nodeId([*value*])](#Sankey.nodeId) ↩︎ | ||
* [.nodes(*nodes*)](#Sankey.nodes) ↩︎ | ||
* [.nodeWidth([*value*])](#Sankey.nodeWidth) ↩︎ | ||
* [.value(*value*)](#Sankey.value) | ||
<a name="new_Sankey_new" href="#new_Sankey_new">#</a> new **Sankey**() | ||
Creates a sankey visualization based on a defined set of nodes and links. [Click here](http://d3plus.org/examples/d3plus-network/sankey-diagram/) for help getting started using the Sankey class. | ||
<a name="Sankey.hover" href="#Sankey.hover">#</a> Sankey.**hover**([*value*]) [<>](https://github.com/d3plus/d3plus-network/blob/master/src/Sankey.js#L194) | ||
If *value* is specified, sets the hover method to the specified function and returns the current class instance. | ||
This is a static method of [<code>Sankey</code>](#Sankey), and is chainable with other methods of this Class. | ||
<a name="Sankey.links" href="#Sankey.links">#</a> Sankey.**links**(*links*) [<>](https://github.com/d3plus/d3plus-network/blob/master/src/Sankey.js#L211) | ||
A predefined *Array* of edges that connect each object passed to the [node](#Sankey.node) method. The `source` and `target` keys in each link need to map to the nodes in one of one way: | ||
1. A *String* value matching the `id` of the node. | ||
The value passed should be an *Array* of data. An optional formatting function can be passed as a second argument to this method. This custom function will be passed the data that has been loaded, as long as there are no errors. This function should return the final links *Array*. | ||
This is a static method of [<code>Sankey</code>](#Sankey), and is chainable with other methods of this Class. | ||
<a name="Sankey.nodeId" href="#Sankey.nodeId">#</a> Sankey.**nodeId**([*value*]) [<>](https://github.com/d3plus/d3plus-network/blob/master/src/Sankey.js#L228) | ||
If *value* is specified, sets the node id accessor(s) to the specified array of values and returns the current class instance. If *value* is not specified, returns the current node group accessor. | ||
This is a static method of [<code>Sankey</code>](#Sankey), and is chainable with other methods of this Class. | ||
<a name="Sankey.nodes" href="#Sankey.nodes">#</a> Sankey.**nodes**(*nodes*) [<>](https://github.com/d3plus/d3plus-network/blob/master/src/Sankey.js#L242) | ||
The list of nodes to be used for drawing the network. The value passed must be an *Array* of data. | ||
Additionally, a custom formatting function can be passed as a second argument to this method. This custom function will be passed the data that has been loaded, as long as there are no errors. This function should return the final node *Array*. | ||
This is a static method of [<code>Sankey</code>](#Sankey), and is chainable with other methods of this Class. | ||
<a name="Sankey.nodeWidth" href="#Sankey.nodeWidth">#</a> Sankey.**nodeWidth**([*value*]) [<>](https://github.com/d3plus/d3plus-network/blob/master/src/Sankey.js#L259) | ||
If *value* is specified, sets the width of the node and returns the current class instance. If *value* is not specified, returns the current nodeWidth. By default, the nodeWidth size is 30. | ||
This is a static method of [<code>Sankey</code>](#Sankey), and is chainable with other methods of this Class. | ||
<a name="Sankey.value" href="#Sankey.value">#</a> Sankey.**value**(*value*) [<>](https://github.com/d3plus/d3plus-network/blob/master/src/Sankey.js#L272) | ||
If *value* is specified, sets the width of the links and returns the current class instance. If *value* is not specified, returns the current value accessor. | ||
This is a static method of [<code>Sankey</code>](#Sankey). | ||
```js | ||
function value(d) { | ||
return d.value; | ||
} | ||
``` | ||
--- | ||
###### <sub>Documentation generated on Mon, 02 Jul 2018 17:45:33 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
347722
14
2417
414
7
+ Addedd3-sankey@^0.7.1
+ Addedd3-sankey@0.7.1(transitive)