function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function _assert_this_initialized(self) {
    if (self === void 0) {
        throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
    }
    return self;
}
function _call_super(_this, derived, args) {
    derived = _get_prototype_of(derived);
    return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
}
function _class_call_check(instance, Constructor) {
    if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
    }
}
function _defineProperties(target, props) {
    for(var i = 0; i < props.length; i++){
        var descriptor = props[i];
        descriptor.enumerable = descriptor.enumerable || false;
        descriptor.configurable = true;
        if ("value" in descriptor) descriptor.writable = true;
        Object.defineProperty(target, descriptor.key, descriptor);
    }
}
function _create_class(Constructor, protoProps, staticProps) {
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
    if (staticProps) _defineProperties(Constructor, staticProps);
    return Constructor;
}
function _get(target, property, receiver) {
    if (typeof Reflect !== "undefined" && Reflect.get) {
        _get = Reflect.get;
    } else {
        _get = function get(target, property, receiver) {
            var base = _super_prop_base(target, property);
            if (!base) return;
            var desc = Object.getOwnPropertyDescriptor(base, property);
            if (desc.get) {
                return desc.get.call(receiver || target);
            }
            return desc.value;
        };
    }
    return _get(target, property, receiver || target);
}
function _get_prototype_of(o) {
    _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
        return o.__proto__ || Object.getPrototypeOf(o);
    };
    return _get_prototype_of(o);
}
function _inherits(subClass, superClass) {
    if (typeof superClass !== "function" && superClass !== null) {
        throw new TypeError("Super expression must either be null or a function");
    }
    subClass.prototype = Object.create(superClass && superClass.prototype, {
        constructor: {
            value: subClass,
            writable: true,
            configurable: true
        }
    });
    if (superClass) _set_prototype_of(subClass, superClass);
}
function _instanceof(left, right) {
    "@swc/helpers - instanceof";
    if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
        return !!right[Symbol.hasInstance](left);
    } else {
        return left instanceof right;
    }
}
function _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _possible_constructor_return(self, call) {
    if (call && (_type_of(call) === "object" || typeof call === "function")) {
        return call;
    }
    return _assert_this_initialized(self);
}
function _set_prototype_of(o, p) {
    _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
        o.__proto__ = p;
        return o;
    };
    return _set_prototype_of(o, p);
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _super_prop_base(object, property) {
    while(!Object.prototype.hasOwnProperty.call(object, property)){
        object = _get_prototype_of(object);
        if (object === null) break;
    }
    return object;
}
function _type_of(obj) {
    "@swc/helpers - typeof";
    return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
function _is_native_reflect_construct() {
    try {
        var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
    } catch (_) {}
    return (_is_native_reflect_construct = function() {
        return !!result;
    })();
}
import { extent, groups, max, mean, min, merge } from "d3-array";
import { forceLink, forceManyBody, forceSimulation } from "d3-force";
import { polygonHull } from "d3-polygon";
import * as scales from "d3-scale";
import { zoomTransform } from "d3-zoom";
import { assign, elem } from "@d3plus/dom";
import { addToQueue } from "@d3plus/data";
import { largestRect, pointDistance, pointRotate } from "@d3plus/math";
import * as shapes from "../shapes/index.js";
import { accessor, configPrep, constant } from "../utils/index.js";
import Viz from "./Viz.js";
/**
 * Fetches the unique ID for a data point, whether it's defined by data or nodes.
 * @private
*/ function getNodeId(d, i) {
    return "".concat(this._id(d, i) || this._nodeGroupBy[min([
        this._drawDepth,
        this._nodeGroupBy.length - 1
    ])](d, i));
}
var Network = /*#__PURE__*/ function(Viz) {
    "use strict";
    _inherits(Network, Viz);
    function Network() {
        _class_call_check(this, Network);
        var _this;
        _this = _call_super(this, Network);
        _this._links = [];
        _this._linkSize = constant(1);
        _this._linkSizeMin = 1;
        _this._linkSizeScale = "sqrt";
        _this._noDataMessage = false;
        _this._nodeGroupBy = [
            accessor("id")
        ];
        _this._nodes = [];
        _this._on["click.shape"] = function(d, i, x, event) {
            _this._tooltipClass.data([]).render();
            if (_this._hover && _this._drawDepth >= _this._groupBy.length - 1) {
                var id = getNodeId.bind(_this)(d, i);
                if (_this._focus && _this._focus === id) {
                    _this.active(false);
                    _this._on.mouseenter.bind(_this)(d, i, x, event);
                    _this._focus = undefined;
                    _this._zoomToBounds(null);
                } else {
                    _this.hover(false);
                    var links = _this._linkLookup[id], node = _this._nodeLookup[id];
                    var filterIds = [
                        id
                    ];
                    var xDomain = [
                        node.x - node.r,
                        node.x + node.r
                    ], yDomain = [
                        node.y - node.r,
                        node.y + node.r
                    ];
                    links.forEach(function(l) {
                        filterIds.push(l.id);
                        if (l.x - l.r < xDomain[0]) xDomain[0] = l.x - l.r;
                        if (l.x + l.r > xDomain[1]) xDomain[1] = l.x + l.r;
                        if (l.y - l.r < yDomain[0]) yDomain[0] = l.y - l.r;
                        if (l.y + l.r > yDomain[1]) yDomain[1] = l.y + l.r;
                    });
                    _this.active(function(h, x) {
                        if (h.source && h.target) return h.source.id === id || h.target.id === id;
                        else return filterIds.includes(getNodeId.bind(_this)(h, x));
                    });
                    _this._focus = id;
                    var t = zoomTransform(_this._container.node());
                    xDomain = xDomain.map(function(d) {
                        return d * t.k + t.x;
                    });
                    yDomain = yDomain.map(function(d) {
                        return d * t.k + t.y;
                    });
                    _this._zoomToBounds([
                        [
                            xDomain[0],
                            yDomain[0]
                        ],
                        [
                            xDomain[1],
                            yDomain[1]
                        ]
                    ]);
                }
            }
        };
        _this._on["click.legend"] = function(d, i, x, event) {
            var ids = _this._id(d);
            var id = _this._ids(d);
            id = id[id.length - 1];
            if (_this._hover && _this._drawDepth >= _this._groupBy.length - 1) {
                if (_this._focus && _this._focus === ids) {
                    _this.active(false);
                    _this._focus = undefined;
                    _this._zoomToBounds(null);
                } else {
                    _this.hover(false);
                    var nodes = ids.map(function(id) {
                        return _this._nodeLookup[id];
                    });
                    var filterIds = [
                        "".concat(id)
                    ];
                    var xDomain = [
                        nodes[0].x - nodes[0].r,
                        nodes[0].x + nodes[0].r
                    ], yDomain = [
                        nodes[0].y - nodes[0].r,
                        nodes[0].y + nodes[0].r
                    ];
                    nodes.forEach(function(l) {
                        filterIds.push(l.id);
                        if (l.x - l.r < xDomain[0]) xDomain[0] = l.x - l.r;
                        if (l.x + l.r > xDomain[1]) xDomain[1] = l.x + l.r;
                        if (l.y - l.r < yDomain[0]) yDomain[0] = l.y - l.r;
                        if (l.y + l.r > yDomain[1]) yDomain[1] = l.y + l.r;
                    });
                    _this.active(function(h, x) {
                        if (h.source && h.target) return filterIds.includes(h.source.id) && filterIds.includes(h.target.id);
                        else {
                            var myIds = _this._ids(h, x);
                            return filterIds.includes("".concat(myIds[myIds.length - 1]));
                        }
                    });
                    _this._focus = ids;
                    var t = zoomTransform(_this._container.node());
                    xDomain = xDomain.map(function(d) {
                        return d * t.k + t.x;
                    });
                    yDomain = yDomain.map(function(d) {
                        return d * t.k + t.y;
                    });
                    _this._zoomToBounds([
                        [
                            xDomain[0],
                            yDomain[0]
                        ],
                        [
                            xDomain[1],
                            yDomain[1]
                        ]
                    ]);
                }
                _this._on.mouseenter.bind(_this)(d, i, x, event);
                _this._on["mousemove.legend"].bind(_this)(d, i, x, event);
            }
        };
        _this._on.mouseenter = function() {};
        _this._on["mouseleave.shape"] = function() {
            _this.hover(false);
        };
        var defaultMouseMove = _this._on["mousemove.shape"];
        _this._on["mousemove.shape"] = function(d, i, x, event) {
            defaultMouseMove(d, i, x, event);
            var id = getNodeId.bind(_this)(d, i), links = _this._linkLookup[id] || [], node = _this._nodeLookup[id];
            var filterIds = [
                id
            ];
            var xDomain = [
                node.x - node.r,
                node.x + node.r
            ], yDomain = [
                node.y - node.r,
                node.y + node.r
            ];
            links.forEach(function(l) {
                filterIds.push(l.id);
                if (l.x - l.r < xDomain[0]) xDomain[0] = l.x - l.r;
                if (l.x + l.r > xDomain[1]) xDomain[1] = l.x + l.r;
                if (l.y - l.r < yDomain[0]) yDomain[0] = l.y - l.r;
                if (l.y + l.r > yDomain[1]) yDomain[1] = l.y + l.r;
            });
            _this.hover(function(h, x) {
                if (h.source && h.target) return h.source.id === id || h.target.id === id;
                else return filterIds.includes("".concat(_this._ids(h, x)[_this._drawDepth]));
            });
        };
        _this._sizeMin = 5;
        _this._sizeScale = "sqrt";
        _this._shape = constant("Circle");
        _this._shapeConfig = assign(_this._shapeConfig, {
            ariaLabel: function ariaLabel(d, i) {
                var validSize = _this._size ? ", ".concat(_this._size(d, i)) : "";
                return "".concat(_this._drawLabel(d, i)).concat(validSize, ".");
            },
            labelConfig: {
                duration: 0,
                fontMin: 1,
                fontResize: true,
                labelPadding: 0,
                textAnchor: "middle",
                verticalAlign: "middle"
            },
            Path: {
                fill: "none",
                label: false,
                stroke: "#eee"
            }
        });
        _this._x = accessor("x");
        _this._y = accessor("y");
        _this._zoom = true;
        return _this;
    }
    _create_class(Network, [
        {
            /**
      Extends the draw behavior of the abstract Viz class.
      @private
*/ key: "_draw",
            value: function _draw(callback) {
                var _this = this;
                _get(_get_prototype_of(Network.prototype), "_draw", this).call(this, callback);
                var duration = this._duration, height = this._height - this._margin.top - this._margin.bottom, transform = "translate(".concat(this._margin.left, ", ").concat(this._margin.top, ")"), width = this._width - this._margin.left - this._margin.right;
                var data = this._filteredData.reduce(function(obj, d, i) {
                    obj[_this._id(d, i)] = d;
                    return obj;
                }, {});
                var nodes = this._nodes.reduce(function(obj, d, i) {
                    obj[getNodeId.bind(_this)(d, i)] = d;
                    return obj;
                }, {});
                nodes = Array.from(new Set(Object.keys(data).concat(Object.keys(nodes)))).map(function(id, i) {
                    var d = data[id], n = nodes[id];
                    if (n === undefined) return false;
                    return {
                        __d3plus__: true,
                        data: d || n,
                        i: i,
                        id: id,
                        fx: d !== undefined && !isNaN(_this._x(d)) ? _this._x(d) : _this._x(n),
                        fy: d !== undefined && !isNaN(_this._y(d)) ? _this._y(d) : _this._y(n),
                        node: n,
                        r: _this._size ? d !== undefined && _this._size(d) !== undefined ? _this._size(d) : _this._size(n) : _this._sizeMin,
                        shape: d !== undefined && _this._shape(d) !== undefined ? _this._shape(d) : _this._shape(n)
                    };
                }).filter(function(n) {
                    return !!n;
                });
                var nodeLookup = this._nodeLookup = nodes.reduce(function(obj, d) {
                    obj[d.id] = d;
                    return obj;
                }, {});
                var nodeIndices = nodes.map(function(n) {
                    return n.node;
                });
                var links = this._links.map(function(l) {
                    var referenceType = _type_of(l.source);
                    return {
                        size: _this._linkSize(l),
                        source: referenceType === "number" ? nodes[nodeIndices.indexOf(_this._nodes[l.source])] : referenceType === "string" ? nodeLookup[l.source] : nodeLookup[l.source.id],
                        target: referenceType === "number" ? nodes[nodeIndices.indexOf(_this._nodes[l.target])] : referenceType === "string" ? nodeLookup[l.target] : nodeLookup[l.target.id]
                    };
                });
                this._linkLookup = links.reduce(function(obj, d) {
                    if (!obj[d.source.id]) obj[d.source.id] = [];
                    obj[d.source.id].push(d.target);
                    if (!obj[d.target.id]) obj[d.target.id] = [];
                    obj[d.target.id].push(d.source);
                    return obj;
                }, {});
                var missingCoords = nodes.some(function(n) {
                    return n.fx === undefined || n.fy === undefined;
                });
                if (missingCoords) {
                    var linkStrength = scales.scaleLinear().domain(extent(links, function(d) {
                        return d.size;
                    })).range([
                        0.1,
                        0.5
                    ]);
                    var simulation = forceSimulation().force("link", forceLink(links).id(function(d) {
                        return d.id;
                    }).distance(1).strength(function(d) {
                        return linkStrength(d.size);
                    }).iterations(4)).force("charge", forceManyBody().strength(-1)).stop();
                    var iterations = 100;
                    var alphaMin = 0.001;
                    var alphaDecay = 1 - Math.pow(alphaMin, 1 / iterations);
                    simulation.velocityDecay(0);
                    simulation.alphaMin(alphaMin);
                    simulation.alphaDecay(alphaDecay);
                    simulation.alphaDecay(0);
                    simulation.nodes(nodes);
                    simulation.tick(iterations).stop();
                    var nodePositions = nodes.map(function(n) {
                        return [
                            n.vx,
                            n.vy
                        ];
                    });
                    var angle = 0, cx = 0, cy = 0;
                    if (nodePositions.length === 2) {
                        angle = 100;
                    } else if (nodePositions.length > 2) {
                        var hull = polygonHull(nodePositions) || [];
                        var rect = largestRect(hull, {
                            verbose: true
                        });
                        angle = rect.angle;
                        cx = rect.cx;
                        cy = rect.cy;
                    }
                    nodes.forEach(function(n) {
                        var p = pointRotate([
                            n.vx,
                            n.vy
                        ], -1 * (Math.PI / 180 * angle), [
                            cx,
                            cy
                        ]);
                        n.fx = p[0];
                        n.fy = p[1];
                    });
                }
                var xExtent = extent(nodes.map(function(n) {
                    return n.fx;
                })), yExtent = extent(nodes.map(function(n) {
                    return n.fy;
                }));
                var x = scales.scaleLinear().domain(xExtent).range([
                    0,
                    width
                ]), y = scales.scaleLinear().domain(yExtent).range([
                    0,
                    height
                ]);
                var nodeRatio = (xExtent[1] - xExtent[0]) / (yExtent[1] - yExtent[0]) || 1, screenRatio = width / height;
                if (nodeRatio > screenRatio) {
                    var h = height * screenRatio / nodeRatio;
                    y.range([
                        (height - h) / 2,
                        height - (height - h) / 2
                    ]);
                } else {
                    var w = width * nodeRatio / screenRatio;
                    x.range([
                        (width - w) / 2,
                        width - (width - w) / 2
                    ]);
                }
                nodes.forEach(function(n) {
                    n.x = x(n.fx);
                    n.y = y(n.fy);
                });
                var rExtent = extent(nodes.map(function(n) {
                    return n.r;
                }));
                var rMax = this._sizeMax || max([
                    1,
                    min(merge(nodes.map(function(n1) {
                        return nodes.map(function(n2) {
                            return n1 === n2 ? null : pointDistance([
                                n1.x,
                                n1.y
                            ], [
                                n2.x,
                                n2.y
                            ]);
                        });
                    }))) / 2
                ]);
                var r = scales["scale".concat(this._sizeScale.charAt(0).toUpperCase()).concat(this._sizeScale.slice(1))]().domain(rExtent).range([
                    rExtent[0] === rExtent[1] ? rMax : min([
                        rMax / 2,
                        this._sizeMin
                    ]),
                    rMax
                ]), xDomain = x.domain(), yDomain = y.domain();
                var xOldSize = xDomain[1] - xDomain[0], yOldSize = yDomain[1] - yDomain[0];
                nodes.forEach(function(n) {
                    var size = r(n.r);
                    if (xDomain[0] > x.invert(n.x - size)) xDomain[0] = x.invert(n.x - size);
                    if (xDomain[1] < x.invert(n.x + size)) xDomain[1] = x.invert(n.x + size);
                    if (yDomain[0] > y.invert(n.y - size)) yDomain[0] = y.invert(n.y - size);
                    if (yDomain[1] < y.invert(n.y + size)) yDomain[1] = y.invert(n.y + size);
                });
                var xNewSize = xDomain[1] - xDomain[0], yNewSize = yDomain[1] - yDomain[0];
                rMax *= min([
                    xOldSize / xNewSize,
                    yOldSize / yNewSize
                ]);
                r.range([
                    rExtent[0] === rExtent[1] ? rMax : min([
                        rMax / 2,
                        this._sizeMin
                    ]),
                    rMax
                ]);
                x.domain(xDomain);
                y.domain(yDomain);
                var fallbackRadius = (nodeRatio > screenRatio ? width : height) / 2;
                nodes.forEach(function(n) {
                    n.x = x(n.fx);
                    n.fx = n.x;
                    n.y = y(n.fy);
                    n.fy = n.y;
                    n.r = r(n.r) || fallbackRadius;
                    n.width = n.r * 2;
                    n.height = n.r * 2;
                });
                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", width).attr("height", height).attr("x", this._margin.left).attr("y", this._margin.top).style("background-color", "transparent").merge(this._container);
                this._container.transition().duration(duration).attr("opacity", 1).attr("width", width).attr("height", height).attr("x", this._margin.left).attr("y", this._margin.top);
                var hitArea = this._container.selectAll("rect.d3plus-network-hitArea").data([
                    0
                ]);
                hitArea.enter().append("rect").attr("class", "d3plus-network-hitArea").merge(hitArea).attr("width", width).attr("height", height).attr("fill", "transparent").on("click", function() {
                    if (_this._focus) {
                        _this.active(false);
                        _this._focus = undefined;
                        _this._zoomToBounds(null);
                    }
                });
                this._zoomGroup = this._container.selectAll("g.d3plus-network-zoomGroup").data([
                    0
                ]);
                var parent = this._zoomGroup = this._zoomGroup.enter().append("g").attr("class", "d3plus-network-zoomGroup").merge(this._zoomGroup);
                var strokeExtent = extent(links, function(d) {
                    return d.size;
                });
                if (strokeExtent[0] !== strokeExtent[1]) {
                    var strokeScale = scales["scale".concat(this._linkSizeScale.charAt(0).toUpperCase()).concat(this._linkSizeScale.slice(1))]().domain(strokeExtent).range([
                        this._linkSizeMin,
                        r.range()[0]
                    ]);
                    links.forEach(function(link) {
                        link.size = strokeScale(link.size);
                    });
                }
                var linkConfig = configPrep.bind(this)(this._shapeConfig, "edge", "Path");
                delete linkConfig.on;
                this._shapes.push(new shapes.Path().config(linkConfig).strokeWidth(function(d) {
                    return d.size;
                }).activeStyle({
                    "stroke-width": function(d) {
                        return d.size;
                    }
                }).d(function(d) {
                    return "M".concat(d.source.x, ",").concat(d.source.y, " ").concat(d.target.x, ",").concat(d.target.y);
                }).data(links).select(elem("g.d3plus-network-links", {
                    parent: parent,
                    duration: duration,
                    enter: {
                        transform: transform
                    },
                    update: {
                        transform: transform
                    }
                }).node()).render());
                var shapeConfig = {
                    label: function label(d) {
                        return nodes.length <= _this._dataCutoff || _this._hover && _this._hover(d) || _this._active && _this._active(d) ? _this._drawLabel(d.data || d.node, d.i) : false;
                    },
                    select: elem("g.d3plus-network-nodes", {
                        parent: parent,
                        duration: duration,
                        enter: {
                            transform: transform
                        },
                        update: {
                            transform: transform
                        }
                    }).node()
                };
                groups(nodes, function(d) {
                    return d.shape;
                }).forEach(function(param) {
                    var _param = _sliced_to_array(param, 2), key = _param[0], values = _param[1];
                    _this._shapes.push(new shapes[key]().config(configPrep.bind(_this)(_this._shapeConfig, "shape", key)).config(shapeConfig).config(shapeConfig[key] || {}).data(values).render());
                });
                return this;
            }
        },
        {
            /**
      The hover callback function for highlighting shapes on mouseover.
*/ key: "hover",
            value: function hover(_) {
                this._hover = _;
                if (this._nodes.length < this._dataCutoff) {
                    this._shapes.forEach(function(s) {
                        return s.hover(_);
                    });
                    if (this._legend) this._legendClass.hover(_);
                }
                return this;
            }
        },
        {
            /**
      A predefined *Array* of edges that connect each object passed to the [node](#Network.node) method. The `source` and `target` keys in each link need to map to the nodes in one of three ways:
1. The index of the node in the nodes array (as in [this](http://d3plus.org/examples/d3plus-network/getting-started/) example).
2. The actual node *Object* itself.
3. A *String* value matching the `id` of the node.

The value passed should either be an *Array* of data or a *String* representing a filepath or URL to be loaded. 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 f Array of link objects or a URL to load links from.
*/ key: "links",
            value: function links(_, f) {
                if (arguments.length) {
                    addToQueue.bind(this)(_, f, "links");
                    return this;
                }
                return this._links;
            }
        },
        {
            /**
      Defines the thickness of the links connecting each node. The value provided can be either a pixel Number to be used for all links, or an accessor function that returns a specific data value to be used in an automatically calculated linear scale.
*/ key: "linkSize",
            value: function linkSize(_) {
                return arguments.length ? (this._linkSize = typeof _ === "function" ? _ : constant(_), this) : this._linkSize;
            }
        },
        {
            /**
      Defines the minimum pixel stroke width used in link sizing.
*/ key: "linkSizeMin",
            value: function linkSizeMin(_) {
                return arguments.length ? (this._linkSizeMin = _, this) : this._linkSizeMin;
            }
        },
        {
            /**
      The type of [continuous d3-scale](https://github.com/d3/d3-scale#continuous-scales) used when calculating the pixel size of links in the network.
*/ key: "linkSizeScale",
            value: function linkSizeScale(_) {
                return arguments.length ? (this._linkSizeScale = _, this) : this._linkSizeScale;
            }
        },
        {
            /**
      The node group accessor(s). This method overrides the default .groupBy() function from being used with the data passed to .nodes().
*/ key: "nodeGroupBy",
            value: function nodeGroupBy(_) {
                var _this = this;
                if (!arguments.length) return this._nodeGroupBy;
                if (!_instanceof(_, Array)) _ = [
                    _
                ];
                return this._nodeGroupBy = _.map(function(k) {
                    if (typeof k === "function") return k;
                    else {
                        if (!_this._aggs[k]) {
                            _this._aggs[k] = function(a, c) {
                                var v = Array.from(new Set(a.map(c)));
                                return v.length === 1 ? v[0] : v;
                            };
                        }
                        return accessor(k);
                    }
                }), this;
            }
        },
        {
            /**
      The list of nodes to be used for drawing the network. The value passed should either be an *Array* of data or a *String* representing a filepath or URL to be loaded.

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 f Array of node objects or a URL to load nodes from.
*/ key: "nodes",
            value: function nodes(_, f) {
                if (arguments.length) {
                    addToQueue.bind(this)(_, f, "nodes");
                    return this;
                }
                return this._nodes;
            }
        },
        {
            /**
      The size accessor for each node in the network.
*/ key: "size",
            value: function size(_) {
                return arguments.length ? (this._size = typeof _ === "function" || !_ ? _ : accessor(_), this) : this._size;
            }
        },
        {
            /**
      Defines the maximum pixel radius used in size scaling. By default, the maximum size is determined by half the distance of the two closest nodes.
*/ key: "sizeMax",
            value: function sizeMax(_) {
                return arguments.length ? (this._sizeMax = _, this) : this._sizeMax;
            }
        },
        {
            /**
      Defines the minimum pixel radius used in size scaling.
*/ key: "sizeMin",
            value: function sizeMin(_) {
                return arguments.length ? (this._sizeMin = _, this) : this._sizeMin;
            }
        },
        {
            /**
      The type of [continuous d3-scale](https://github.com/d3/d3-scale#continuous-scales) used when calculating the pixel size of nodes in the network.
*/ key: "sizeScale",
            value: function sizeScale(_) {
                return arguments.length ? (this._sizeScale = _, this) : this._sizeScale;
            }
        },
        {
            /**
      The x position accessor for each node. The data passed to .data() takes priority over the .nodes() data array. By default, the x and y positions are determined dynamically based on default force layout properties.
*/ key: "x",
            value: function x(_) {
                if (arguments.length) {
                    if (typeof _ === "function") this._x = _;
                    else {
                        this._x = accessor(_);
                        if (!this._aggs[_]) this._aggs[_] = mean;
                    }
                    return this;
                } else return this._x;
            }
        },
        {
            /**
      The y position accessor for each node. The data passed to .data() takes priority over the .nodes() data array. By default, the x and y positions are determined dynamically based on default force layout properties.
*/ key: "y",
            value: function y(_) {
                if (arguments.length) {
                    if (typeof _ === "function") this._y = _;
                    else {
                        this._y = accessor(_);
                        if (!this._aggs[_]) this._aggs[_] = mean;
                    }
                    return this;
                } else return this._y;
            }
        }
    ]);
    return Network;
}(Viz);
/**
    Creates a network visualization based on a defined set of nodes and edges. [Click here](http://d3plus.org/examples/d3plus-network/getting-started/) for help getting started using the Network class.
*/ export { Network as default };
