From 51513e122a416b79ab6aab7ddec20ae5dd18de93 Mon Sep 17 00:00:00 2001 From: Max Franz Date: Thu, 8 Aug 2019 14:42:03 -0400 Subject: [PATCH] Build 3.9.0 --- .size-snapshot.json | 22 +- dist/cytoscape.cjs.js | 3416 +++++++++++++++-------------- dist/cytoscape.esm.js | 3416 +++++++++++++++-------------- dist/cytoscape.min.js | 2 +- dist/cytoscape.umd.js | 3224 ++++++++++++++------------- documentation/index.html | 663 +++++- documentation/js/cytoscape.min.js | 2 +- package-lock.json | 114 +- 8 files changed, 6004 insertions(+), 4855 deletions(-) diff --git a/.size-snapshot.json b/.size-snapshot.json index 07ff908c4e..3d0cd3ab43 100644 --- a/.size-snapshot.json +++ b/.size-snapshot.json @@ -1,25 +1,25 @@ { "build/cytoscape.umd.js": { - "bundled": 897790, - "minified": 332573, - "gzipped": 103470 + "bundled": 903349, + "minified": 335679, + "gzipped": 104267 }, "build/cytoscape.cjs.js": { - "bundled": 827112, - "minified": 349788, - "gzipped": 105510 + "bundled": 831866, + "minified": 353440, + "gzipped": 106477 }, "build/cytoscape.esm.js": { - "bundled": 826939, - "minified": 349645, - "gzipped": 105476, + "bundled": 831693, + "minified": 353297, + "gzipped": 106441, "treeshaked": { "rollup": { - "code": 327269, + "code": 330332, "import_statements": 51 }, "webpack": { - "code": 329136 + "code": 332199 } } } diff --git a/dist/cytoscape.cjs.js b/dist/cytoscape.cjs.js index 8882458114..a5af5bb00a 100644 --- a/dist/cytoscape.cjs.js +++ b/dist/cytoscape.cjs.js @@ -970,7 +970,7 @@ function () { var Map$1 = typeof Map !== 'undefined' ? Map : ObjectMap; /* global Set */ -var undef = "undefined"; +var undef = "undefined" ; var ObjectSet = /*#__PURE__*/ @@ -1121,6 +1121,8 @@ var Element = function Element(cy, params, restore) { // whether the element is grabbed by the mouse; renderer sets this privately grabbable: params.grabbable === undefined ? true : params.grabbable ? true : false, // whether the element can be grabbed + pannable: params.pannable === undefined ? group === 'edges' ? true : false : params.pannable ? true : false, + // whether the element has passthrough panning enabled active: false, // whether the element is active from user interaction classes: new Set$1(), @@ -1148,8 +1150,26 @@ var Element = function Element(cy, params, restore) { // cache of the current bounding box bbCacheShift: { x: 0, - y: 0 // shift applied to cached bb to be applied on next get - + y: 0 + }, + // shift applied to cached bb to be applied on next get + bodyBounds: null, + // bounds cache of element body, w/o overlay + overlayBounds: null, + // bounds cache of element body, including overlay + labelBounds: { + // bounds cache of labels + all: null, + source: null, + target: null, + main: null + }, + arrowBounds: { + // bounds cache of edge arrows + source: null, + target: null, + 'mid-source': null, + 'mid-target': null } }; @@ -1209,18 +1229,18 @@ var defineSearch = function defineSearch(params) { dfs: params.dfs || !params.bfs }; // from pseudocode on wikipedia - return function searchFn(roots, fn$$1, directed) { + return function searchFn(roots, fn$1, directed) { var options; if (plainObject(roots) && !elementOrCollection(roots)) { options = roots; roots = options.roots || options.root; - fn$$1 = options.visit; + fn$1 = options.visit; directed = options.directed; } - directed = arguments.length === 2 && !fn(fn$$1) ? fn$$1 : directed; - fn$$1 = fn(fn$$1) ? fn$$1 : function () {}; + directed = arguments.length === 2 && !fn(fn$1) ? fn$1 : directed; + fn$1 = fn(fn$1) ? fn$1 : function () {}; var cy = this._private.cy; var v = roots = string(roots) ? this.filter(roots) : roots; var Q = []; @@ -1271,7 +1291,7 @@ var defineSearch = function defineSearch(params) { var tgt = prevEdge != null ? prevEdge.target() : null; var prevNode = prevEdge == null ? undefined : v.same(src) ? tgt[0] : src[0]; var ret = void 0; - ret = fn$$1(v, prevEdge, prevNode, j++, depth); + ret = fn$1(v, prevEdge, prevNode, j++, depth); if (ret === true) { found = v; @@ -3826,7 +3846,7 @@ var addLoops = function addLoops(M, n, val) { } }; -var normalize$1 = function normalize(M, n) { +var normalize = function normalize(M, n) { var sum; for (var col = 0; col < n; col++) { @@ -3883,7 +3903,7 @@ var inflate = function inflate(M, n, inflateFactor _M[i] = Math.pow(M[i], inflateFactor); } - normalize$1(_M, n); + normalize(_M, n); return _M; }; @@ -3983,7 +4003,7 @@ var markovClustering = function markovClustering(options) { addLoops(M, n, opts.multFactor); // Step 2: M = normalize( M ); - normalize$1(M, n); + normalize(M, n); var isStillMoving = true; var iterations = 0; @@ -4109,17 +4129,20 @@ var setOptions$1 = function setOptions(options) { var getDist = function getDist(type, node, centroid, attributes, mode) { - var getP = mode === 'kMedoids' ? function (i) { - return attributes[i](centroid); - } : function (i) { + var noNodeP = mode !== 'kMedoids'; + var getP = noNodeP ? function (i) { return centroid[i]; + } : function (i) { + return attributes[i](centroid); }; var getQ = function getQ(i) { return attributes[i](node); }; - return clusteringDistance(type, attributes.length, getP, getQ); + var nodeP = centroid; + var nodeQ = node; + return clusteringDistance(type, attributes.length, getP, getQ, nodeP, nodeQ); }; var randomCentroids = function randomCentroids(nodes, k, attributes) { @@ -4255,9 +4278,7 @@ var kMeans = function kMeans(options) { if (opts.testMode) { if (typeof opts.testCentroids === 'number') { - // TODO: implement a seeded random number generator. - var seed = opts.testCentroids; - centroids = randomCentroids(nodes, opts.k, opts.attributes, seed); + centroids = randomCentroids(nodes, opts.k, opts.attributes); } else if (_typeof(opts.testCentroids) === 'object') { centroids = opts.testCentroids; } else { @@ -4604,7 +4625,7 @@ var mergeClosest = function mergeClosest(clusters, index, dists, mins, opts) { return attrs[i](n1); }, function (i) { return attrs[i](n2); - }); + }, n1, n2); }; for (var i = 0; i < clusters.length; i++) { @@ -4700,8 +4721,8 @@ var getAllChildren = function getAllChildren(root, arr, cy) { if (root.value) { arr.push(root.value); } else { - if (root.left) getAllChildren(root.left, arr, cy); - if (root.right) getAllChildren(root.right, arr, cy); + if (root.left) getAllChildren(root.left, arr); + if (root.right) getAllChildren(root.right, arr); } }; @@ -4745,8 +4766,8 @@ var buildClustersFromTree = function buildClustersFromTree(root, k, cy) { if (k === 0) { // don't cut tree, simply return all nodes as 1 single cluster - if (root.left) getAllChildren(root.left, left, cy); - if (root.right) getAllChildren(root.right, right, cy); + if (root.left) getAllChildren(root.left, left); + if (root.right) getAllChildren(root.right, right); leaves = left.concat(right); return [cy.collection(leaves)]; } else if (k === 1) { @@ -4755,8 +4776,8 @@ var buildClustersFromTree = function buildClustersFromTree(root, k, cy) { // leaf node return [cy.collection(root.value)]; } else { - if (root.left) getAllChildren(root.left, left, cy); - if (root.right) getAllChildren(root.right, right, cy); + if (root.left) getAllChildren(root.left, left); + if (root.right) getAllChildren(root.right, right); return [cy.collection(left), cy.collection(right)]; } } else { @@ -4784,7 +4805,7 @@ var hierarchicalClustering = function hierarchicalClustering(options) { return attrs[i](n1); }, function (i) { return attrs[i](n2); - }); + }, n1, n2); }; // Begin hierarchical algorithm @@ -4951,14 +4972,14 @@ var assignClusters = function assignClusters(n, S, exemplars) { for (var i = 0; i < n; i++) { var index = -1; - var max$$1 = -Infinity; + var max = -Infinity; for (var ei = 0; ei < exemplars.length; ei++) { var e = exemplars[ei]; - if (S[i * n + e] > max$$1) { + if (S[i * n + e] > max) { index = e; - max$$1 = S[i * n + e]; + max = S[i * n + e]; } } @@ -5093,7 +5114,7 @@ var affinityPropagation = function affinityPropagation(options) { // main algorithmic loop // Update R responsibility matrix for (var _i8 = 0; _i8 < n; _i8++) { - var max$$1 = -Infinity, + var max = -Infinity, max2 = -Infinity, maxI = -1, AS = 0.0; @@ -5102,9 +5123,9 @@ var affinityPropagation = function affinityPropagation(options) { old[_j] = R[_i8 * n + _j]; AS = A[_i8 * n + _j] + S[_i8 * n + _j]; - if (AS >= max$$1) { - max2 = max$$1; - max$$1 = AS; + if (AS >= max) { + max2 = max; + max = AS; maxI = _j; } else if (AS > max2) { max2 = AS; @@ -5112,7 +5133,7 @@ var affinityPropagation = function affinityPropagation(options) { } for (var _j2 = 0; _j2 < n; _j2++) { - R[_i8 * n + _j2] = (1 - opts.damping) * (S[_i8 * n + _j2] - max$$1) + opts.damping * old[_j2]; + R[_i8 * n + _j2] = (1 - opts.damping) * (S[_i8 * n + _j2] - max) + opts.damping * old[_j2]; } R[_i8 * n + maxI] = (1 - opts.damping) * (S[_i8 * n + maxI] - max2) + opts.damping * old[maxI]; @@ -5173,7 +5194,7 @@ var affinityPropagation = function affinityPropagation(options) { var exemplarsIndices = findExemplars(n, R, A); // Assign nodes to clusters - var clusterIndices = assign$2(n, S, exemplarsIndices, nodes, id2position); + var clusterIndices = assign$2(n, S, exemplarsIndices); var clusters = {}; for (var c = 0; c < exemplarsIndices.length; c++) { @@ -5701,7 +5722,7 @@ extend(anifn, { return this; }, - promise: function promise$$1(type) { + promise: function promise(type) { var _p = this._private; var arr; @@ -5815,7 +5836,7 @@ var define = { return this; } - var style$$1 = cy.style(); + var style = cy.style(); properties = extend({}, properties, params); var propertiesEmpty = Object.keys(properties).length === 0; @@ -5838,7 +5859,7 @@ var define = { } if (isEles) { - properties.style = style$$1.getPropsList(properties.style || properties.css); + properties.style = style.getPropsList(properties.style || properties.css); properties.css = undefined; } @@ -5979,7 +6000,7 @@ var define = { var define$1 = { // access data field data: function data(params) { - var defaults$$1 = { + var defaults = { field: 'data', bindingEvent: 'data', allowBinding: false, @@ -5998,7 +6019,7 @@ var define$1 = { return true; } }; - params = extend({}, defaults$$1, params); + params = extend({}, defaults, params); return function dataImpl(name, value) { var p = params; var self = this; @@ -6089,8 +6110,8 @@ var define$1 = { } else if (p.allowBinding && fn(name)) { // bind to event - var fn$$1 = name; - self.on(p.bindingEvent, fn$$1); // .data() + var fn$1 = name; + self.on(p.bindingEvent, fn$1); // .data() } else if (p.allowGetting && name === undefined) { // get whole object var _ret; @@ -6109,7 +6130,7 @@ var define$1 = { // data // remove data field removeData: function removeData(params) { - var defaults$$1 = { + var defaults = { field: 'data', event: 'data', triggerFnName: 'trigger', @@ -6117,7 +6138,7 @@ var define$1 = { immutableKeys: {} // key => true if immutable }; - params = extend({}, defaults$$1, params); + params = extend({}, defaults, params); return function removeDataImpl(names) { var p = params; var self = this; @@ -7510,7 +7531,7 @@ match[Type.DATA_BOOL] = function (check, ele) { match[Type.DATA_EXIST] = function (check, ele) { var field = check.field, operator = check.operator; - return existCmp(data(ele, field), operator); + return existCmp(data(ele, field)); }; match[Type.UNDIRECTED_EDGE] = function (check, ele) { @@ -7613,7 +7634,7 @@ var filter = function filter(collection) { // does selector match a single element? -var matches$1 = function matches$$1(ele) { +var matches$1 = function matches$1(ele) { var self = this; for (var j = 0; j < self.length; j++) { @@ -7659,7 +7680,7 @@ var Selector = function Selector(selector) { this.invalid = true; } } else { - error('A selector must be created from a string; found ', selector); + error('A selector must be created from a string; found '); } }; @@ -7773,7 +7794,7 @@ elesfn$e.allAreNeighbours = elesfn$e.allAreNeighbors; elesfn$e.has = elesfn$e.contains; elesfn$e.equal = elesfn$e.equals = elesfn$e.same; -var cache = function cache(fn$$1, name) { +var cache = function cache(fn, name) { return function traversalCache(arg1, arg2, arg3, arg4) { var selectorOrEles = arg1; var eles = this; @@ -7795,10 +7816,10 @@ var cache = function cache(fn$$1, name) { if (cacheHit) { return cacheHit; } else { - return ch[hash] = fn$$1.call(eles, arg1, arg2, arg3, arg4); + return ch[hash] = fn.call(eles, arg1, arg2, arg3, arg4); } } else { - return fn$$1.call(eles, arg1, arg2, arg3, arg4); + return fn.call(eles, arg1, arg2, arg3, arg4); } }; }; @@ -8526,7 +8547,7 @@ elesfn$j.updateCompoundBounds = function () { var _p = parent._private; var children = parent.children(); var includeLabels = parent.pstyle('compound-sizing-wrt-labels').value === 'include'; - var min$$1 = { + var min = { width: { val: parent.pstyle('min-width').pfValue, left: parent.pstyle('min-width-bias-left'), @@ -8603,40 +8624,40 @@ elesfn$j.updateCompoundBounds = function () { } } - var leftVal = min$$1.width.left.value; + var leftVal = min.width.left.value; - if (min$$1.width.left.units === 'px' && min$$1.width.val > 0) { - leftVal = leftVal * 100 / min$$1.width.val; + if (min.width.left.units === 'px' && min.width.val > 0) { + leftVal = leftVal * 100 / min.width.val; } - var rightVal = min$$1.width.right.value; + var rightVal = min.width.right.value; - if (min$$1.width.right.units === 'px' && min$$1.width.val > 0) { - rightVal = rightVal * 100 / min$$1.width.val; + if (min.width.right.units === 'px' && min.width.val > 0) { + rightVal = rightVal * 100 / min.width.val; } - var topVal = min$$1.height.top.value; + var topVal = min.height.top.value; - if (min$$1.height.top.units === 'px' && min$$1.height.val > 0) { - topVal = topVal * 100 / min$$1.height.val; + if (min.height.top.units === 'px' && min.height.val > 0) { + topVal = topVal * 100 / min.height.val; } - var bottomVal = min$$1.height.bottom.value; + var bottomVal = min.height.bottom.value; - if (min$$1.height.bottom.units === 'px' && min$$1.height.val > 0) { - bottomVal = bottomVal * 100 / min$$1.height.val; + if (min.height.bottom.units === 'px' && min.height.val > 0) { + bottomVal = bottomVal * 100 / min.height.val; } - var widthBiasDiffs = computeBiasValues(min$$1.width.val - bb.w, leftVal, rightVal); + var widthBiasDiffs = computeBiasValues(min.width.val - bb.w, leftVal, rightVal); var diffLeft = widthBiasDiffs.biasDiff; var diffRight = widthBiasDiffs.biasComplementDiff; - var heightBiasDiffs = computeBiasValues(min$$1.height.val - bb.h, topVal, bottomVal); + var heightBiasDiffs = computeBiasValues(min.height.val - bb.h, topVal, bottomVal); var diffTop = heightBiasDiffs.biasDiff; var diffBottom = heightBiasDiffs.biasComplementDiff; _p.autoPadding = computePaddingValues(bb.w, bb.h, parent.pstyle('padding'), parent.pstyle('padding-relative-to').value); - _p.autoWidth = Math.max(bb.w, min$$1.width.val); + _p.autoWidth = Math.max(bb.w, min.width.val); pos.x = (-diffLeft + bb.x1 + bb.x2 + diffRight) / 2; - _p.autoHeight = Math.max(bb.h, min$$1.height.val); + _p.autoHeight = Math.max(bb.h, min.height.val); pos.y = (-diffTop + bb.y1 + bb.y2 + diffBottom) / 2; } @@ -8684,6 +8705,10 @@ var updateBounds = function updateBounds(b, x1, y1, x2, y2) { }; var updateBoundsFromBox = function updateBoundsFromBox(b, b2) { + if (b2 == null) { + return b; + } + return updateBounds(b, b2.x1, b2.y1, b2.x2, b2.y2); }; @@ -8761,8 +8786,8 @@ var updateBoundsFromLabel = function updateBoundsFromLabel(bounds, ele, prefix) var borderWidth = ele.pstyle('text-border-width').pfValue; var halfBorderWidth = borderWidth / 2; var padding = ele.pstyle('text-background-padding').pfValue; - var lh = labelHeight + 2 * padding; - var lw = labelWidth + 2 * padding; + var lh = labelHeight; + var lw = labelWidth; var lw_2 = lw / 2; var lh_2 = lh / 2; var lx1, lx2, ly1, ly2; @@ -8809,10 +8834,10 @@ var updateBoundsFromLabel = function updateBoundsFromLabel(bounds, ele, prefix) } // shift by margin and expand by outline and border - lx1 += marginX - Math.max(outlineWidth, halfBorderWidth); - lx2 += marginX + Math.max(outlineWidth, halfBorderWidth); - ly1 += marginY - Math.max(outlineWidth, halfBorderWidth); - ly2 += marginY + Math.max(outlineWidth, halfBorderWidth); // always store the unrotated label bounds separately + lx1 += marginX - Math.max(outlineWidth, halfBorderWidth) - padding; + lx2 += marginX + Math.max(outlineWidth, halfBorderWidth) + padding; + ly1 += marginY - Math.max(outlineWidth, halfBorderWidth) - padding; + ly2 += marginY + Math.max(outlineWidth, halfBorderWidth) + padding; // always store the unrotated label bounds separately var bbPrefix = prefix || 'main'; var bbs = _p.labelBounds; @@ -8891,18 +8916,25 @@ var boundingBoxImpl = function boundingBoxImpl(ele, options) { var headless = cy.headless(); var bounds = makeBoundingBox(); var _p = ele._private; - var display = styleEnabled ? ele.pstyle('display').value : 'element'; var isNode = ele.isNode(); var isEdge = ele.isEdge(); var ex1, ex2, ey1, ey2; // extrema of body / lines var x, y; // node pos - var displayed = display !== 'none'; var rstyle = _p.rstyle; - var manualExpansion = isNode && styleEnabled ? ele.pstyle('bounds-expansion').pfValue : 0; + var manualExpansion = isNode && styleEnabled ? ele.pstyle('bounds-expansion').pfValue : 0; // must use `display` prop only, as reading `compound.width()` causes recursion + // (other factors like width values will be considered later in this function anyway) + + var isDisplayed = function isDisplayed(ele) { + return ele.pstyle('display').value !== 'none'; + }; + + var displayed = !styleEnabled || isDisplayed(ele) // must take into account connected nodes b/c of implicit edge hiding on display:none node + && (!isEdge || isDisplayed(ele.source()) && isDisplayed(ele.target())); if (displayed) { + // displayed suffices, since we will find zero area eles anyway var overlayOpacity = 0; var overlayPadding = 0; @@ -9028,10 +9060,10 @@ var boundingBoxImpl = function boundingBoxImpl(ele, options) { if (styleEnabled && options.includeEdges && isEdge) { - updateBoundsFromArrow(bounds, ele, 'mid-source', options); - updateBoundsFromArrow(bounds, ele, 'mid-target', options); - updateBoundsFromArrow(bounds, ele, 'source', options); - updateBoundsFromArrow(bounds, ele, 'target', options); + updateBoundsFromArrow(bounds, ele, 'mid-source'); + updateBoundsFromArrow(bounds, ele, 'mid-target'); + updateBoundsFromArrow(bounds, ele, 'source'); + updateBoundsFromArrow(bounds, ele, 'target'); } // ghost //////// @@ -9079,11 +9111,11 @@ var boundingBoxImpl = function boundingBoxImpl(ele, options) { } if (styleEnabled && options.includeLabels) { - updateBoundsFromLabel(bounds, ele, null, options); + updateBoundsFromLabel(bounds, ele, null); if (isEdge) { - updateBoundsFromLabel(bounds, ele, 'source', options); - updateBoundsFromLabel(bounds, ele, 'target', options); + updateBoundsFromLabel(bounds, ele, 'source'); + updateBoundsFromLabel(bounds, ele, 'target'); } } // style enabled for labels @@ -9229,9 +9261,10 @@ var defBbOptsKey = getKey(defBbOpts); var filledBbOpts = defaults(defBbOpts); elesfn$j.boundingBox = function (options) { - // the main usecase is ele.boundingBox() for a single element with no/def options + var bounds; // the main usecase is ele.boundingBox() for a single element with no/def options // specified s.t. the cache is used, so check for this case to make it faster by // avoiding the overhead of the rest of the function + if (this.length === 1 && this[0]._private.bbCache != null && (options === undefined || options.useCache === undefined || options.useCache === true)) { if (options === undefined) { options = defBbOpts; @@ -9239,32 +9272,32 @@ elesfn$j.boundingBox = function (options) { options = filledBbOpts(options); } - return cachedBoundingBoxImpl(this[0], options); - } - - var bounds = makeBoundingBox(); - options = options || defBbOpts; - var opts = filledBbOpts(options); - var eles = this; - var cy = eles.cy(); - var styleEnabled = cy.styleEnabled(); + bounds = cachedBoundingBoxImpl(this[0], options); + } else { + bounds = makeBoundingBox(); + options = options || defBbOpts; + var opts = filledBbOpts(options); + var eles = this; + var cy = eles.cy(); + var styleEnabled = cy.styleEnabled(); - if (styleEnabled) { - for (var i = 0; i < eles.length; i++) { - var ele = eles[i]; - var _p = ele._private; - var currPosKey = getBoundingBoxPosKey(ele); - var isPosKeySame = _p.bbCachePosKey === currPosKey; - var useCache = opts.useCache && isPosKeySame; - ele.recalculateRenderedStyle(useCache); + if (styleEnabled) { + for (var i = 0; i < eles.length; i++) { + var ele = eles[i]; + var _p = ele._private; + var currPosKey = getBoundingBoxPosKey(ele); + var isPosKeySame = _p.bbCachePosKey === currPosKey; + var useCache = opts.useCache && isPosKeySame; + ele.recalculateRenderedStyle(useCache); + } } - } - this.updateCompoundBounds(); + this.updateCompoundBounds(); - for (var _i = 0; _i < eles.length; _i++) { - var _ele = eles[_i]; - updateBoundsFromBox(bounds, cachedBoundingBoxImpl(_ele, opts)); + for (var _i = 0; _i < eles.length; _i++) { + var _ele = eles[_i]; + updateBoundsFromBox(bounds, cachedBoundingBoxImpl(_ele, opts)); + } } bounds.x1 = noninf(bounds.x1); @@ -9282,6 +9315,16 @@ elesfn$j.dirtyBoundingBoxCache = function () { _p.bbCache = null; _p.bbCacheShift.x = _p.bbCacheShift.y = 0; _p.bbCachePosKey = null; + _p.bodyBounds = null; + _p.overlayBounds = null; + _p.labelBounds.all = null; + _p.labelBounds.source = null; + _p.labelBounds.target = null; + _p.labelBounds.main = null; + _p.arrowBounds.source = null; + _p.arrowBounds.target = null; + _p.arrowBounds['mid-source'] = null; + _p.arrowBounds['mid-target'] = null; } this.emitAndNotify('bounds'); @@ -9308,7 +9351,7 @@ elesfn$j.shiftCachedBoundingBox = function (delta) { // - try to use for only things like discrete layouts where the node position would change anyway -elesfn$j.boundingBoxAt = function (fn$$1) { +elesfn$j.boundingBoxAt = function (fn) { var nodes = this.nodes(); var cy = this.cy(); var hasCompoundNodes = cy.hasCompoundNodes(); @@ -9319,16 +9362,16 @@ elesfn$j.boundingBoxAt = function (fn$$1) { }); } - if (plainObject(fn$$1)) { - var obj = fn$$1; + if (plainObject(fn)) { + var obj = fn; - fn$$1 = function fn$$1() { + fn = function fn() { return obj; }; } var storeOldPos = function storeOldPos(node, i) { - return node._private.bbAtOldPos = fn$$1(node, i); + return node._private.bbAtOldPos = fn(node, i); }; var getOldPos = function getOldPos(node) { @@ -9336,7 +9379,7 @@ elesfn$j.boundingBoxAt = function (fn$$1) { }; cy.startBatch(); - nodes.forEach(storeOldPos).silentPositions(fn$$1); + nodes.forEach(storeOldPos).silentPositions(fn); if (hasCompoundNodes) { this.updateCompoundBounds(true); // force update b/c we're inside a batch cycle @@ -9691,8 +9734,12 @@ var defaults$8 = { context: null }; var defaultsKeys = Object.keys(defaults$8); +var emptyOpts = {}; + +function Emitter() { + var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : emptyOpts; + var context = arguments.length > 1 ? arguments[1] : undefined; -function Emitter(opts, context) { // micro-optimisation vs Object.assign() -- reduces Element instantiation time for (var i = 0; i < defaultsKeys.length; i++) { var key = defaultsKeys[i]; @@ -9783,10 +9830,10 @@ var forEachEventObj = function forEachEventObj(self, handler, events) { }; p.on = p.addListener = function (events, qualifier, callback, conf, confOverrides) { - forEachEvent(this, function (self, event$$1, type, namespace, qualifier, callback, conf) { + forEachEvent(this, function (self, event, type, namespace, qualifier, callback, conf) { if (fn(callback)) { self.listeners.push({ - event: event$$1, + event: event, // full event string callback: callback, // callback to run @@ -9821,10 +9868,10 @@ p.removeListener = p.off = function (events, qualifier, callback, conf) { var _loop = function _loop(i) { var listener = listeners[i]; - forEachEvent(_this, function (self, event$$1, type, namespace, qualifier, callback + forEachEvent(_this, function (self, event, type, namespace, qualifier, callback /*, conf*/ ) { - if (listener.type === type && (!namespace || listener.namespace === namespace) && (!qualifier || self.qualifierCompare(listener.qualifier, qualifier)) && (!callback || listener.callback === callback)) { + if ((listener.type === type || events === '*') && (!namespace && listener.namespace !== '.*' || listener.namespace === namespace) && (!qualifier || self.qualifierCompare(listener.qualifier, qualifier)) && (!callback || listener.callback === callback)) { listeners.splice(i, 1); return false; } @@ -9838,6 +9885,10 @@ p.removeListener = p.off = function (events, qualifier, callback, conf) { return this; }; +p.removeAllListeners = function () { + return this.removeListener('*'); +}; + p.emit = p.trigger = function (events, extraParams, manualCallback) { var listeners = this.listeners; var numListenersBeforeEmit = listeners.length; @@ -9984,6 +10035,14 @@ var elesfn$l = { return this; }, + removeAllListeners: function removeAllListeners() { + for (var i = 0; i < this.length; i++) { + var ele = this[i]; + ele.emitter().removeAllListeners(); + } + + return this; + }, one: function one(events, selector, callback) { var argSel = argSelector(selector); @@ -10013,7 +10072,7 @@ var elesfn$l = { return this; }, - emitAndNotify: function emitAndNotify(event$$1, extraParams) { + emitAndNotify: function emitAndNotify(event, extraParams) { // for internal use only if (this.length === 0) { return; @@ -10021,8 +10080,8 @@ var elesfn$l = { // notify renderer - this.cy().notify(event$$1, this); - this.emit(event$$1, extraParams); + this.cy().notify(event, this); + this.emit(event, extraParams); return this; } }; @@ -10095,11 +10154,11 @@ var elesfn$m = { var rMap = toRemove._private.map; for (var i = 0; i < this.length; i++) { - var element$$1 = this[i]; - var remove = rMap.has(element$$1.id()); + var element = this[i]; + var remove = rMap.has(element.id()); if (!remove) { - elements.push(element$$1); + elements.push(element); } } @@ -10358,12 +10417,12 @@ var elesfn$m = { return arr; }, - reduce: function reduce(fn$$1, initialValue) { + reduce: function reduce(fn, initialValue) { var val = initialValue; var eles = this; for (var i = 0; i < eles.length; i++) { - val = fn$$1(val, eles[i], i, eles); + val = fn(val, eles[i], i, eles); } return val; @@ -10506,13 +10565,13 @@ var zIndexSort = function zIndexSort(a, b) { }; var elesfn$o = { - forEach: function forEach(fn$$1, thisArg) { - if (fn(fn$$1)) { + forEach: function forEach(fn$1, thisArg) { + if (fn(fn$1)) { var N = this.length; for (var i = 0; i < N; i++) { var ele = this[i]; - var ret = thisArg ? fn$$1.apply(thisArg, [ele, i, this]) : fn$$1(ele, i, this); + var ret = thisArg ? fn$1.apply(thisArg, [ele, i, this]) : fn$1(ele, i, this); if (ret === false) { break; @@ -10524,16 +10583,16 @@ var elesfn$o = { return this; }, toArray: function toArray() { - var array$$1 = []; + var array = []; for (var i = 0; i < this.length; i++) { - array$$1.push(this[i]); + array.push(this[i]); } - return array$$1; + return array; }, slice: function slice(start, end) { - var array$$1 = []; + var array = []; var thisSize = this.length; if (end == null) { @@ -10553,10 +10612,10 @@ var elesfn$o = { } for (var i = start; i >= 0 && i < end && i < thisSize; i++) { - array$$1.push(this[i]); + array.push(this[i]); } - return this.spawn(array$$1); + return this.spawn(array); }, size: function size() { return this.length; @@ -10576,7 +10635,7 @@ var elesfn$o = { nonempty: function nonempty() { return !this.empty(); }, - sort: function sort$$1(sortFn) { + sort: function sort(sortFn) { if (!fn(sortFn)) { return this; } @@ -10624,19 +10683,32 @@ var elesfn$p = { // Calculates and returns node dimensions { x, y } based on options given layoutDimensions: function layoutDimensions(options) { options = getLayoutDimensionOptions(options); + var dims; - if (options.nodeDimensionsIncludeLabels) { + if (!this.takesUpSpace()) { + dims = { + w: 0, + h: 0 + }; + } else if (options.nodeDimensionsIncludeLabels) { var bbDim = this.boundingBox(); - return { + dims = { w: bbDim.w, h: bbDim.h }; } else { - return { + dims = { w: this.outerWidth(), h: this.outerHeight() }; + } // sanitise the dimensions for external layouts (avoid division by zero) + + + if (dims.w === 0 || dims.h === 0) { + dims.w = dims.h = 1; } + + return dims; }, // using standard layout options, apply position function (w/ or w/o animation) layoutPositions: function layoutPositions(layout, options, fn) { @@ -10800,7 +10872,7 @@ var elesfn$p = { elesfn$p.createLayout = elesfn$p.makeLayout = elesfn$p.layout; -function styleCache(key, fn$$1, ele) { +function styleCache(key, fn, ele) { var _p = ele._private; var cache = _p.styleCache = _p.styleCache || []; var val; @@ -10808,23 +10880,23 @@ function styleCache(key, fn$$1, ele) { if ((val = cache[key]) != null) { return val; } else { - val = cache[key] = fn$$1(ele); + val = cache[key] = fn(ele); return val; } } -function cacheStyleFunction(key, fn$$1) { +function cacheStyleFunction(key, fn) { key = hashString(key); return function cachedStyleFunction(ele) { - return styleCache(key, fn$$1, ele); + return styleCache(key, fn, ele); }; } -function cachePrototypeStyleFunction(key, fn$$1) { +function cachePrototypeStyleFunction(key, fn) { key = hashString(key); var selfFn = function selfFn(ele) { - return fn$$1.call(ele); + return fn.call(ele); }; return function cachedPrototypeStyleFunction() { @@ -10884,7 +10956,7 @@ var elesfn$q = { } var hasCompounds = cy.hasCompoundNodes(); - var style$$1 = cy.style(); + var style = cy.style(); var updatedEles = this; notifyRenderer = notifyRenderer || notifyRenderer === undefined ? true : false; @@ -10893,7 +10965,7 @@ var elesfn$q = { updatedEles = this.spawnSelf().merge(this.descendants()).merge(this.parents()); } - var changedEles = style$$1.apply(updatedEles); + var changedEles = style.apply(updatedEles); if (notifyRenderer) { changedEles.emitAndNotify('style'); // let renderer know we changed style @@ -10964,7 +11036,7 @@ var elesfn$q = { } }, // read the calculated css style of the element or override the style (via a bypass) - style: function style$$1(name, value) { + style: function style(name, value) { var cy = this.cy(); if (!cy.styleEnabled()) { @@ -10972,12 +11044,12 @@ var elesfn$q = { } var updateTransitions = false; - var style$$1 = cy.style(); + var style = cy.style(); if (plainObject(name)) { // then extend the bypass var props = name; - style$$1.applyBypass(this, props, updateTransitions); + style.applyBypass(this, props, updateTransitions); this.emitAndNotify('style'); // let the renderer know we've updated style } else if (string(name)) { if (value === undefined) { @@ -10985,21 +11057,21 @@ var elesfn$q = { var ele = this[0]; if (ele) { - return style$$1.getStylePropertyValue(ele, name); + return style.getStylePropertyValue(ele, name); } else { // empty collection => can't get any value return; } } else { // then set the bypass with the property value - style$$1.applyBypass(this, name, value, updateTransitions); + style.applyBypass(this, name, value, updateTransitions); this.emitAndNotify('style'); // let the renderer know we've updated style } } else if (name === undefined) { var _ele = this[0]; if (_ele) { - return style$$1.getRawStyle(_ele); + return style.getRawStyle(_ele); } else { // empty collection => can't get any value return; @@ -11016,20 +11088,20 @@ var elesfn$q = { } var updateTransitions = false; - var style$$1 = cy.style(); + var style = cy.style(); var eles = this; if (names === undefined) { for (var i = 0; i < eles.length; i++) { var ele = eles[i]; - style$$1.removeAllBypasses(ele, updateTransitions); + style.removeAllBypasses(ele, updateTransitions); } } else { names = names.split(/\s+/); for (var _i = 0; _i < eles.length; _i++) { var _ele2 = eles[_i]; - style$$1.removeBypasses(_ele2, names, updateTransitions); + style.removeBypasses(_ele2, names, updateTransitions); } } @@ -11199,6 +11271,10 @@ elesfn$q.hidden = function () { }; elesfn$q.isBundledBezier = cachePrototypeStyleFunction('isBundledBezier', function () { + if (!this.cy().styleEnabled()) { + return false; + } + return !this.removed() && this.pstyle('curve-style').value === 'bezier' && this.takesUpSpace(); }); elesfn$q.bypass = elesfn$q.css = elesfn$q.style; @@ -11311,7 +11387,7 @@ defineSwitchSet({ defineSwitchSet({ field: 'grabbable', overrideField: function overrideField(ele) { - return ele.cy().autoungrabify() ? false : undefined; + return ele.cy().autoungrabify() || ele.pannable() ? false : undefined; }, on: 'grabify', off: 'ungrabify' @@ -11348,6 +11424,11 @@ defineSwitchSet({ on: 'activate', off: 'unactivate' }); +defineSwitchSet({ + field: 'pannable', + on: 'panify', + off: 'unpanify' +}); elesfn$r.inactive = function () { var ele = this[0]; @@ -11700,10 +11781,10 @@ extend(elesfn$s, { }); function defineParallelEdgesFunction(params) { - var defaults$$1 = { + var defaults = { codirected: false }; - params = extend({}, defaults$$1, params); + params = extend({}, defaults, params); return function parallelEdgesImpl(selector) { // micro-optimised for renderer var elements = []; @@ -11801,7 +11882,7 @@ extend(elesfn$s, { elesfn$s.componentsOf = elesfn$s.components; var idFactory = { - generate: function generate(cy, element$$1, tryThisId) { + generate: function generate(cy, element, tryThisId) { var id = tryThisId != null ? tryThisId : uuid(); while (cy.hasElementWithId(id)) { @@ -11855,20 +11936,20 @@ var Collection = function Collection(cy, elements, options) { this.length = 0; for (var _i = 0, _l = elements.length; _i < _l; _i++) { - var element$$1 = elements[_i]; + var element$1 = elements[_i][0]; // [0] in case elements is an array of collections, rather than array of elements - if (element$$1 == null) { + if (element$1 == null) { continue; } - var id = element$$1._private.data.id; + var id = element$1._private.data.id; if (options == null || options.unique && !map.has(id)) { map.set(id, { index: this.length, - ele: element$$1 + ele: element$1 }); - this[this.length] = element$$1; + this[this.length] = element$1; this.length++; } } @@ -11936,10 +12017,14 @@ elesfn$t.unique = function () { }; elesfn$t.hasElementWithId = function (id) { + id = '' + id; // id must be string + return this._private.map.has(id); }; elesfn$t.getElementById = function (id) { + id = '' + id; // id must be string + var cy = this._private.cy; var entry = this._private.map.get(id); @@ -11962,6 +12047,8 @@ elesfn$t.indexOf = function (ele) { }; elesfn$t.indexOfId = function (id) { + id = '' + id; // id must be string + return this._private.map.get(id).index; }; @@ -11996,13 +12083,15 @@ elesfn$t.json = function (obj) { var src = obj.data.source; var tgt = obj.data.target; - if (src != null && src !== _data2.source) { - spec.source = src; + if (src != null && src != _data2.source) { + spec.source = '' + src; // id must be string + move = true; } - if (tgt != null && tgt !== _data2.target) { - spec.target = tgt; + if (tgt != null && tgt != _data2.target) { + spec.target = '' + tgt; // id must be string + move = true; } @@ -12013,12 +12102,16 @@ elesfn$t.json = function (obj) { // parent is immutable via data() var parent = obj.data.parent; - if ((parent != null || _data2.parent != null) && parent !== _data2.parent) { + if ((parent != null || _data2.parent != null) && parent != _data2.parent) { if (parent === undefined) { // can't set undefined imperatively, so use null parent = null; } + if (parent != null) { + parent = '' + parent; // id must be string + } + ele = ele.move({ parent: parent }); @@ -12048,6 +12141,7 @@ elesfn$t.json = function (obj) { checkSwitch('selectable', 'selectify', 'unselectify'); checkSwitch('locked', 'lock', 'unlock'); checkSwitch('grabbable', 'grabify', 'ungrabify'); + checkSwitch('pannable', 'panify', 'unpanify'); if (obj.classes != null) { ele.classes(obj.classes); @@ -12066,6 +12160,7 @@ elesfn$t.json = function (obj) { selectable: p.selectable, locked: p.locked, grabbable: p.grabbable, + pannable: p.pannable, classes: null }; json.classes = ''; @@ -12096,9 +12191,9 @@ elesfn$t.clone = function () { for (var i = 0; i < this.length; i++) { var ele = this[i]; var json = ele.json(); - var clone$$1 = new Element(cy, json, false); // NB no restore + var clone = new Element(cy, json, false); // NB no restore - elesArr.push(clone$$1); + elesArr.push(clone); } return new Collection(cy, elesArr); @@ -12217,11 +12312,15 @@ elesfn$t.restore = function () { var src = cy.getElementById(_data3.source); - var tgt = cy.getElementById(_data3.target); + var tgt = cy.getElementById(_data3.target); // only one edge in node if loop - src._private.edges.push(edge); + if (src.same(tgt)) { + src._private.edges.push(edge); + } else { + src._private.edges.push(edge); - tgt._private.edges.push(edge); + tgt._private.edges.push(edge); + } edge._private.source = src; edge._private.target = tgt; @@ -12513,9 +12612,14 @@ elesfn$t.move = function (struct) { var notifyRenderer = false; var modifyPool = false; + var toString = function toString(id) { + return id == null ? id : '' + id; + }; // id must be string + + if (struct.source !== undefined || struct.target !== undefined) { - var srcId = struct.source; - var tgtId = struct.target; + var srcId = toString(struct.source); + var tgtId = toString(struct.target); var srcExists = srcId != null && cy.hasElementWithId(srcId); var tgtExists = tgtId != null && cy.hasElementWithId(tgtId); @@ -12547,7 +12651,7 @@ elesfn$t.move = function (struct) { } } else if (struct.parent !== undefined) { // move node to new parent - var parentId = struct.parent; + var parentId = toString(struct.parent); var parentExists = parentId === null || cy.hasElementWithId(parentId); if (parentExists) { @@ -12636,13 +12740,13 @@ var corefn = { return elements; }, - remove: function remove(collection$$1) { - if (elementOrCollection(collection$$1)) ; else if (string(collection$$1)) { - var selector = collection$$1; - collection$$1 = this.$(selector); + remove: function remove(collection) { + if (elementOrCollection(collection)) ; else if (string(collection)) { + var selector = collection; + collection = this.$(selector); } - return collection$$1.remove(); + return collection.remove(); } }; @@ -13042,7 +13146,7 @@ function step(self, ani, now, isCore) { var pEasing = ani_p.easing; var startTime = ani_p.startTime; var cy = isCore ? self : self.cy(); - var style$$1 = cy.style(); + var style = cy.style(); if (!ani_p.easingImpl) { if (pEasing == null) { @@ -13053,7 +13157,7 @@ function step(self, ani, now, isCore) { var easingVals; if (string(pEasing)) { - var easingProp = style$$1.parse('transition-timing-function', pEasing); + var easingProp = style.parse('transition-timing-function', pEasing); easingVals = easingProp.value; } else { // then assume preparsed array @@ -13147,7 +13251,7 @@ function step(self, ani, now, isCore) { if (animatingZoom) { if (valid(startZoom, endZoom)) { - _p.zoom = ease(startZoom, endZoom, percent, easing); + _p.zoom = bound(_p.minZoom, ease(startZoom, endZoom, percent, easing), _p.maxZoom); } self.emit('zoom'); @@ -13165,9 +13269,9 @@ function step(self, ani, now, isCore) { var _name = prop.name; var end = prop; var start = ani_p.startStyle[_name]; - var propSpec = style$$1.properties[start.name]; + var propSpec = style.properties[start.name]; var easedVal = ease(start, end, percent, easing, propSpec); - style$$1.overrideBypass(self, _name, easedVal); + style.overrideBypass(self, _name, easedVal); } // for props @@ -13262,7 +13366,7 @@ function stepAll(now, cy) { } if (!ani_p.started) { - startAnimation(ele, ani, now, isCore); + startAnimation(ele, ani, now); } step(ele, ani, now, isCore); @@ -13359,8 +13463,8 @@ var corefn$1 = { return; } - requestAnimationFrame(function animationStep(now$$1) { - stepAll(now$$1, cy); + requestAnimationFrame(function animationStep(now) { + stepAll(now, cy); headlessStep(); }); } @@ -13369,8 +13473,8 @@ var corefn$1 = { if (renderer && renderer.beforeRender) { // let the renderer schedule animations - renderer.beforeRender(function rendererAnimationStep(willDraw, now$$1) { - stepAll(now$$1, cy); + renderer.beforeRender(function rendererAnimationStep(willDraw, now) { + stepAll(now, cy); }, renderer.beforeRenderPriorities.animations); } else { // manage the animation loop ourselves @@ -13434,6 +13538,10 @@ var elesfn$u = { this.emitter().removeListener(events, argSelector$1(selector), callback); return this; }, + removeAllListeners: function removeAllListeners() { + this.emitter().removeAllListeners(); + return this; + }, one: function one(events, selector, callback) { this.emitter().one(events, argSelector$1(selector), callback); return this; @@ -13446,9 +13554,9 @@ var elesfn$u = { this.emitter().emit(events, extraParams); return this; }, - emitAndNotify: function emitAndNotify(event$$1, eles) { - this.emit(event$$1); - this.notify(event$$1, eles); + emitAndNotify: function emitAndNotify(event, eles) { + this.emit(event); + this.notify(event, eles); return this; } }; @@ -13530,7 +13638,7 @@ var corefn$4 = { var renderer = this.renderer(); // exit if destroy() called on core or renderer in between frames #1499 #1528 - if (this.isDestroyed() || !renderer) { + if (this.destroyed() || !renderer) { return; } @@ -13706,7 +13814,7 @@ var corefn$6 = { // - empty collection on no args // - collection of elements in the graph on selector arg // - guarantee a returned collection when elements or collection specified - collection: function collection$$1(eles, opts) { + collection: function collection(eles, opts) { if (string(eles)) { return this.$(eles); } else if (elementOrCollection(eles)) { @@ -13917,7 +14025,7 @@ styfn.getContextStyle = function (cxtMeta) { return cxtStyles[cxtKey]; } - var style$$1 = { + var style = { _private: { key: cxtKey } @@ -13933,12 +14041,12 @@ styfn.getContextStyle = function (cxtMeta) { for (var j = 0; j < cxt.properties.length; j++) { var prop = cxt.properties[j]; - style$$1[prop.name] = prop; + style[prop.name] = prop; } } - cxtStyles[cxtKey] = style$$1; - return style$$1; + cxtStyles[cxtKey] = style; + return style; }; styfn.applyContextStyle = function (cxtMeta, cxtStyle, ele) { @@ -13977,6 +14085,7 @@ styfn.applyContextStyle = function (cxtMeta, cxtStyle, ele) { if (cxtProp.mapped === types.fn // context prop is function mapper + && eleProp != null // some props can be null even by default (e.g. a prop that overrides another one) && eleProp.mapping != null // ele prop is a concrete value from from a mapper && eleProp.mapping.value === cxtProp.value // the current prop on the ele is a flat prop value for the function mapper ) { @@ -14036,6 +14145,12 @@ styfn.updateStyleHints = function (ele) { var updateGrKey = function updateGrKey(val, grKey) { return _p.styleKeys[grKey] = hashInt(val, _p.styleKeys[grKey]); + }; + + var updateGrKeyWStr = function updateGrKeyWStr(strVal, grKey) { + for (var j = 0; j < strVal.length; j++) { + updateGrKey(strVal.charCodeAt(j), grKey); + } }; // - hashing works on 32 bit ints b/c we use bitwise ops // - small numbers get cut off (e.g. 0.123 is seen as 0 by the hashing function) // - raise up small numbers so more significant digits are seen by hashing @@ -14057,12 +14172,25 @@ styfn.updateStyleHints = function (ele) { var propInfo = this.properties[name]; var type = propInfo.type; - var _grKey = propInfo.groupKey; // numbers are cheaper to hash than strings + var _grKey = propInfo.groupKey; + var normalizedNumberVal = void 0; + + if (propInfo.hashOverride != null) { + normalizedNumberVal = propInfo.hashOverride(ele, parsedProp); + } else if (parsedProp.pfValue != null) { + normalizedNumberVal = parsedProp.pfValue; + } // might not be a number if it allows enums + + + var numberVal = propInfo.enums == null ? parsedProp.value : null; + var haveNormNum = normalizedNumberVal != null; + var haveUnitedNum = numberVal != null; + var haveNum = haveNormNum || haveUnitedNum; + var units = parsedProp.units; // numbers are cheaper to hash than strings // 1 hash op vs n hash ops (for length n string) - if (type.number) { - // use pfValue if available (e.g. normalised units) - var v = parsedProp.pfValue != null ? parsedProp.pfValue : parsedProp.value; + if (type.number && haveNum) { + var v = haveNormNum ? normalizedNumberVal : numberVal; if (type.multiple) { for (var _i2 = 0; _i2 < v.length; _i2++) { @@ -14071,12 +14199,12 @@ styfn.updateStyleHints = function (ele) { } else { updateGrKey(cleanNum(v), _grKey); } - } else { - var strVal = parsedProp.strValue; - for (var j = 0; j < strVal.length; j++) { - updateGrKey(strVal.charCodeAt(j), _grKey); + if (!haveNormNum && units != null) { + updateGrKeyWStr(units, _grKey); } + } else { + updateGrKeyWStr(parsedProp.strValue, _grKey); } } // overall style key // @@ -14153,12 +14281,12 @@ styfn.clearStyleHints = function (ele) { styfn.applyParsedProperty = function (ele, parsedProp) { var self = this; var prop = parsedProp; - var style$$1 = ele._private.style; + var style = ele._private.style; var flatProp; var types = self.types; var type = self.properties[prop.name].type; var propIsBypass = prop.bypass; - var origProp = style$$1[prop.name]; + var origProp = style[prop.name]; var origPropIsBypass = origProp && origProp.bypass; var _p = ele._private; var flatPropMapping = 'mapping'; @@ -14188,7 +14316,7 @@ styfn.applyParsedProperty = function (ele, parsedProp) { if (prop.delete) { // delete the property and use the default value on falsey value - style$$1[prop.name] = undefined; + style[prop.name] = undefined; checkTriggers(); return true; } @@ -14217,7 +14345,7 @@ styfn.applyParsedProperty = function (ele, parsedProp) { } else if (origProp.bypass) { // then replace the bypass property with the original // because the bypassed property was already applied (and therefore parsed), we can just replace it (no reapplying necessary) - style$$1[prop.name] = origProp.bypassed; + style[prop.name] = origProp.bypassed; checkTriggers(); return true; } else { @@ -14342,8 +14470,8 @@ styfn.applyParsedProperty = function (ele, parsedProp) { case types.fn: { - var fn$$1 = prop.value; - var fnRetVal = prop.fnValue != null ? prop.fnValue : fn$$1(ele); // check for cached value before calling function + var fn = prop.value; + var fnRetVal = prop.fnValue != null ? prop.fnValue : fn(ele); // check for cached value before calling function prop.prevFnValue = fnRetVal; @@ -14385,7 +14513,7 @@ styfn.applyParsedProperty = function (ele, parsedProp) { prop.bypassed = origProp; } - style$$1[prop.name] = prop; // and set + style[prop.name] = prop; // and set } else { // prop is not bypass if (origPropIsBypass) { @@ -14393,7 +14521,7 @@ styfn.applyParsedProperty = function (ele, parsedProp) { origProp.bypassed = prop; } else { // then just replace the old prop with the new one - style$$1[prop.name] = prop; + style[prop.name] = prop; } } @@ -14411,18 +14539,18 @@ styfn.cleanElements = function (eles, keepBypasses) { if (!keepBypasses) { ele._private.style = {}; } else { - var style$$1 = ele._private.style; - var propNames = Object.keys(style$$1); + var style = ele._private.style; + var propNames = Object.keys(style); for (var j = 0; j < propNames.length; j++) { var propName = propNames[j]; - var eleProp = style$$1[propName]; + var eleProp = style[propName]; if (eleProp != null) { if (eleProp.bypass) { eleProp.bypassed = null; } else { - style$$1[propName] = null; + style[propName] = null; } } } @@ -14446,7 +14574,7 @@ styfn.updateTransitions = function (ele, diffProps) { var delay = ele.pstyle('transition-delay').pfValue; if (props.length > 0 && duration > 0) { - var style$$1 = {}; // build up the style to animate towards + var style = {}; // build up the style to animate towards var anyPrev = false; @@ -14486,7 +14614,7 @@ styfn.updateTransitions = function (ele, diffProps) { if (diff) { - style$$1[prop] = toProp.strValue; // to val + style[prop] = toProp.strValue; // to val this.applyBypass(ele, prop, initVal); // from val @@ -14509,7 +14637,7 @@ styfn.updateTransitions = function (ele, diffProps) { } }).then(function () { return ele.animation({ - style: style$$1, + style: style, duration: duration, easing: ele.pstyle('transition-timing-function').value, queue: false @@ -14902,15 +15030,15 @@ styfn$3.getAnimationStartStyle = function (ele, aniProps) { styfn$3.getPropsList = function (propsObj) { var self = this; var rstyle = []; - var style$$1 = propsObj; + var style = propsObj; var props = self.properties; - if (style$$1) { - var names = Object.keys(style$$1); + if (style) { + var names = Object.keys(style); for (var i = 0; i < names.length; i++) { var name = names[i]; - var val = style$$1[name]; + var val = style[name]; var prop = props[name] || props[camel2dash(name)]; var styleProp = this.parse(prop.name, val); @@ -15142,19 +15270,19 @@ styfn$5.fromString = function (string) { var styfn$6 = {}; (function () { - var number$$1 = number$1; - var rgba$$1 = rgbaNoBackRefs; - var hsla$$1 = hslaNoBackRefs; - var hex3$$1 = hex3; - var hex6$$1 = hex6; + var number = number$1; + var rgba = rgbaNoBackRefs; + var hsla = hslaNoBackRefs; + var hex3$1 = hex3; + var hex6$1 = hex6; var data = function data(prefix) { return '^' + prefix + '\\s*\\(\\s*([\\w\\.]+)\\s*\\)$'; }; var mapData = function mapData(prefix) { - var mapArg = number$$1 + '|\\w+|' + rgba$$1 + '|' + hsla$$1 + '|' + hex3$$1 + '|' + hex6$$1; - return '^' + prefix + '\\s*\\(([\\w\\.]+)\\s*\\,\\s*(' + number$$1 + ')\\s*\\,\\s*(' + number$$1 + ')\\s*,\\s*(' + mapArg + ')\\s*\\,\\s*(' + mapArg + ')\\)$'; + var mapArg = number + '|\\w+|' + rgba + '|' + hsla + '|' + hex3$1 + '|' + hex6$1; + return '^' + prefix + '\\s*\\(([\\w\\.]+)\\s*\\,\\s*(' + number + ')\\s*\\,\\s*(' + number + ')\\s*,\\s*(' + mapArg + ')\\s*\\,\\s*(' + mapArg + ')\\)$'; }; var urlRegexes = ['^url\\s*\\(\\s*[\'"]?(.+?)[\'"]?\\s*\\)$', '^(none)$', '^(.+)$']; // each visual style property has a type and needs to be validated according to it @@ -15282,7 +15410,8 @@ var styfn$6 = {}; multiple: true }, bgClip: { - enums: ['none', 'node'] + enums: ['none', 'node'], + multiple: true }, color: { color: true @@ -15327,6 +15456,9 @@ var styfn$6 = {}; textWrap: { enums: ['none', 'wrap', 'ellipsis'] }, + textOverflowWrap: { + enums: ['whitespace', 'anywhere'] + }, textBackgroundShape: { enums: ['rectangle', 'roundrectangle', 'round-rectangle'] }, @@ -15360,6 +15492,9 @@ var styfn$6 = {}; halign: { enums: ['left', 'center', 'right'] }, + justification: { + enums: ['left', 'center', 'right', 'auto'] + }, text: { string: true }, @@ -15448,7 +15583,7 @@ var styfn$6 = {}; } }, easing: { - regexes: ['^(spring)\\s*\\(\\s*(' + number$$1 + ')\\s*,\\s*(' + number$$1 + ')\\s*\\)$', '^(cubic-bezier)\\s*\\(\\s*(' + number$$1 + ')\\s*,\\s*(' + number$$1 + ')\\s*,\\s*(' + number$$1 + ')\\s*,\\s*(' + number$$1 + ')\\s*\\)$'], + regexes: ['^(spring)\\s*\\(\\s*(' + number + ')\\s*,\\s*(' + number + ')\\s*\\)$', '^(cubic-bezier)\\s*\\(\\s*(' + number + ')\\s*,\\s*(' + number + ')\\s*,\\s*(' + number + ')\\s*,\\s*(' + number + ')\\s*\\)$'], enums: ['linear', 'ease', 'ease-in', 'ease-out', 'ease-in-out', 'ease-in-sine', 'ease-out-sine', 'ease-in-out-sine', 'ease-in-quad', 'ease-out-quad', 'ease-in-out-quad', 'ease-in-cubic', 'ease-out-cubic', 'ease-in-out-cubic', 'ease-in-quart', 'ease-out-quart', 'ease-in-out-quart', 'ease-in-quint', 'ease-out-quint', 'ease-in-out-quint', 'ease-in-expo', 'ease-out-expo', 'ease-in-out-expo', 'ease-in-circ', 'ease-out-circ', 'ease-in-out-circ'] }, gradientDirection: { @@ -15561,6 +15696,10 @@ var styfn$6 = {}; name: 'text-wrap', type: t.textWrap, triggersBounds: diff.any + }, { + name: 'text-overflow-wrap', + type: t.textOverflowWrap, + triggersBounds: diff.any }, { name: 'text-max-width', type: t.size, @@ -15569,6 +15708,10 @@ var styfn$6 = {}; name: 'text-outline-width', type: t.size, triggersBounds: diff.any + }, { + name: 'line-height', + type: t.positiveNumber, + triggersBounds: diff.any }]; var commonLabel = [{ name: 'text-valign', @@ -15615,6 +15758,9 @@ var styfn$6 = {}; name: 'text-background-shape', type: t.textBackgroundShape, triggersBounds: diff.any + }, { + name: 'text-justification', + type: t.justification }]; var behavior = [{ name: 'events', @@ -15681,14 +15827,25 @@ var styfn$6 = {}; name: 'transition-timing-function', type: t.easing }]; + + var nodeSizeHashOverride = function nodeSizeHashOverride(ele, parsedProp) { + if (parsedProp.value === 'label') { + return -ele.poolIndex(); // no hash key hits is using label size (hitrate for perf probably low anyway) + } else { + return parsedProp.pfValue; + } + }; + var nodeBody = [{ name: 'height', type: t.nodeSize, - triggersBounds: diff.any + triggersBounds: diff.any, + hashOverride: nodeSizeHashOverride }, { name: 'width', type: t.nodeSize, - triggersBounds: diff.any + triggersBounds: diff.any, + hashOverride: nodeSizeHashOverride }, { name: 'shape', type: t.nodeShape, @@ -15935,7 +16092,7 @@ var styfn$6 = {}; name: 'ghost-opacity', type: t.zeroOneNumber }]; - var core$$1 = [{ + var core = [{ name: 'selection-box-color', type: t.color }, { @@ -15992,7 +16149,8 @@ var styfn$6 = {}; var arrowPrefixes = styfn$6.arrowPrefixes = ['source', 'mid-source', 'target', 'mid-target']; [{ name: 'arrow-shape', - type: t.arrowShape + type: t.arrowShape, + triggersBounds: diff.any }, { name: 'arrow-color', type: t.color @@ -16002,14 +16160,16 @@ var styfn$6 = {}; }].forEach(function (prop) { arrowPrefixes.forEach(function (prefix) { var name = prefix + '-' + prop.name; - var type = prop.type; + var type = prop.type, + triggersBounds = prop.triggersBounds; edgeArrow.push({ name: name, - type: type + type: type, + triggersBounds: triggersBounds }); }); }, {}); - var props = styfn$6.properties = [].concat(behavior, transition, visibility, overlay, ghost, commonLabel, labelDimensions, mainLabel, sourceLabel, targetLabel, nodeBody, nodeBorder, backgroundImage, pie, compound, edgeLine, edgeArrow, core$$1); + var props = styfn$6.properties = [].concat(behavior, transition, visibility, overlay, ghost, commonLabel, labelDimensions, mainLabel, sourceLabel, targetLabel, nodeBody, nodeBorder, backgroundImage, pie, compound, edgeLine, edgeArrow, core); var propGroups = styfn$6.propertyGroups = { // common to all eles behavior: behavior, @@ -16032,7 +16192,7 @@ var styfn$6 = {}; // edge props edgeLine: edgeLine, edgeArrow: edgeArrow, - core: core$$1 + core: core }; var propGroupNames = styfn$6.propertyGroupNames = {}; var propGroupKeys = styfn$6.propertyGroupKeys = Object.keys(propGroups); @@ -16122,6 +16282,8 @@ styfn$6.getDefaultProperties = function () { 'text-events': 'no', 'text-valign': 'top', 'text-halign': 'center', + 'text-justification': 'auto', + 'line-height': 1, 'color': '#000', 'text-outline-color': '#000', 'text-outline-width': 0, @@ -16130,6 +16292,7 @@ styfn$6.getDefaultProperties = function () { 'text-decoration': 'none', 'text-transform': 'none', 'text-wrap': 'none', + 'text-overflow-wrap': 'whitespace', 'text-max-width': 9999, 'text-background-color': '#000', 'text-background-opacity': 0, @@ -16749,9 +16912,9 @@ styfn$7.parseImpl = function (name, value, propIsBypass, propIsFlat) { var regexes = type.regexes ? type.regexes : [type.regex]; for (var _i3 = 0; _i3 < regexes.length; _i3++) { - var regex$$1 = new RegExp(regexes[_i3]); // make a regex from the type string + var regex = new RegExp(regexes[_i3]); // make a regex from the type string - var m = regex$$1.exec(value); + var m = regex.exec(value); if (m) { // regex matches @@ -16901,13 +17064,13 @@ styfn$8.cssRule = function (name, value) { return this; // chaining }; -styfn$8.append = function (style$$1) { - if (stylesheet(style$$1)) { - style$$1.appendToStyle(this); - } else if (array(style$$1)) { - this.appendFromJson(style$$1); - } else if (string(style$$1)) { - this.appendFromString(style$$1); +styfn$8.append = function (style) { + if (stylesheet(style)) { + style.appendToStyle(this); + } else if (array(style)) { + this.appendFromJson(style); + } else if (string(style)) { + this.appendFromString(style); } // you probably wouldn't want to append a Style, since you'd duplicate the default parts @@ -16916,13 +17079,13 @@ styfn$8.append = function (style$$1) { Style.fromJson = function (cy, json) { - var style$$1 = new Style(cy); - style$$1.fromJson(json); - return style$$1; + var style = new Style(cy); + style.fromJson(json); + return style; }; -Style.fromString = function (cy, string$$1) { - return new Style(cy).fromString(string$$1); +Style.fromString = function (cy, string) { + return new Style(cy).fromString(string); }; [styfn, styfn$1, styfn$2, styfn$3, styfn$4, styfn$5, styfn$6, styfn$7].forEach(function (props) { @@ -16935,7 +17098,7 @@ Style.propertyGroupNames = styfn$8.propertyGroupNames; Style.propertyGroupKeys = styfn$8.propertyGroupKeys; var corefn$7 = { - style: function style$$1(newStyle) { + style: function style(newStyle) { if (newStyle) { var s = this.setStyle(newStyle); s.update(); @@ -16943,15 +17106,15 @@ var corefn$7 = { return this._private.style; }, - setStyle: function setStyle(style$$1) { + setStyle: function setStyle(style) { var _p = this._private; - if (stylesheet(style$$1)) { - _p.style = style$$1.generateStyle(this); - } else if (array(style$$1)) { - _p.style = Style.fromJson(this, style$$1); - } else if (string(style$$1)) { - _p.style = Style.fromString(this, style$$1); + if (stylesheet(style)) { + _p.style = style.generateStyle(this); + } else if (array(style)) { + _p.style = Style.fromJson(this, style); + } else if (string(style)) { + _p.style = Style.fromString(this, style); } else { _p.style = Style(this); } @@ -16962,27 +17125,27 @@ var corefn$7 = { var defaultSelectionType = 'single'; var corefn$8 = { - autolock: function autolock(bool$$1) { - if (bool$$1 !== undefined) { - this._private.autolock = bool$$1 ? true : false; + autolock: function autolock(bool) { + if (bool !== undefined) { + this._private.autolock = bool ? true : false; } else { return this._private.autolock; } return this; // chaining }, - autoungrabify: function autoungrabify(bool$$1) { - if (bool$$1 !== undefined) { - this._private.autoungrabify = bool$$1 ? true : false; + autoungrabify: function autoungrabify(bool) { + if (bool !== undefined) { + this._private.autoungrabify = bool ? true : false; } else { return this._private.autoungrabify; } return this; // chaining }, - autounselectify: function autounselectify(bool$$1) { - if (bool$$1 !== undefined) { - this._private.autounselectify = bool$$1 ? true : false; + autounselectify: function autounselectify(bool) { + if (bool !== undefined) { + this._private.autounselectify = bool ? true : false; } else { return this._private.autounselectify; } @@ -17006,45 +17169,45 @@ var corefn$8 = { return this; }, - panningEnabled: function panningEnabled(bool$$1) { - if (bool$$1 !== undefined) { - this._private.panningEnabled = bool$$1 ? true : false; + panningEnabled: function panningEnabled(bool) { + if (bool !== undefined) { + this._private.panningEnabled = bool ? true : false; } else { return this._private.panningEnabled; } return this; // chaining }, - userPanningEnabled: function userPanningEnabled(bool$$1) { - if (bool$$1 !== undefined) { - this._private.userPanningEnabled = bool$$1 ? true : false; + userPanningEnabled: function userPanningEnabled(bool) { + if (bool !== undefined) { + this._private.userPanningEnabled = bool ? true : false; } else { return this._private.userPanningEnabled; } return this; // chaining }, - zoomingEnabled: function zoomingEnabled(bool$$1) { - if (bool$$1 !== undefined) { - this._private.zoomingEnabled = bool$$1 ? true : false; + zoomingEnabled: function zoomingEnabled(bool) { + if (bool !== undefined) { + this._private.zoomingEnabled = bool ? true : false; } else { return this._private.zoomingEnabled; } return this; // chaining }, - userZoomingEnabled: function userZoomingEnabled(bool$$1) { - if (bool$$1 !== undefined) { - this._private.userZoomingEnabled = bool$$1 ? true : false; + userZoomingEnabled: function userZoomingEnabled(bool) { + if (bool !== undefined) { + this._private.userZoomingEnabled = bool ? true : false; } else { return this._private.userZoomingEnabled; } return this; // chaining }, - boxSelectionEnabled: function boxSelectionEnabled(bool$$1) { - if (bool$$1 !== undefined) { - this._private.boxSelectionEnabled = bool$$1 ? true : false; + boxSelectionEnabled: function boxSelectionEnabled(bool) { + if (bool !== undefined) { + this._private.boxSelectionEnabled = bool ? true : false; } else { return this._private.boxSelectionEnabled; } @@ -17236,22 +17399,22 @@ var corefn$8 = { return; }, - zoomRange: function zoomRange(min$$1, max$$1) { + zoomRange: function zoomRange(min, max) { var _p = this._private; - if (max$$1 == null) { - var opts = min$$1; - min$$1 = opts.min; - max$$1 = opts.max; + if (max == null) { + var opts = min; + min = opts.min; + max = opts.max; } - if (number(min$$1) && number(max$$1) && min$$1 <= max$$1) { - _p.minZoom = min$$1; - _p.maxZoom = max$$1; - } else if (number(min$$1) && max$$1 === undefined && min$$1 <= _p.maxZoom) { - _p.minZoom = min$$1; - } else if (number(max$$1) && min$$1 === undefined && max$$1 >= _p.minZoom) { - _p.maxZoom = max$$1; + if (number(min) && number(max) && min <= max) { + _p.minZoom = min; + _p.maxZoom = max; + } else if (number(min) && max === undefined && min <= _p.maxZoom) { + _p.minZoom = min; + } else if (number(max) && min === undefined && max >= _p.minZoom) { + _p.maxZoom = max; } return this; @@ -17487,10 +17650,10 @@ var corefn$8 = { var _p = this._private; var container = _p.container; return _p.sizeCache = _p.sizeCache || (container ? function () { - var style$$1 = window$1.getComputedStyle(container); + var style = window$1.getComputedStyle(container); var val = function val(name) { - return parseFloat(style$$1.getPropertyValue(name)); + return parseFloat(style.getPropertyValue(name)); }; return { @@ -17542,6 +17705,44 @@ corefn$8.centre = corefn$8.center; // backwards compatibility corefn$8.autolockNodes = corefn$8.autolock; corefn$8.autoungrabifyNodes = corefn$8.autoungrabify; +var fn$6 = { + data: define$3.data({ + field: 'data', + bindingEvent: 'data', + allowBinding: true, + allowSetting: true, + settingEvent: 'data', + settingTriggersEvent: true, + triggerFnName: 'trigger', + allowGetting: true + }), + removeData: define$3.removeData({ + field: 'data', + event: 'data', + triggerFnName: 'trigger', + triggerEvent: true + }), + scratch: define$3.data({ + field: 'scratch', + bindingEvent: 'scratch', + allowBinding: true, + allowSetting: true, + settingEvent: 'scratch', + settingTriggersEvent: true, + triggerFnName: 'trigger', + allowGetting: true + }), + removeScratch: define$3.removeData({ + field: 'scratch', + event: 'scratch', + triggerFnName: 'trigger', + triggerEvent: true + }) +}; // aliases + +fn$6.attr = fn$6.data; +fn$6.removeAttr = fn$6.removeData; + var Core = function Core(opts) { var cy = this; opts = extend({}, opts); @@ -17601,6 +17802,8 @@ var Core = function Core(opts) { // list of listeners aniEles: new Collection(this), // elements being animated + data: {}, + // data for the core scratch: {}, // scratch object for core layout: null, @@ -17712,8 +17915,8 @@ var Core = function Core(opts) { for (var i = 0; i < readies.length; i++) { - var fn$$1 = readies[i]; - cy.on('ready', fn$$1); + var fn$1 = readies[i]; + cy.on('ready', fn$1); } if (reg) { @@ -17735,21 +17938,21 @@ extend(corefn$9, { isReady: function isReady() { return this._private.ready; }, - isDestroyed: function isDestroyed() { + destroyed: function destroyed() { return this._private.destroyed; }, - ready: function ready(fn$$1) { + ready: function ready(fn) { if (this.isReady()) { - this.emitter().emit('ready', [], fn$$1); // just calls fn as though triggered via ready event + this.emitter().emit('ready', [], fn); // just calls fn as though triggered via ready event } else { - this.on('ready', fn$$1); + this.on('ready', fn); } return this; }, destroy: function destroy() { var cy = this; - if (cy.isDestroyed()) return; + if (cy.destroyed()) return; cy.stopAnimationLoop(); cy.destroyRenderer(); this.emit('destroy'); @@ -17784,7 +17987,7 @@ extend(corefn$9, { container: function container() { return this._private.container || null; }, - mount: function mount(container, rendererOptions) { + mount: function mount(container) { if (container == null) { return; } @@ -17792,10 +17995,6 @@ extend(corefn$9, { var cy = this; var _p = cy._private; var options = _p.options; - var rOpts = rendererOptions ? rendererOptions : { - name: 'canvas' - }; - options.renderer = rOpts; if (!htmlElement(container) && htmlElement(container[0])) { container = container[0]; @@ -17805,7 +18004,11 @@ extend(corefn$9, { cy.destroyRenderer(); _p.container = container; _p.styleEnabled = true; - cy.initRenderer(rOpts); + cy.invalidateSize(); + cy.initRenderer(extend({}, options, options.renderer, { + // allow custom renderer name to be re-used, otherwise use canvas + name: options.renderer.name === 'null' ? 'canvas' : options.renderer.name + })); cy.startAnimationLoop(); cy.style(options.style); cy.emit('mount'); @@ -17846,7 +18049,8 @@ extend(corefn$9, { for (var i = 0; i < jsons.length; i++) { var json = jsons[i]; - var id = json.data.id; + var id = '' + json.data.id; // id must be string + var ele = cy.getElementById(id); idInJson[id] = true; @@ -17931,6 +18135,10 @@ extend(corefn$9, { } } + if (obj.data) { + cy.data(obj.data); + } + var fields = ['minZoom', 'maxZoom', 'zoomingEnabled', 'userZoomingEnabled', 'panningEnabled', 'userPanningEnabled', 'boxSelectionEnabled', 'autolock', 'autoungrabify', 'autounselectify']; for (var _i2 = 0; _i2 < fields.length; _i2++) { @@ -17969,6 +18177,7 @@ extend(corefn$9, { json.style = cy.style().json(); } + json.data = copy(cy.data()); var options = _p.options; json.zoomingEnabled = _p.zoomingEnabled; json.userZoomingEnabled = _p.userZoomingEnabled; @@ -17986,26 +18195,10 @@ extend(corefn$9, { json.motionBlur = options.motionBlur; return json; } - }, - scratch: define$3.data({ - field: 'scratch', - bindingEvent: 'scratch', - allowBinding: true, - allowSetting: true, - settingEvent: 'scratch', - settingTriggersEvent: true, - triggerFnName: 'trigger', - allowGetting: true - }), - removeScratch: define$3.removeData({ - field: 'scratch', - event: 'scratch', - triggerFnName: 'trigger', - triggerEvent: true - }) + } }); corefn$9.$id = corefn$9.getElementById; -[corefn, corefn$1, elesfn$u, corefn$2, corefn$3, corefn$4, corefn$5, corefn$6, corefn$7, corefn$8].forEach(function (props) { +[corefn, corefn$1, elesfn$u, corefn$2, corefn$3, corefn$4, corefn$5, corefn$6, corefn$7, corefn$8, fn$6].forEach(function (props) { extend(corefn$9, props); }); @@ -18305,7 +18498,7 @@ BreadthFirstLayout.prototype.run = function () { if (depth < eleDepth) { // only get influenced by elements above - percent += index / (nDepth - 1); + percent += index / nDepth; samples++; } } @@ -18361,8 +18554,8 @@ BreadthFirstLayout.prototype.run = function () { x: bb.x1 + bb.w / 2, y: bb.x1 + bb.h / 2 }; - var maxDepthSize = depths.reduce(function (max$$1, eles) { - return Math.max(max$$1, eles.length); + var maxDepthSize = depths.reduce(function (max, eles) { + return Math.max(max, eles.length); }, 0); var getPosition = function getPosition(ele) { @@ -18805,9 +18998,7 @@ var defaults$c = { // Cooling factor (how the temperature is reduced between consecutive iterations coolingFactor: 0.99, // Lower temperature threshold (below this point the layout will end) - minTemp: 1.0, - // Pass a reference to weaver to use threads for calculations - weaver: false + minTemp: 1.0 }; /** * @brief : constructor @@ -18827,67 +19018,6 @@ CoseLayout.prototype.run = function () { var options = this.options; var cy = options.cy; var layout = this; - var thread$$1 = this.thread; - var Thread = options.weaver ? options.weaver.Thread : null; - var falseThread = { - // use false thread as polyfill - listeners: [], - on: function on(e, cb) { - this.listeners.push({ - event: e, - callback: cb - }); - return this; - }, - trigger: function trigger(e) { - if (string(e)) { - e = { - type: e - }; - } - - var matchesEvent = function matchesEvent(l) { - return l.event === e.type; - }; - - var trigger = function trigger(l) { - l.callback(e); - }; - - this.listeners.filter(matchesEvent).forEach(trigger); - return this; - }, - pass: function pass(data) { - this.pass = data; - return this; - }, - run: function run(cb) { - var pass = this.pass; - return new Promise$1(function (resolve) { - resolve(cb(pass)); - }); - }, - stop: function stop() { - return this; - }, - stopped: function stopped() { - return true; - } - }; - - function broadcast(message) { - // for false thread - var e = { - type: 'message', - message: message - }; - falseThread.trigger(e); - } - - if (!thread$$1 || thread$$1.stopped()) { - thread$$1 = this.thread = Thread ? new Thread() : falseThread; - } - layout.stopped = false; if (options.animate === true || options.animate === false) { @@ -18913,753 +19043,115 @@ CoseLayout.prototype.run = function () { if (options.randomize) { - randomizePositions(layoutInfo, cy); + randomizePositions(layoutInfo); } - var startTime = Date.now(); - var refreshRequested = false; - - var refresh = function refresh(rOpts) { - rOpts = rOpts || {}; + var startTime = performanceNow(); - if (refreshRequested && !rOpts.next) { - return; - } + var refresh = function refresh() { + refreshPositions(layoutInfo, cy, options); // Fit the graph if necessary - if (!rOpts.force && Date.now() - startTime < options.animationThreshold) { - return; + if (true === options.fit) { + cy.fit(options.padding); } + }; - refreshRequested = true; - requestAnimationFrame(function () { - refreshPositions(layoutInfo, cy, options); // Fit the graph if necessary + var mainLoop = function mainLoop(i) { + if (layout.stopped || i >= options.numIter) { + // logDebug("Layout manually stopped. Stopping computation in step " + i); + return false; + } // Do one step in the phisical simulation - if (true === options.fit) { - cy.fit(options.padding); - } - refreshRequested = false; + step$1(layoutInfo, options); // Update temperature - if (rOpts.next) { - rOpts.next(); - } - }); - }; + layoutInfo.temperature = layoutInfo.temperature * options.coolingFactor; // logDebug("New temperature: " + layoutInfo.temperature); - thread$$1.on('message', function (e) { - var layoutNodes = e.message; - layoutInfo.layoutNodes = layoutNodes; - refresh(); - }); - thread$$1.pass({ - layoutInfo: layoutInfo, - options: { - animate: options.animate, - refresh: options.refresh, - componentSpacing: options.componentSpacing, - nodeOverlap: options.nodeOverlap, - nestingFactor: options.nestingFactor, - gravity: options.gravity, - numIter: options.numIter, - initialTemp: options.initialTemp, - coolingFactor: options.coolingFactor, - minTemp: options.minTemp - } - }).run(function (pass) { - var layoutInfo = pass.layoutInfo; - var options = pass.options; - /** - * @brief : Performs one iteration of the physical simulation - * @arg layoutInfo : LayoutInfo object already initialized - * @arg cy : Cytoscape object - * @arg options : Layout options - */ - - var step = function step(layoutInfo, options, _step) { - // var s = "\n\n###############################"; - // s += "\nSTEP: " + step; - // s += "\n###############################\n"; - // logDebug(s); - // Calculate node repulsions - calculateNodeForces(layoutInfo, options); // Calculate edge forces + if (layoutInfo.temperature < options.minTemp) { + // logDebug("Temperature drop below minimum threshold. Stopping computation in step " + i); + return false; + } - calculateEdgeForces(layoutInfo, options); // Calculate gravity forces + return true; + }; - calculateGravityForces(layoutInfo, options); // Propagate forces from parent to child + var done = function done() { + if (options.animate === true || options.animate === false) { + refresh(); // Layout has finished - propagateForces(layoutInfo, options); // Update positions based on calculated forces + layout.one('layoutstop', options.stop); + layout.emit({ + type: 'layoutstop', + layout: layout + }); + } else { + var nodes = options.eles.nodes(); + var getScaledPos = getScaleInBoundsFn(layoutInfo, options, nodes); + nodes.layoutPositions(layout, options, getScaledPos); + } + }; - updatePositions(layoutInfo, options); - }; - /** - * @brief : Computes the node repulsion forces - */ + var i = 0; + var loopRet = true; + if (options.animate === true) { + var frame = function frame() { + var f = 0; - var calculateNodeForces = function calculateNodeForces(layoutInfo, options) { - // Go through each of the graphs in graphSet - // Nodes only repel each other if they belong to the same graph - // var s = 'calculateNodeForces'; - // logDebug(s); - for (var i = 0; i < layoutInfo.graphSet.length; i++) { - var graph = layoutInfo.graphSet[i]; - var numNodes = graph.length; // s = "Set: " + graph.toString(); - // logDebug(s); - // Now get all the pairs of nodes - // Only get each pair once, (A, B) = (B, A) + while (loopRet && f < options.refresh) { + loopRet = mainLoop(i); + i++; + f++; + } - for (var j = 0; j < numNodes; j++) { - var node1 = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[j]]]; + if (!loopRet) { + // it's done + separateComponents(layoutInfo, options); + done(); + } else { + var now = performanceNow(); - for (var k = j + 1; k < numNodes; k++) { - var node2 = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[k]]]; - nodeRepulsion(node1, node2, layoutInfo, options); - } + if (now - startTime >= options.animationThreshold) { + refresh(); } - } - }; - var randomDistance = function randomDistance(max$$1) { - return -max$$1 + 2 * max$$1 * Math.random(); + requestAnimationFrame(frame); + } }; - /** - * @brief : Compute the node repulsion forces between a pair of nodes - */ + frame(); + } else { + while (loopRet) { + loopRet = mainLoop(i); + i++; + } - var nodeRepulsion = function nodeRepulsion(node1, node2, layoutInfo, options) { - // var s = "Node repulsion. Node1: " + node1.id + " Node2: " + node2.id; - var cmptId1 = node1.cmptId; - var cmptId2 = node2.cmptId; - - if (cmptId1 !== cmptId2 && !layoutInfo.isCompound) { - return; - } // Get direction of line connecting both node centers - + separateComponents(layoutInfo, options); + done(); + } - var directionX = node2.positionX - node1.positionX; - var directionY = node2.positionY - node1.positionY; - var maxRandDist = 1; // s += "\ndirectionX: " + directionX + ", directionY: " + directionY; - // If both centers are the same, apply a random force + return this; // chaining +}; +/** + * @brief : called on continuous layouts to stop them before they finish + */ - if (0 === directionX && 0 === directionY) { - directionX = randomDistance(maxRandDist); - directionY = randomDistance(maxRandDist); - } - var overlap = nodesOverlap(node1, node2, directionX, directionY); +CoseLayout.prototype.stop = function () { + this.stopped = true; - if (overlap > 0) { - // s += "\nNodes DO overlap."; - // s += "\nOverlap: " + overlap; - // If nodes overlap, repulsion force is proportional - // to the overlap - var force = options.nodeOverlap * overlap; // Compute the module and components of the force vector + if (this.thread) { + this.thread.stop(); + } - var distance = Math.sqrt(directionX * directionX + directionY * directionY); // s += "\nDistance: " + distance; + this.emit('layoutstop'); + return this; // chaining +}; - var forceX = force * directionX / distance; - var forceY = force * directionY / distance; - } else { - // s += "\nNodes do NOT overlap."; - // If there's no overlap, force is inversely proportional - // to squared distance - // Get clipping points for both nodes - var point1 = findClippingPoint(node1, directionX, directionY); - var point2 = findClippingPoint(node2, -1 * directionX, -1 * directionY); // Use clipping points to compute distance - - var distanceX = point2.x - point1.x; - var distanceY = point2.y - point1.y; - var distanceSqr = distanceX * distanceX + distanceY * distanceY; - var distance = Math.sqrt(distanceSqr); // s += "\nDistance: " + distance; - // Compute the module and components of the force vector - - var force = (node1.nodeRepulsion + node2.nodeRepulsion) / distanceSqr; - var forceX = force * distanceX / distance; - var forceY = force * distanceY / distance; - } // Apply force - - - if (!node1.isLocked) { - node1.offsetX -= forceX; - node1.offsetY -= forceY; - } - - if (!node2.isLocked) { - node2.offsetX += forceX; - node2.offsetY += forceY; - } // s += "\nForceX: " + forceX + " ForceY: " + forceY; - // logDebug(s); - - - return; - }; - /** - * @brief : Determines whether two nodes overlap or not - * @return : Amount of overlapping (0 => no overlap) - */ - - - var nodesOverlap = function nodesOverlap(node1, node2, dX, dY) { - if (dX > 0) { - var overlapX = node1.maxX - node2.minX; - } else { - var overlapX = node2.maxX - node1.minX; - } - - if (dY > 0) { - var overlapY = node1.maxY - node2.minY; - } else { - var overlapY = node2.maxY - node1.minY; - } - - if (overlapX >= 0 && overlapY >= 0) { - return Math.sqrt(overlapX * overlapX + overlapY * overlapY); - } else { - return 0; - } - }; - /** - * @brief : Finds the point in which an edge (direction dX, dY) intersects - * the rectangular bounding box of it's source/target node - */ - - - var findClippingPoint = function findClippingPoint(node, dX, dY) { - // Shorcuts - var X = node.positionX; - var Y = node.positionY; - var H = node.height || 1; - var W = node.width || 1; - var dirSlope = dY / dX; - var nodeSlope = H / W; // var s = 'Computing clipping point of node ' + node.id + - // " . Height: " + H + ", Width: " + W + - // "\nDirection " + dX + ", " + dY; - // - // Compute intersection - - var res = {}; // Case: Vertical direction (up) - - if (0 === dX && 0 < dY) { - res.x = X; // s += "\nUp direction"; - - res.y = Y + H / 2; - return res; - } // Case: Vertical direction (down) - - - if (0 === dX && 0 > dY) { - res.x = X; - res.y = Y + H / 2; // s += "\nDown direction"; - - return res; - } // Case: Intersects the right border - - - if (0 < dX && -1 * nodeSlope <= dirSlope && dirSlope <= nodeSlope) { - res.x = X + W / 2; - res.y = Y + W * dY / 2 / dX; // s += "\nRightborder"; - - return res; - } // Case: Intersects the left border - - - if (0 > dX && -1 * nodeSlope <= dirSlope && dirSlope <= nodeSlope) { - res.x = X - W / 2; - res.y = Y - W * dY / 2 / dX; // s += "\nLeftborder"; - - return res; - } // Case: Intersects the top border - - - if (0 < dY && (dirSlope <= -1 * nodeSlope || dirSlope >= nodeSlope)) { - res.x = X + H * dX / 2 / dY; - res.y = Y + H / 2; // s += "\nTop border"; - - return res; - } // Case: Intersects the bottom border - - - if (0 > dY && (dirSlope <= -1 * nodeSlope || dirSlope >= nodeSlope)) { - res.x = X - H * dX / 2 / dY; - res.y = Y - H / 2; // s += "\nBottom border"; - - return res; - } // s += "\nClipping point found at " + res.x + ", " + res.y; - // logDebug(s); - - - return res; - }; - /** - * @brief : Calculates all edge forces - */ - - - var calculateEdgeForces = function calculateEdgeForces(layoutInfo, options) { - // Iterate over all edges - for (var i = 0; i < layoutInfo.edgeSize; i++) { - // Get edge, source & target nodes - var edge = layoutInfo.layoutEdges[i]; - var sourceIx = layoutInfo.idToIndex[edge.sourceId]; - var source = layoutInfo.layoutNodes[sourceIx]; - var targetIx = layoutInfo.idToIndex[edge.targetId]; - var target = layoutInfo.layoutNodes[targetIx]; // Get direction of line connecting both node centers - - var directionX = target.positionX - source.positionX; - var directionY = target.positionY - source.positionY; // If both centers are the same, do nothing. - // A random force has already been applied as node repulsion - - if (0 === directionX && 0 === directionY) { - continue; - } // Get clipping points for both nodes - - - var point1 = findClippingPoint(source, directionX, directionY); - var point2 = findClippingPoint(target, -1 * directionX, -1 * directionY); - var lx = point2.x - point1.x; - var ly = point2.y - point1.y; - var l = Math.sqrt(lx * lx + ly * ly); - var force = Math.pow(edge.idealLength - l, 2) / edge.elasticity; - - if (0 !== l) { - var forceX = force * lx / l; - var forceY = force * ly / l; - } else { - var forceX = 0; - var forceY = 0; - } // Add this force to target and source nodes - - - if (!source.isLocked) { - source.offsetX += forceX; - source.offsetY += forceY; - } - - if (!target.isLocked) { - target.offsetX -= forceX; - target.offsetY -= forceY; - } // var s = 'Edge force between nodes ' + source.id + ' and ' + target.id; - // s += "\nDistance: " + l + " Force: (" + forceX + ", " + forceY + ")"; - // logDebug(s); - - } - }; - /** - * @brief : Computes gravity forces for all nodes - */ - - - var calculateGravityForces = function calculateGravityForces(layoutInfo, options) { - var distThreshold = 1; // var s = 'calculateGravityForces'; - // logDebug(s); - - for (var i = 0; i < layoutInfo.graphSet.length; i++) { - var graph = layoutInfo.graphSet[i]; - var numNodes = graph.length; // s = "Set: " + graph.toString(); - // logDebug(s); - // Compute graph center - - if (0 === i) { - var centerX = layoutInfo.clientHeight / 2; - var centerY = layoutInfo.clientWidth / 2; - } else { - // Get Parent node for this graph, and use its position as center - var temp = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[0]]]; - var parent = layoutInfo.layoutNodes[layoutInfo.idToIndex[temp.parentId]]; - var centerX = parent.positionX; - var centerY = parent.positionY; - } // s = "Center found at: " + centerX + ", " + centerY; - // logDebug(s); - // Apply force to all nodes in graph - - - for (var j = 0; j < numNodes; j++) { - var node = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[j]]]; // s = "Node: " + node.id; - - if (node.isLocked) { - continue; - } - - var dx = centerX - node.positionX; - var dy = centerY - node.positionY; - var d = Math.sqrt(dx * dx + dy * dy); - - if (d > distThreshold) { - var fx = options.gravity * dx / d; - var fy = options.gravity * dy / d; - node.offsetX += fx; - node.offsetY += fy; // s += ": Applied force: " + fx + ", " + fy; - } // s += ": skypped since it's too close to center"; - // logDebug(s); - - } - } - }; - /** - * @brief : This function propagates the existing offsets from - * parent nodes to its descendents. - * @arg layoutInfo : layoutInfo Object - * @arg cy : cytoscape Object - * @arg options : Layout options - */ - - - var propagateForces = function propagateForces(layoutInfo, options) { - // Inline implementation of a queue, used for traversing the graph in BFS order - var queue = []; - var start = 0; // Points to the start the queue - - var end = -1; // Points to the end of the queue - // logDebug('propagateForces'); - // Start by visiting the nodes in the root graph - - queue.push.apply(queue, layoutInfo.graphSet[0]); - end += layoutInfo.graphSet[0].length; // Traverse the graph, level by level, - - while (start <= end) { - // Get the node to visit and remove it from queue - var nodeId = queue[start++]; - var nodeIndex = layoutInfo.idToIndex[nodeId]; - var node = layoutInfo.layoutNodes[nodeIndex]; - var children = node.children; // We only need to process the node if it's compound - - if (0 < children.length && !node.isLocked) { - var offX = node.offsetX; - var offY = node.offsetY; // var s = "Propagating offset from parent node : " + node.id + - // ". OffsetX: " + offX + ". OffsetY: " + offY; - // s += "\n Children: " + children.toString(); - // logDebug(s); - - for (var i = 0; i < children.length; i++) { - var childNode = layoutInfo.layoutNodes[layoutInfo.idToIndex[children[i]]]; // Propagate offset - - childNode.offsetX += offX; - childNode.offsetY += offY; // Add children to queue to be visited - - queue[++end] = children[i]; - } // Reset parent offsets - - - node.offsetX = 0; - node.offsetY = 0; - } - } - }; - /** - * @brief : Updates the layout model positions, based on - * the accumulated forces - */ - - - var updatePositions = function updatePositions(layoutInfo, options) { - // var s = 'Updating positions'; - // logDebug(s); - // Reset boundaries for compound nodes - for (var i = 0; i < layoutInfo.nodeSize; i++) { - var n = layoutInfo.layoutNodes[i]; - - if (0 < n.children.length) { - // logDebug("Resetting boundaries of compound node: " + n.id); - n.maxX = undefined; - n.minX = undefined; - n.maxY = undefined; - n.minY = undefined; - } - } - - for (var i = 0; i < layoutInfo.nodeSize; i++) { - var n = layoutInfo.layoutNodes[i]; - - if (0 < n.children.length || n.isLocked) { - // No need to set compound or locked node position - // logDebug("Skipping position update of node: " + n.id); - continue; - } // s = "Node: " + n.id + " Previous position: (" + - // n.positionX + ", " + n.positionY + ")."; - // Limit displacement in order to improve stability - - - var tempForce = limitForce(n.offsetX, n.offsetY, layoutInfo.temperature); - n.positionX += tempForce.x; - n.positionY += tempForce.y; - n.offsetX = 0; - n.offsetY = 0; - n.minX = n.positionX - n.width; - n.maxX = n.positionX + n.width; - n.minY = n.positionY - n.height; - n.maxY = n.positionY + n.height; // s += " New Position: (" + n.positionX + ", " + n.positionY + ")."; - // logDebug(s); - // Update ancestry boudaries - - updateAncestryBoundaries(n, layoutInfo); - } // Update size, position of compund nodes - - - for (var i = 0; i < layoutInfo.nodeSize; i++) { - var n = layoutInfo.layoutNodes[i]; - - if (0 < n.children.length && !n.isLocked) { - n.positionX = (n.maxX + n.minX) / 2; - n.positionY = (n.maxY + n.minY) / 2; - n.width = n.maxX - n.minX; - n.height = n.maxY - n.minY; // s = "Updating position, size of compound node " + n.id; - // s += "\nPositionX: " + n.positionX + ", PositionY: " + n.positionY; - // s += "\nWidth: " + n.width + ", Height: " + n.height; - // logDebug(s); - } - } - }; - /** - * @brief : Limits a force (forceX, forceY) to be not - * greater (in modulo) than max. - 8 Preserves force direction. - */ - - - var limitForce = function limitForce(forceX, forceY, max$$1) { - // var s = "Limiting force: (" + forceX + ", " + forceY + "). Max: " + max; - var force = Math.sqrt(forceX * forceX + forceY * forceY); - - if (force > max$$1) { - var res = { - x: max$$1 * forceX / force, - y: max$$1 * forceY / force - }; - } else { - var res = { - x: forceX, - y: forceY - }; - } // s += ".\nResult: (" + res.x + ", " + res.y + ")"; - // logDebug(s); - - - return res; - }; - /** - * @brief : Function used for keeping track of compound node - * sizes, since they should bound all their subnodes. - */ - - - var updateAncestryBoundaries = function updateAncestryBoundaries(node, layoutInfo) { - // var s = "Propagating new position/size of node " + node.id; - var parentId = node.parentId; - - if (null == parentId) { - // If there's no parent, we are done - // s += ". No parent node."; - // logDebug(s); - return; - } // Get Parent Node - - - var p = layoutInfo.layoutNodes[layoutInfo.idToIndex[parentId]]; - var flag = false; // MaxX - - if (null == p.maxX || node.maxX + p.padRight > p.maxX) { - p.maxX = node.maxX + p.padRight; - flag = true; // s += "\nNew maxX for parent node " + p.id + ": " + p.maxX; - } // MinX - - - if (null == p.minX || node.minX - p.padLeft < p.minX) { - p.minX = node.minX - p.padLeft; - flag = true; // s += "\nNew minX for parent node " + p.id + ": " + p.minX; - } // MaxY - - - if (null == p.maxY || node.maxY + p.padBottom > p.maxY) { - p.maxY = node.maxY + p.padBottom; - flag = true; // s += "\nNew maxY for parent node " + p.id + ": " + p.maxY; - } // MinY - - - if (null == p.minY || node.minY - p.padTop < p.minY) { - p.minY = node.minY - p.padTop; - flag = true; // s += "\nNew minY for parent node " + p.id + ": " + p.minY; - } // If updated boundaries, propagate changes upward - - - if (flag) { - // logDebug(s); - return updateAncestryBoundaries(p, layoutInfo); - } // s += ". No changes in boundaries/position of parent node " + p.id; - // logDebug(s); - - - return; - }; - - var separateComponents = function separateComponents(layutInfo, options) { - var nodes = layoutInfo.layoutNodes; - var components = []; - - for (var i = 0; i < nodes.length; i++) { - var node = nodes[i]; - var cid = node.cmptId; - var component = components[cid] = components[cid] || []; - component.push(node); - } - - var totalA = 0; - - for (var i = 0; i < components.length; i++) { - var c = components[i]; - - if (!c) { - continue; - } - - c.x1 = Infinity; - c.x2 = -Infinity; - c.y1 = Infinity; - c.y2 = -Infinity; - - for (var j = 0; j < c.length; j++) { - var n = c[j]; - c.x1 = Math.min(c.x1, n.positionX - n.width / 2); - c.x2 = Math.max(c.x2, n.positionX + n.width / 2); - c.y1 = Math.min(c.y1, n.positionY - n.height / 2); - c.y2 = Math.max(c.y2, n.positionY + n.height / 2); - } - - c.w = c.x2 - c.x1; - c.h = c.y2 - c.y1; - totalA += c.w * c.h; - } - - components.sort(function (c1, c2) { - return c2.w * c2.h - c1.w * c1.h; - }); - var x = 0; - var y = 0; - var usedW = 0; - var rowH = 0; - var maxRowW = Math.sqrt(totalA) * layoutInfo.clientWidth / layoutInfo.clientHeight; - - for (var i = 0; i < components.length; i++) { - var c = components[i]; - - if (!c) { - continue; - } - - for (var j = 0; j < c.length; j++) { - var n = c[j]; - - if (!n.isLocked) { - n.positionX += x; - n.positionY += y; - } - } - - x += c.w + options.componentSpacing; - usedW += c.w + options.componentSpacing; - rowH = Math.max(rowH, c.h); - - if (usedW > maxRowW) { - y += rowH + options.componentSpacing; - x = 0; - usedW = 0; - rowH = 0; - } - } - }; - - var mainLoop = function mainLoop(i) { - - - step(layoutInfo, options, i); // Update temperature - - layoutInfo.temperature = layoutInfo.temperature * options.coolingFactor; // logDebug("New temperature: " + layoutInfo.temperature); - - if (layoutInfo.temperature < options.minTemp) { - // logDebug("Temperature drop below minimum threshold. Stopping computation in step " + i); - return false; - } - - return true; - }; - - var i = 0; - var loopRet; - - do { - var f = 0; - - while ((f < options.refresh || options.refresh === 0) && i < options.numIter) { - var loopRet = mainLoop(i); - - if (!loopRet) { - break; - } - - f++; - i++; - } - - if (options.animate === true) { - broadcast(layoutInfo.layoutNodes); // eslint-disable-line no-undef - } - } while (loopRet && i + 1 < options.numIter); - - separateComponents(layoutInfo, options); - return layoutInfo; - }).then(function (layoutInfoUpdated) { - layoutInfo.layoutNodes = layoutInfoUpdated.layoutNodes; // get the positions - - thread$$1.stop(); - done(); - }); - - var done = function done() { - if (options.animate === true || options.animate === false) { - refresh({ - force: true, - next: function next() { - // Layout has finished - layout.one('layoutstop', options.stop); - layout.emit({ - type: 'layoutstop', - layout: layout - }); - } - }); - } else { - options.eles.nodes().layoutPositions(layout, options, function (node) { - var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[node.data('id')]]; - return { - x: lnode.positionX, - y: lnode.positionY - }; - }); - } - }; - - return this; // chaining -}; -/** - * @brief : called on continuous layouts to stop them before they finish - */ - - -CoseLayout.prototype.stop = function () { - this.stopped = true; - - if (this.thread) { - this.thread.stop(); - } - - this.emit('layoutstop'); - return this; // chaining -}; - -CoseLayout.prototype.destroy = function () { - if (this.thread) { - this.thread.stop(); - } +CoseLayout.prototype.destroy = function () { + if (this.thread) { + this.thread.stop(); + } return this; // chaining }; @@ -19959,69 +19451,681 @@ var randomizePositions = function randomizePositions(layoutInfo, cy) { } } }; -/** - * @brief : Updates the positions of nodes in the network - * @arg layoutInfo : LayoutInfo object - * @arg cy : Cytoscape object - * @arg options : Layout options - */ +var getScaleInBoundsFn = function getScaleInBoundsFn(layoutInfo, options, nodes) { + var bb = layoutInfo.boundingBox; + var coseBB = { + x1: Infinity, + x2: -Infinity, + y1: Infinity, + y2: -Infinity + }; + + if (options.boundingBox) { + nodes.forEach(function (node) { + var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[node.data('id')]]; + coseBB.x1 = Math.min(coseBB.x1, lnode.positionX); + coseBB.x2 = Math.max(coseBB.x2, lnode.positionX); + coseBB.y1 = Math.min(coseBB.y1, lnode.positionY); + coseBB.y2 = Math.max(coseBB.y2, lnode.positionY); + }); + coseBB.w = coseBB.x2 - coseBB.x1; + coseBB.h = coseBB.y2 - coseBB.y1; + } + + return function (ele, i) { + var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[ele.data('id')]]; + + if (options.boundingBox) { + // then add extra bounding box constraint + var pctX = (lnode.positionX - coseBB.x1) / coseBB.w; + var pctY = (lnode.positionY - coseBB.y1) / coseBB.h; + return { + x: bb.x1 + pctX * bb.w, + y: bb.y1 + pctY * bb.h + }; + } else { + return { + x: lnode.positionX, + y: lnode.positionY + }; + } + }; +}; +/** + * @brief : Updates the positions of nodes in the network + * @arg layoutInfo : LayoutInfo object + * @arg cy : Cytoscape object + * @arg options : Layout options + */ + + +var refreshPositions = function refreshPositions(layoutInfo, cy, options) { + // var s = 'Refreshing positions'; + // logDebug(s); + var layout = options.layout; + var nodes = options.eles.nodes(); + var getScaledPos = getScaleInBoundsFn(layoutInfo, options, nodes); + nodes.positions(getScaledPos); // Trigger layoutReady only on first call + + if (true !== layoutInfo.ready) { + // s = 'Triggering layoutready'; + // logDebug(s); + layoutInfo.ready = true; + layout.one('layoutready', options.ready); + layout.emit({ + type: 'layoutready', + layout: this + }); + } +}; +/** + * @brief : Logs a debug message in JS console, if DEBUG is ON + */ +// var logDebug = function(text) { +// if (DEBUG) { +// console.debug(text); +// } +// }; + +/** + * @brief : Performs one iteration of the physical simulation + * @arg layoutInfo : LayoutInfo object already initialized + * @arg cy : Cytoscape object + * @arg options : Layout options + */ + + +var step$1 = function step(layoutInfo, options, _step) { + // var s = "\n\n###############################"; + // s += "\nSTEP: " + step; + // s += "\n###############################\n"; + // logDebug(s); + // Calculate node repulsions + calculateNodeForces(layoutInfo, options); // Calculate edge forces + + calculateEdgeForces(layoutInfo); // Calculate gravity forces + + calculateGravityForces(layoutInfo, options); // Propagate forces from parent to child + + propagateForces(layoutInfo); // Update positions based on calculated forces + + updatePositions(layoutInfo); +}; +/** + * @brief : Computes the node repulsion forces + */ + + +var calculateNodeForces = function calculateNodeForces(layoutInfo, options) { + // Go through each of the graphs in graphSet + // Nodes only repel each other if they belong to the same graph + // var s = 'calculateNodeForces'; + // logDebug(s); + for (var i = 0; i < layoutInfo.graphSet.length; i++) { + var graph = layoutInfo.graphSet[i]; + var numNodes = graph.length; // s = "Set: " + graph.toString(); + // logDebug(s); + // Now get all the pairs of nodes + // Only get each pair once, (A, B) = (B, A) + + for (var j = 0; j < numNodes; j++) { + var node1 = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[j]]]; + + for (var k = j + 1; k < numNodes; k++) { + var node2 = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[k]]]; + nodeRepulsion(node1, node2, layoutInfo, options); + } + } + } +}; + +var randomDistance = function randomDistance(max) { + return -max + 2 * max * Math.random(); +}; +/** + * @brief : Compute the node repulsion forces between a pair of nodes + */ + + +var nodeRepulsion = function nodeRepulsion(node1, node2, layoutInfo, options) { + // var s = "Node repulsion. Node1: " + node1.id + " Node2: " + node2.id; + var cmptId1 = node1.cmptId; + var cmptId2 = node2.cmptId; + + if (cmptId1 !== cmptId2 && !layoutInfo.isCompound) { + return; + } // Get direction of line connecting both node centers + + + var directionX = node2.positionX - node1.positionX; + var directionY = node2.positionY - node1.positionY; + var maxRandDist = 1; // s += "\ndirectionX: " + directionX + ", directionY: " + directionY; + // If both centers are the same, apply a random force + + if (0 === directionX && 0 === directionY) { + directionX = randomDistance(maxRandDist); + directionY = randomDistance(maxRandDist); + } + + var overlap = nodesOverlap(node1, node2, directionX, directionY); + + if (overlap > 0) { + // s += "\nNodes DO overlap."; + // s += "\nOverlap: " + overlap; + // If nodes overlap, repulsion force is proportional + // to the overlap + var force = options.nodeOverlap * overlap; // Compute the module and components of the force vector + + var distance = Math.sqrt(directionX * directionX + directionY * directionY); // s += "\nDistance: " + distance; + + var forceX = force * directionX / distance; + var forceY = force * directionY / distance; + } else { + // s += "\nNodes do NOT overlap."; + // If there's no overlap, force is inversely proportional + // to squared distance + // Get clipping points for both nodes + var point1 = findClippingPoint(node1, directionX, directionY); + var point2 = findClippingPoint(node2, -1 * directionX, -1 * directionY); // Use clipping points to compute distance + + var distanceX = point2.x - point1.x; + var distanceY = point2.y - point1.y; + var distanceSqr = distanceX * distanceX + distanceY * distanceY; + var distance = Math.sqrt(distanceSqr); // s += "\nDistance: " + distance; + // Compute the module and components of the force vector + + var force = (node1.nodeRepulsion + node2.nodeRepulsion) / distanceSqr; + var forceX = force * distanceX / distance; + var forceY = force * distanceY / distance; + } // Apply force + + + if (!node1.isLocked) { + node1.offsetX -= forceX; + node1.offsetY -= forceY; + } + + if (!node2.isLocked) { + node2.offsetX += forceX; + node2.offsetY += forceY; + } // s += "\nForceX: " + forceX + " ForceY: " + forceY; + // logDebug(s); + + + return; +}; +/** + * @brief : Determines whether two nodes overlap or not + * @return : Amount of overlapping (0 => no overlap) + */ + + +var nodesOverlap = function nodesOverlap(node1, node2, dX, dY) { + if (dX > 0) { + var overlapX = node1.maxX - node2.minX; + } else { + var overlapX = node2.maxX - node1.minX; + } + + if (dY > 0) { + var overlapY = node1.maxY - node2.minY; + } else { + var overlapY = node2.maxY - node1.minY; + } + + if (overlapX >= 0 && overlapY >= 0) { + return Math.sqrt(overlapX * overlapX + overlapY * overlapY); + } else { + return 0; + } +}; +/** + * @brief : Finds the point in which an edge (direction dX, dY) intersects + * the rectangular bounding box of it's source/target node + */ + + +var findClippingPoint = function findClippingPoint(node, dX, dY) { + // Shorcuts + var X = node.positionX; + var Y = node.positionY; + var H = node.height || 1; + var W = node.width || 1; + var dirSlope = dY / dX; + var nodeSlope = H / W; // var s = 'Computing clipping point of node ' + node.id + + // " . Height: " + H + ", Width: " + W + + // "\nDirection " + dX + ", " + dY; + // + // Compute intersection + + var res = {}; // Case: Vertical direction (up) + + if (0 === dX && 0 < dY) { + res.x = X; // s += "\nUp direction"; + + res.y = Y + H / 2; + return res; + } // Case: Vertical direction (down) + + + if (0 === dX && 0 > dY) { + res.x = X; + res.y = Y + H / 2; // s += "\nDown direction"; + + return res; + } // Case: Intersects the right border + + + if (0 < dX && -1 * nodeSlope <= dirSlope && dirSlope <= nodeSlope) { + res.x = X + W / 2; + res.y = Y + W * dY / 2 / dX; // s += "\nRightborder"; + + return res; + } // Case: Intersects the left border + + + if (0 > dX && -1 * nodeSlope <= dirSlope && dirSlope <= nodeSlope) { + res.x = X - W / 2; + res.y = Y - W * dY / 2 / dX; // s += "\nLeftborder"; + + return res; + } // Case: Intersects the top border + + + if (0 < dY && (dirSlope <= -1 * nodeSlope || dirSlope >= nodeSlope)) { + res.x = X + H * dX / 2 / dY; + res.y = Y + H / 2; // s += "\nTop border"; + + return res; + } // Case: Intersects the bottom border + + + if (0 > dY && (dirSlope <= -1 * nodeSlope || dirSlope >= nodeSlope)) { + res.x = X - H * dX / 2 / dY; + res.y = Y - H / 2; // s += "\nBottom border"; + + return res; + } // s += "\nClipping point found at " + res.x + ", " + res.y; + // logDebug(s); + + + return res; +}; +/** + * @brief : Calculates all edge forces + */ + + +var calculateEdgeForces = function calculateEdgeForces(layoutInfo, options) { + // Iterate over all edges + for (var i = 0; i < layoutInfo.edgeSize; i++) { + // Get edge, source & target nodes + var edge = layoutInfo.layoutEdges[i]; + var sourceIx = layoutInfo.idToIndex[edge.sourceId]; + var source = layoutInfo.layoutNodes[sourceIx]; + var targetIx = layoutInfo.idToIndex[edge.targetId]; + var target = layoutInfo.layoutNodes[targetIx]; // Get direction of line connecting both node centers + + var directionX = target.positionX - source.positionX; + var directionY = target.positionY - source.positionY; // If both centers are the same, do nothing. + // A random force has already been applied as node repulsion + + if (0 === directionX && 0 === directionY) { + continue; + } // Get clipping points for both nodes + + + var point1 = findClippingPoint(source, directionX, directionY); + var point2 = findClippingPoint(target, -1 * directionX, -1 * directionY); + var lx = point2.x - point1.x; + var ly = point2.y - point1.y; + var l = Math.sqrt(lx * lx + ly * ly); + var force = Math.pow(edge.idealLength - l, 2) / edge.elasticity; + + if (0 !== l) { + var forceX = force * lx / l; + var forceY = force * ly / l; + } else { + var forceX = 0; + var forceY = 0; + } // Add this force to target and source nodes + + + if (!source.isLocked) { + source.offsetX += forceX; + source.offsetY += forceY; + } + + if (!target.isLocked) { + target.offsetX -= forceX; + target.offsetY -= forceY; + } // var s = 'Edge force between nodes ' + source.id + ' and ' + target.id; + // s += "\nDistance: " + l + " Force: (" + forceX + ", " + forceY + ")"; + // logDebug(s); + + } +}; +/** + * @brief : Computes gravity forces for all nodes + */ + + +var calculateGravityForces = function calculateGravityForces(layoutInfo, options) { + var distThreshold = 1; // var s = 'calculateGravityForces'; + // logDebug(s); + + for (var i = 0; i < layoutInfo.graphSet.length; i++) { + var graph = layoutInfo.graphSet[i]; + var numNodes = graph.length; // s = "Set: " + graph.toString(); + // logDebug(s); + // Compute graph center + + if (0 === i) { + var centerX = layoutInfo.clientHeight / 2; + var centerY = layoutInfo.clientWidth / 2; + } else { + // Get Parent node for this graph, and use its position as center + var temp = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[0]]]; + var parent = layoutInfo.layoutNodes[layoutInfo.idToIndex[temp.parentId]]; + var centerX = parent.positionX; + var centerY = parent.positionY; + } // s = "Center found at: " + centerX + ", " + centerY; + // logDebug(s); + // Apply force to all nodes in graph + + + for (var j = 0; j < numNodes; j++) { + var node = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[j]]]; // s = "Node: " + node.id; + + if (node.isLocked) { + continue; + } + + var dx = centerX - node.positionX; + var dy = centerY - node.positionY; + var d = Math.sqrt(dx * dx + dy * dy); + + if (d > distThreshold) { + var fx = options.gravity * dx / d; + var fy = options.gravity * dy / d; + node.offsetX += fx; + node.offsetY += fy; // s += ": Applied force: " + fx + ", " + fy; + } // s += ": skypped since it's too close to center"; + // logDebug(s); + + } + } +}; +/** + * @brief : This function propagates the existing offsets from + * parent nodes to its descendents. + * @arg layoutInfo : layoutInfo Object + * @arg cy : cytoscape Object + * @arg options : Layout options + */ + + +var propagateForces = function propagateForces(layoutInfo, options) { + // Inline implementation of a queue, used for traversing the graph in BFS order + var queue = []; + var start = 0; // Points to the start the queue + + var end = -1; // Points to the end of the queue + // logDebug('propagateForces'); + // Start by visiting the nodes in the root graph + + queue.push.apply(queue, layoutInfo.graphSet[0]); + end += layoutInfo.graphSet[0].length; // Traverse the graph, level by level, + + while (start <= end) { + // Get the node to visit and remove it from queue + var nodeId = queue[start++]; + var nodeIndex = layoutInfo.idToIndex[nodeId]; + var node = layoutInfo.layoutNodes[nodeIndex]; + var children = node.children; // We only need to process the node if it's compound + + if (0 < children.length && !node.isLocked) { + var offX = node.offsetX; + var offY = node.offsetY; // var s = "Propagating offset from parent node : " + node.id + + // ". OffsetX: " + offX + ". OffsetY: " + offY; + // s += "\n Children: " + children.toString(); + // logDebug(s); + + for (var i = 0; i < children.length; i++) { + var childNode = layoutInfo.layoutNodes[layoutInfo.idToIndex[children[i]]]; // Propagate offset + + childNode.offsetX += offX; + childNode.offsetY += offY; // Add children to queue to be visited + + queue[++end] = children[i]; + } // Reset parent offsets + + + node.offsetX = 0; + node.offsetY = 0; + } + } +}; +/** + * @brief : Updates the layout model positions, based on + * the accumulated forces + */ + + +var updatePositions = function updatePositions(layoutInfo, options) { + // var s = 'Updating positions'; + // logDebug(s); + // Reset boundaries for compound nodes + for (var i = 0; i < layoutInfo.nodeSize; i++) { + var n = layoutInfo.layoutNodes[i]; + + if (0 < n.children.length) { + // logDebug("Resetting boundaries of compound node: " + n.id); + n.maxX = undefined; + n.minX = undefined; + n.maxY = undefined; + n.minY = undefined; + } + } + + for (var i = 0; i < layoutInfo.nodeSize; i++) { + var n = layoutInfo.layoutNodes[i]; + + if (0 < n.children.length || n.isLocked) { + // No need to set compound or locked node position + // logDebug("Skipping position update of node: " + n.id); + continue; + } // s = "Node: " + n.id + " Previous position: (" + + // n.positionX + ", " + n.positionY + ")."; + // Limit displacement in order to improve stability + + + var tempForce = limitForce(n.offsetX, n.offsetY, layoutInfo.temperature); + n.positionX += tempForce.x; + n.positionY += tempForce.y; + n.offsetX = 0; + n.offsetY = 0; + n.minX = n.positionX - n.width; + n.maxX = n.positionX + n.width; + n.minY = n.positionY - n.height; + n.maxY = n.positionY + n.height; // s += " New Position: (" + n.positionX + ", " + n.positionY + ")."; + // logDebug(s); + // Update ancestry boudaries + + updateAncestryBoundaries(n, layoutInfo); + } // Update size, position of compund nodes + + + for (var i = 0; i < layoutInfo.nodeSize; i++) { + var n = layoutInfo.layoutNodes[i]; + + if (0 < n.children.length && !n.isLocked) { + n.positionX = (n.maxX + n.minX) / 2; + n.positionY = (n.maxY + n.minY) / 2; + n.width = n.maxX - n.minX; + n.height = n.maxY - n.minY; // s = "Updating position, size of compound node " + n.id; + // s += "\nPositionX: " + n.positionX + ", PositionY: " + n.positionY; + // s += "\nWidth: " + n.width + ", Height: " + n.height; + // logDebug(s); + } + } +}; +/** + * @brief : Limits a force (forceX, forceY) to be not + * greater (in modulo) than max. + 8 Preserves force direction. + */ + + +var limitForce = function limitForce(forceX, forceY, max) { + // var s = "Limiting force: (" + forceX + ", " + forceY + "). Max: " + max; + var force = Math.sqrt(forceX * forceX + forceY * forceY); + + if (force > max) { + var res = { + x: max * forceX / force, + y: max * forceY / force + }; + } else { + var res = { + x: forceX, + y: forceY + }; + } // s += ".\nResult: (" + res.x + ", " + res.y + ")"; + // logDebug(s); + + + return res; +}; +/** + * @brief : Function used for keeping track of compound node + * sizes, since they should bound all their subnodes. + */ + + +var updateAncestryBoundaries = function updateAncestryBoundaries(node, layoutInfo) { + // var s = "Propagating new position/size of node " + node.id; + var parentId = node.parentId; + + if (null == parentId) { + // If there's no parent, we are done + // s += ". No parent node."; + // logDebug(s); + return; + } // Get Parent Node + + + var p = layoutInfo.layoutNodes[layoutInfo.idToIndex[parentId]]; + var flag = false; // MaxX + + if (null == p.maxX || node.maxX + p.padRight > p.maxX) { + p.maxX = node.maxX + p.padRight; + flag = true; // s += "\nNew maxX for parent node " + p.id + ": " + p.maxX; + } // MinX + + + if (null == p.minX || node.minX - p.padLeft < p.minX) { + p.minX = node.minX - p.padLeft; + flag = true; // s += "\nNew minX for parent node " + p.id + ": " + p.minX; + } // MaxY + + + if (null == p.maxY || node.maxY + p.padBottom > p.maxY) { + p.maxY = node.maxY + p.padBottom; + flag = true; // s += "\nNew maxY for parent node " + p.id + ": " + p.maxY; + } // MinY + + + if (null == p.minY || node.minY - p.padTop < p.minY) { + p.minY = node.minY - p.padTop; + flag = true; // s += "\nNew minY for parent node " + p.id + ": " + p.minY; + } // If updated boundaries, propagate changes upward + + + if (flag) { + // logDebug(s); + return updateAncestryBoundaries(p, layoutInfo); + } // s += ". No changes in boundaries/position of parent node " + p.id; + // logDebug(s); + + + return; +}; + +var separateComponents = function separateComponents(layoutInfo, options) { + var nodes = layoutInfo.layoutNodes; + var components = []; + + for (var i = 0; i < nodes.length; i++) { + var node = nodes[i]; + var cid = node.cmptId; + var component = components[cid] = components[cid] || []; + component.push(node); + } + + var totalA = 0; + + for (var i = 0; i < components.length; i++) { + var c = components[i]; + + if (!c) { + continue; + } -var refreshPositions = function refreshPositions(layoutInfo, cy, options) { - // var s = 'Refreshing positions'; - // logDebug(s); - var layout = options.layout; - var nodes = options.eles.nodes(); - var bb = layoutInfo.boundingBox; - var coseBB = { - x1: Infinity, - x2: -Infinity, - y1: Infinity, - y2: -Infinity - }; + c.x1 = Infinity; + c.x2 = -Infinity; + c.y1 = Infinity; + c.y2 = -Infinity; - if (options.boundingBox) { - nodes.forEach(function (node) { - var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[node.data('id')]]; - coseBB.x1 = Math.min(coseBB.x1, lnode.positionX); - coseBB.x2 = Math.max(coseBB.x2, lnode.positionX); - coseBB.y1 = Math.min(coseBB.y1, lnode.positionY); - coseBB.y2 = Math.max(coseBB.y2, lnode.positionY); - }); - coseBB.w = coseBB.x2 - coseBB.x1; - coseBB.h = coseBB.y2 - coseBB.y1; + for (var j = 0; j < c.length; j++) { + var n = c[j]; + c.x1 = Math.min(c.x1, n.positionX - n.width / 2); + c.x2 = Math.max(c.x2, n.positionX + n.width / 2); + c.y1 = Math.min(c.y1, n.positionY - n.height / 2); + c.y2 = Math.max(c.y2, n.positionY + n.height / 2); + } + + c.w = c.x2 - c.x1; + c.h = c.y2 - c.y1; + totalA += c.w * c.h; } - nodes.positions(function (ele, i) { - var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[ele.data('id')]]; // s = "Node: " + lnode.id + ". Refreshed position: (" + - // lnode.positionX + ", " + lnode.positionY + ")."; - // logDebug(s); + components.sort(function (c1, c2) { + return c2.w * c2.h - c1.w * c1.h; + }); + var x = 0; + var y = 0; + var usedW = 0; + var rowH = 0; + var maxRowW = Math.sqrt(totalA) * layoutInfo.clientWidth / layoutInfo.clientHeight; - if (options.boundingBox) { - // then add extra bounding box constraint - var pctX = (lnode.positionX - coseBB.x1) / coseBB.w; - var pctY = (lnode.positionY - coseBB.y1) / coseBB.h; - return { - x: bb.x1 + pctX * bb.w, - y: bb.y1 + pctY * bb.h - }; - } else { - return { - x: lnode.positionX, - y: lnode.positionY - }; + for (var i = 0; i < components.length; i++) { + var c = components[i]; + + if (!c) { + continue; } - }); // Trigger layoutReady only on first call - if (true !== layoutInfo.ready) { - // s = 'Triggering layoutready'; - // logDebug(s); - layoutInfo.ready = true; - layout.one('layoutready', options.ready); - layout.emit({ - type: 'layoutready', - layout: this - }); + for (var j = 0; j < c.length; j++) { + var n = c[j]; + + if (!n.isLocked) { + n.positionX += x - c.x1; + n.positionY += y - c.y1; + } + } + + x += c.w + options.componentSpacing; + usedW += c.w + options.componentSpacing; + rowH = Math.max(rowH, c.h); + + if (usedW > maxRowW) { + y += rowH + options.componentSpacing; + x = 0; + usedW = 0; + rowH = 0; + } } }; @@ -20110,9 +20214,9 @@ GridLayout.prototype.run = function () { if (val == null) { return Math.min(rows, cols); } else { - var min$$1 = Math.min(rows, cols); + var min = Math.min(rows, cols); - if (min$$1 == rows) { + if (min == rows) { rows = val; } else { cols = val; @@ -20124,9 +20228,9 @@ GridLayout.prototype.run = function () { if (val == null) { return Math.max(rows, cols); } else { - var max$$1 = Math.max(rows, cols); + var max = Math.max(rows, cols); - if (max$$1 == rows) { + if (max == rows) { rows = val; } else { cols = val; @@ -20943,6 +21047,7 @@ BRp$1.findNearestElements = function (x, y, interactiveElementsOnly, isTouch) { prefixDash = ''; } + var bb = _p.labelBounds[prefix || 'main']; var text = ele.pstyle(prefixDash + 'label').value; var eventsEnabled = ele.pstyle('text-events').strValue === 'yes'; @@ -20951,17 +21056,13 @@ BRp$1.findNearestElements = function (x, y, interactiveElementsOnly, isTouch) { } var rstyle = _p.rstyle; - var bw = ele.pstyle('text-border-width').pfValue; - var pw = ele.pstyle('text-background-padding').pfValue; - var lw = preprop(rstyle, 'labelWidth', prefix) + bw + 2 * th + 2 * pw; - var lh = preprop(rstyle, 'labelHeight', prefix) + bw + 2 * th + 2 * pw; var lx = preprop(rstyle, 'labelX', prefix); var ly = preprop(rstyle, 'labelY', prefix); var theta = preprop(_p.rscratch, 'labelAngle', prefix); - var lx1 = lx - lw / 2; - var lx2 = lx + lw / 2; - var ly1 = ly - lh / 2; - var ly2 = ly + lh / 2; + var lx1 = bb.x1 - th; + var lx2 = bb.x2 + th; + var ly1 = bb.y1 - th; + var ly2 = bb.y2 + th; if (theta) { var cos = Math.cos(theta); @@ -20988,15 +21089,6 @@ BRp$1.findNearestElements = function (x, y, interactiveElementsOnly, isTouch) { } } else { // do a cheaper bb check - var bb = { - w: lw, - h: lh, - x1: lx1, - x2: lx2, - y1: ly1, - y2: ly2 - }; - if (inBoundingBox(bb, x, y)) { addEle(ele); return true; @@ -21773,7 +21865,28 @@ BRp$3.findEdgeControlPoints = function (edges) { var r = this; var cy = r.cy; var hasCompounds = cy.hasCompoundNodes(); - var hashTable = new Map$1(); + var hashTable = { + map: new Map$1(), + get: function get(pairId) { + var map2 = this.map.get(pairId[0]); + + if (map2 != null) { + return map2.get(pairId[1]); + } else { + return null; + } + }, + set: function set(pairId, val) { + var map2 = this.map.get(pairId[0]); + + if (map2 == null) { + map2 = new Map$1(); + this.map.set(pairId[0], map2); + } + + map2.set(pairId[1], val); + } + }; var pairIds = []; var haystackEdges = []; // create a table of edge (src, tgt) => list of edges between them @@ -21794,13 +21907,11 @@ BRp$3.findEdgeControlPoints = function (edges) { var edgeIsUnbundled = curveStyle === 'unbundled-bezier' || curveStyle === 'segments' || curveStyle === 'straight' || curveStyle === 'taxi'; var edgeIsBezier = curveStyle === 'unbundled-bezier' || curveStyle === 'bezier'; - - var srcIndex = _p.source.poolIndex(); - - var tgtIndex = _p.target.poolIndex(); - - var hash = (edgeIsUnbundled ? -1 : 1) * hashIntsArray([srcIndex, tgtIndex].sort()); - var pairId = hash; + var src = _p.source; + var tgt = _p.target; + var srcIndex = src.poolIndex(); + var tgtIndex = tgt.poolIndex(); + var pairId = [srcIndex, tgtIndex].sort(); var tableEntry = hashTable.get(pairId); if (tableEntry == null) { @@ -22106,18 +22217,21 @@ BRp$4.findEndpoints = function (edge) { var srcArShape = edge.pstyle('source-arrow-shape').value; var tgtDist = edge.pstyle('target-distance-from-node').pfValue; var srcDist = edge.pstyle('source-distance-from-node').pfValue; + var curveStyle = edge.pstyle('curve-style').value; var rs = edge._private.rscratch; var et = rs.edgeType; + var taxi = curveStyle === 'taxi'; var self = et === 'self' || et === 'compound'; var bezier = et === 'bezier' || et === 'multibezier' || self; var multi = et !== 'bezier'; var lines = et === 'straight' || et === 'segments'; var segments = et === 'segments'; var hasEndpts = bezier || multi || lines; + var overrideEndpts = self || taxi; var srcManEndpt = edge.pstyle('source-endpoint'); - var srcManEndptVal = self ? 'outside-to-node' : srcManEndpt.value; + var srcManEndptVal = overrideEndpts ? 'outside-to-node' : srcManEndpt.value; var tgtManEndpt = edge.pstyle('target-endpoint'); - var tgtManEndptVal = self ? 'outside-to-node' : tgtManEndpt.value; + var tgtManEndptVal = overrideEndpts ? 'outside-to-node' : tgtManEndpt.value; rs.srcManEndpt = srcManEndpt; rs.tgtManEndpt = tgtManEndpt; var p1; // last known point of edge on target side @@ -22303,7 +22417,7 @@ BRp$4.getTargetEndpoint = function (edge) { var BRp$5 = {}; function pushBezierPts(r, edge, pts) { - var qbezierAt$$1 = function qbezierAt$$1(p1, p2, p3, t) { + var qbezierAt$1 = function qbezierAt$1(p1, p2, p3, t) { return qbezierAt(p1, p2, p3, t); }; @@ -22313,8 +22427,8 @@ function pushBezierPts(r, edge, pts) { for (var i = 0; i < r.bezierProjPcts.length; i++) { var p = r.bezierProjPcts[i]; bpts.push({ - x: qbezierAt$$1(pts[0], pts[2], pts[4], p), - y: qbezierAt$$1(pts[1], pts[3], pts[5], p) + x: qbezierAt$1(pts[0], pts[2], pts[4], p), + y: qbezierAt$1(pts[1], pts[3], pts[5], p) }); } } @@ -22523,21 +22637,21 @@ BRp$6.recalculateEdgeLabelProjections = function (edge) { } // update each ctrlpt with segment info - for (var i = 0; i < ctrlpts.length; i++) { - var cp = ctrlpts[i]; - var prevCp = ctrlpts[i - 1]; + for (var _i = 0; _i < ctrlpts.length; _i++) { + var cp = ctrlpts[_i]; + var prevCp = ctrlpts[_i - 1]; if (prevCp) { cp.startDist = prevCp.startDist + prevCp.length; } - addSegment(cp, cp.p0, bpts[i * nProjs], 0, r.bezierProjPcts[0]); // first + addSegment(cp, cp.p0, bpts[_i * nProjs], 0, r.bezierProjPcts[0]); // first for (var j = 0; j < nProjs - 1; j++) { - addSegment(cp, bpts[i * nProjs + j], bpts[i * nProjs + j + 1], r.bezierProjPcts[j], r.bezierProjPcts[j + 1]); + addSegment(cp, bpts[_i * nProjs + j], bpts[_i * nProjs + j + 1], r.bezierProjPcts[j], r.bezierProjPcts[j + 1]); } - addSegment(cp, bpts[i * nProjs + nProjs - 1], cp.p2, r.bezierProjPcts[nProjs - 1], 1); // last + addSegment(cp, bpts[_i * nProjs + nProjs - 1], cp.p2, r.bezierProjPcts[nProjs - 1], 1); // last } return createControlPointInfo.cache = ctrlpts; @@ -22558,89 +22672,95 @@ BRp$6.recalculateEdgeLabelProjections = function (edge) { case 'compound': case 'bezier': case 'multibezier': - var cps = createControlPointInfo(); - var selected; - var startDist = 0; - var totalDist = 0; // find the segment we're on - - for (var i = 0; i < cps.length; i++) { - var cp = cps[isSrc ? i : cps.length - 1 - i]; - - for (var j = 0; j < cp.segments.length; j++) { - var seg = cp.segments[isSrc ? j : cp.segments.length - 1 - j]; - var lastSeg = i === cps.length - 1 && j === cp.segments.length - 1; - startDist = totalDist; - totalDist += seg.length; - - if (totalDist >= offset || lastSeg) { - selected = { - cp: cp, - segment: seg - }; + { + var cps = createControlPointInfo(); + var selected; + var startDist = 0; + var totalDist = 0; // find the segment we're on + + for (var i = 0; i < cps.length; i++) { + var _cp = cps[isSrc ? i : cps.length - 1 - i]; + + for (var j = 0; j < _cp.segments.length; j++) { + var _seg = _cp.segments[isSrc ? j : _cp.segments.length - 1 - j]; + var lastSeg = i === cps.length - 1 && j === _cp.segments.length - 1; + startDist = totalDist; + totalDist += _seg.length; + + if (totalDist >= offset || lastSeg) { + selected = { + cp: _cp, + segment: _seg + }; + break; + } + } + + if (selected) { break; } } - if (selected) { - break; - } + var cp = selected.cp; + var seg = selected.segment; + var tSegment = (offset - startDist) / seg.length; + var segDt = seg.t1 - seg.t0; + var t = isSrc ? seg.t0 + segDt * tSegment : seg.t1 - segDt * tSegment; + t = bound(0, t, 1); + p = qbezierPtAt(cp.p0, cp.p1, cp.p2, t); + angle = bezierAngle(cp.p0, cp.p1, cp.p2, t); + break; } - var cp = selected.cp; - var seg = selected.segment; - var tSegment = (offset - startDist) / seg.length; - var segDt = seg.t1 - seg.t0; - var t = isSrc ? seg.t0 + segDt * tSegment : seg.t1 - segDt * tSegment; - t = bound(0, t, 1); - p = qbezierPtAt(cp.p0, cp.p1, cp.p2, t); - angle = bezierAngle(cp.p0, cp.p1, cp.p2, t, p); - break; - case 'straight': case 'segments': case 'haystack': - var d = 0, - di, - d0; - var p0, p1; - var l = rs.allpts.length; - - for (var i = 0; i + 3 < l; i += 2) { - if (isSrc) { - p0 = { - x: rs.allpts[i], - y: rs.allpts[i + 1] - }; - p1 = { - x: rs.allpts[i + 2], - y: rs.allpts[i + 3] - }; - } else { - p0 = { - x: rs.allpts[l - 2 - i], - y: rs.allpts[l - 1 - i] - }; - p1 = { - x: rs.allpts[l - 4 - i], - y: rs.allpts[l - 3 - i] - }; - } + { + var d = 0, + di, + d0; + var p0, p1; + var l = rs.allpts.length; + + for (var _i2 = 0; _i2 + 3 < l; _i2 += 2) { + if (isSrc) { + p0 = { + x: rs.allpts[_i2], + y: rs.allpts[_i2 + 1] + }; + p1 = { + x: rs.allpts[_i2 + 2], + y: rs.allpts[_i2 + 3] + }; + } else { + p0 = { + x: rs.allpts[l - 2 - _i2], + y: rs.allpts[l - 1 - _i2] + }; + p1 = { + x: rs.allpts[l - 4 - _i2], + y: rs.allpts[l - 3 - _i2] + }; + } - di = dist(p0, p1); - d0 = d; - d += di; + di = dist(p0, p1); + d0 = d; + d += di; - if (d >= offset) { - break; + if (d >= offset) { + break; + } } - } - var pD = offset - d0; - var t = pD / di; - t = bound(0, t, 1); - p = lineAt(p0, p1, t); - angle = lineAngle(p0, p1); - break; + var pD = offset - d0; + + var _t = pD / di; + + _t = bound(0, _t, 1); + p = lineAt(p0, p1, _t); + angle = lineAngle(p0, p1); + break; + } } setRs('labelX', prefix, p.x); @@ -22666,10 +22786,19 @@ BRp$6.applyPrefixedLabelDimensions = function (ele, prefix) { var _p = ele._private; var text = this.getLabelText(ele, prefix); var labelDims = this.calculateLabelDimensions(ele, text); - setPrefixedProperty(_p.rstyle, 'labelWidth', prefix, labelDims.width); - setPrefixedProperty(_p.rscratch, 'labelWidth', prefix, labelDims.width); - setPrefixedProperty(_p.rstyle, 'labelHeight', prefix, labelDims.height); - setPrefixedProperty(_p.rscratch, 'labelHeight', prefix, labelDims.height); + var lineHeight = ele.pstyle('line-height').pfValue; + var textWrap = ele.pstyle('text-wrap').strValue; + var lines = getPrefixedProperty(_p.rscratch, 'labelWrapCachedLines', prefix) || []; + var numLines = textWrap !== 'wrap' ? 1 : Math.max(lines.length, 1); + var normPerLineHeight = labelDims.height / numLines; + var labelLineHeight = normPerLineHeight * lineHeight; + var width = labelDims.width; + var height = labelDims.height + (numLines - 1) * (lineHeight - 1) * normPerLineHeight; + setPrefixedProperty(_p.rstyle, 'labelWidth', prefix, width); + setPrefixedProperty(_p.rscratch, 'labelWidth', prefix, width); + setPrefixedProperty(_p.rstyle, 'labelHeight', prefix, height); + setPrefixedProperty(_p.rscratch, 'labelHeight', prefix, height); + setPrefixedProperty(_p.rscratch, 'labelLineHeight', prefix, labelLineHeight); }; BRp$6.getLabelText = function (ele, prefix) { @@ -22701,48 +22830,54 @@ BRp$6.getLabelText = function (ele, prefix) { var wrapStyle = ele.pstyle('text-wrap').value; if (wrapStyle === 'wrap') { - //console.log('wrap'); var labelKey = rscratch('labelKey'); // save recalc if the label is the same as before if (labelKey != null && rscratch('labelWrapKey') === labelKey) { - // console.log('wrap cache hit'); return rscratch('labelWrapCachedText'); - } // console.log('wrap cache miss'); - + } + var zwsp = "\u200B"; var lines = text.split('\n'); var maxW = ele.pstyle('text-max-width').pfValue; + var overflow = ele.pstyle('text-overflow-wrap').value; + var overflowAny = overflow === 'anywhere'; var wrappedLines = []; + var wordsRegex = /[\s\u200b]+/; + var wordSeparator = overflowAny ? '' : ' '; for (var l = 0; l < lines.length; l++) { var line = lines[l]; var lineDims = this.calculateLabelDimensions(ele, line); var lineW = lineDims.width; + if (overflowAny) { + var processedLine = line.split('').join(zwsp); + line = processedLine; + } + if (lineW > maxW) { // line is too long - var words = line.split(/\s+/); // NB: assume collapsed whitespace into single space - + var words = line.split(wordsRegex); var subline = ''; for (var w = 0; w < words.length; w++) { var word = words[w]; - var testLine = subline.length === 0 ? word : subline + ' ' + word; + var testLine = subline.length === 0 ? word : subline + wordSeparator + word; var testDims = this.calculateLabelDimensions(ele, testLine); var testW = testDims.width; if (testW <= maxW) { // word fits on current line - subline += word + ' '; + subline += word + wordSeparator; } else { // word starts new line wrappedLines.push(subline); - subline = word + ' '; + subline = word + wordSeparator; } } // if there's remaining text, put it in a wrapped line - if (!subline.match(/^\s+$/)) { + if (!subline.match(/^[\s\u200b]+$/)) { wrappedLines.push(subline); } } else { @@ -22754,9 +22889,9 @@ BRp$6.getLabelText = function (ele, prefix) { rscratch('labelWrapCachedLines', wrappedLines); text = rscratch('labelWrapCachedText', wrappedLines.join('\n')); - rscratch('labelWrapKey', labelKey); // console.log(text) + rscratch('labelWrapKey', labelKey); } else if (wrapStyle === 'ellipsis') { - var maxW = ele.pstyle('text-max-width').pfValue; + var _maxW = ele.pstyle('text-max-width').pfValue; var ellipsized = ''; var ellipsis = "\u2026"; var incLastCh = false; @@ -22764,7 +22899,7 @@ BRp$6.getLabelText = function (ele, prefix) { for (var i = 0; i < text.length; i++) { var widthWithNextCh = this.calculateLabelDimensions(ele, ellipsized + text[i] + ellipsis).width; - if (widthWithNextCh > maxW) { + if (widthWithNextCh > _maxW) { break; } @@ -22786,6 +22921,30 @@ BRp$6.getLabelText = function (ele, prefix) { return text; }; +BRp$6.getLabelJustification = function (ele) { + var justification = ele.pstyle('text-justification').strValue; + var textHalign = ele.pstyle('text-halign').strValue; + + if (justification === 'auto') { + if (ele.isNode()) { + switch (textHalign) { + case 'left': + return 'right'; + + case 'right': + return 'left'; + + default: + return 'center'; + } + } else { + return 'center'; + } + } else { + return justification; + } +}; + BRp$6.calculateLabelDimensions = function (ele, text) { var r = this; var cacheKey = hashString(text, ele._private.labelDimsKey); @@ -22922,6 +23081,7 @@ BRp$8.registerCalculationListeners = function () { var _p = ele._private; var rstyle = _p.rstyle; rstyle.clean = false; + rstyle.cleanConnected = false; } } }; @@ -22940,9 +23100,11 @@ BRp$8.registerCalculationListeners = function () { for (var i = 0; i < elesToUpdate.length; i++) { var ele = elesToUpdate[i]; + var rstyle = ele._private.rstyle; - if (ele.isNode() && !ele._private.rstyle.clean) { + if (ele.isNode() && !rstyle.cleanConnected) { enqueue(ele.connectedEdges()); + rstyle.cleanConnected = true; } } @@ -23135,9 +23297,9 @@ BRp$b.getCachedImage = function (url, crossOrigin, onLoad) { }; var BRp$c = {}; -/* global document, window */ +/* global document, window, ResizeObserver, MutationObserver */ -BRp$c.registerBinding = function (target, event$$1, handler, useCapture) { +BRp$c.registerBinding = function (target, event, handler, useCapture) { // eslint-disable-line no-unused-vars var args = Array.prototype.slice.apply(arguments, [1]); // copy @@ -23167,7 +23329,7 @@ BRp$c.binder = function (tgt) { r.supportsPassiveEvents = supportsPassive; } - var on = function on(event$$1, handler, useCapture) { + var on = function on(event, handler, useCapture) { var args = Array.prototype.slice.call(arguments); if (tgtIsDom && r.supportsPassiveEvents) { @@ -23232,8 +23394,8 @@ BRp$c.load = function () { var allowPanningPassthrough = function allowPanningPassthrough(down, downs) { var allowPassthrough = true; - if (r.cy.hasCompoundNodes() && down && down.isEdge()) { - // a compound node below the edge => no passthrough panning + if (r.cy.hasCompoundNodes() && down && down.pannable()) { + // a grabbable compound node below the ele => no passthrough panning for (var i = 0; downs && i < downs.length; i++) { var down = downs[i]; @@ -23390,7 +23552,8 @@ BRp$c.load = function () { } }; - var haveMutationsApi = typeof MutationObserver !== 'undefined'; // watch for when the cy container is removed from the dom + var haveMutationsApi = typeof MutationObserver !== 'undefined'; + var haveResizeObserverApi = typeof ResizeObserver !== 'undefined'; // watch for when the cy container is removed from the dom if (haveMutationsApi) { r.removeObserver = new MutationObserver(function (mutns) { @@ -23439,9 +23602,15 @@ BRp$c.load = function () { r.registerBinding(window, 'resize', onResize); // eslint-disable-line no-undef - var forEachUp = function forEachUp(domEle, fn$$1) { + if (haveResizeObserverApi) { + r.resizeObserver = new ResizeObserver(onResize); // eslint-disable-line no-undef + + r.resizeObserver.observe(r.container); + } + + var forEachUp = function forEachUp(domEle, fn) { while (domEle != null) { - fn$$1(domEle); + fn(domEle); domEle = domEle.parentNode; } }; @@ -23650,7 +23819,7 @@ BRp$c.load = function () { }; r.redrawHint('select', true); r.redraw(); - } else if (near.isEdge()) { + } else if (near.pannable()) { select[4] = 1; // for future pan } @@ -23816,7 +23985,7 @@ BRp$c.load = function () { pos = r.projectIntoViewport(e.clientX, e.clientY); // Checks primary button down & out of time & mouse not moved much - } else if (select[4] == 1 && (down == null || down.isEdge())) { + } else if (select[4] == 1 && (down == null || down.pannable())) { if (isOverThresholdDrag) { if (!r.hoverData.dragging && cy.boxSelectionEnabled() && (multSelKeyDown || !cy.panningEnabled() || !cy.userPanningEnabled())) { goIntoBoxMode(); @@ -23833,12 +24002,12 @@ BRp$c.load = function () { } } - if (down && down.isEdge() && down.active()) { + if (down && down.pannable() && down.active()) { down.unactivate(); } } } else { - if (down && down.isEdge() && down.active()) { + if (down && down.pannable() && down.active()) { down.unactivate(); } @@ -24257,29 +24426,30 @@ BRp$c.load = function () { r.touchData.capture = true; r.data.bgActivePosistion = undefined; var cy = r.cy; - var now$$1 = r.touchData.now; + var now = r.touchData.now; var earlier = r.touchData.earlier; if (e.touches[0]) { var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY); - now$$1[0] = pos[0]; - now$$1[1] = pos[1]; + now[0] = pos[0]; + now[1] = pos[1]; } if (e.touches[1]) { var pos = r.projectIntoViewport(e.touches[1].clientX, e.touches[1].clientY); - now$$1[2] = pos[0]; - now$$1[3] = pos[1]; + now[2] = pos[0]; + now[3] = pos[1]; } if (e.touches[2]) { var pos = r.projectIntoViewport(e.touches[2].clientX, e.touches[2].clientY); - now$$1[4] = pos[0]; - now$$1[5] = pos[1]; + now[4] = pos[0]; + now[5] = pos[1]; } // record starting points for pinch-to-zoom if (e.touches[1]) { + r.touchData.singleTouchMoved = true; freeDraggedElements(r.dragData.touchDragEles); var offsets = r.findContainerClientCoords(); offsetLeft = offsets[0]; @@ -24302,16 +24472,16 @@ BRp$c.load = function () { var cxtDistThresholdSq = cxtDistThreshold * cxtDistThreshold; if (distance1Sq < cxtDistThresholdSq && !e.touches[2]) { - var near1 = r.findNearestElement(now$$1[0], now$$1[1], true, true); - var near2 = r.findNearestElement(now$$1[2], now$$1[3], true, true); + var near1 = r.findNearestElement(now[0], now[1], true, true); + var near2 = r.findNearestElement(now[2], now[3], true, true); if (near1 && near1.isNode()) { near1.activate().emit({ originalEvent: e, type: 'cxttapstart', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }); r.touchData.start = near1; @@ -24320,8 +24490,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxttapstart', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }); r.touchData.start = near2; @@ -24330,8 +24500,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxttapstart', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }); } @@ -24348,8 +24518,14 @@ BRp$c.load = function () { } } - if (e.touches[2]) ; else if (e.touches[1]) ; else if (e.touches[0]) { - var nears = r.findNearestElements(now$$1[0], now$$1[1], true, true); + if (e.touches[2]) { + // ignore + // safari on ios pans the page otherwise (normally you should be able to preventdefault on touchmove...) + if (cy.boxSelectionEnabled()) { + e.preventDefault(); + } + } else if (e.touches[1]) ; else if (e.touches[0]) { + var nears = r.findNearestElements(now[0], now[1], true, true); var near = nears[0]; if (near != null) { @@ -24384,8 +24560,8 @@ BRp$c.load = function () { originalEvent: e, type: type, position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }; }; @@ -24403,8 +24579,8 @@ BRp$c.load = function () { } triggerEvents(near, ['touchstart', 'tapstart', 'vmousedown'], e, { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] }); if (near == null) { @@ -24426,8 +24602,8 @@ BRp$c.load = function () { && !r.touchData.selecting // box selection shouldn't allow taphold through ) { triggerEvents(r.touchData.start, ['taphold'], e, { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] }); } }, r.tapholdDuration); @@ -24436,8 +24612,8 @@ BRp$c.load = function () { if (e.touches.length >= 1) { var sPos = r.touchData.startPosition = []; - for (var i = 0; i < now$$1.length; i++) { - sPos[i] = earlier[i] = now$$1[i]; + for (var i = 0; i < now.length; i++) { + sPos[i] = earlier[i] = now[i]; } var touch0 = e.touches[0]; @@ -24455,26 +24631,26 @@ BRp$c.load = function () { var select = r.selection; var cy = r.cy; - var now$$1 = r.touchData.now; + var now = r.touchData.now; var earlier = r.touchData.earlier; var zoom = cy.zoom(); if (e.touches[0]) { var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY); - now$$1[0] = pos[0]; - now$$1[1] = pos[1]; + now[0] = pos[0]; + now[1] = pos[1]; } if (e.touches[1]) { var pos = r.projectIntoViewport(e.touches[1].clientX, e.touches[1].clientY); - now$$1[2] = pos[0]; - now$$1[3] = pos[1]; + now[2] = pos[0]; + now[3] = pos[1]; } if (e.touches[2]) { var pos = r.projectIntoViewport(e.touches[2].clientX, e.touches[2].clientY); - now$$1[4] = pos[0]; - now$$1[5] = pos[1]; + now[4] = pos[0]; + now[5] = pos[1]; } var startGPos = r.touchData.startGPosition; @@ -24483,8 +24659,8 @@ BRp$c.load = function () { if (capture && e.touches[0] && startGPos) { var disp = []; - for (var j = 0; j < now$$1.length; j++) { - disp[j] = now$$1[j] - earlier[j]; + for (var j = 0; j < now.length; j++) { + disp[j] = now[j] - earlier[j]; } var dx = e.touches[0].clientX - startGPos[0]; @@ -24518,8 +24694,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxttapend', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }; @@ -24538,8 +24714,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxtdrag', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }; r.data.bgActivePosistion = undefined; @@ -24556,7 +24732,7 @@ BRp$c.load = function () { } r.touchData.cxtDragged = true; - var near = r.findNearestElement(now$$1[0], now$$1[1], true, true); + var near = r.findNearestElement(now[0], now[1], true, true); if (!r.touchData.cxtOver || near !== r.touchData.cxtOver) { if (r.touchData.cxtOver) { @@ -24564,8 +24740,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxtdragout', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }); } @@ -24577,8 +24753,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxtdragover', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }); } @@ -24594,29 +24770,30 @@ BRp$c.load = function () { originalEvent: e, type: 'boxstart', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }); } r.touchData.selecting = true; - r.redrawHint('select', true); + r.touchData.didSelect = true; + select[4] = 1; if (!select || select.length === 0 || select[0] === undefined) { - select[0] = (now$$1[0] + now$$1[2] + now$$1[4]) / 3; - select[1] = (now$$1[1] + now$$1[3] + now$$1[5]) / 3; - select[2] = (now$$1[0] + now$$1[2] + now$$1[4]) / 3 + 1; - select[3] = (now$$1[1] + now$$1[3] + now$$1[5]) / 3 + 1; + select[0] = (now[0] + now[2] + now[4]) / 3; + select[1] = (now[1] + now[3] + now[5]) / 3; + select[2] = (now[0] + now[2] + now[4]) / 3 + 1; + select[3] = (now[1] + now[3] + now[5]) / 3 + 1; } else { - select[2] = (now$$1[0] + now$$1[2] + now$$1[4]) / 3; - select[3] = (now$$1[1] + now$$1[3] + now$$1[5]) / 3; + select[2] = (now[0] + now[2] + now[4]) / 3; + select[3] = (now[1] + now[3] + now[5]) / 3; } - select[4] = 1; - r.touchData.selecting = true; + r.redrawHint('select', true); r.redraw(); // pinch to zoom - } else if (capture && e.touches[1] && cy.zoomingEnabled() && cy.panningEnabled() && cy.userZoomingEnabled() && cy.userPanningEnabled()) { + } else if (capture && e.touches[1] && !r.touchData.didSelect // don't allow box selection to degrade to pinch-to-zoom + && cy.zoomingEnabled() && cy.panningEnabled() && cy.userZoomingEnabled() && cy.userPanningEnabled()) { // two fingers => pinch to zoom e.preventDefault(); r.data.bgActivePosistion = undefined; @@ -24700,174 +24877,174 @@ BRp$c.load = function () { if (e.touches[0]) { var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY); - now$$1[0] = pos[0]; - now$$1[1] = pos[1]; + now[0] = pos[0]; + now[1] = pos[1]; } if (e.touches[1]) { var pos = r.projectIntoViewport(e.touches[1].clientX, e.touches[1].clientY); - now$$1[2] = pos[0]; - now$$1[3] = pos[1]; + now[2] = pos[0]; + now[3] = pos[1]; } if (e.touches[2]) { var pos = r.projectIntoViewport(e.touches[2].clientX, e.touches[2].clientY); - now$$1[4] = pos[0]; - now$$1[5] = pos[1]; + now[4] = pos[0]; + now[5] = pos[1]; } - } else if (e.touches[0]) { - var start = r.touchData.start; - var last = r.touchData.last; - var near; + } else if (e.touches[0] && !r.touchData.didSelect // don't allow box selection to degrade to single finger events like panning + ) { + var start = r.touchData.start; + var last = r.touchData.last; + var near; - if (!r.hoverData.draggingEles && !r.swipePanning) { - near = r.findNearestElement(now$$1[0], now$$1[1], true, true); - } + if (!r.hoverData.draggingEles && !r.swipePanning) { + near = r.findNearestElement(now[0], now[1], true, true); + } - if (capture && start != null) { - e.preventDefault(); - } // dragging nodes + if (capture && start != null) { + e.preventDefault(); + } // dragging nodes - if (capture && start != null && r.nodeIsDraggable(start)) { - if (isOverThresholdDrag) { - // then dragging can happen - var draggedEles = r.dragData.touchDragEles; - var justStartedDrag = !r.dragData.didDrag; + if (capture && start != null && r.nodeIsDraggable(start)) { + if (isOverThresholdDrag) { + // then dragging can happen + var draggedEles = r.dragData.touchDragEles; + var justStartedDrag = !r.dragData.didDrag; - if (justStartedDrag) { - addNodesToDrag(draggedEles, { - inDragLayer: true - }); - } + if (justStartedDrag) { + addNodesToDrag(draggedEles, { + inDragLayer: true + }); + } - r.dragData.didDrag = true; - var totalShift = { - x: 0, - y: 0 - }; + r.dragData.didDrag = true; + var totalShift = { + x: 0, + y: 0 + }; - if (number(disp[0]) && number(disp[1])) { - totalShift.x += disp[0]; - totalShift.y += disp[1]; + if (number(disp[0]) && number(disp[1])) { + totalShift.x += disp[0]; + totalShift.y += disp[1]; - if (justStartedDrag) { - r.redrawHint('eles', true); - var dragDelta = r.touchData.dragDelta; + if (justStartedDrag) { + r.redrawHint('eles', true); + var dragDelta = r.touchData.dragDelta; - if (dragDelta && number(dragDelta[0]) && number(dragDelta[1])) { - totalShift.x += dragDelta[0]; - totalShift.y += dragDelta[1]; + if (dragDelta && number(dragDelta[0]) && number(dragDelta[1])) { + totalShift.x += dragDelta[0]; + totalShift.y += dragDelta[1]; + } } } - } - - r.hoverData.draggingEles = true; - draggedEles.silentShift(totalShift).emit('position drag'); - r.redrawHint('drag', true); - if (r.touchData.startPosition[0] == earlier[0] && r.touchData.startPosition[1] == earlier[1]) { - r.redrawHint('eles', true); - } + r.hoverData.draggingEles = true; + draggedEles.silentShift(totalShift).emit('position drag'); + r.redrawHint('drag', true); - r.redraw(); - } else { - // otherise keep track of drag delta for later - var dragDelta = r.touchData.dragDelta = r.touchData.dragDelta || []; + if (r.touchData.startPosition[0] == earlier[0] && r.touchData.startPosition[1] == earlier[1]) { + r.redrawHint('eles', true); + } - if (dragDelta.length === 0) { - dragDelta.push(disp[0]); - dragDelta.push(disp[1]); + r.redraw(); } else { - dragDelta[0] += disp[0]; - dragDelta[1] += disp[1]; + // otherise keep track of drag delta for later + var dragDelta = r.touchData.dragDelta = r.touchData.dragDelta || []; + + if (dragDelta.length === 0) { + dragDelta.push(disp[0]); + dragDelta.push(disp[1]); + } else { + dragDelta[0] += disp[0]; + dragDelta[1] += disp[1]; + } } - } - } // touchmove + } // touchmove - { - triggerEvents(start || near, ['touchmove', 'tapdrag', 'vmousemove'], e, { - x: now$$1[0], - y: now$$1[1] - }); + { + triggerEvents(start || near, ['touchmove', 'tapdrag', 'vmousemove'], e, { + x: now[0], + y: now[1] + }); - if ((!start || !start.grabbed()) && near != last) { - if (last) { - last.emit({ - originalEvent: e, - type: 'tapdragout', - position: { - x: now$$1[0], - y: now$$1[1] - } - }); - } + if ((!start || !start.grabbed()) && near != last) { + if (last) { + last.emit({ + originalEvent: e, + type: 'tapdragout', + position: { + x: now[0], + y: now[1] + } + }); + } - if (near) { - near.emit({ - originalEvent: e, - type: 'tapdragover', - position: { - x: now$$1[0], - y: now$$1[1] - } - }); + if (near) { + near.emit({ + originalEvent: e, + type: 'tapdragover', + position: { + x: now[0], + y: now[1] + } + }); + } } - } - r.touchData.last = near; - } // check to cancel taphold + r.touchData.last = near; + } // check to cancel taphold - if (capture) { - for (var i = 0; i < now$$1.length; i++) { - if (now$$1[i] && r.touchData.startPosition[i] && isOverThresholdDrag) { - r.touchData.singleTouchMoved = true; + if (capture) { + for (var i = 0; i < now.length; i++) { + if (now[i] && r.touchData.startPosition[i] && isOverThresholdDrag) { + r.touchData.singleTouchMoved = true; + } } - } - } // panning + } // panning - if (capture && (start == null || start.isEdge()) && cy.panningEnabled() && cy.userPanningEnabled()) { - var allowPassthrough = allowPanningPassthrough(start, r.touchData.starts); + if (capture && (start == null || start.pannable()) && cy.panningEnabled() && cy.userPanningEnabled()) { + var allowPassthrough = allowPanningPassthrough(start, r.touchData.starts); - if (allowPassthrough) { - e.preventDefault(); + if (allowPassthrough) { + e.preventDefault(); - if (r.swipePanning) { - cy.panBy({ - x: disp[0] * zoom, - y: disp[1] * zoom - }); - } else if (isOverThresholdDrag) { - r.swipePanning = true; - cy.panBy({ - x: dx * zoom, - y: dy * zoom - }); + if (!r.data.bgActivePosistion) { + r.data.bgActivePosistion = array2point(r.touchData.startPosition); + } - if (start) { - start.unactivate(); + if (r.swipePanning) { + cy.panBy({ + x: disp[0] * zoom, + y: disp[1] * zoom + }); + } else if (isOverThresholdDrag) { + r.swipePanning = true; + cy.panBy({ + x: dx * zoom, + y: dy * zoom + }); - if (!r.data.bgActivePosistion) { - r.data.bgActivePosistion = array2point(r.touchData.startPosition); + if (start) { + start.unactivate(); + r.redrawHint('select', true); + r.touchData.start = null; } - - r.redrawHint('select', true); - r.touchData.start = null; } - } - } // Re-project + } // Re-project - var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY); - now$$1[0] = pos[0]; - now$$1[1] = pos[1]; + var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY); + now[0] = pos[0]; + now[1] = pos[1]; + } } - } - for (var j = 0; j < now$$1.length; j++) { - earlier[j] = now$$1[j]; + for (var j = 0; j < now.length; j++) { + earlier[j] = now[j]; } // the active bg indicator should be removed when making a swipe that is neither for dragging nodes or panning @@ -24908,25 +25085,25 @@ BRp$c.load = function () { r.hoverData.draggingEles = false; var cy = r.cy; var zoom = cy.zoom(); - var now$$1 = r.touchData.now; + var now = r.touchData.now; var earlier = r.touchData.earlier; if (e.touches[0]) { var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY); - now$$1[0] = pos[0]; - now$$1[1] = pos[1]; + now[0] = pos[0]; + now[1] = pos[1]; } if (e.touches[1]) { var pos = r.projectIntoViewport(e.touches[1].clientX, e.touches[1].clientY); - now$$1[2] = pos[0]; - now$$1[3] = pos[1]; + now[2] = pos[0]; + now[3] = pos[1]; } if (e.touches[2]) { var pos = r.projectIntoViewport(e.touches[2].clientX, e.touches[2].clientY); - now$$1[4] = pos[0]; - now$$1[5] = pos[1]; + now[4] = pos[0]; + now[5] = pos[1]; } if (start) { @@ -24940,8 +25117,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxttapend', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }; @@ -24956,8 +25133,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxttap', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }; @@ -24992,8 +25169,8 @@ BRp$c.load = function () { type: 'boxend', originalEvent: e, position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }); @@ -25039,22 +25216,22 @@ BRp$c.load = function () { } triggerEvents(start, ['touchend', 'tapend', 'vmouseup', 'tapdragout'], e, { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] }); start.unactivate(); r.touchData.start = null; } else { - var near = r.findNearestElement(now$$1[0], now$$1[1], true, true); + var near = r.findNearestElement(now[0], now[1], true, true); triggerEvents(near, ['touchend', 'tapend', 'vmouseup', 'tapdragout'], e, { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] }); } - var dx = r.touchData.startPosition[0] - now$$1[0]; + var dx = r.touchData.startPosition[0] - now[0]; var dx2 = dx * dx; - var dy = r.touchData.startPosition[1] - now$$1[1]; + var dy = r.touchData.startPosition[1] - now[1]; var dy2 = dy * dy; var dist2 = dx2 + dy2; var rdist2 = dist2 * zoom * zoom; // Tap event, roughly same as mouse click event for touch @@ -25065,8 +25242,8 @@ BRp$c.load = function () { } triggerEvents(start, ['tap', 'vclick'], e, { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] }); } // Prepare to select the currently touched node, only if it hasn't been dragged past a certain distance @@ -25091,19 +25268,25 @@ BRp$c.load = function () { r.touchData.singleTouchMoved = true; } - for (var j = 0; j < now$$1.length; j++) { - earlier[j] = now$$1[j]; + for (var j = 0; j < now.length; j++) { + earlier[j] = now[j]; } - r.dragData.didDrag = false; // reset for next mousedown + r.dragData.didDrag = false; // reset for next touchstart if (e.touches.length === 0) { r.touchData.dragDelta = []; r.touchData.startPosition = null; r.touchData.startGPosition = null; + r.touchData.didSelect = false; } if (e.touches.length < 2) { + if (e.touches.length === 1) { + // the old start global pos'n may not be the same finger that remains + r.touchData.startGPosition = [e.touches[0].clientX, e.touches[0].clientY]; + } + r.pinching = false; r.redrawHint('eles', true); r.redraw(); @@ -25746,10 +25929,10 @@ BRp$f.init = function (options) { } if (!stylesheetAlreadyExists) { - var stylesheet$$1 = document.createElement('style'); - stylesheet$$1.id = stylesheetId; - stylesheet$$1.innerHTML = '.' + className + ' { position: relative; }'; - head.insertBefore(stylesheet$$1, head.children[0]); // first so lowest priority + var stylesheet = document.createElement('style'); + stylesheet.id = stylesheetId; + stylesheet.innerHTML = '.' + className + ' { position: relative; }'; + head.insertBefore(stylesheet, head.children[0]); // first so lowest priority } var computedStyle = window$1.getComputedStyle(ctr); @@ -25887,6 +26070,10 @@ BRp$f.destroy = function () { r.styleObserver.disconnect(); } + if (r.resizeObserver) { + r.resizeObserver.disconnect(); + } + if (r.labelCalcDiv) { try { document.body.removeChild(r.labelCalcDiv); // eslint-disable-line no-undef @@ -25938,9 +26125,9 @@ var defs = { while (true) { // eslint-disable-line no-constant-condition - var now$$1 = performanceNow(); - var duration = now$$1 - startTime; - var frameDuration = now$$1 - frameStartTime; + var now = performanceNow(); + var duration = now - startTime; + var frameDuration = now - frameStartTime; if (renderTime < fullFpsTime) { // if we're rendering faster than the ideal fps, then do dequeueing @@ -26738,8 +26925,8 @@ var LayeredTextureCache = function LayeredTextureCache(renderer) { self.refineElementTextures(self.eleTxrDeqs); self.eleTxrDeqs.unmerge(self.eleTxrDeqs); }, refineEleDebounceTime); - r.beforeRender(function (willDraw, now$$1) { - if (now$$1 - self.lastInvalidationTime <= invalidThreshold) { + r.beforeRender(function (willDraw, now) { + if (now - self.lastInvalidationTime <= invalidThreshold) { self.skipping = true; } else { self.skipping = false; @@ -26901,7 +27088,7 @@ LTCp.getLayers = function (eles, pxRatio, lvl) { var layer = null; var maxElesPerLayer = eles.length / defNumLayers; - var allowLazyQueueing = !firstGet; + var allowLazyQueueing = !firstGet; for (var i = 0; i < eles.length; i++) { var ele = eles[i]; @@ -27408,7 +27595,7 @@ CRp$1.drawElementOverlay = function (context, ele) { } }; -CRp$1.drawCachedElementPortion = function (context, ele, eleTxrCache, pxRatio, lvl, reason, getRotation) { +CRp$1.drawCachedElementPortion = function (context, ele, eleTxrCache, pxRatio, lvl, reason, getRotation, getOpacity) { var r = this; var bb = eleTxrCache.getBoundingBox(ele); @@ -27420,7 +27607,7 @@ CRp$1.drawCachedElementPortion = function (context, ele, eleTxrCache, pxRatio, l var eleCache = eleTxrCache.getElement(ele, bb, pxRatio, lvl, reason); if (eleCache != null) { - var opacity = ele.effectiveOpacity(); + var opacity = getOpacity(r, ele); if (opacity === 0) { return; @@ -27495,6 +27682,14 @@ var getTargetLabelRotation = function getTargetLabelRotation(r, ele) { return r.getTextAngle(ele, 'target'); }; +var getOpacity = function getOpacity(r, ele) { + return ele.effectiveOpacity(); +}; + +var getTextOpacity = function getTextOpacity(e, ele) { + return ele.pstyle('text-opacity').pfValue * ele.effectiveOpacity(); +}; + CRp$1.drawCachedElement = function (context, ele, pxRatio, extent, lvl, requestHighQuality) { var r = this; var _r$data = r.data, @@ -27510,12 +27705,12 @@ CRp$1.drawCachedElement = function (context, ele, pxRatio, extent, lvl, requestH } if (!extent || boundingBoxesIntersect(bb, extent)) { - r.drawCachedElementPortion(context, ele, eleTxrCache, pxRatio, lvl, reason, getZeroRotation); - r.drawCachedElementPortion(context, ele, lblTxrCache, pxRatio, lvl, reason, getLabelRotation); + r.drawCachedElementPortion(context, ele, eleTxrCache, pxRatio, lvl, reason, getZeroRotation, getOpacity); + r.drawCachedElementPortion(context, ele, lblTxrCache, pxRatio, lvl, reason, getLabelRotation, getTextOpacity); if (ele.isEdge()) { - r.drawCachedElementPortion(context, ele, slbTxrCache, pxRatio, lvl, reason, getSourceLabelRotation); - r.drawCachedElementPortion(context, ele, tlbTxrCache, pxRatio, lvl, reason, getTargetLabelRotation); + r.drawCachedElementPortion(context, ele, slbTxrCache, pxRatio, lvl, reason, getSourceLabelRotation, getTextOpacity); + r.drawCachedElementPortion(context, ele, tlbTxrCache, pxRatio, lvl, reason, getTargetLabelRotation, getTextOpacity); } r.drawElementOverlay(context, ele); @@ -27585,7 +27780,7 @@ CRp$2.drawEdge = function (context, edge, shiftToOriginWithBb) { var r = this; var rs = edge._private.rscratch; - if (!edge.visible()) { + if (shouldDrawOpacity && !edge.visible()) { return; } // if bezier ctrl pts can not be calculated, then die @@ -27936,7 +28131,7 @@ CRp$3.drawInscribedImage = function (context, img, node, index, nodeOpacity) { var nodeTW = nodeW + (getIndexedStyle(node, 'background-width-relative-to', 'value', index) === 'inner' ? 0 : paddingX2); var nodeTH = nodeH + (getIndexedStyle(node, 'background-height-relative-to', 'value', index) === 'inner' ? 0 : paddingX2); var rs = node._private.rscratch; - var clip = node.pstyle('background-clip').value; + var clip = getIndexedStyle(node, 'background-clip', 'value', index); var shouldClip = clip === 'node'; var imgOpacity = getIndexedStyle(node, 'background-image-opacity', 'value', index) * nodeOpacity; var imgW = img.width || img.cachedW; @@ -28088,7 +28283,7 @@ CRp$4.drawElementText = function (context, ele, shiftToOriginWithBb, force, pref var r = this; if (force == null) { - if (!r.eleTextBiggerThanMin(ele)) { + if (useEleOpacity && !r.eleTextBiggerThanMin(ele)) { return; } } else if (force === false) { @@ -28102,29 +28297,16 @@ CRp$4.drawElementText = function (context, ele, shiftToOriginWithBb, force, pref return; } - var textHalign = ele.pstyle('text-halign').strValue; - - switch (textHalign) { - case 'left': - context.textAlign = 'right'; - break; - - case 'right': - context.textAlign = 'left'; - break; - - default: - // e.g. center - context.textAlign = 'center'; - } - + var justification = r.getLabelJustification(ele); + context.textAlign = justification; context.textBaseline = 'bottom'; } else { - var label = ele.pstyle('label'); + var _label = ele.pstyle('label'); + var srcLabel = ele.pstyle('source-label'); var tgtLabel = ele.pstyle('target-label'); - if ((!label || !label.value) && (!srcLabel || !srcLabel.value) && (!tgtLabel || !tgtLabel.value)) { + if ((!_label || !_label.value) && (!srcLabel || !srcLabel.value) && (!tgtLabel || !tgtLabel.value)) { return; } @@ -28184,7 +28366,7 @@ CRp$4.setupTextStyle = function (context, ele) { var labelSize = ele.pstyle('font-size').pfValue + 'px'; var labelFamily = ele.pstyle('font-family').strValue; var labelWeight = ele.pstyle('font-weight').strValue; - var opacity = ele.pstyle('text-opacity').value * (useEleOpacity ? ele.effectiveOpacity() : 1); + var opacity = useEleOpacity ? ele.effectiveOpacity() * ele.pstyle('text-opacity').value : 1; var outlineOpacity = ele.pstyle('text-outline-opacity').value * opacity; var color = ele.pstyle('color').value; var outlineColor = ele.pstyle('text-outline-color').value; @@ -28196,8 +28378,8 @@ CRp$4.setupTextStyle = function (context, ele) { }; // TODO ensure re-used -function roundRect(ctx, x, y, width, height, radius) { - var radius = radius || 5; +function roundRect(ctx, x, y, width, height) { + var radius = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 5; ctx.beginPath(); ctx.moveTo(x + radius, y); ctx.lineTo(x + width - radius, y); @@ -28238,7 +28420,7 @@ CRp$4.drawText = function (context, ele, prefix) { var rscratch = _p.rscratch; var parentOpacity = useEleOpacity ? ele.effectiveOpacity() : 1; - if (parentOpacity === 0 || ele.pstyle('text-opacity').value === 0) { + if (useEleOpacity && (parentOpacity === 0 || ele.pstyle('text-opacity').value === 0)) { return; } // use 'main' as an alias for the main label (i.e. null prefix) @@ -28249,6 +28431,8 @@ CRp$4.drawText = function (context, ele, prefix) { var textX = getPrefixedProperty(rscratch, 'labelX', prefix); var textY = getPrefixedProperty(rscratch, 'labelY', prefix); + var orgTextX, orgTextY; // used for rotation + var text = this.getLabelText(ele, prefix); if (text != null && text !== '' && !isNaN(textX) && !isNaN(textY)) { @@ -28278,8 +28462,8 @@ CRp$4.drawText = function (context, ele, prefix) { } if (theta !== 0) { - var orgTextX = textX; - var orgTextY = textY; + orgTextX = textX; + orgTextY = textY; context.translate(orgTextX, orgTextY); context.rotate(theta); textX = 0; @@ -28395,7 +28579,35 @@ CRp$4.drawText = function (context, ele, prefix) { if (ele.pstyle('text-wrap').value === 'wrap') { var lines = getPrefixedProperty(rscratch, 'labelWrapCachedLines', prefix); - var lineHeight = textH / lines.length; + var lineHeight = getPrefixedProperty(rscratch, 'labelLineHeight', prefix); + var halfTextW = textW / 2; + var justification = this.getLabelJustification(ele); + + if (justification === 'auto') ; else if (halign === 'left') { + // auto justification : right + if (justification === 'left') { + textX += -textW; + } else if (justification === 'center') { + textX += -halfTextW; + } // else same as auto + + } else if (halign === 'center') { + // auto justfication : center + if (justification === 'left') { + textX += -halfTextW; + } else if (justification === 'right') { + textX += halfTextW; + } // else same as auto + + } else if (halign === 'right') { + // auto justification : left + if (justification === 'center') { + textX += halfTextW; + } else if (justification === 'right') { + textX += textW; + } // else same as auto + + } switch (valign) { case 'top': @@ -28448,7 +28660,7 @@ CRp$5.drawNode = function (context, node, shiftToOriginWithBb) { return; // can't draw node with undefined position } - if (!node.visible()) { + if (shouldDrawOpacity && !node.visible()) { return; } @@ -28839,7 +29051,7 @@ CRp$6.paintCache = function (context) { CRp$6.createGradientStyleFor = function (context, shapeStyleName, ele, fill, opacity) { var gradientStyle; var usePaths = this.usePaths(); - var colors$$1 = ele.pstyle(shapeStyleName + '-gradient-stop-colors').value, + var colors = ele.pstyle(shapeStyleName + '-gradient-stop-colors').value, positions = ele.pstyle(shapeStyleName + '-gradient-stop-positions').pfValue; if (fill === 'radial-gradient') { @@ -28919,11 +29131,11 @@ CRp$6.createGradientStyleFor = function (context, shapeStyleName, ele, fill, opa if (!gradientStyle) return null; // invalid gradient style - var hasPositions = positions.length === colors$$1.length; - var length = colors$$1.length; + var hasPositions = positions.length === colors.length; + var length = colors.length; for (var i = 0; i < length; i++) { - gradientStyle.addColorStop(hasPositions ? positions[i] : i / (length - 1), 'rgba(' + colors$$1[i][0] + ',' + colors$$1[i][1] + ',' + colors$$1[i][2] + ',' + opacity + ')'); + gradientStyle.addColorStop(hasPositions ? positions[i] : i / (length - 1), 'rgba(' + colors[i][0] + ',' + colors[i][1] + ',' + colors[i][2] + ',' + opacity + ')'); } return gradientStyle; @@ -29254,7 +29466,7 @@ CRp$6.render = function (options) { } var extent = cy.extent(); - var vpManip = r.pinching || r.hoverData.dragging || r.swipePanning || r.data.wheelZooming || r.hoverData.draggingEles; + var vpManip = r.pinching || r.hoverData.dragging || r.swipePanning || r.data.wheelZooming || r.hoverData.draggingEles || r.cy.animated(); var hideEdges = r.hideEdgesOnViewport && vpManip; var needMbClear = []; needMbClear[r.NODE] = !needDraw[r.NODE] && motionBlur && !r.clearedForMotionBlur[r.NODE] || r.clearingMotionBlur; @@ -29774,26 +29986,38 @@ function CanvasRenderer(options) { bufferCanvases: new Array(CRp$a.BUFFER_COUNT), bufferContexts: new Array(CRp$a.CANVAS_LAYERS) }; - var tapHlOff = '-webkit-tap-highlight-color: rgba(0,0,0,0);'; + var tapHlOffAttr = '-webkit-tap-highlight-color'; + var tapHlOffStyle = 'rgba(0,0,0,0)'; r.data.canvasContainer = document.createElement('div'); // eslint-disable-line no-undef var containerStyle = r.data.canvasContainer.style; - r.data.canvasContainer.setAttribute('style', tapHlOff); + r.data.canvasContainer.style[tapHlOffAttr] = tapHlOffStyle; containerStyle.position = 'relative'; containerStyle.zIndex = '0'; containerStyle.overflow = 'hidden'; var container = options.cy.container(); container.appendChild(r.data.canvasContainer); + container.style[tapHlOffAttr] = tapHlOffStyle; + var styleMap = { + '-webkit-user-select': 'none', + '-moz-user-select': '-moz-none', + 'user-select': 'none', + '-webkit-tap-highlight-color': 'rgba(0,0,0,0)', + 'outline-style': 'none' + }; - if ((container.getAttribute('style') || '').indexOf(tapHlOff) < 0) { - container.setAttribute('style', (container.getAttribute('style') || '') + tapHlOff); + if (ms()) { + styleMap['-ms-touch-action'] = 'none'; + styleMap['touch-action'] = 'none'; } for (var i = 0; i < CRp$a.CANVAS_LAYERS; i++) { var canvas = r.data.canvases[i] = document.createElement('canvas'); // eslint-disable-line no-undef r.data.contexts[i] = canvas.getContext('2d'); - canvas.setAttribute('style', '-webkit-user-select: none; -moz-user-select: -moz-none; user-select: none; -webkit-tap-highlight-color: rgba(0,0,0,0); outline-style: none;' + (ms() ? ' -ms-touch-action: none; touch-action: none; ' : '')); + Object.keys(styleMap).forEach(function (k) { + canvas.style[k] = styleMap[k]; + }); canvas.style.position = 'absolute'; canvas.setAttribute('data-id', 'layer' + i); canvas.style.zIndex = String(CRp$a.CANVAS_LAYERS - i); @@ -30029,20 +30253,20 @@ function CanvasRenderer(options) { tlbTxrCache.onDequeue(refineInLayers); } -CRp$a.redrawHint = function (group, bool$$1) { +CRp$a.redrawHint = function (group, bool) { var r = this; switch (group) { case 'eles': - r.data.canvasNeedsRedraw[CRp$a.NODE] = bool$$1; + r.data.canvasNeedsRedraw[CRp$a.NODE] = bool; break; case 'drag': - r.data.canvasNeedsRedraw[CRp$a.DRAG] = bool$$1; + r.data.canvasNeedsRedraw[CRp$a.DRAG] = bool; break; case 'select': - r.data.canvasNeedsRedraw[CRp$a.SELECT_BOX] = bool$$1; + r.data.canvasNeedsRedraw[CRp$a.SELECT_BOX] = bool; break; } }; // whether to use Path2D caching for drawing @@ -30062,13 +30286,13 @@ CRp$a.usePaths = function () { return pathsImpld && this.pathsEnabled; }; -CRp$a.setImgSmoothing = function (context, bool$$1) { +CRp$a.setImgSmoothing = function (context, bool) { if (context.imageSmoothingEnabled != null) { - context.imageSmoothingEnabled = bool$$1; + context.imageSmoothingEnabled = bool; } else { - context.webkitImageSmoothingEnabled = bool$$1; - context.mozImageSmoothingEnabled = bool$$1; - context.msImageSmoothingEnabled = bool$$1; + context.webkitImageSmoothingEnabled = bool; + context.mozImageSmoothingEnabled = bool; + context.msImageSmoothingEnabled = bool; } }; @@ -30083,7 +30307,7 @@ CRp$a.getImgSmoothing = function (context) { CRp$a.makeOffscreenCanvas = function (width, height) { var canvas; - if ((typeof OffscreenCanvas === "undefined" ? "undefined" : _typeof(OffscreenCanvas)) !== ("undefined")) { + if ((typeof OffscreenCanvas === "undefined" ? "undefined" : _typeof(OffscreenCanvas)) !== ( "undefined" )) { canvas = new OffscreenCanvas(width, height); } else { canvas = document.createElement('canvas'); // eslint-disable-line no-undef @@ -30255,6 +30479,10 @@ function setExtension(type, name, registrant) { this.emitter().removeListener(evt, cb); return this; }, + removeAllListeners: function removeAllListeners() { + this.emitter().removeAllListeners(); + return this; + }, emit: function emit(evt, params) { this.emitter().emit(evt, params); return this; @@ -30423,28 +30651,28 @@ sheetfn.css = function (name, value) { sheetfn.style = sheetfn.css; // generate a real style object from the dummy stylesheet sheetfn.generateStyle = function (cy) { - var style$$1 = new Style(cy); - return this.appendToStyle(style$$1); + var style = new Style(cy); + return this.appendToStyle(style); }; // append a dummy stylesheet object on a real style object -sheetfn.appendToStyle = function (style$$1) { +sheetfn.appendToStyle = function (style) { for (var i = 0; i < this.length; i++) { var context = this[i]; var selector = context.selector; var props = context.properties; - style$$1.selector(selector); // apply selector + style.selector(selector); // apply selector for (var j = 0; j < props.length; j++) { var prop = props[j]; - style$$1.css(prop.name, prop.value); // apply property + style.css(prop.name, prop.value); // apply property } } - return style$$1; + return style; }; -var version = "3.5.0"; +var version = "3.9.0"; var cytoscape = function cytoscape(options) { // if no options specified, use default @@ -30471,8 +30699,8 @@ cytoscape.use = function (ext) { return this; }; -cytoscape.warnings = function (bool$$1) { - return warnings(bool$$1); +cytoscape.warnings = function (bool) { + return warnings(bool); }; // replaced by build system diff --git a/dist/cytoscape.esm.js b/dist/cytoscape.esm.js index 33225c9922..89526e2655 100644 --- a/dist/cytoscape.esm.js +++ b/dist/cytoscape.esm.js @@ -966,7 +966,7 @@ function () { var Map$1 = typeof Map !== 'undefined' ? Map : ObjectMap; /* global Set */ -var undef = "undefined"; +var undef = "undefined" ; var ObjectSet = /*#__PURE__*/ @@ -1117,6 +1117,8 @@ var Element = function Element(cy, params, restore) { // whether the element is grabbed by the mouse; renderer sets this privately grabbable: params.grabbable === undefined ? true : params.grabbable ? true : false, // whether the element can be grabbed + pannable: params.pannable === undefined ? group === 'edges' ? true : false : params.pannable ? true : false, + // whether the element has passthrough panning enabled active: false, // whether the element is active from user interaction classes: new Set$1(), @@ -1144,8 +1146,26 @@ var Element = function Element(cy, params, restore) { // cache of the current bounding box bbCacheShift: { x: 0, - y: 0 // shift applied to cached bb to be applied on next get - + y: 0 + }, + // shift applied to cached bb to be applied on next get + bodyBounds: null, + // bounds cache of element body, w/o overlay + overlayBounds: null, + // bounds cache of element body, including overlay + labelBounds: { + // bounds cache of labels + all: null, + source: null, + target: null, + main: null + }, + arrowBounds: { + // bounds cache of edge arrows + source: null, + target: null, + 'mid-source': null, + 'mid-target': null } }; @@ -1205,18 +1225,18 @@ var defineSearch = function defineSearch(params) { dfs: params.dfs || !params.bfs }; // from pseudocode on wikipedia - return function searchFn(roots, fn$$1, directed) { + return function searchFn(roots, fn$1, directed) { var options; if (plainObject(roots) && !elementOrCollection(roots)) { options = roots; roots = options.roots || options.root; - fn$$1 = options.visit; + fn$1 = options.visit; directed = options.directed; } - directed = arguments.length === 2 && !fn(fn$$1) ? fn$$1 : directed; - fn$$1 = fn(fn$$1) ? fn$$1 : function () {}; + directed = arguments.length === 2 && !fn(fn$1) ? fn$1 : directed; + fn$1 = fn(fn$1) ? fn$1 : function () {}; var cy = this._private.cy; var v = roots = string(roots) ? this.filter(roots) : roots; var Q = []; @@ -1267,7 +1287,7 @@ var defineSearch = function defineSearch(params) { var tgt = prevEdge != null ? prevEdge.target() : null; var prevNode = prevEdge == null ? undefined : v.same(src) ? tgt[0] : src[0]; var ret = void 0; - ret = fn$$1(v, prevEdge, prevNode, j++, depth); + ret = fn$1(v, prevEdge, prevNode, j++, depth); if (ret === true) { found = v; @@ -3822,7 +3842,7 @@ var addLoops = function addLoops(M, n, val) { } }; -var normalize$1 = function normalize(M, n) { +var normalize = function normalize(M, n) { var sum; for (var col = 0; col < n; col++) { @@ -3879,7 +3899,7 @@ var inflate = function inflate(M, n, inflateFactor _M[i] = Math.pow(M[i], inflateFactor); } - normalize$1(_M, n); + normalize(_M, n); return _M; }; @@ -3979,7 +3999,7 @@ var markovClustering = function markovClustering(options) { addLoops(M, n, opts.multFactor); // Step 2: M = normalize( M ); - normalize$1(M, n); + normalize(M, n); var isStillMoving = true; var iterations = 0; @@ -4105,17 +4125,20 @@ var setOptions$1 = function setOptions(options) { var getDist = function getDist(type, node, centroid, attributes, mode) { - var getP = mode === 'kMedoids' ? function (i) { - return attributes[i](centroid); - } : function (i) { + var noNodeP = mode !== 'kMedoids'; + var getP = noNodeP ? function (i) { return centroid[i]; + } : function (i) { + return attributes[i](centroid); }; var getQ = function getQ(i) { return attributes[i](node); }; - return clusteringDistance(type, attributes.length, getP, getQ); + var nodeP = centroid; + var nodeQ = node; + return clusteringDistance(type, attributes.length, getP, getQ, nodeP, nodeQ); }; var randomCentroids = function randomCentroids(nodes, k, attributes) { @@ -4251,9 +4274,7 @@ var kMeans = function kMeans(options) { if (opts.testMode) { if (typeof opts.testCentroids === 'number') { - // TODO: implement a seeded random number generator. - var seed = opts.testCentroids; - centroids = randomCentroids(nodes, opts.k, opts.attributes, seed); + centroids = randomCentroids(nodes, opts.k, opts.attributes); } else if (_typeof(opts.testCentroids) === 'object') { centroids = opts.testCentroids; } else { @@ -4600,7 +4621,7 @@ var mergeClosest = function mergeClosest(clusters, index, dists, mins, opts) { return attrs[i](n1); }, function (i) { return attrs[i](n2); - }); + }, n1, n2); }; for (var i = 0; i < clusters.length; i++) { @@ -4696,8 +4717,8 @@ var getAllChildren = function getAllChildren(root, arr, cy) { if (root.value) { arr.push(root.value); } else { - if (root.left) getAllChildren(root.left, arr, cy); - if (root.right) getAllChildren(root.right, arr, cy); + if (root.left) getAllChildren(root.left, arr); + if (root.right) getAllChildren(root.right, arr); } }; @@ -4741,8 +4762,8 @@ var buildClustersFromTree = function buildClustersFromTree(root, k, cy) { if (k === 0) { // don't cut tree, simply return all nodes as 1 single cluster - if (root.left) getAllChildren(root.left, left, cy); - if (root.right) getAllChildren(root.right, right, cy); + if (root.left) getAllChildren(root.left, left); + if (root.right) getAllChildren(root.right, right); leaves = left.concat(right); return [cy.collection(leaves)]; } else if (k === 1) { @@ -4751,8 +4772,8 @@ var buildClustersFromTree = function buildClustersFromTree(root, k, cy) { // leaf node return [cy.collection(root.value)]; } else { - if (root.left) getAllChildren(root.left, left, cy); - if (root.right) getAllChildren(root.right, right, cy); + if (root.left) getAllChildren(root.left, left); + if (root.right) getAllChildren(root.right, right); return [cy.collection(left), cy.collection(right)]; } } else { @@ -4780,7 +4801,7 @@ var hierarchicalClustering = function hierarchicalClustering(options) { return attrs[i](n1); }, function (i) { return attrs[i](n2); - }); + }, n1, n2); }; // Begin hierarchical algorithm @@ -4947,14 +4968,14 @@ var assignClusters = function assignClusters(n, S, exemplars) { for (var i = 0; i < n; i++) { var index = -1; - var max$$1 = -Infinity; + var max = -Infinity; for (var ei = 0; ei < exemplars.length; ei++) { var e = exemplars[ei]; - if (S[i * n + e] > max$$1) { + if (S[i * n + e] > max) { index = e; - max$$1 = S[i * n + e]; + max = S[i * n + e]; } } @@ -5089,7 +5110,7 @@ var affinityPropagation = function affinityPropagation(options) { // main algorithmic loop // Update R responsibility matrix for (var _i8 = 0; _i8 < n; _i8++) { - var max$$1 = -Infinity, + var max = -Infinity, max2 = -Infinity, maxI = -1, AS = 0.0; @@ -5098,9 +5119,9 @@ var affinityPropagation = function affinityPropagation(options) { old[_j] = R[_i8 * n + _j]; AS = A[_i8 * n + _j] + S[_i8 * n + _j]; - if (AS >= max$$1) { - max2 = max$$1; - max$$1 = AS; + if (AS >= max) { + max2 = max; + max = AS; maxI = _j; } else if (AS > max2) { max2 = AS; @@ -5108,7 +5129,7 @@ var affinityPropagation = function affinityPropagation(options) { } for (var _j2 = 0; _j2 < n; _j2++) { - R[_i8 * n + _j2] = (1 - opts.damping) * (S[_i8 * n + _j2] - max$$1) + opts.damping * old[_j2]; + R[_i8 * n + _j2] = (1 - opts.damping) * (S[_i8 * n + _j2] - max) + opts.damping * old[_j2]; } R[_i8 * n + maxI] = (1 - opts.damping) * (S[_i8 * n + maxI] - max2) + opts.damping * old[maxI]; @@ -5169,7 +5190,7 @@ var affinityPropagation = function affinityPropagation(options) { var exemplarsIndices = findExemplars(n, R, A); // Assign nodes to clusters - var clusterIndices = assign$2(n, S, exemplarsIndices, nodes, id2position); + var clusterIndices = assign$2(n, S, exemplarsIndices); var clusters = {}; for (var c = 0; c < exemplarsIndices.length; c++) { @@ -5697,7 +5718,7 @@ extend(anifn, { return this; }, - promise: function promise$$1(type) { + promise: function promise(type) { var _p = this._private; var arr; @@ -5811,7 +5832,7 @@ var define = { return this; } - var style$$1 = cy.style(); + var style = cy.style(); properties = extend({}, properties, params); var propertiesEmpty = Object.keys(properties).length === 0; @@ -5834,7 +5855,7 @@ var define = { } if (isEles) { - properties.style = style$$1.getPropsList(properties.style || properties.css); + properties.style = style.getPropsList(properties.style || properties.css); properties.css = undefined; } @@ -5975,7 +5996,7 @@ var define = { var define$1 = { // access data field data: function data(params) { - var defaults$$1 = { + var defaults = { field: 'data', bindingEvent: 'data', allowBinding: false, @@ -5994,7 +6015,7 @@ var define$1 = { return true; } }; - params = extend({}, defaults$$1, params); + params = extend({}, defaults, params); return function dataImpl(name, value) { var p = params; var self = this; @@ -6085,8 +6106,8 @@ var define$1 = { } else if (p.allowBinding && fn(name)) { // bind to event - var fn$$1 = name; - self.on(p.bindingEvent, fn$$1); // .data() + var fn$1 = name; + self.on(p.bindingEvent, fn$1); // .data() } else if (p.allowGetting && name === undefined) { // get whole object var _ret; @@ -6105,7 +6126,7 @@ var define$1 = { // data // remove data field removeData: function removeData(params) { - var defaults$$1 = { + var defaults = { field: 'data', event: 'data', triggerFnName: 'trigger', @@ -6113,7 +6134,7 @@ var define$1 = { immutableKeys: {} // key => true if immutable }; - params = extend({}, defaults$$1, params); + params = extend({}, defaults, params); return function removeDataImpl(names) { var p = params; var self = this; @@ -7506,7 +7527,7 @@ match[Type.DATA_BOOL] = function (check, ele) { match[Type.DATA_EXIST] = function (check, ele) { var field = check.field, operator = check.operator; - return existCmp(data(ele, field), operator); + return existCmp(data(ele, field)); }; match[Type.UNDIRECTED_EDGE] = function (check, ele) { @@ -7609,7 +7630,7 @@ var filter = function filter(collection) { // does selector match a single element? -var matches$1 = function matches$$1(ele) { +var matches$1 = function matches$1(ele) { var self = this; for (var j = 0; j < self.length; j++) { @@ -7655,7 +7676,7 @@ var Selector = function Selector(selector) { this.invalid = true; } } else { - error('A selector must be created from a string; found ', selector); + error('A selector must be created from a string; found '); } }; @@ -7769,7 +7790,7 @@ elesfn$e.allAreNeighbours = elesfn$e.allAreNeighbors; elesfn$e.has = elesfn$e.contains; elesfn$e.equal = elesfn$e.equals = elesfn$e.same; -var cache = function cache(fn$$1, name) { +var cache = function cache(fn, name) { return function traversalCache(arg1, arg2, arg3, arg4) { var selectorOrEles = arg1; var eles = this; @@ -7791,10 +7812,10 @@ var cache = function cache(fn$$1, name) { if (cacheHit) { return cacheHit; } else { - return ch[hash] = fn$$1.call(eles, arg1, arg2, arg3, arg4); + return ch[hash] = fn.call(eles, arg1, arg2, arg3, arg4); } } else { - return fn$$1.call(eles, arg1, arg2, arg3, arg4); + return fn.call(eles, arg1, arg2, arg3, arg4); } }; }; @@ -8522,7 +8543,7 @@ elesfn$j.updateCompoundBounds = function () { var _p = parent._private; var children = parent.children(); var includeLabels = parent.pstyle('compound-sizing-wrt-labels').value === 'include'; - var min$$1 = { + var min = { width: { val: parent.pstyle('min-width').pfValue, left: parent.pstyle('min-width-bias-left'), @@ -8599,40 +8620,40 @@ elesfn$j.updateCompoundBounds = function () { } } - var leftVal = min$$1.width.left.value; + var leftVal = min.width.left.value; - if (min$$1.width.left.units === 'px' && min$$1.width.val > 0) { - leftVal = leftVal * 100 / min$$1.width.val; + if (min.width.left.units === 'px' && min.width.val > 0) { + leftVal = leftVal * 100 / min.width.val; } - var rightVal = min$$1.width.right.value; + var rightVal = min.width.right.value; - if (min$$1.width.right.units === 'px' && min$$1.width.val > 0) { - rightVal = rightVal * 100 / min$$1.width.val; + if (min.width.right.units === 'px' && min.width.val > 0) { + rightVal = rightVal * 100 / min.width.val; } - var topVal = min$$1.height.top.value; + var topVal = min.height.top.value; - if (min$$1.height.top.units === 'px' && min$$1.height.val > 0) { - topVal = topVal * 100 / min$$1.height.val; + if (min.height.top.units === 'px' && min.height.val > 0) { + topVal = topVal * 100 / min.height.val; } - var bottomVal = min$$1.height.bottom.value; + var bottomVal = min.height.bottom.value; - if (min$$1.height.bottom.units === 'px' && min$$1.height.val > 0) { - bottomVal = bottomVal * 100 / min$$1.height.val; + if (min.height.bottom.units === 'px' && min.height.val > 0) { + bottomVal = bottomVal * 100 / min.height.val; } - var widthBiasDiffs = computeBiasValues(min$$1.width.val - bb.w, leftVal, rightVal); + var widthBiasDiffs = computeBiasValues(min.width.val - bb.w, leftVal, rightVal); var diffLeft = widthBiasDiffs.biasDiff; var diffRight = widthBiasDiffs.biasComplementDiff; - var heightBiasDiffs = computeBiasValues(min$$1.height.val - bb.h, topVal, bottomVal); + var heightBiasDiffs = computeBiasValues(min.height.val - bb.h, topVal, bottomVal); var diffTop = heightBiasDiffs.biasDiff; var diffBottom = heightBiasDiffs.biasComplementDiff; _p.autoPadding = computePaddingValues(bb.w, bb.h, parent.pstyle('padding'), parent.pstyle('padding-relative-to').value); - _p.autoWidth = Math.max(bb.w, min$$1.width.val); + _p.autoWidth = Math.max(bb.w, min.width.val); pos.x = (-diffLeft + bb.x1 + bb.x2 + diffRight) / 2; - _p.autoHeight = Math.max(bb.h, min$$1.height.val); + _p.autoHeight = Math.max(bb.h, min.height.val); pos.y = (-diffTop + bb.y1 + bb.y2 + diffBottom) / 2; } @@ -8680,6 +8701,10 @@ var updateBounds = function updateBounds(b, x1, y1, x2, y2) { }; var updateBoundsFromBox = function updateBoundsFromBox(b, b2) { + if (b2 == null) { + return b; + } + return updateBounds(b, b2.x1, b2.y1, b2.x2, b2.y2); }; @@ -8757,8 +8782,8 @@ var updateBoundsFromLabel = function updateBoundsFromLabel(bounds, ele, prefix) var borderWidth = ele.pstyle('text-border-width').pfValue; var halfBorderWidth = borderWidth / 2; var padding = ele.pstyle('text-background-padding').pfValue; - var lh = labelHeight + 2 * padding; - var lw = labelWidth + 2 * padding; + var lh = labelHeight; + var lw = labelWidth; var lw_2 = lw / 2; var lh_2 = lh / 2; var lx1, lx2, ly1, ly2; @@ -8805,10 +8830,10 @@ var updateBoundsFromLabel = function updateBoundsFromLabel(bounds, ele, prefix) } // shift by margin and expand by outline and border - lx1 += marginX - Math.max(outlineWidth, halfBorderWidth); - lx2 += marginX + Math.max(outlineWidth, halfBorderWidth); - ly1 += marginY - Math.max(outlineWidth, halfBorderWidth); - ly2 += marginY + Math.max(outlineWidth, halfBorderWidth); // always store the unrotated label bounds separately + lx1 += marginX - Math.max(outlineWidth, halfBorderWidth) - padding; + lx2 += marginX + Math.max(outlineWidth, halfBorderWidth) + padding; + ly1 += marginY - Math.max(outlineWidth, halfBorderWidth) - padding; + ly2 += marginY + Math.max(outlineWidth, halfBorderWidth) + padding; // always store the unrotated label bounds separately var bbPrefix = prefix || 'main'; var bbs = _p.labelBounds; @@ -8887,18 +8912,25 @@ var boundingBoxImpl = function boundingBoxImpl(ele, options) { var headless = cy.headless(); var bounds = makeBoundingBox(); var _p = ele._private; - var display = styleEnabled ? ele.pstyle('display').value : 'element'; var isNode = ele.isNode(); var isEdge = ele.isEdge(); var ex1, ex2, ey1, ey2; // extrema of body / lines var x, y; // node pos - var displayed = display !== 'none'; var rstyle = _p.rstyle; - var manualExpansion = isNode && styleEnabled ? ele.pstyle('bounds-expansion').pfValue : 0; + var manualExpansion = isNode && styleEnabled ? ele.pstyle('bounds-expansion').pfValue : 0; // must use `display` prop only, as reading `compound.width()` causes recursion + // (other factors like width values will be considered later in this function anyway) + + var isDisplayed = function isDisplayed(ele) { + return ele.pstyle('display').value !== 'none'; + }; + + var displayed = !styleEnabled || isDisplayed(ele) // must take into account connected nodes b/c of implicit edge hiding on display:none node + && (!isEdge || isDisplayed(ele.source()) && isDisplayed(ele.target())); if (displayed) { + // displayed suffices, since we will find zero area eles anyway var overlayOpacity = 0; var overlayPadding = 0; @@ -9024,10 +9056,10 @@ var boundingBoxImpl = function boundingBoxImpl(ele, options) { if (styleEnabled && options.includeEdges && isEdge) { - updateBoundsFromArrow(bounds, ele, 'mid-source', options); - updateBoundsFromArrow(bounds, ele, 'mid-target', options); - updateBoundsFromArrow(bounds, ele, 'source', options); - updateBoundsFromArrow(bounds, ele, 'target', options); + updateBoundsFromArrow(bounds, ele, 'mid-source'); + updateBoundsFromArrow(bounds, ele, 'mid-target'); + updateBoundsFromArrow(bounds, ele, 'source'); + updateBoundsFromArrow(bounds, ele, 'target'); } // ghost //////// @@ -9075,11 +9107,11 @@ var boundingBoxImpl = function boundingBoxImpl(ele, options) { } if (styleEnabled && options.includeLabels) { - updateBoundsFromLabel(bounds, ele, null, options); + updateBoundsFromLabel(bounds, ele, null); if (isEdge) { - updateBoundsFromLabel(bounds, ele, 'source', options); - updateBoundsFromLabel(bounds, ele, 'target', options); + updateBoundsFromLabel(bounds, ele, 'source'); + updateBoundsFromLabel(bounds, ele, 'target'); } } // style enabled for labels @@ -9225,9 +9257,10 @@ var defBbOptsKey = getKey(defBbOpts); var filledBbOpts = defaults(defBbOpts); elesfn$j.boundingBox = function (options) { - // the main usecase is ele.boundingBox() for a single element with no/def options + var bounds; // the main usecase is ele.boundingBox() for a single element with no/def options // specified s.t. the cache is used, so check for this case to make it faster by // avoiding the overhead of the rest of the function + if (this.length === 1 && this[0]._private.bbCache != null && (options === undefined || options.useCache === undefined || options.useCache === true)) { if (options === undefined) { options = defBbOpts; @@ -9235,32 +9268,32 @@ elesfn$j.boundingBox = function (options) { options = filledBbOpts(options); } - return cachedBoundingBoxImpl(this[0], options); - } - - var bounds = makeBoundingBox(); - options = options || defBbOpts; - var opts = filledBbOpts(options); - var eles = this; - var cy = eles.cy(); - var styleEnabled = cy.styleEnabled(); + bounds = cachedBoundingBoxImpl(this[0], options); + } else { + bounds = makeBoundingBox(); + options = options || defBbOpts; + var opts = filledBbOpts(options); + var eles = this; + var cy = eles.cy(); + var styleEnabled = cy.styleEnabled(); - if (styleEnabled) { - for (var i = 0; i < eles.length; i++) { - var ele = eles[i]; - var _p = ele._private; - var currPosKey = getBoundingBoxPosKey(ele); - var isPosKeySame = _p.bbCachePosKey === currPosKey; - var useCache = opts.useCache && isPosKeySame; - ele.recalculateRenderedStyle(useCache); + if (styleEnabled) { + for (var i = 0; i < eles.length; i++) { + var ele = eles[i]; + var _p = ele._private; + var currPosKey = getBoundingBoxPosKey(ele); + var isPosKeySame = _p.bbCachePosKey === currPosKey; + var useCache = opts.useCache && isPosKeySame; + ele.recalculateRenderedStyle(useCache); + } } - } - this.updateCompoundBounds(); + this.updateCompoundBounds(); - for (var _i = 0; _i < eles.length; _i++) { - var _ele = eles[_i]; - updateBoundsFromBox(bounds, cachedBoundingBoxImpl(_ele, opts)); + for (var _i = 0; _i < eles.length; _i++) { + var _ele = eles[_i]; + updateBoundsFromBox(bounds, cachedBoundingBoxImpl(_ele, opts)); + } } bounds.x1 = noninf(bounds.x1); @@ -9278,6 +9311,16 @@ elesfn$j.dirtyBoundingBoxCache = function () { _p.bbCache = null; _p.bbCacheShift.x = _p.bbCacheShift.y = 0; _p.bbCachePosKey = null; + _p.bodyBounds = null; + _p.overlayBounds = null; + _p.labelBounds.all = null; + _p.labelBounds.source = null; + _p.labelBounds.target = null; + _p.labelBounds.main = null; + _p.arrowBounds.source = null; + _p.arrowBounds.target = null; + _p.arrowBounds['mid-source'] = null; + _p.arrowBounds['mid-target'] = null; } this.emitAndNotify('bounds'); @@ -9304,7 +9347,7 @@ elesfn$j.shiftCachedBoundingBox = function (delta) { // - try to use for only things like discrete layouts where the node position would change anyway -elesfn$j.boundingBoxAt = function (fn$$1) { +elesfn$j.boundingBoxAt = function (fn) { var nodes = this.nodes(); var cy = this.cy(); var hasCompoundNodes = cy.hasCompoundNodes(); @@ -9315,16 +9358,16 @@ elesfn$j.boundingBoxAt = function (fn$$1) { }); } - if (plainObject(fn$$1)) { - var obj = fn$$1; + if (plainObject(fn)) { + var obj = fn; - fn$$1 = function fn$$1() { + fn = function fn() { return obj; }; } var storeOldPos = function storeOldPos(node, i) { - return node._private.bbAtOldPos = fn$$1(node, i); + return node._private.bbAtOldPos = fn(node, i); }; var getOldPos = function getOldPos(node) { @@ -9332,7 +9375,7 @@ elesfn$j.boundingBoxAt = function (fn$$1) { }; cy.startBatch(); - nodes.forEach(storeOldPos).silentPositions(fn$$1); + nodes.forEach(storeOldPos).silentPositions(fn); if (hasCompoundNodes) { this.updateCompoundBounds(true); // force update b/c we're inside a batch cycle @@ -9687,8 +9730,12 @@ var defaults$8 = { context: null }; var defaultsKeys = Object.keys(defaults$8); +var emptyOpts = {}; + +function Emitter() { + var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : emptyOpts; + var context = arguments.length > 1 ? arguments[1] : undefined; -function Emitter(opts, context) { // micro-optimisation vs Object.assign() -- reduces Element instantiation time for (var i = 0; i < defaultsKeys.length; i++) { var key = defaultsKeys[i]; @@ -9779,10 +9826,10 @@ var forEachEventObj = function forEachEventObj(self, handler, events) { }; p.on = p.addListener = function (events, qualifier, callback, conf, confOverrides) { - forEachEvent(this, function (self, event$$1, type, namespace, qualifier, callback, conf) { + forEachEvent(this, function (self, event, type, namespace, qualifier, callback, conf) { if (fn(callback)) { self.listeners.push({ - event: event$$1, + event: event, // full event string callback: callback, // callback to run @@ -9817,10 +9864,10 @@ p.removeListener = p.off = function (events, qualifier, callback, conf) { var _loop = function _loop(i) { var listener = listeners[i]; - forEachEvent(_this, function (self, event$$1, type, namespace, qualifier, callback + forEachEvent(_this, function (self, event, type, namespace, qualifier, callback /*, conf*/ ) { - if (listener.type === type && (!namespace || listener.namespace === namespace) && (!qualifier || self.qualifierCompare(listener.qualifier, qualifier)) && (!callback || listener.callback === callback)) { + if ((listener.type === type || events === '*') && (!namespace && listener.namespace !== '.*' || listener.namespace === namespace) && (!qualifier || self.qualifierCompare(listener.qualifier, qualifier)) && (!callback || listener.callback === callback)) { listeners.splice(i, 1); return false; } @@ -9834,6 +9881,10 @@ p.removeListener = p.off = function (events, qualifier, callback, conf) { return this; }; +p.removeAllListeners = function () { + return this.removeListener('*'); +}; + p.emit = p.trigger = function (events, extraParams, manualCallback) { var listeners = this.listeners; var numListenersBeforeEmit = listeners.length; @@ -9980,6 +10031,14 @@ var elesfn$l = { return this; }, + removeAllListeners: function removeAllListeners() { + for (var i = 0; i < this.length; i++) { + var ele = this[i]; + ele.emitter().removeAllListeners(); + } + + return this; + }, one: function one(events, selector, callback) { var argSel = argSelector(selector); @@ -10009,7 +10068,7 @@ var elesfn$l = { return this; }, - emitAndNotify: function emitAndNotify(event$$1, extraParams) { + emitAndNotify: function emitAndNotify(event, extraParams) { // for internal use only if (this.length === 0) { return; @@ -10017,8 +10076,8 @@ var elesfn$l = { // notify renderer - this.cy().notify(event$$1, this); - this.emit(event$$1, extraParams); + this.cy().notify(event, this); + this.emit(event, extraParams); return this; } }; @@ -10091,11 +10150,11 @@ var elesfn$m = { var rMap = toRemove._private.map; for (var i = 0; i < this.length; i++) { - var element$$1 = this[i]; - var remove = rMap.has(element$$1.id()); + var element = this[i]; + var remove = rMap.has(element.id()); if (!remove) { - elements.push(element$$1); + elements.push(element); } } @@ -10354,12 +10413,12 @@ var elesfn$m = { return arr; }, - reduce: function reduce(fn$$1, initialValue) { + reduce: function reduce(fn, initialValue) { var val = initialValue; var eles = this; for (var i = 0; i < eles.length; i++) { - val = fn$$1(val, eles[i], i, eles); + val = fn(val, eles[i], i, eles); } return val; @@ -10502,13 +10561,13 @@ var zIndexSort = function zIndexSort(a, b) { }; var elesfn$o = { - forEach: function forEach(fn$$1, thisArg) { - if (fn(fn$$1)) { + forEach: function forEach(fn$1, thisArg) { + if (fn(fn$1)) { var N = this.length; for (var i = 0; i < N; i++) { var ele = this[i]; - var ret = thisArg ? fn$$1.apply(thisArg, [ele, i, this]) : fn$$1(ele, i, this); + var ret = thisArg ? fn$1.apply(thisArg, [ele, i, this]) : fn$1(ele, i, this); if (ret === false) { break; @@ -10520,16 +10579,16 @@ var elesfn$o = { return this; }, toArray: function toArray() { - var array$$1 = []; + var array = []; for (var i = 0; i < this.length; i++) { - array$$1.push(this[i]); + array.push(this[i]); } - return array$$1; + return array; }, slice: function slice(start, end) { - var array$$1 = []; + var array = []; var thisSize = this.length; if (end == null) { @@ -10549,10 +10608,10 @@ var elesfn$o = { } for (var i = start; i >= 0 && i < end && i < thisSize; i++) { - array$$1.push(this[i]); + array.push(this[i]); } - return this.spawn(array$$1); + return this.spawn(array); }, size: function size() { return this.length; @@ -10572,7 +10631,7 @@ var elesfn$o = { nonempty: function nonempty() { return !this.empty(); }, - sort: function sort$$1(sortFn) { + sort: function sort(sortFn) { if (!fn(sortFn)) { return this; } @@ -10620,19 +10679,32 @@ var elesfn$p = { // Calculates and returns node dimensions { x, y } based on options given layoutDimensions: function layoutDimensions(options) { options = getLayoutDimensionOptions(options); + var dims; - if (options.nodeDimensionsIncludeLabels) { + if (!this.takesUpSpace()) { + dims = { + w: 0, + h: 0 + }; + } else if (options.nodeDimensionsIncludeLabels) { var bbDim = this.boundingBox(); - return { + dims = { w: bbDim.w, h: bbDim.h }; } else { - return { + dims = { w: this.outerWidth(), h: this.outerHeight() }; + } // sanitise the dimensions for external layouts (avoid division by zero) + + + if (dims.w === 0 || dims.h === 0) { + dims.w = dims.h = 1; } + + return dims; }, // using standard layout options, apply position function (w/ or w/o animation) layoutPositions: function layoutPositions(layout, options, fn) { @@ -10796,7 +10868,7 @@ var elesfn$p = { elesfn$p.createLayout = elesfn$p.makeLayout = elesfn$p.layout; -function styleCache(key, fn$$1, ele) { +function styleCache(key, fn, ele) { var _p = ele._private; var cache = _p.styleCache = _p.styleCache || []; var val; @@ -10804,23 +10876,23 @@ function styleCache(key, fn$$1, ele) { if ((val = cache[key]) != null) { return val; } else { - val = cache[key] = fn$$1(ele); + val = cache[key] = fn(ele); return val; } } -function cacheStyleFunction(key, fn$$1) { +function cacheStyleFunction(key, fn) { key = hashString(key); return function cachedStyleFunction(ele) { - return styleCache(key, fn$$1, ele); + return styleCache(key, fn, ele); }; } -function cachePrototypeStyleFunction(key, fn$$1) { +function cachePrototypeStyleFunction(key, fn) { key = hashString(key); var selfFn = function selfFn(ele) { - return fn$$1.call(ele); + return fn.call(ele); }; return function cachedPrototypeStyleFunction() { @@ -10880,7 +10952,7 @@ var elesfn$q = { } var hasCompounds = cy.hasCompoundNodes(); - var style$$1 = cy.style(); + var style = cy.style(); var updatedEles = this; notifyRenderer = notifyRenderer || notifyRenderer === undefined ? true : false; @@ -10889,7 +10961,7 @@ var elesfn$q = { updatedEles = this.spawnSelf().merge(this.descendants()).merge(this.parents()); } - var changedEles = style$$1.apply(updatedEles); + var changedEles = style.apply(updatedEles); if (notifyRenderer) { changedEles.emitAndNotify('style'); // let renderer know we changed style @@ -10960,7 +11032,7 @@ var elesfn$q = { } }, // read the calculated css style of the element or override the style (via a bypass) - style: function style$$1(name, value) { + style: function style(name, value) { var cy = this.cy(); if (!cy.styleEnabled()) { @@ -10968,12 +11040,12 @@ var elesfn$q = { } var updateTransitions = false; - var style$$1 = cy.style(); + var style = cy.style(); if (plainObject(name)) { // then extend the bypass var props = name; - style$$1.applyBypass(this, props, updateTransitions); + style.applyBypass(this, props, updateTransitions); this.emitAndNotify('style'); // let the renderer know we've updated style } else if (string(name)) { if (value === undefined) { @@ -10981,21 +11053,21 @@ var elesfn$q = { var ele = this[0]; if (ele) { - return style$$1.getStylePropertyValue(ele, name); + return style.getStylePropertyValue(ele, name); } else { // empty collection => can't get any value return; } } else { // then set the bypass with the property value - style$$1.applyBypass(this, name, value, updateTransitions); + style.applyBypass(this, name, value, updateTransitions); this.emitAndNotify('style'); // let the renderer know we've updated style } } else if (name === undefined) { var _ele = this[0]; if (_ele) { - return style$$1.getRawStyle(_ele); + return style.getRawStyle(_ele); } else { // empty collection => can't get any value return; @@ -11012,20 +11084,20 @@ var elesfn$q = { } var updateTransitions = false; - var style$$1 = cy.style(); + var style = cy.style(); var eles = this; if (names === undefined) { for (var i = 0; i < eles.length; i++) { var ele = eles[i]; - style$$1.removeAllBypasses(ele, updateTransitions); + style.removeAllBypasses(ele, updateTransitions); } } else { names = names.split(/\s+/); for (var _i = 0; _i < eles.length; _i++) { var _ele2 = eles[_i]; - style$$1.removeBypasses(_ele2, names, updateTransitions); + style.removeBypasses(_ele2, names, updateTransitions); } } @@ -11195,6 +11267,10 @@ elesfn$q.hidden = function () { }; elesfn$q.isBundledBezier = cachePrototypeStyleFunction('isBundledBezier', function () { + if (!this.cy().styleEnabled()) { + return false; + } + return !this.removed() && this.pstyle('curve-style').value === 'bezier' && this.takesUpSpace(); }); elesfn$q.bypass = elesfn$q.css = elesfn$q.style; @@ -11307,7 +11383,7 @@ defineSwitchSet({ defineSwitchSet({ field: 'grabbable', overrideField: function overrideField(ele) { - return ele.cy().autoungrabify() ? false : undefined; + return ele.cy().autoungrabify() || ele.pannable() ? false : undefined; }, on: 'grabify', off: 'ungrabify' @@ -11344,6 +11420,11 @@ defineSwitchSet({ on: 'activate', off: 'unactivate' }); +defineSwitchSet({ + field: 'pannable', + on: 'panify', + off: 'unpanify' +}); elesfn$r.inactive = function () { var ele = this[0]; @@ -11696,10 +11777,10 @@ extend(elesfn$s, { }); function defineParallelEdgesFunction(params) { - var defaults$$1 = { + var defaults = { codirected: false }; - params = extend({}, defaults$$1, params); + params = extend({}, defaults, params); return function parallelEdgesImpl(selector) { // micro-optimised for renderer var elements = []; @@ -11797,7 +11878,7 @@ extend(elesfn$s, { elesfn$s.componentsOf = elesfn$s.components; var idFactory = { - generate: function generate(cy, element$$1, tryThisId) { + generate: function generate(cy, element, tryThisId) { var id = tryThisId != null ? tryThisId : uuid(); while (cy.hasElementWithId(id)) { @@ -11851,20 +11932,20 @@ var Collection = function Collection(cy, elements, options) { this.length = 0; for (var _i = 0, _l = elements.length; _i < _l; _i++) { - var element$$1 = elements[_i]; + var element$1 = elements[_i][0]; // [0] in case elements is an array of collections, rather than array of elements - if (element$$1 == null) { + if (element$1 == null) { continue; } - var id = element$$1._private.data.id; + var id = element$1._private.data.id; if (options == null || options.unique && !map.has(id)) { map.set(id, { index: this.length, - ele: element$$1 + ele: element$1 }); - this[this.length] = element$$1; + this[this.length] = element$1; this.length++; } } @@ -11932,10 +12013,14 @@ elesfn$t.unique = function () { }; elesfn$t.hasElementWithId = function (id) { + id = '' + id; // id must be string + return this._private.map.has(id); }; elesfn$t.getElementById = function (id) { + id = '' + id; // id must be string + var cy = this._private.cy; var entry = this._private.map.get(id); @@ -11958,6 +12043,8 @@ elesfn$t.indexOf = function (ele) { }; elesfn$t.indexOfId = function (id) { + id = '' + id; // id must be string + return this._private.map.get(id).index; }; @@ -11992,13 +12079,15 @@ elesfn$t.json = function (obj) { var src = obj.data.source; var tgt = obj.data.target; - if (src != null && src !== _data2.source) { - spec.source = src; + if (src != null && src != _data2.source) { + spec.source = '' + src; // id must be string + move = true; } - if (tgt != null && tgt !== _data2.target) { - spec.target = tgt; + if (tgt != null && tgt != _data2.target) { + spec.target = '' + tgt; // id must be string + move = true; } @@ -12009,12 +12098,16 @@ elesfn$t.json = function (obj) { // parent is immutable via data() var parent = obj.data.parent; - if ((parent != null || _data2.parent != null) && parent !== _data2.parent) { + if ((parent != null || _data2.parent != null) && parent != _data2.parent) { if (parent === undefined) { // can't set undefined imperatively, so use null parent = null; } + if (parent != null) { + parent = '' + parent; // id must be string + } + ele = ele.move({ parent: parent }); @@ -12044,6 +12137,7 @@ elesfn$t.json = function (obj) { checkSwitch('selectable', 'selectify', 'unselectify'); checkSwitch('locked', 'lock', 'unlock'); checkSwitch('grabbable', 'grabify', 'ungrabify'); + checkSwitch('pannable', 'panify', 'unpanify'); if (obj.classes != null) { ele.classes(obj.classes); @@ -12062,6 +12156,7 @@ elesfn$t.json = function (obj) { selectable: p.selectable, locked: p.locked, grabbable: p.grabbable, + pannable: p.pannable, classes: null }; json.classes = ''; @@ -12092,9 +12187,9 @@ elesfn$t.clone = function () { for (var i = 0; i < this.length; i++) { var ele = this[i]; var json = ele.json(); - var clone$$1 = new Element(cy, json, false); // NB no restore + var clone = new Element(cy, json, false); // NB no restore - elesArr.push(clone$$1); + elesArr.push(clone); } return new Collection(cy, elesArr); @@ -12213,11 +12308,15 @@ elesfn$t.restore = function () { var src = cy.getElementById(_data3.source); - var tgt = cy.getElementById(_data3.target); + var tgt = cy.getElementById(_data3.target); // only one edge in node if loop - src._private.edges.push(edge); + if (src.same(tgt)) { + src._private.edges.push(edge); + } else { + src._private.edges.push(edge); - tgt._private.edges.push(edge); + tgt._private.edges.push(edge); + } edge._private.source = src; edge._private.target = tgt; @@ -12509,9 +12608,14 @@ elesfn$t.move = function (struct) { var notifyRenderer = false; var modifyPool = false; + var toString = function toString(id) { + return id == null ? id : '' + id; + }; // id must be string + + if (struct.source !== undefined || struct.target !== undefined) { - var srcId = struct.source; - var tgtId = struct.target; + var srcId = toString(struct.source); + var tgtId = toString(struct.target); var srcExists = srcId != null && cy.hasElementWithId(srcId); var tgtExists = tgtId != null && cy.hasElementWithId(tgtId); @@ -12543,7 +12647,7 @@ elesfn$t.move = function (struct) { } } else if (struct.parent !== undefined) { // move node to new parent - var parentId = struct.parent; + var parentId = toString(struct.parent); var parentExists = parentId === null || cy.hasElementWithId(parentId); if (parentExists) { @@ -12632,13 +12736,13 @@ var corefn = { return elements; }, - remove: function remove(collection$$1) { - if (elementOrCollection(collection$$1)) ; else if (string(collection$$1)) { - var selector = collection$$1; - collection$$1 = this.$(selector); + remove: function remove(collection) { + if (elementOrCollection(collection)) ; else if (string(collection)) { + var selector = collection; + collection = this.$(selector); } - return collection$$1.remove(); + return collection.remove(); } }; @@ -13038,7 +13142,7 @@ function step(self, ani, now, isCore) { var pEasing = ani_p.easing; var startTime = ani_p.startTime; var cy = isCore ? self : self.cy(); - var style$$1 = cy.style(); + var style = cy.style(); if (!ani_p.easingImpl) { if (pEasing == null) { @@ -13049,7 +13153,7 @@ function step(self, ani, now, isCore) { var easingVals; if (string(pEasing)) { - var easingProp = style$$1.parse('transition-timing-function', pEasing); + var easingProp = style.parse('transition-timing-function', pEasing); easingVals = easingProp.value; } else { // then assume preparsed array @@ -13143,7 +13247,7 @@ function step(self, ani, now, isCore) { if (animatingZoom) { if (valid(startZoom, endZoom)) { - _p.zoom = ease(startZoom, endZoom, percent, easing); + _p.zoom = bound(_p.minZoom, ease(startZoom, endZoom, percent, easing), _p.maxZoom); } self.emit('zoom'); @@ -13161,9 +13265,9 @@ function step(self, ani, now, isCore) { var _name = prop.name; var end = prop; var start = ani_p.startStyle[_name]; - var propSpec = style$$1.properties[start.name]; + var propSpec = style.properties[start.name]; var easedVal = ease(start, end, percent, easing, propSpec); - style$$1.overrideBypass(self, _name, easedVal); + style.overrideBypass(self, _name, easedVal); } // for props @@ -13258,7 +13362,7 @@ function stepAll(now, cy) { } if (!ani_p.started) { - startAnimation(ele, ani, now, isCore); + startAnimation(ele, ani, now); } step(ele, ani, now, isCore); @@ -13355,8 +13459,8 @@ var corefn$1 = { return; } - requestAnimationFrame(function animationStep(now$$1) { - stepAll(now$$1, cy); + requestAnimationFrame(function animationStep(now) { + stepAll(now, cy); headlessStep(); }); } @@ -13365,8 +13469,8 @@ var corefn$1 = { if (renderer && renderer.beforeRender) { // let the renderer schedule animations - renderer.beforeRender(function rendererAnimationStep(willDraw, now$$1) { - stepAll(now$$1, cy); + renderer.beforeRender(function rendererAnimationStep(willDraw, now) { + stepAll(now, cy); }, renderer.beforeRenderPriorities.animations); } else { // manage the animation loop ourselves @@ -13430,6 +13534,10 @@ var elesfn$u = { this.emitter().removeListener(events, argSelector$1(selector), callback); return this; }, + removeAllListeners: function removeAllListeners() { + this.emitter().removeAllListeners(); + return this; + }, one: function one(events, selector, callback) { this.emitter().one(events, argSelector$1(selector), callback); return this; @@ -13442,9 +13550,9 @@ var elesfn$u = { this.emitter().emit(events, extraParams); return this; }, - emitAndNotify: function emitAndNotify(event$$1, eles) { - this.emit(event$$1); - this.notify(event$$1, eles); + emitAndNotify: function emitAndNotify(event, eles) { + this.emit(event); + this.notify(event, eles); return this; } }; @@ -13526,7 +13634,7 @@ var corefn$4 = { var renderer = this.renderer(); // exit if destroy() called on core or renderer in between frames #1499 #1528 - if (this.isDestroyed() || !renderer) { + if (this.destroyed() || !renderer) { return; } @@ -13702,7 +13810,7 @@ var corefn$6 = { // - empty collection on no args // - collection of elements in the graph on selector arg // - guarantee a returned collection when elements or collection specified - collection: function collection$$1(eles, opts) { + collection: function collection(eles, opts) { if (string(eles)) { return this.$(eles); } else if (elementOrCollection(eles)) { @@ -13913,7 +14021,7 @@ styfn.getContextStyle = function (cxtMeta) { return cxtStyles[cxtKey]; } - var style$$1 = { + var style = { _private: { key: cxtKey } @@ -13929,12 +14037,12 @@ styfn.getContextStyle = function (cxtMeta) { for (var j = 0; j < cxt.properties.length; j++) { var prop = cxt.properties[j]; - style$$1[prop.name] = prop; + style[prop.name] = prop; } } - cxtStyles[cxtKey] = style$$1; - return style$$1; + cxtStyles[cxtKey] = style; + return style; }; styfn.applyContextStyle = function (cxtMeta, cxtStyle, ele) { @@ -13973,6 +14081,7 @@ styfn.applyContextStyle = function (cxtMeta, cxtStyle, ele) { if (cxtProp.mapped === types.fn // context prop is function mapper + && eleProp != null // some props can be null even by default (e.g. a prop that overrides another one) && eleProp.mapping != null // ele prop is a concrete value from from a mapper && eleProp.mapping.value === cxtProp.value // the current prop on the ele is a flat prop value for the function mapper ) { @@ -14032,6 +14141,12 @@ styfn.updateStyleHints = function (ele) { var updateGrKey = function updateGrKey(val, grKey) { return _p.styleKeys[grKey] = hashInt(val, _p.styleKeys[grKey]); + }; + + var updateGrKeyWStr = function updateGrKeyWStr(strVal, grKey) { + for (var j = 0; j < strVal.length; j++) { + updateGrKey(strVal.charCodeAt(j), grKey); + } }; // - hashing works on 32 bit ints b/c we use bitwise ops // - small numbers get cut off (e.g. 0.123 is seen as 0 by the hashing function) // - raise up small numbers so more significant digits are seen by hashing @@ -14053,12 +14168,25 @@ styfn.updateStyleHints = function (ele) { var propInfo = this.properties[name]; var type = propInfo.type; - var _grKey = propInfo.groupKey; // numbers are cheaper to hash than strings + var _grKey = propInfo.groupKey; + var normalizedNumberVal = void 0; + + if (propInfo.hashOverride != null) { + normalizedNumberVal = propInfo.hashOverride(ele, parsedProp); + } else if (parsedProp.pfValue != null) { + normalizedNumberVal = parsedProp.pfValue; + } // might not be a number if it allows enums + + + var numberVal = propInfo.enums == null ? parsedProp.value : null; + var haveNormNum = normalizedNumberVal != null; + var haveUnitedNum = numberVal != null; + var haveNum = haveNormNum || haveUnitedNum; + var units = parsedProp.units; // numbers are cheaper to hash than strings // 1 hash op vs n hash ops (for length n string) - if (type.number) { - // use pfValue if available (e.g. normalised units) - var v = parsedProp.pfValue != null ? parsedProp.pfValue : parsedProp.value; + if (type.number && haveNum) { + var v = haveNormNum ? normalizedNumberVal : numberVal; if (type.multiple) { for (var _i2 = 0; _i2 < v.length; _i2++) { @@ -14067,12 +14195,12 @@ styfn.updateStyleHints = function (ele) { } else { updateGrKey(cleanNum(v), _grKey); } - } else { - var strVal = parsedProp.strValue; - for (var j = 0; j < strVal.length; j++) { - updateGrKey(strVal.charCodeAt(j), _grKey); + if (!haveNormNum && units != null) { + updateGrKeyWStr(units, _grKey); } + } else { + updateGrKeyWStr(parsedProp.strValue, _grKey); } } // overall style key // @@ -14149,12 +14277,12 @@ styfn.clearStyleHints = function (ele) { styfn.applyParsedProperty = function (ele, parsedProp) { var self = this; var prop = parsedProp; - var style$$1 = ele._private.style; + var style = ele._private.style; var flatProp; var types = self.types; var type = self.properties[prop.name].type; var propIsBypass = prop.bypass; - var origProp = style$$1[prop.name]; + var origProp = style[prop.name]; var origPropIsBypass = origProp && origProp.bypass; var _p = ele._private; var flatPropMapping = 'mapping'; @@ -14184,7 +14312,7 @@ styfn.applyParsedProperty = function (ele, parsedProp) { if (prop.delete) { // delete the property and use the default value on falsey value - style$$1[prop.name] = undefined; + style[prop.name] = undefined; checkTriggers(); return true; } @@ -14213,7 +14341,7 @@ styfn.applyParsedProperty = function (ele, parsedProp) { } else if (origProp.bypass) { // then replace the bypass property with the original // because the bypassed property was already applied (and therefore parsed), we can just replace it (no reapplying necessary) - style$$1[prop.name] = origProp.bypassed; + style[prop.name] = origProp.bypassed; checkTriggers(); return true; } else { @@ -14338,8 +14466,8 @@ styfn.applyParsedProperty = function (ele, parsedProp) { case types.fn: { - var fn$$1 = prop.value; - var fnRetVal = prop.fnValue != null ? prop.fnValue : fn$$1(ele); // check for cached value before calling function + var fn = prop.value; + var fnRetVal = prop.fnValue != null ? prop.fnValue : fn(ele); // check for cached value before calling function prop.prevFnValue = fnRetVal; @@ -14381,7 +14509,7 @@ styfn.applyParsedProperty = function (ele, parsedProp) { prop.bypassed = origProp; } - style$$1[prop.name] = prop; // and set + style[prop.name] = prop; // and set } else { // prop is not bypass if (origPropIsBypass) { @@ -14389,7 +14517,7 @@ styfn.applyParsedProperty = function (ele, parsedProp) { origProp.bypassed = prop; } else { // then just replace the old prop with the new one - style$$1[prop.name] = prop; + style[prop.name] = prop; } } @@ -14407,18 +14535,18 @@ styfn.cleanElements = function (eles, keepBypasses) { if (!keepBypasses) { ele._private.style = {}; } else { - var style$$1 = ele._private.style; - var propNames = Object.keys(style$$1); + var style = ele._private.style; + var propNames = Object.keys(style); for (var j = 0; j < propNames.length; j++) { var propName = propNames[j]; - var eleProp = style$$1[propName]; + var eleProp = style[propName]; if (eleProp != null) { if (eleProp.bypass) { eleProp.bypassed = null; } else { - style$$1[propName] = null; + style[propName] = null; } } } @@ -14442,7 +14570,7 @@ styfn.updateTransitions = function (ele, diffProps) { var delay = ele.pstyle('transition-delay').pfValue; if (props.length > 0 && duration > 0) { - var style$$1 = {}; // build up the style to animate towards + var style = {}; // build up the style to animate towards var anyPrev = false; @@ -14482,7 +14610,7 @@ styfn.updateTransitions = function (ele, diffProps) { if (diff) { - style$$1[prop] = toProp.strValue; // to val + style[prop] = toProp.strValue; // to val this.applyBypass(ele, prop, initVal); // from val @@ -14505,7 +14633,7 @@ styfn.updateTransitions = function (ele, diffProps) { } }).then(function () { return ele.animation({ - style: style$$1, + style: style, duration: duration, easing: ele.pstyle('transition-timing-function').value, queue: false @@ -14898,15 +15026,15 @@ styfn$3.getAnimationStartStyle = function (ele, aniProps) { styfn$3.getPropsList = function (propsObj) { var self = this; var rstyle = []; - var style$$1 = propsObj; + var style = propsObj; var props = self.properties; - if (style$$1) { - var names = Object.keys(style$$1); + if (style) { + var names = Object.keys(style); for (var i = 0; i < names.length; i++) { var name = names[i]; - var val = style$$1[name]; + var val = style[name]; var prop = props[name] || props[camel2dash(name)]; var styleProp = this.parse(prop.name, val); @@ -15138,19 +15266,19 @@ styfn$5.fromString = function (string) { var styfn$6 = {}; (function () { - var number$$1 = number$1; - var rgba$$1 = rgbaNoBackRefs; - var hsla$$1 = hslaNoBackRefs; - var hex3$$1 = hex3; - var hex6$$1 = hex6; + var number = number$1; + var rgba = rgbaNoBackRefs; + var hsla = hslaNoBackRefs; + var hex3$1 = hex3; + var hex6$1 = hex6; var data = function data(prefix) { return '^' + prefix + '\\s*\\(\\s*([\\w\\.]+)\\s*\\)$'; }; var mapData = function mapData(prefix) { - var mapArg = number$$1 + '|\\w+|' + rgba$$1 + '|' + hsla$$1 + '|' + hex3$$1 + '|' + hex6$$1; - return '^' + prefix + '\\s*\\(([\\w\\.]+)\\s*\\,\\s*(' + number$$1 + ')\\s*\\,\\s*(' + number$$1 + ')\\s*,\\s*(' + mapArg + ')\\s*\\,\\s*(' + mapArg + ')\\)$'; + var mapArg = number + '|\\w+|' + rgba + '|' + hsla + '|' + hex3$1 + '|' + hex6$1; + return '^' + prefix + '\\s*\\(([\\w\\.]+)\\s*\\,\\s*(' + number + ')\\s*\\,\\s*(' + number + ')\\s*,\\s*(' + mapArg + ')\\s*\\,\\s*(' + mapArg + ')\\)$'; }; var urlRegexes = ['^url\\s*\\(\\s*[\'"]?(.+?)[\'"]?\\s*\\)$', '^(none)$', '^(.+)$']; // each visual style property has a type and needs to be validated according to it @@ -15278,7 +15406,8 @@ var styfn$6 = {}; multiple: true }, bgClip: { - enums: ['none', 'node'] + enums: ['none', 'node'], + multiple: true }, color: { color: true @@ -15323,6 +15452,9 @@ var styfn$6 = {}; textWrap: { enums: ['none', 'wrap', 'ellipsis'] }, + textOverflowWrap: { + enums: ['whitespace', 'anywhere'] + }, textBackgroundShape: { enums: ['rectangle', 'roundrectangle', 'round-rectangle'] }, @@ -15356,6 +15488,9 @@ var styfn$6 = {}; halign: { enums: ['left', 'center', 'right'] }, + justification: { + enums: ['left', 'center', 'right', 'auto'] + }, text: { string: true }, @@ -15444,7 +15579,7 @@ var styfn$6 = {}; } }, easing: { - regexes: ['^(spring)\\s*\\(\\s*(' + number$$1 + ')\\s*,\\s*(' + number$$1 + ')\\s*\\)$', '^(cubic-bezier)\\s*\\(\\s*(' + number$$1 + ')\\s*,\\s*(' + number$$1 + ')\\s*,\\s*(' + number$$1 + ')\\s*,\\s*(' + number$$1 + ')\\s*\\)$'], + regexes: ['^(spring)\\s*\\(\\s*(' + number + ')\\s*,\\s*(' + number + ')\\s*\\)$', '^(cubic-bezier)\\s*\\(\\s*(' + number + ')\\s*,\\s*(' + number + ')\\s*,\\s*(' + number + ')\\s*,\\s*(' + number + ')\\s*\\)$'], enums: ['linear', 'ease', 'ease-in', 'ease-out', 'ease-in-out', 'ease-in-sine', 'ease-out-sine', 'ease-in-out-sine', 'ease-in-quad', 'ease-out-quad', 'ease-in-out-quad', 'ease-in-cubic', 'ease-out-cubic', 'ease-in-out-cubic', 'ease-in-quart', 'ease-out-quart', 'ease-in-out-quart', 'ease-in-quint', 'ease-out-quint', 'ease-in-out-quint', 'ease-in-expo', 'ease-out-expo', 'ease-in-out-expo', 'ease-in-circ', 'ease-out-circ', 'ease-in-out-circ'] }, gradientDirection: { @@ -15557,6 +15692,10 @@ var styfn$6 = {}; name: 'text-wrap', type: t.textWrap, triggersBounds: diff.any + }, { + name: 'text-overflow-wrap', + type: t.textOverflowWrap, + triggersBounds: diff.any }, { name: 'text-max-width', type: t.size, @@ -15565,6 +15704,10 @@ var styfn$6 = {}; name: 'text-outline-width', type: t.size, triggersBounds: diff.any + }, { + name: 'line-height', + type: t.positiveNumber, + triggersBounds: diff.any }]; var commonLabel = [{ name: 'text-valign', @@ -15611,6 +15754,9 @@ var styfn$6 = {}; name: 'text-background-shape', type: t.textBackgroundShape, triggersBounds: diff.any + }, { + name: 'text-justification', + type: t.justification }]; var behavior = [{ name: 'events', @@ -15677,14 +15823,25 @@ var styfn$6 = {}; name: 'transition-timing-function', type: t.easing }]; + + var nodeSizeHashOverride = function nodeSizeHashOverride(ele, parsedProp) { + if (parsedProp.value === 'label') { + return -ele.poolIndex(); // no hash key hits is using label size (hitrate for perf probably low anyway) + } else { + return parsedProp.pfValue; + } + }; + var nodeBody = [{ name: 'height', type: t.nodeSize, - triggersBounds: diff.any + triggersBounds: diff.any, + hashOverride: nodeSizeHashOverride }, { name: 'width', type: t.nodeSize, - triggersBounds: diff.any + triggersBounds: diff.any, + hashOverride: nodeSizeHashOverride }, { name: 'shape', type: t.nodeShape, @@ -15931,7 +16088,7 @@ var styfn$6 = {}; name: 'ghost-opacity', type: t.zeroOneNumber }]; - var core$$1 = [{ + var core = [{ name: 'selection-box-color', type: t.color }, { @@ -15988,7 +16145,8 @@ var styfn$6 = {}; var arrowPrefixes = styfn$6.arrowPrefixes = ['source', 'mid-source', 'target', 'mid-target']; [{ name: 'arrow-shape', - type: t.arrowShape + type: t.arrowShape, + triggersBounds: diff.any }, { name: 'arrow-color', type: t.color @@ -15998,14 +16156,16 @@ var styfn$6 = {}; }].forEach(function (prop) { arrowPrefixes.forEach(function (prefix) { var name = prefix + '-' + prop.name; - var type = prop.type; + var type = prop.type, + triggersBounds = prop.triggersBounds; edgeArrow.push({ name: name, - type: type + type: type, + triggersBounds: triggersBounds }); }); }, {}); - var props = styfn$6.properties = [].concat(behavior, transition, visibility, overlay, ghost, commonLabel, labelDimensions, mainLabel, sourceLabel, targetLabel, nodeBody, nodeBorder, backgroundImage, pie, compound, edgeLine, edgeArrow, core$$1); + var props = styfn$6.properties = [].concat(behavior, transition, visibility, overlay, ghost, commonLabel, labelDimensions, mainLabel, sourceLabel, targetLabel, nodeBody, nodeBorder, backgroundImage, pie, compound, edgeLine, edgeArrow, core); var propGroups = styfn$6.propertyGroups = { // common to all eles behavior: behavior, @@ -16028,7 +16188,7 @@ var styfn$6 = {}; // edge props edgeLine: edgeLine, edgeArrow: edgeArrow, - core: core$$1 + core: core }; var propGroupNames = styfn$6.propertyGroupNames = {}; var propGroupKeys = styfn$6.propertyGroupKeys = Object.keys(propGroups); @@ -16118,6 +16278,8 @@ styfn$6.getDefaultProperties = function () { 'text-events': 'no', 'text-valign': 'top', 'text-halign': 'center', + 'text-justification': 'auto', + 'line-height': 1, 'color': '#000', 'text-outline-color': '#000', 'text-outline-width': 0, @@ -16126,6 +16288,7 @@ styfn$6.getDefaultProperties = function () { 'text-decoration': 'none', 'text-transform': 'none', 'text-wrap': 'none', + 'text-overflow-wrap': 'whitespace', 'text-max-width': 9999, 'text-background-color': '#000', 'text-background-opacity': 0, @@ -16745,9 +16908,9 @@ styfn$7.parseImpl = function (name, value, propIsBypass, propIsFlat) { var regexes = type.regexes ? type.regexes : [type.regex]; for (var _i3 = 0; _i3 < regexes.length; _i3++) { - var regex$$1 = new RegExp(regexes[_i3]); // make a regex from the type string + var regex = new RegExp(regexes[_i3]); // make a regex from the type string - var m = regex$$1.exec(value); + var m = regex.exec(value); if (m) { // regex matches @@ -16897,13 +17060,13 @@ styfn$8.cssRule = function (name, value) { return this; // chaining }; -styfn$8.append = function (style$$1) { - if (stylesheet(style$$1)) { - style$$1.appendToStyle(this); - } else if (array(style$$1)) { - this.appendFromJson(style$$1); - } else if (string(style$$1)) { - this.appendFromString(style$$1); +styfn$8.append = function (style) { + if (stylesheet(style)) { + style.appendToStyle(this); + } else if (array(style)) { + this.appendFromJson(style); + } else if (string(style)) { + this.appendFromString(style); } // you probably wouldn't want to append a Style, since you'd duplicate the default parts @@ -16912,13 +17075,13 @@ styfn$8.append = function (style$$1) { Style.fromJson = function (cy, json) { - var style$$1 = new Style(cy); - style$$1.fromJson(json); - return style$$1; + var style = new Style(cy); + style.fromJson(json); + return style; }; -Style.fromString = function (cy, string$$1) { - return new Style(cy).fromString(string$$1); +Style.fromString = function (cy, string) { + return new Style(cy).fromString(string); }; [styfn, styfn$1, styfn$2, styfn$3, styfn$4, styfn$5, styfn$6, styfn$7].forEach(function (props) { @@ -16931,7 +17094,7 @@ Style.propertyGroupNames = styfn$8.propertyGroupNames; Style.propertyGroupKeys = styfn$8.propertyGroupKeys; var corefn$7 = { - style: function style$$1(newStyle) { + style: function style(newStyle) { if (newStyle) { var s = this.setStyle(newStyle); s.update(); @@ -16939,15 +17102,15 @@ var corefn$7 = { return this._private.style; }, - setStyle: function setStyle(style$$1) { + setStyle: function setStyle(style) { var _p = this._private; - if (stylesheet(style$$1)) { - _p.style = style$$1.generateStyle(this); - } else if (array(style$$1)) { - _p.style = Style.fromJson(this, style$$1); - } else if (string(style$$1)) { - _p.style = Style.fromString(this, style$$1); + if (stylesheet(style)) { + _p.style = style.generateStyle(this); + } else if (array(style)) { + _p.style = Style.fromJson(this, style); + } else if (string(style)) { + _p.style = Style.fromString(this, style); } else { _p.style = Style(this); } @@ -16958,27 +17121,27 @@ var corefn$7 = { var defaultSelectionType = 'single'; var corefn$8 = { - autolock: function autolock(bool$$1) { - if (bool$$1 !== undefined) { - this._private.autolock = bool$$1 ? true : false; + autolock: function autolock(bool) { + if (bool !== undefined) { + this._private.autolock = bool ? true : false; } else { return this._private.autolock; } return this; // chaining }, - autoungrabify: function autoungrabify(bool$$1) { - if (bool$$1 !== undefined) { - this._private.autoungrabify = bool$$1 ? true : false; + autoungrabify: function autoungrabify(bool) { + if (bool !== undefined) { + this._private.autoungrabify = bool ? true : false; } else { return this._private.autoungrabify; } return this; // chaining }, - autounselectify: function autounselectify(bool$$1) { - if (bool$$1 !== undefined) { - this._private.autounselectify = bool$$1 ? true : false; + autounselectify: function autounselectify(bool) { + if (bool !== undefined) { + this._private.autounselectify = bool ? true : false; } else { return this._private.autounselectify; } @@ -17002,45 +17165,45 @@ var corefn$8 = { return this; }, - panningEnabled: function panningEnabled(bool$$1) { - if (bool$$1 !== undefined) { - this._private.panningEnabled = bool$$1 ? true : false; + panningEnabled: function panningEnabled(bool) { + if (bool !== undefined) { + this._private.panningEnabled = bool ? true : false; } else { return this._private.panningEnabled; } return this; // chaining }, - userPanningEnabled: function userPanningEnabled(bool$$1) { - if (bool$$1 !== undefined) { - this._private.userPanningEnabled = bool$$1 ? true : false; + userPanningEnabled: function userPanningEnabled(bool) { + if (bool !== undefined) { + this._private.userPanningEnabled = bool ? true : false; } else { return this._private.userPanningEnabled; } return this; // chaining }, - zoomingEnabled: function zoomingEnabled(bool$$1) { - if (bool$$1 !== undefined) { - this._private.zoomingEnabled = bool$$1 ? true : false; + zoomingEnabled: function zoomingEnabled(bool) { + if (bool !== undefined) { + this._private.zoomingEnabled = bool ? true : false; } else { return this._private.zoomingEnabled; } return this; // chaining }, - userZoomingEnabled: function userZoomingEnabled(bool$$1) { - if (bool$$1 !== undefined) { - this._private.userZoomingEnabled = bool$$1 ? true : false; + userZoomingEnabled: function userZoomingEnabled(bool) { + if (bool !== undefined) { + this._private.userZoomingEnabled = bool ? true : false; } else { return this._private.userZoomingEnabled; } return this; // chaining }, - boxSelectionEnabled: function boxSelectionEnabled(bool$$1) { - if (bool$$1 !== undefined) { - this._private.boxSelectionEnabled = bool$$1 ? true : false; + boxSelectionEnabled: function boxSelectionEnabled(bool) { + if (bool !== undefined) { + this._private.boxSelectionEnabled = bool ? true : false; } else { return this._private.boxSelectionEnabled; } @@ -17232,22 +17395,22 @@ var corefn$8 = { return; }, - zoomRange: function zoomRange(min$$1, max$$1) { + zoomRange: function zoomRange(min, max) { var _p = this._private; - if (max$$1 == null) { - var opts = min$$1; - min$$1 = opts.min; - max$$1 = opts.max; + if (max == null) { + var opts = min; + min = opts.min; + max = opts.max; } - if (number(min$$1) && number(max$$1) && min$$1 <= max$$1) { - _p.minZoom = min$$1; - _p.maxZoom = max$$1; - } else if (number(min$$1) && max$$1 === undefined && min$$1 <= _p.maxZoom) { - _p.minZoom = min$$1; - } else if (number(max$$1) && min$$1 === undefined && max$$1 >= _p.minZoom) { - _p.maxZoom = max$$1; + if (number(min) && number(max) && min <= max) { + _p.minZoom = min; + _p.maxZoom = max; + } else if (number(min) && max === undefined && min <= _p.maxZoom) { + _p.minZoom = min; + } else if (number(max) && min === undefined && max >= _p.minZoom) { + _p.maxZoom = max; } return this; @@ -17483,10 +17646,10 @@ var corefn$8 = { var _p = this._private; var container = _p.container; return _p.sizeCache = _p.sizeCache || (container ? function () { - var style$$1 = window$1.getComputedStyle(container); + var style = window$1.getComputedStyle(container); var val = function val(name) { - return parseFloat(style$$1.getPropertyValue(name)); + return parseFloat(style.getPropertyValue(name)); }; return { @@ -17538,6 +17701,44 @@ corefn$8.centre = corefn$8.center; // backwards compatibility corefn$8.autolockNodes = corefn$8.autolock; corefn$8.autoungrabifyNodes = corefn$8.autoungrabify; +var fn$6 = { + data: define$3.data({ + field: 'data', + bindingEvent: 'data', + allowBinding: true, + allowSetting: true, + settingEvent: 'data', + settingTriggersEvent: true, + triggerFnName: 'trigger', + allowGetting: true + }), + removeData: define$3.removeData({ + field: 'data', + event: 'data', + triggerFnName: 'trigger', + triggerEvent: true + }), + scratch: define$3.data({ + field: 'scratch', + bindingEvent: 'scratch', + allowBinding: true, + allowSetting: true, + settingEvent: 'scratch', + settingTriggersEvent: true, + triggerFnName: 'trigger', + allowGetting: true + }), + removeScratch: define$3.removeData({ + field: 'scratch', + event: 'scratch', + triggerFnName: 'trigger', + triggerEvent: true + }) +}; // aliases + +fn$6.attr = fn$6.data; +fn$6.removeAttr = fn$6.removeData; + var Core = function Core(opts) { var cy = this; opts = extend({}, opts); @@ -17597,6 +17798,8 @@ var Core = function Core(opts) { // list of listeners aniEles: new Collection(this), // elements being animated + data: {}, + // data for the core scratch: {}, // scratch object for core layout: null, @@ -17708,8 +17911,8 @@ var Core = function Core(opts) { for (var i = 0; i < readies.length; i++) { - var fn$$1 = readies[i]; - cy.on('ready', fn$$1); + var fn$1 = readies[i]; + cy.on('ready', fn$1); } if (reg) { @@ -17731,21 +17934,21 @@ extend(corefn$9, { isReady: function isReady() { return this._private.ready; }, - isDestroyed: function isDestroyed() { + destroyed: function destroyed() { return this._private.destroyed; }, - ready: function ready(fn$$1) { + ready: function ready(fn) { if (this.isReady()) { - this.emitter().emit('ready', [], fn$$1); // just calls fn as though triggered via ready event + this.emitter().emit('ready', [], fn); // just calls fn as though triggered via ready event } else { - this.on('ready', fn$$1); + this.on('ready', fn); } return this; }, destroy: function destroy() { var cy = this; - if (cy.isDestroyed()) return; + if (cy.destroyed()) return; cy.stopAnimationLoop(); cy.destroyRenderer(); this.emit('destroy'); @@ -17780,7 +17983,7 @@ extend(corefn$9, { container: function container() { return this._private.container || null; }, - mount: function mount(container, rendererOptions) { + mount: function mount(container) { if (container == null) { return; } @@ -17788,10 +17991,6 @@ extend(corefn$9, { var cy = this; var _p = cy._private; var options = _p.options; - var rOpts = rendererOptions ? rendererOptions : { - name: 'canvas' - }; - options.renderer = rOpts; if (!htmlElement(container) && htmlElement(container[0])) { container = container[0]; @@ -17801,7 +18000,11 @@ extend(corefn$9, { cy.destroyRenderer(); _p.container = container; _p.styleEnabled = true; - cy.initRenderer(rOpts); + cy.invalidateSize(); + cy.initRenderer(extend({}, options, options.renderer, { + // allow custom renderer name to be re-used, otherwise use canvas + name: options.renderer.name === 'null' ? 'canvas' : options.renderer.name + })); cy.startAnimationLoop(); cy.style(options.style); cy.emit('mount'); @@ -17842,7 +18045,8 @@ extend(corefn$9, { for (var i = 0; i < jsons.length; i++) { var json = jsons[i]; - var id = json.data.id; + var id = '' + json.data.id; // id must be string + var ele = cy.getElementById(id); idInJson[id] = true; @@ -17927,6 +18131,10 @@ extend(corefn$9, { } } + if (obj.data) { + cy.data(obj.data); + } + var fields = ['minZoom', 'maxZoom', 'zoomingEnabled', 'userZoomingEnabled', 'panningEnabled', 'userPanningEnabled', 'boxSelectionEnabled', 'autolock', 'autoungrabify', 'autounselectify']; for (var _i2 = 0; _i2 < fields.length; _i2++) { @@ -17965,6 +18173,7 @@ extend(corefn$9, { json.style = cy.style().json(); } + json.data = copy(cy.data()); var options = _p.options; json.zoomingEnabled = _p.zoomingEnabled; json.userZoomingEnabled = _p.userZoomingEnabled; @@ -17982,26 +18191,10 @@ extend(corefn$9, { json.motionBlur = options.motionBlur; return json; } - }, - scratch: define$3.data({ - field: 'scratch', - bindingEvent: 'scratch', - allowBinding: true, - allowSetting: true, - settingEvent: 'scratch', - settingTriggersEvent: true, - triggerFnName: 'trigger', - allowGetting: true - }), - removeScratch: define$3.removeData({ - field: 'scratch', - event: 'scratch', - triggerFnName: 'trigger', - triggerEvent: true - }) + } }); corefn$9.$id = corefn$9.getElementById; -[corefn, corefn$1, elesfn$u, corefn$2, corefn$3, corefn$4, corefn$5, corefn$6, corefn$7, corefn$8].forEach(function (props) { +[corefn, corefn$1, elesfn$u, corefn$2, corefn$3, corefn$4, corefn$5, corefn$6, corefn$7, corefn$8, fn$6].forEach(function (props) { extend(corefn$9, props); }); @@ -18301,7 +18494,7 @@ BreadthFirstLayout.prototype.run = function () { if (depth < eleDepth) { // only get influenced by elements above - percent += index / (nDepth - 1); + percent += index / nDepth; samples++; } } @@ -18357,8 +18550,8 @@ BreadthFirstLayout.prototype.run = function () { x: bb.x1 + bb.w / 2, y: bb.x1 + bb.h / 2 }; - var maxDepthSize = depths.reduce(function (max$$1, eles) { - return Math.max(max$$1, eles.length); + var maxDepthSize = depths.reduce(function (max, eles) { + return Math.max(max, eles.length); }, 0); var getPosition = function getPosition(ele) { @@ -18801,9 +18994,7 @@ var defaults$c = { // Cooling factor (how the temperature is reduced between consecutive iterations coolingFactor: 0.99, // Lower temperature threshold (below this point the layout will end) - minTemp: 1.0, - // Pass a reference to weaver to use threads for calculations - weaver: false + minTemp: 1.0 }; /** * @brief : constructor @@ -18823,67 +19014,6 @@ CoseLayout.prototype.run = function () { var options = this.options; var cy = options.cy; var layout = this; - var thread$$1 = this.thread; - var Thread = options.weaver ? options.weaver.Thread : null; - var falseThread = { - // use false thread as polyfill - listeners: [], - on: function on(e, cb) { - this.listeners.push({ - event: e, - callback: cb - }); - return this; - }, - trigger: function trigger(e) { - if (string(e)) { - e = { - type: e - }; - } - - var matchesEvent = function matchesEvent(l) { - return l.event === e.type; - }; - - var trigger = function trigger(l) { - l.callback(e); - }; - - this.listeners.filter(matchesEvent).forEach(trigger); - return this; - }, - pass: function pass(data) { - this.pass = data; - return this; - }, - run: function run(cb) { - var pass = this.pass; - return new Promise$1(function (resolve) { - resolve(cb(pass)); - }); - }, - stop: function stop() { - return this; - }, - stopped: function stopped() { - return true; - } - }; - - function broadcast(message) { - // for false thread - var e = { - type: 'message', - message: message - }; - falseThread.trigger(e); - } - - if (!thread$$1 || thread$$1.stopped()) { - thread$$1 = this.thread = Thread ? new Thread() : falseThread; - } - layout.stopped = false; if (options.animate === true || options.animate === false) { @@ -18909,753 +19039,115 @@ CoseLayout.prototype.run = function () { if (options.randomize) { - randomizePositions(layoutInfo, cy); + randomizePositions(layoutInfo); } - var startTime = Date.now(); - var refreshRequested = false; - - var refresh = function refresh(rOpts) { - rOpts = rOpts || {}; + var startTime = performanceNow(); - if (refreshRequested && !rOpts.next) { - return; - } + var refresh = function refresh() { + refreshPositions(layoutInfo, cy, options); // Fit the graph if necessary - if (!rOpts.force && Date.now() - startTime < options.animationThreshold) { - return; + if (true === options.fit) { + cy.fit(options.padding); } + }; - refreshRequested = true; - requestAnimationFrame(function () { - refreshPositions(layoutInfo, cy, options); // Fit the graph if necessary + var mainLoop = function mainLoop(i) { + if (layout.stopped || i >= options.numIter) { + // logDebug("Layout manually stopped. Stopping computation in step " + i); + return false; + } // Do one step in the phisical simulation - if (true === options.fit) { - cy.fit(options.padding); - } - refreshRequested = false; + step$1(layoutInfo, options); // Update temperature - if (rOpts.next) { - rOpts.next(); - } - }); - }; + layoutInfo.temperature = layoutInfo.temperature * options.coolingFactor; // logDebug("New temperature: " + layoutInfo.temperature); - thread$$1.on('message', function (e) { - var layoutNodes = e.message; - layoutInfo.layoutNodes = layoutNodes; - refresh(); - }); - thread$$1.pass({ - layoutInfo: layoutInfo, - options: { - animate: options.animate, - refresh: options.refresh, - componentSpacing: options.componentSpacing, - nodeOverlap: options.nodeOverlap, - nestingFactor: options.nestingFactor, - gravity: options.gravity, - numIter: options.numIter, - initialTemp: options.initialTemp, - coolingFactor: options.coolingFactor, - minTemp: options.minTemp - } - }).run(function (pass) { - var layoutInfo = pass.layoutInfo; - var options = pass.options; - /** - * @brief : Performs one iteration of the physical simulation - * @arg layoutInfo : LayoutInfo object already initialized - * @arg cy : Cytoscape object - * @arg options : Layout options - */ - - var step = function step(layoutInfo, options, _step) { - // var s = "\n\n###############################"; - // s += "\nSTEP: " + step; - // s += "\n###############################\n"; - // logDebug(s); - // Calculate node repulsions - calculateNodeForces(layoutInfo, options); // Calculate edge forces + if (layoutInfo.temperature < options.minTemp) { + // logDebug("Temperature drop below minimum threshold. Stopping computation in step " + i); + return false; + } - calculateEdgeForces(layoutInfo, options); // Calculate gravity forces + return true; + }; - calculateGravityForces(layoutInfo, options); // Propagate forces from parent to child + var done = function done() { + if (options.animate === true || options.animate === false) { + refresh(); // Layout has finished - propagateForces(layoutInfo, options); // Update positions based on calculated forces + layout.one('layoutstop', options.stop); + layout.emit({ + type: 'layoutstop', + layout: layout + }); + } else { + var nodes = options.eles.nodes(); + var getScaledPos = getScaleInBoundsFn(layoutInfo, options, nodes); + nodes.layoutPositions(layout, options, getScaledPos); + } + }; - updatePositions(layoutInfo, options); - }; - /** - * @brief : Computes the node repulsion forces - */ + var i = 0; + var loopRet = true; + if (options.animate === true) { + var frame = function frame() { + var f = 0; - var calculateNodeForces = function calculateNodeForces(layoutInfo, options) { - // Go through each of the graphs in graphSet - // Nodes only repel each other if they belong to the same graph - // var s = 'calculateNodeForces'; - // logDebug(s); - for (var i = 0; i < layoutInfo.graphSet.length; i++) { - var graph = layoutInfo.graphSet[i]; - var numNodes = graph.length; // s = "Set: " + graph.toString(); - // logDebug(s); - // Now get all the pairs of nodes - // Only get each pair once, (A, B) = (B, A) + while (loopRet && f < options.refresh) { + loopRet = mainLoop(i); + i++; + f++; + } - for (var j = 0; j < numNodes; j++) { - var node1 = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[j]]]; + if (!loopRet) { + // it's done + separateComponents(layoutInfo, options); + done(); + } else { + var now = performanceNow(); - for (var k = j + 1; k < numNodes; k++) { - var node2 = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[k]]]; - nodeRepulsion(node1, node2, layoutInfo, options); - } + if (now - startTime >= options.animationThreshold) { + refresh(); } - } - }; - var randomDistance = function randomDistance(max$$1) { - return -max$$1 + 2 * max$$1 * Math.random(); + requestAnimationFrame(frame); + } }; - /** - * @brief : Compute the node repulsion forces between a pair of nodes - */ + frame(); + } else { + while (loopRet) { + loopRet = mainLoop(i); + i++; + } - var nodeRepulsion = function nodeRepulsion(node1, node2, layoutInfo, options) { - // var s = "Node repulsion. Node1: " + node1.id + " Node2: " + node2.id; - var cmptId1 = node1.cmptId; - var cmptId2 = node2.cmptId; - - if (cmptId1 !== cmptId2 && !layoutInfo.isCompound) { - return; - } // Get direction of line connecting both node centers - + separateComponents(layoutInfo, options); + done(); + } - var directionX = node2.positionX - node1.positionX; - var directionY = node2.positionY - node1.positionY; - var maxRandDist = 1; // s += "\ndirectionX: " + directionX + ", directionY: " + directionY; - // If both centers are the same, apply a random force + return this; // chaining +}; +/** + * @brief : called on continuous layouts to stop them before they finish + */ - if (0 === directionX && 0 === directionY) { - directionX = randomDistance(maxRandDist); - directionY = randomDistance(maxRandDist); - } - var overlap = nodesOverlap(node1, node2, directionX, directionY); +CoseLayout.prototype.stop = function () { + this.stopped = true; - if (overlap > 0) { - // s += "\nNodes DO overlap."; - // s += "\nOverlap: " + overlap; - // If nodes overlap, repulsion force is proportional - // to the overlap - var force = options.nodeOverlap * overlap; // Compute the module and components of the force vector + if (this.thread) { + this.thread.stop(); + } - var distance = Math.sqrt(directionX * directionX + directionY * directionY); // s += "\nDistance: " + distance; + this.emit('layoutstop'); + return this; // chaining +}; - var forceX = force * directionX / distance; - var forceY = force * directionY / distance; - } else { - // s += "\nNodes do NOT overlap."; - // If there's no overlap, force is inversely proportional - // to squared distance - // Get clipping points for both nodes - var point1 = findClippingPoint(node1, directionX, directionY); - var point2 = findClippingPoint(node2, -1 * directionX, -1 * directionY); // Use clipping points to compute distance - - var distanceX = point2.x - point1.x; - var distanceY = point2.y - point1.y; - var distanceSqr = distanceX * distanceX + distanceY * distanceY; - var distance = Math.sqrt(distanceSqr); // s += "\nDistance: " + distance; - // Compute the module and components of the force vector - - var force = (node1.nodeRepulsion + node2.nodeRepulsion) / distanceSqr; - var forceX = force * distanceX / distance; - var forceY = force * distanceY / distance; - } // Apply force - - - if (!node1.isLocked) { - node1.offsetX -= forceX; - node1.offsetY -= forceY; - } - - if (!node2.isLocked) { - node2.offsetX += forceX; - node2.offsetY += forceY; - } // s += "\nForceX: " + forceX + " ForceY: " + forceY; - // logDebug(s); - - - return; - }; - /** - * @brief : Determines whether two nodes overlap or not - * @return : Amount of overlapping (0 => no overlap) - */ - - - var nodesOverlap = function nodesOverlap(node1, node2, dX, dY) { - if (dX > 0) { - var overlapX = node1.maxX - node2.minX; - } else { - var overlapX = node2.maxX - node1.minX; - } - - if (dY > 0) { - var overlapY = node1.maxY - node2.minY; - } else { - var overlapY = node2.maxY - node1.minY; - } - - if (overlapX >= 0 && overlapY >= 0) { - return Math.sqrt(overlapX * overlapX + overlapY * overlapY); - } else { - return 0; - } - }; - /** - * @brief : Finds the point in which an edge (direction dX, dY) intersects - * the rectangular bounding box of it's source/target node - */ - - - var findClippingPoint = function findClippingPoint(node, dX, dY) { - // Shorcuts - var X = node.positionX; - var Y = node.positionY; - var H = node.height || 1; - var W = node.width || 1; - var dirSlope = dY / dX; - var nodeSlope = H / W; // var s = 'Computing clipping point of node ' + node.id + - // " . Height: " + H + ", Width: " + W + - // "\nDirection " + dX + ", " + dY; - // - // Compute intersection - - var res = {}; // Case: Vertical direction (up) - - if (0 === dX && 0 < dY) { - res.x = X; // s += "\nUp direction"; - - res.y = Y + H / 2; - return res; - } // Case: Vertical direction (down) - - - if (0 === dX && 0 > dY) { - res.x = X; - res.y = Y + H / 2; // s += "\nDown direction"; - - return res; - } // Case: Intersects the right border - - - if (0 < dX && -1 * nodeSlope <= dirSlope && dirSlope <= nodeSlope) { - res.x = X + W / 2; - res.y = Y + W * dY / 2 / dX; // s += "\nRightborder"; - - return res; - } // Case: Intersects the left border - - - if (0 > dX && -1 * nodeSlope <= dirSlope && dirSlope <= nodeSlope) { - res.x = X - W / 2; - res.y = Y - W * dY / 2 / dX; // s += "\nLeftborder"; - - return res; - } // Case: Intersects the top border - - - if (0 < dY && (dirSlope <= -1 * nodeSlope || dirSlope >= nodeSlope)) { - res.x = X + H * dX / 2 / dY; - res.y = Y + H / 2; // s += "\nTop border"; - - return res; - } // Case: Intersects the bottom border - - - if (0 > dY && (dirSlope <= -1 * nodeSlope || dirSlope >= nodeSlope)) { - res.x = X - H * dX / 2 / dY; - res.y = Y - H / 2; // s += "\nBottom border"; - - return res; - } // s += "\nClipping point found at " + res.x + ", " + res.y; - // logDebug(s); - - - return res; - }; - /** - * @brief : Calculates all edge forces - */ - - - var calculateEdgeForces = function calculateEdgeForces(layoutInfo, options) { - // Iterate over all edges - for (var i = 0; i < layoutInfo.edgeSize; i++) { - // Get edge, source & target nodes - var edge = layoutInfo.layoutEdges[i]; - var sourceIx = layoutInfo.idToIndex[edge.sourceId]; - var source = layoutInfo.layoutNodes[sourceIx]; - var targetIx = layoutInfo.idToIndex[edge.targetId]; - var target = layoutInfo.layoutNodes[targetIx]; // Get direction of line connecting both node centers - - var directionX = target.positionX - source.positionX; - var directionY = target.positionY - source.positionY; // If both centers are the same, do nothing. - // A random force has already been applied as node repulsion - - if (0 === directionX && 0 === directionY) { - continue; - } // Get clipping points for both nodes - - - var point1 = findClippingPoint(source, directionX, directionY); - var point2 = findClippingPoint(target, -1 * directionX, -1 * directionY); - var lx = point2.x - point1.x; - var ly = point2.y - point1.y; - var l = Math.sqrt(lx * lx + ly * ly); - var force = Math.pow(edge.idealLength - l, 2) / edge.elasticity; - - if (0 !== l) { - var forceX = force * lx / l; - var forceY = force * ly / l; - } else { - var forceX = 0; - var forceY = 0; - } // Add this force to target and source nodes - - - if (!source.isLocked) { - source.offsetX += forceX; - source.offsetY += forceY; - } - - if (!target.isLocked) { - target.offsetX -= forceX; - target.offsetY -= forceY; - } // var s = 'Edge force between nodes ' + source.id + ' and ' + target.id; - // s += "\nDistance: " + l + " Force: (" + forceX + ", " + forceY + ")"; - // logDebug(s); - - } - }; - /** - * @brief : Computes gravity forces for all nodes - */ - - - var calculateGravityForces = function calculateGravityForces(layoutInfo, options) { - var distThreshold = 1; // var s = 'calculateGravityForces'; - // logDebug(s); - - for (var i = 0; i < layoutInfo.graphSet.length; i++) { - var graph = layoutInfo.graphSet[i]; - var numNodes = graph.length; // s = "Set: " + graph.toString(); - // logDebug(s); - // Compute graph center - - if (0 === i) { - var centerX = layoutInfo.clientHeight / 2; - var centerY = layoutInfo.clientWidth / 2; - } else { - // Get Parent node for this graph, and use its position as center - var temp = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[0]]]; - var parent = layoutInfo.layoutNodes[layoutInfo.idToIndex[temp.parentId]]; - var centerX = parent.positionX; - var centerY = parent.positionY; - } // s = "Center found at: " + centerX + ", " + centerY; - // logDebug(s); - // Apply force to all nodes in graph - - - for (var j = 0; j < numNodes; j++) { - var node = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[j]]]; // s = "Node: " + node.id; - - if (node.isLocked) { - continue; - } - - var dx = centerX - node.positionX; - var dy = centerY - node.positionY; - var d = Math.sqrt(dx * dx + dy * dy); - - if (d > distThreshold) { - var fx = options.gravity * dx / d; - var fy = options.gravity * dy / d; - node.offsetX += fx; - node.offsetY += fy; // s += ": Applied force: " + fx + ", " + fy; - } // s += ": skypped since it's too close to center"; - // logDebug(s); - - } - } - }; - /** - * @brief : This function propagates the existing offsets from - * parent nodes to its descendents. - * @arg layoutInfo : layoutInfo Object - * @arg cy : cytoscape Object - * @arg options : Layout options - */ - - - var propagateForces = function propagateForces(layoutInfo, options) { - // Inline implementation of a queue, used for traversing the graph in BFS order - var queue = []; - var start = 0; // Points to the start the queue - - var end = -1; // Points to the end of the queue - // logDebug('propagateForces'); - // Start by visiting the nodes in the root graph - - queue.push.apply(queue, layoutInfo.graphSet[0]); - end += layoutInfo.graphSet[0].length; // Traverse the graph, level by level, - - while (start <= end) { - // Get the node to visit and remove it from queue - var nodeId = queue[start++]; - var nodeIndex = layoutInfo.idToIndex[nodeId]; - var node = layoutInfo.layoutNodes[nodeIndex]; - var children = node.children; // We only need to process the node if it's compound - - if (0 < children.length && !node.isLocked) { - var offX = node.offsetX; - var offY = node.offsetY; // var s = "Propagating offset from parent node : " + node.id + - // ". OffsetX: " + offX + ". OffsetY: " + offY; - // s += "\n Children: " + children.toString(); - // logDebug(s); - - for (var i = 0; i < children.length; i++) { - var childNode = layoutInfo.layoutNodes[layoutInfo.idToIndex[children[i]]]; // Propagate offset - - childNode.offsetX += offX; - childNode.offsetY += offY; // Add children to queue to be visited - - queue[++end] = children[i]; - } // Reset parent offsets - - - node.offsetX = 0; - node.offsetY = 0; - } - } - }; - /** - * @brief : Updates the layout model positions, based on - * the accumulated forces - */ - - - var updatePositions = function updatePositions(layoutInfo, options) { - // var s = 'Updating positions'; - // logDebug(s); - // Reset boundaries for compound nodes - for (var i = 0; i < layoutInfo.nodeSize; i++) { - var n = layoutInfo.layoutNodes[i]; - - if (0 < n.children.length) { - // logDebug("Resetting boundaries of compound node: " + n.id); - n.maxX = undefined; - n.minX = undefined; - n.maxY = undefined; - n.minY = undefined; - } - } - - for (var i = 0; i < layoutInfo.nodeSize; i++) { - var n = layoutInfo.layoutNodes[i]; - - if (0 < n.children.length || n.isLocked) { - // No need to set compound or locked node position - // logDebug("Skipping position update of node: " + n.id); - continue; - } // s = "Node: " + n.id + " Previous position: (" + - // n.positionX + ", " + n.positionY + ")."; - // Limit displacement in order to improve stability - - - var tempForce = limitForce(n.offsetX, n.offsetY, layoutInfo.temperature); - n.positionX += tempForce.x; - n.positionY += tempForce.y; - n.offsetX = 0; - n.offsetY = 0; - n.minX = n.positionX - n.width; - n.maxX = n.positionX + n.width; - n.minY = n.positionY - n.height; - n.maxY = n.positionY + n.height; // s += " New Position: (" + n.positionX + ", " + n.positionY + ")."; - // logDebug(s); - // Update ancestry boudaries - - updateAncestryBoundaries(n, layoutInfo); - } // Update size, position of compund nodes - - - for (var i = 0; i < layoutInfo.nodeSize; i++) { - var n = layoutInfo.layoutNodes[i]; - - if (0 < n.children.length && !n.isLocked) { - n.positionX = (n.maxX + n.minX) / 2; - n.positionY = (n.maxY + n.minY) / 2; - n.width = n.maxX - n.minX; - n.height = n.maxY - n.minY; // s = "Updating position, size of compound node " + n.id; - // s += "\nPositionX: " + n.positionX + ", PositionY: " + n.positionY; - // s += "\nWidth: " + n.width + ", Height: " + n.height; - // logDebug(s); - } - } - }; - /** - * @brief : Limits a force (forceX, forceY) to be not - * greater (in modulo) than max. - 8 Preserves force direction. - */ - - - var limitForce = function limitForce(forceX, forceY, max$$1) { - // var s = "Limiting force: (" + forceX + ", " + forceY + "). Max: " + max; - var force = Math.sqrt(forceX * forceX + forceY * forceY); - - if (force > max$$1) { - var res = { - x: max$$1 * forceX / force, - y: max$$1 * forceY / force - }; - } else { - var res = { - x: forceX, - y: forceY - }; - } // s += ".\nResult: (" + res.x + ", " + res.y + ")"; - // logDebug(s); - - - return res; - }; - /** - * @brief : Function used for keeping track of compound node - * sizes, since they should bound all their subnodes. - */ - - - var updateAncestryBoundaries = function updateAncestryBoundaries(node, layoutInfo) { - // var s = "Propagating new position/size of node " + node.id; - var parentId = node.parentId; - - if (null == parentId) { - // If there's no parent, we are done - // s += ". No parent node."; - // logDebug(s); - return; - } // Get Parent Node - - - var p = layoutInfo.layoutNodes[layoutInfo.idToIndex[parentId]]; - var flag = false; // MaxX - - if (null == p.maxX || node.maxX + p.padRight > p.maxX) { - p.maxX = node.maxX + p.padRight; - flag = true; // s += "\nNew maxX for parent node " + p.id + ": " + p.maxX; - } // MinX - - - if (null == p.minX || node.minX - p.padLeft < p.minX) { - p.minX = node.minX - p.padLeft; - flag = true; // s += "\nNew minX for parent node " + p.id + ": " + p.minX; - } // MaxY - - - if (null == p.maxY || node.maxY + p.padBottom > p.maxY) { - p.maxY = node.maxY + p.padBottom; - flag = true; // s += "\nNew maxY for parent node " + p.id + ": " + p.maxY; - } // MinY - - - if (null == p.minY || node.minY - p.padTop < p.minY) { - p.minY = node.minY - p.padTop; - flag = true; // s += "\nNew minY for parent node " + p.id + ": " + p.minY; - } // If updated boundaries, propagate changes upward - - - if (flag) { - // logDebug(s); - return updateAncestryBoundaries(p, layoutInfo); - } // s += ". No changes in boundaries/position of parent node " + p.id; - // logDebug(s); - - - return; - }; - - var separateComponents = function separateComponents(layutInfo, options) { - var nodes = layoutInfo.layoutNodes; - var components = []; - - for (var i = 0; i < nodes.length; i++) { - var node = nodes[i]; - var cid = node.cmptId; - var component = components[cid] = components[cid] || []; - component.push(node); - } - - var totalA = 0; - - for (var i = 0; i < components.length; i++) { - var c = components[i]; - - if (!c) { - continue; - } - - c.x1 = Infinity; - c.x2 = -Infinity; - c.y1 = Infinity; - c.y2 = -Infinity; - - for (var j = 0; j < c.length; j++) { - var n = c[j]; - c.x1 = Math.min(c.x1, n.positionX - n.width / 2); - c.x2 = Math.max(c.x2, n.positionX + n.width / 2); - c.y1 = Math.min(c.y1, n.positionY - n.height / 2); - c.y2 = Math.max(c.y2, n.positionY + n.height / 2); - } - - c.w = c.x2 - c.x1; - c.h = c.y2 - c.y1; - totalA += c.w * c.h; - } - - components.sort(function (c1, c2) { - return c2.w * c2.h - c1.w * c1.h; - }); - var x = 0; - var y = 0; - var usedW = 0; - var rowH = 0; - var maxRowW = Math.sqrt(totalA) * layoutInfo.clientWidth / layoutInfo.clientHeight; - - for (var i = 0; i < components.length; i++) { - var c = components[i]; - - if (!c) { - continue; - } - - for (var j = 0; j < c.length; j++) { - var n = c[j]; - - if (!n.isLocked) { - n.positionX += x; - n.positionY += y; - } - } - - x += c.w + options.componentSpacing; - usedW += c.w + options.componentSpacing; - rowH = Math.max(rowH, c.h); - - if (usedW > maxRowW) { - y += rowH + options.componentSpacing; - x = 0; - usedW = 0; - rowH = 0; - } - } - }; - - var mainLoop = function mainLoop(i) { - - - step(layoutInfo, options, i); // Update temperature - - layoutInfo.temperature = layoutInfo.temperature * options.coolingFactor; // logDebug("New temperature: " + layoutInfo.temperature); - - if (layoutInfo.temperature < options.minTemp) { - // logDebug("Temperature drop below minimum threshold. Stopping computation in step " + i); - return false; - } - - return true; - }; - - var i = 0; - var loopRet; - - do { - var f = 0; - - while ((f < options.refresh || options.refresh === 0) && i < options.numIter) { - var loopRet = mainLoop(i); - - if (!loopRet) { - break; - } - - f++; - i++; - } - - if (options.animate === true) { - broadcast(layoutInfo.layoutNodes); // eslint-disable-line no-undef - } - } while (loopRet && i + 1 < options.numIter); - - separateComponents(layoutInfo, options); - return layoutInfo; - }).then(function (layoutInfoUpdated) { - layoutInfo.layoutNodes = layoutInfoUpdated.layoutNodes; // get the positions - - thread$$1.stop(); - done(); - }); - - var done = function done() { - if (options.animate === true || options.animate === false) { - refresh({ - force: true, - next: function next() { - // Layout has finished - layout.one('layoutstop', options.stop); - layout.emit({ - type: 'layoutstop', - layout: layout - }); - } - }); - } else { - options.eles.nodes().layoutPositions(layout, options, function (node) { - var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[node.data('id')]]; - return { - x: lnode.positionX, - y: lnode.positionY - }; - }); - } - }; - - return this; // chaining -}; -/** - * @brief : called on continuous layouts to stop them before they finish - */ - - -CoseLayout.prototype.stop = function () { - this.stopped = true; - - if (this.thread) { - this.thread.stop(); - } - - this.emit('layoutstop'); - return this; // chaining -}; - -CoseLayout.prototype.destroy = function () { - if (this.thread) { - this.thread.stop(); - } +CoseLayout.prototype.destroy = function () { + if (this.thread) { + this.thread.stop(); + } return this; // chaining }; @@ -19955,69 +19447,681 @@ var randomizePositions = function randomizePositions(layoutInfo, cy) { } } }; -/** - * @brief : Updates the positions of nodes in the network - * @arg layoutInfo : LayoutInfo object - * @arg cy : Cytoscape object - * @arg options : Layout options - */ +var getScaleInBoundsFn = function getScaleInBoundsFn(layoutInfo, options, nodes) { + var bb = layoutInfo.boundingBox; + var coseBB = { + x1: Infinity, + x2: -Infinity, + y1: Infinity, + y2: -Infinity + }; + + if (options.boundingBox) { + nodes.forEach(function (node) { + var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[node.data('id')]]; + coseBB.x1 = Math.min(coseBB.x1, lnode.positionX); + coseBB.x2 = Math.max(coseBB.x2, lnode.positionX); + coseBB.y1 = Math.min(coseBB.y1, lnode.positionY); + coseBB.y2 = Math.max(coseBB.y2, lnode.positionY); + }); + coseBB.w = coseBB.x2 - coseBB.x1; + coseBB.h = coseBB.y2 - coseBB.y1; + } + + return function (ele, i) { + var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[ele.data('id')]]; + + if (options.boundingBox) { + // then add extra bounding box constraint + var pctX = (lnode.positionX - coseBB.x1) / coseBB.w; + var pctY = (lnode.positionY - coseBB.y1) / coseBB.h; + return { + x: bb.x1 + pctX * bb.w, + y: bb.y1 + pctY * bb.h + }; + } else { + return { + x: lnode.positionX, + y: lnode.positionY + }; + } + }; +}; +/** + * @brief : Updates the positions of nodes in the network + * @arg layoutInfo : LayoutInfo object + * @arg cy : Cytoscape object + * @arg options : Layout options + */ + + +var refreshPositions = function refreshPositions(layoutInfo, cy, options) { + // var s = 'Refreshing positions'; + // logDebug(s); + var layout = options.layout; + var nodes = options.eles.nodes(); + var getScaledPos = getScaleInBoundsFn(layoutInfo, options, nodes); + nodes.positions(getScaledPos); // Trigger layoutReady only on first call + + if (true !== layoutInfo.ready) { + // s = 'Triggering layoutready'; + // logDebug(s); + layoutInfo.ready = true; + layout.one('layoutready', options.ready); + layout.emit({ + type: 'layoutready', + layout: this + }); + } +}; +/** + * @brief : Logs a debug message in JS console, if DEBUG is ON + */ +// var logDebug = function(text) { +// if (DEBUG) { +// console.debug(text); +// } +// }; + +/** + * @brief : Performs one iteration of the physical simulation + * @arg layoutInfo : LayoutInfo object already initialized + * @arg cy : Cytoscape object + * @arg options : Layout options + */ + + +var step$1 = function step(layoutInfo, options, _step) { + // var s = "\n\n###############################"; + // s += "\nSTEP: " + step; + // s += "\n###############################\n"; + // logDebug(s); + // Calculate node repulsions + calculateNodeForces(layoutInfo, options); // Calculate edge forces + + calculateEdgeForces(layoutInfo); // Calculate gravity forces + + calculateGravityForces(layoutInfo, options); // Propagate forces from parent to child + + propagateForces(layoutInfo); // Update positions based on calculated forces + + updatePositions(layoutInfo); +}; +/** + * @brief : Computes the node repulsion forces + */ + + +var calculateNodeForces = function calculateNodeForces(layoutInfo, options) { + // Go through each of the graphs in graphSet + // Nodes only repel each other if they belong to the same graph + // var s = 'calculateNodeForces'; + // logDebug(s); + for (var i = 0; i < layoutInfo.graphSet.length; i++) { + var graph = layoutInfo.graphSet[i]; + var numNodes = graph.length; // s = "Set: " + graph.toString(); + // logDebug(s); + // Now get all the pairs of nodes + // Only get each pair once, (A, B) = (B, A) + + for (var j = 0; j < numNodes; j++) { + var node1 = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[j]]]; + + for (var k = j + 1; k < numNodes; k++) { + var node2 = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[k]]]; + nodeRepulsion(node1, node2, layoutInfo, options); + } + } + } +}; + +var randomDistance = function randomDistance(max) { + return -max + 2 * max * Math.random(); +}; +/** + * @brief : Compute the node repulsion forces between a pair of nodes + */ + + +var nodeRepulsion = function nodeRepulsion(node1, node2, layoutInfo, options) { + // var s = "Node repulsion. Node1: " + node1.id + " Node2: " + node2.id; + var cmptId1 = node1.cmptId; + var cmptId2 = node2.cmptId; + + if (cmptId1 !== cmptId2 && !layoutInfo.isCompound) { + return; + } // Get direction of line connecting both node centers + + + var directionX = node2.positionX - node1.positionX; + var directionY = node2.positionY - node1.positionY; + var maxRandDist = 1; // s += "\ndirectionX: " + directionX + ", directionY: " + directionY; + // If both centers are the same, apply a random force + + if (0 === directionX && 0 === directionY) { + directionX = randomDistance(maxRandDist); + directionY = randomDistance(maxRandDist); + } + + var overlap = nodesOverlap(node1, node2, directionX, directionY); + + if (overlap > 0) { + // s += "\nNodes DO overlap."; + // s += "\nOverlap: " + overlap; + // If nodes overlap, repulsion force is proportional + // to the overlap + var force = options.nodeOverlap * overlap; // Compute the module and components of the force vector + + var distance = Math.sqrt(directionX * directionX + directionY * directionY); // s += "\nDistance: " + distance; + + var forceX = force * directionX / distance; + var forceY = force * directionY / distance; + } else { + // s += "\nNodes do NOT overlap."; + // If there's no overlap, force is inversely proportional + // to squared distance + // Get clipping points for both nodes + var point1 = findClippingPoint(node1, directionX, directionY); + var point2 = findClippingPoint(node2, -1 * directionX, -1 * directionY); // Use clipping points to compute distance + + var distanceX = point2.x - point1.x; + var distanceY = point2.y - point1.y; + var distanceSqr = distanceX * distanceX + distanceY * distanceY; + var distance = Math.sqrt(distanceSqr); // s += "\nDistance: " + distance; + // Compute the module and components of the force vector + + var force = (node1.nodeRepulsion + node2.nodeRepulsion) / distanceSqr; + var forceX = force * distanceX / distance; + var forceY = force * distanceY / distance; + } // Apply force + + + if (!node1.isLocked) { + node1.offsetX -= forceX; + node1.offsetY -= forceY; + } + + if (!node2.isLocked) { + node2.offsetX += forceX; + node2.offsetY += forceY; + } // s += "\nForceX: " + forceX + " ForceY: " + forceY; + // logDebug(s); + + + return; +}; +/** + * @brief : Determines whether two nodes overlap or not + * @return : Amount of overlapping (0 => no overlap) + */ + + +var nodesOverlap = function nodesOverlap(node1, node2, dX, dY) { + if (dX > 0) { + var overlapX = node1.maxX - node2.minX; + } else { + var overlapX = node2.maxX - node1.minX; + } + + if (dY > 0) { + var overlapY = node1.maxY - node2.minY; + } else { + var overlapY = node2.maxY - node1.minY; + } + + if (overlapX >= 0 && overlapY >= 0) { + return Math.sqrt(overlapX * overlapX + overlapY * overlapY); + } else { + return 0; + } +}; +/** + * @brief : Finds the point in which an edge (direction dX, dY) intersects + * the rectangular bounding box of it's source/target node + */ + + +var findClippingPoint = function findClippingPoint(node, dX, dY) { + // Shorcuts + var X = node.positionX; + var Y = node.positionY; + var H = node.height || 1; + var W = node.width || 1; + var dirSlope = dY / dX; + var nodeSlope = H / W; // var s = 'Computing clipping point of node ' + node.id + + // " . Height: " + H + ", Width: " + W + + // "\nDirection " + dX + ", " + dY; + // + // Compute intersection + + var res = {}; // Case: Vertical direction (up) + + if (0 === dX && 0 < dY) { + res.x = X; // s += "\nUp direction"; + + res.y = Y + H / 2; + return res; + } // Case: Vertical direction (down) + + + if (0 === dX && 0 > dY) { + res.x = X; + res.y = Y + H / 2; // s += "\nDown direction"; + + return res; + } // Case: Intersects the right border + + + if (0 < dX && -1 * nodeSlope <= dirSlope && dirSlope <= nodeSlope) { + res.x = X + W / 2; + res.y = Y + W * dY / 2 / dX; // s += "\nRightborder"; + + return res; + } // Case: Intersects the left border + + + if (0 > dX && -1 * nodeSlope <= dirSlope && dirSlope <= nodeSlope) { + res.x = X - W / 2; + res.y = Y - W * dY / 2 / dX; // s += "\nLeftborder"; + + return res; + } // Case: Intersects the top border + + + if (0 < dY && (dirSlope <= -1 * nodeSlope || dirSlope >= nodeSlope)) { + res.x = X + H * dX / 2 / dY; + res.y = Y + H / 2; // s += "\nTop border"; + + return res; + } // Case: Intersects the bottom border + + + if (0 > dY && (dirSlope <= -1 * nodeSlope || dirSlope >= nodeSlope)) { + res.x = X - H * dX / 2 / dY; + res.y = Y - H / 2; // s += "\nBottom border"; + + return res; + } // s += "\nClipping point found at " + res.x + ", " + res.y; + // logDebug(s); + + + return res; +}; +/** + * @brief : Calculates all edge forces + */ + + +var calculateEdgeForces = function calculateEdgeForces(layoutInfo, options) { + // Iterate over all edges + for (var i = 0; i < layoutInfo.edgeSize; i++) { + // Get edge, source & target nodes + var edge = layoutInfo.layoutEdges[i]; + var sourceIx = layoutInfo.idToIndex[edge.sourceId]; + var source = layoutInfo.layoutNodes[sourceIx]; + var targetIx = layoutInfo.idToIndex[edge.targetId]; + var target = layoutInfo.layoutNodes[targetIx]; // Get direction of line connecting both node centers + + var directionX = target.positionX - source.positionX; + var directionY = target.positionY - source.positionY; // If both centers are the same, do nothing. + // A random force has already been applied as node repulsion + + if (0 === directionX && 0 === directionY) { + continue; + } // Get clipping points for both nodes + + + var point1 = findClippingPoint(source, directionX, directionY); + var point2 = findClippingPoint(target, -1 * directionX, -1 * directionY); + var lx = point2.x - point1.x; + var ly = point2.y - point1.y; + var l = Math.sqrt(lx * lx + ly * ly); + var force = Math.pow(edge.idealLength - l, 2) / edge.elasticity; + + if (0 !== l) { + var forceX = force * lx / l; + var forceY = force * ly / l; + } else { + var forceX = 0; + var forceY = 0; + } // Add this force to target and source nodes + + + if (!source.isLocked) { + source.offsetX += forceX; + source.offsetY += forceY; + } + + if (!target.isLocked) { + target.offsetX -= forceX; + target.offsetY -= forceY; + } // var s = 'Edge force between nodes ' + source.id + ' and ' + target.id; + // s += "\nDistance: " + l + " Force: (" + forceX + ", " + forceY + ")"; + // logDebug(s); + + } +}; +/** + * @brief : Computes gravity forces for all nodes + */ + + +var calculateGravityForces = function calculateGravityForces(layoutInfo, options) { + var distThreshold = 1; // var s = 'calculateGravityForces'; + // logDebug(s); + + for (var i = 0; i < layoutInfo.graphSet.length; i++) { + var graph = layoutInfo.graphSet[i]; + var numNodes = graph.length; // s = "Set: " + graph.toString(); + // logDebug(s); + // Compute graph center + + if (0 === i) { + var centerX = layoutInfo.clientHeight / 2; + var centerY = layoutInfo.clientWidth / 2; + } else { + // Get Parent node for this graph, and use its position as center + var temp = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[0]]]; + var parent = layoutInfo.layoutNodes[layoutInfo.idToIndex[temp.parentId]]; + var centerX = parent.positionX; + var centerY = parent.positionY; + } // s = "Center found at: " + centerX + ", " + centerY; + // logDebug(s); + // Apply force to all nodes in graph + + + for (var j = 0; j < numNodes; j++) { + var node = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[j]]]; // s = "Node: " + node.id; + + if (node.isLocked) { + continue; + } + + var dx = centerX - node.positionX; + var dy = centerY - node.positionY; + var d = Math.sqrt(dx * dx + dy * dy); + + if (d > distThreshold) { + var fx = options.gravity * dx / d; + var fy = options.gravity * dy / d; + node.offsetX += fx; + node.offsetY += fy; // s += ": Applied force: " + fx + ", " + fy; + } // s += ": skypped since it's too close to center"; + // logDebug(s); + + } + } +}; +/** + * @brief : This function propagates the existing offsets from + * parent nodes to its descendents. + * @arg layoutInfo : layoutInfo Object + * @arg cy : cytoscape Object + * @arg options : Layout options + */ + + +var propagateForces = function propagateForces(layoutInfo, options) { + // Inline implementation of a queue, used for traversing the graph in BFS order + var queue = []; + var start = 0; // Points to the start the queue + + var end = -1; // Points to the end of the queue + // logDebug('propagateForces'); + // Start by visiting the nodes in the root graph + + queue.push.apply(queue, layoutInfo.graphSet[0]); + end += layoutInfo.graphSet[0].length; // Traverse the graph, level by level, + + while (start <= end) { + // Get the node to visit and remove it from queue + var nodeId = queue[start++]; + var nodeIndex = layoutInfo.idToIndex[nodeId]; + var node = layoutInfo.layoutNodes[nodeIndex]; + var children = node.children; // We only need to process the node if it's compound + + if (0 < children.length && !node.isLocked) { + var offX = node.offsetX; + var offY = node.offsetY; // var s = "Propagating offset from parent node : " + node.id + + // ". OffsetX: " + offX + ". OffsetY: " + offY; + // s += "\n Children: " + children.toString(); + // logDebug(s); + + for (var i = 0; i < children.length; i++) { + var childNode = layoutInfo.layoutNodes[layoutInfo.idToIndex[children[i]]]; // Propagate offset + + childNode.offsetX += offX; + childNode.offsetY += offY; // Add children to queue to be visited + + queue[++end] = children[i]; + } // Reset parent offsets + + + node.offsetX = 0; + node.offsetY = 0; + } + } +}; +/** + * @brief : Updates the layout model positions, based on + * the accumulated forces + */ + + +var updatePositions = function updatePositions(layoutInfo, options) { + // var s = 'Updating positions'; + // logDebug(s); + // Reset boundaries for compound nodes + for (var i = 0; i < layoutInfo.nodeSize; i++) { + var n = layoutInfo.layoutNodes[i]; + + if (0 < n.children.length) { + // logDebug("Resetting boundaries of compound node: " + n.id); + n.maxX = undefined; + n.minX = undefined; + n.maxY = undefined; + n.minY = undefined; + } + } + + for (var i = 0; i < layoutInfo.nodeSize; i++) { + var n = layoutInfo.layoutNodes[i]; + + if (0 < n.children.length || n.isLocked) { + // No need to set compound or locked node position + // logDebug("Skipping position update of node: " + n.id); + continue; + } // s = "Node: " + n.id + " Previous position: (" + + // n.positionX + ", " + n.positionY + ")."; + // Limit displacement in order to improve stability + + + var tempForce = limitForce(n.offsetX, n.offsetY, layoutInfo.temperature); + n.positionX += tempForce.x; + n.positionY += tempForce.y; + n.offsetX = 0; + n.offsetY = 0; + n.minX = n.positionX - n.width; + n.maxX = n.positionX + n.width; + n.minY = n.positionY - n.height; + n.maxY = n.positionY + n.height; // s += " New Position: (" + n.positionX + ", " + n.positionY + ")."; + // logDebug(s); + // Update ancestry boudaries + + updateAncestryBoundaries(n, layoutInfo); + } // Update size, position of compund nodes + + + for (var i = 0; i < layoutInfo.nodeSize; i++) { + var n = layoutInfo.layoutNodes[i]; + + if (0 < n.children.length && !n.isLocked) { + n.positionX = (n.maxX + n.minX) / 2; + n.positionY = (n.maxY + n.minY) / 2; + n.width = n.maxX - n.minX; + n.height = n.maxY - n.minY; // s = "Updating position, size of compound node " + n.id; + // s += "\nPositionX: " + n.positionX + ", PositionY: " + n.positionY; + // s += "\nWidth: " + n.width + ", Height: " + n.height; + // logDebug(s); + } + } +}; +/** + * @brief : Limits a force (forceX, forceY) to be not + * greater (in modulo) than max. + 8 Preserves force direction. + */ + + +var limitForce = function limitForce(forceX, forceY, max) { + // var s = "Limiting force: (" + forceX + ", " + forceY + "). Max: " + max; + var force = Math.sqrt(forceX * forceX + forceY * forceY); + + if (force > max) { + var res = { + x: max * forceX / force, + y: max * forceY / force + }; + } else { + var res = { + x: forceX, + y: forceY + }; + } // s += ".\nResult: (" + res.x + ", " + res.y + ")"; + // logDebug(s); + + + return res; +}; +/** + * @brief : Function used for keeping track of compound node + * sizes, since they should bound all their subnodes. + */ + + +var updateAncestryBoundaries = function updateAncestryBoundaries(node, layoutInfo) { + // var s = "Propagating new position/size of node " + node.id; + var parentId = node.parentId; + + if (null == parentId) { + // If there's no parent, we are done + // s += ". No parent node."; + // logDebug(s); + return; + } // Get Parent Node + + + var p = layoutInfo.layoutNodes[layoutInfo.idToIndex[parentId]]; + var flag = false; // MaxX + + if (null == p.maxX || node.maxX + p.padRight > p.maxX) { + p.maxX = node.maxX + p.padRight; + flag = true; // s += "\nNew maxX for parent node " + p.id + ": " + p.maxX; + } // MinX + + + if (null == p.minX || node.minX - p.padLeft < p.minX) { + p.minX = node.minX - p.padLeft; + flag = true; // s += "\nNew minX for parent node " + p.id + ": " + p.minX; + } // MaxY + + + if (null == p.maxY || node.maxY + p.padBottom > p.maxY) { + p.maxY = node.maxY + p.padBottom; + flag = true; // s += "\nNew maxY for parent node " + p.id + ": " + p.maxY; + } // MinY + + + if (null == p.minY || node.minY - p.padTop < p.minY) { + p.minY = node.minY - p.padTop; + flag = true; // s += "\nNew minY for parent node " + p.id + ": " + p.minY; + } // If updated boundaries, propagate changes upward + + + if (flag) { + // logDebug(s); + return updateAncestryBoundaries(p, layoutInfo); + } // s += ". No changes in boundaries/position of parent node " + p.id; + // logDebug(s); + + + return; +}; + +var separateComponents = function separateComponents(layoutInfo, options) { + var nodes = layoutInfo.layoutNodes; + var components = []; + + for (var i = 0; i < nodes.length; i++) { + var node = nodes[i]; + var cid = node.cmptId; + var component = components[cid] = components[cid] || []; + component.push(node); + } + + var totalA = 0; + + for (var i = 0; i < components.length; i++) { + var c = components[i]; + + if (!c) { + continue; + } -var refreshPositions = function refreshPositions(layoutInfo, cy, options) { - // var s = 'Refreshing positions'; - // logDebug(s); - var layout = options.layout; - var nodes = options.eles.nodes(); - var bb = layoutInfo.boundingBox; - var coseBB = { - x1: Infinity, - x2: -Infinity, - y1: Infinity, - y2: -Infinity - }; + c.x1 = Infinity; + c.x2 = -Infinity; + c.y1 = Infinity; + c.y2 = -Infinity; - if (options.boundingBox) { - nodes.forEach(function (node) { - var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[node.data('id')]]; - coseBB.x1 = Math.min(coseBB.x1, lnode.positionX); - coseBB.x2 = Math.max(coseBB.x2, lnode.positionX); - coseBB.y1 = Math.min(coseBB.y1, lnode.positionY); - coseBB.y2 = Math.max(coseBB.y2, lnode.positionY); - }); - coseBB.w = coseBB.x2 - coseBB.x1; - coseBB.h = coseBB.y2 - coseBB.y1; + for (var j = 0; j < c.length; j++) { + var n = c[j]; + c.x1 = Math.min(c.x1, n.positionX - n.width / 2); + c.x2 = Math.max(c.x2, n.positionX + n.width / 2); + c.y1 = Math.min(c.y1, n.positionY - n.height / 2); + c.y2 = Math.max(c.y2, n.positionY + n.height / 2); + } + + c.w = c.x2 - c.x1; + c.h = c.y2 - c.y1; + totalA += c.w * c.h; } - nodes.positions(function (ele, i) { - var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[ele.data('id')]]; // s = "Node: " + lnode.id + ". Refreshed position: (" + - // lnode.positionX + ", " + lnode.positionY + ")."; - // logDebug(s); + components.sort(function (c1, c2) { + return c2.w * c2.h - c1.w * c1.h; + }); + var x = 0; + var y = 0; + var usedW = 0; + var rowH = 0; + var maxRowW = Math.sqrt(totalA) * layoutInfo.clientWidth / layoutInfo.clientHeight; - if (options.boundingBox) { - // then add extra bounding box constraint - var pctX = (lnode.positionX - coseBB.x1) / coseBB.w; - var pctY = (lnode.positionY - coseBB.y1) / coseBB.h; - return { - x: bb.x1 + pctX * bb.w, - y: bb.y1 + pctY * bb.h - }; - } else { - return { - x: lnode.positionX, - y: lnode.positionY - }; + for (var i = 0; i < components.length; i++) { + var c = components[i]; + + if (!c) { + continue; } - }); // Trigger layoutReady only on first call - if (true !== layoutInfo.ready) { - // s = 'Triggering layoutready'; - // logDebug(s); - layoutInfo.ready = true; - layout.one('layoutready', options.ready); - layout.emit({ - type: 'layoutready', - layout: this - }); + for (var j = 0; j < c.length; j++) { + var n = c[j]; + + if (!n.isLocked) { + n.positionX += x - c.x1; + n.positionY += y - c.y1; + } + } + + x += c.w + options.componentSpacing; + usedW += c.w + options.componentSpacing; + rowH = Math.max(rowH, c.h); + + if (usedW > maxRowW) { + y += rowH + options.componentSpacing; + x = 0; + usedW = 0; + rowH = 0; + } } }; @@ -20106,9 +20210,9 @@ GridLayout.prototype.run = function () { if (val == null) { return Math.min(rows, cols); } else { - var min$$1 = Math.min(rows, cols); + var min = Math.min(rows, cols); - if (min$$1 == rows) { + if (min == rows) { rows = val; } else { cols = val; @@ -20120,9 +20224,9 @@ GridLayout.prototype.run = function () { if (val == null) { return Math.max(rows, cols); } else { - var max$$1 = Math.max(rows, cols); + var max = Math.max(rows, cols); - if (max$$1 == rows) { + if (max == rows) { rows = val; } else { cols = val; @@ -20939,6 +21043,7 @@ BRp$1.findNearestElements = function (x, y, interactiveElementsOnly, isTouch) { prefixDash = ''; } + var bb = _p.labelBounds[prefix || 'main']; var text = ele.pstyle(prefixDash + 'label').value; var eventsEnabled = ele.pstyle('text-events').strValue === 'yes'; @@ -20947,17 +21052,13 @@ BRp$1.findNearestElements = function (x, y, interactiveElementsOnly, isTouch) { } var rstyle = _p.rstyle; - var bw = ele.pstyle('text-border-width').pfValue; - var pw = ele.pstyle('text-background-padding').pfValue; - var lw = preprop(rstyle, 'labelWidth', prefix) + bw + 2 * th + 2 * pw; - var lh = preprop(rstyle, 'labelHeight', prefix) + bw + 2 * th + 2 * pw; var lx = preprop(rstyle, 'labelX', prefix); var ly = preprop(rstyle, 'labelY', prefix); var theta = preprop(_p.rscratch, 'labelAngle', prefix); - var lx1 = lx - lw / 2; - var lx2 = lx + lw / 2; - var ly1 = ly - lh / 2; - var ly2 = ly + lh / 2; + var lx1 = bb.x1 - th; + var lx2 = bb.x2 + th; + var ly1 = bb.y1 - th; + var ly2 = bb.y2 + th; if (theta) { var cos = Math.cos(theta); @@ -20984,15 +21085,6 @@ BRp$1.findNearestElements = function (x, y, interactiveElementsOnly, isTouch) { } } else { // do a cheaper bb check - var bb = { - w: lw, - h: lh, - x1: lx1, - x2: lx2, - y1: ly1, - y2: ly2 - }; - if (inBoundingBox(bb, x, y)) { addEle(ele); return true; @@ -21769,7 +21861,28 @@ BRp$3.findEdgeControlPoints = function (edges) { var r = this; var cy = r.cy; var hasCompounds = cy.hasCompoundNodes(); - var hashTable = new Map$1(); + var hashTable = { + map: new Map$1(), + get: function get(pairId) { + var map2 = this.map.get(pairId[0]); + + if (map2 != null) { + return map2.get(pairId[1]); + } else { + return null; + } + }, + set: function set(pairId, val) { + var map2 = this.map.get(pairId[0]); + + if (map2 == null) { + map2 = new Map$1(); + this.map.set(pairId[0], map2); + } + + map2.set(pairId[1], val); + } + }; var pairIds = []; var haystackEdges = []; // create a table of edge (src, tgt) => list of edges between them @@ -21790,13 +21903,11 @@ BRp$3.findEdgeControlPoints = function (edges) { var edgeIsUnbundled = curveStyle === 'unbundled-bezier' || curveStyle === 'segments' || curveStyle === 'straight' || curveStyle === 'taxi'; var edgeIsBezier = curveStyle === 'unbundled-bezier' || curveStyle === 'bezier'; - - var srcIndex = _p.source.poolIndex(); - - var tgtIndex = _p.target.poolIndex(); - - var hash = (edgeIsUnbundled ? -1 : 1) * hashIntsArray([srcIndex, tgtIndex].sort()); - var pairId = hash; + var src = _p.source; + var tgt = _p.target; + var srcIndex = src.poolIndex(); + var tgtIndex = tgt.poolIndex(); + var pairId = [srcIndex, tgtIndex].sort(); var tableEntry = hashTable.get(pairId); if (tableEntry == null) { @@ -22102,18 +22213,21 @@ BRp$4.findEndpoints = function (edge) { var srcArShape = edge.pstyle('source-arrow-shape').value; var tgtDist = edge.pstyle('target-distance-from-node').pfValue; var srcDist = edge.pstyle('source-distance-from-node').pfValue; + var curveStyle = edge.pstyle('curve-style').value; var rs = edge._private.rscratch; var et = rs.edgeType; + var taxi = curveStyle === 'taxi'; var self = et === 'self' || et === 'compound'; var bezier = et === 'bezier' || et === 'multibezier' || self; var multi = et !== 'bezier'; var lines = et === 'straight' || et === 'segments'; var segments = et === 'segments'; var hasEndpts = bezier || multi || lines; + var overrideEndpts = self || taxi; var srcManEndpt = edge.pstyle('source-endpoint'); - var srcManEndptVal = self ? 'outside-to-node' : srcManEndpt.value; + var srcManEndptVal = overrideEndpts ? 'outside-to-node' : srcManEndpt.value; var tgtManEndpt = edge.pstyle('target-endpoint'); - var tgtManEndptVal = self ? 'outside-to-node' : tgtManEndpt.value; + var tgtManEndptVal = overrideEndpts ? 'outside-to-node' : tgtManEndpt.value; rs.srcManEndpt = srcManEndpt; rs.tgtManEndpt = tgtManEndpt; var p1; // last known point of edge on target side @@ -22299,7 +22413,7 @@ BRp$4.getTargetEndpoint = function (edge) { var BRp$5 = {}; function pushBezierPts(r, edge, pts) { - var qbezierAt$$1 = function qbezierAt$$1(p1, p2, p3, t) { + var qbezierAt$1 = function qbezierAt$1(p1, p2, p3, t) { return qbezierAt(p1, p2, p3, t); }; @@ -22309,8 +22423,8 @@ function pushBezierPts(r, edge, pts) { for (var i = 0; i < r.bezierProjPcts.length; i++) { var p = r.bezierProjPcts[i]; bpts.push({ - x: qbezierAt$$1(pts[0], pts[2], pts[4], p), - y: qbezierAt$$1(pts[1], pts[3], pts[5], p) + x: qbezierAt$1(pts[0], pts[2], pts[4], p), + y: qbezierAt$1(pts[1], pts[3], pts[5], p) }); } } @@ -22519,21 +22633,21 @@ BRp$6.recalculateEdgeLabelProjections = function (edge) { } // update each ctrlpt with segment info - for (var i = 0; i < ctrlpts.length; i++) { - var cp = ctrlpts[i]; - var prevCp = ctrlpts[i - 1]; + for (var _i = 0; _i < ctrlpts.length; _i++) { + var cp = ctrlpts[_i]; + var prevCp = ctrlpts[_i - 1]; if (prevCp) { cp.startDist = prevCp.startDist + prevCp.length; } - addSegment(cp, cp.p0, bpts[i * nProjs], 0, r.bezierProjPcts[0]); // first + addSegment(cp, cp.p0, bpts[_i * nProjs], 0, r.bezierProjPcts[0]); // first for (var j = 0; j < nProjs - 1; j++) { - addSegment(cp, bpts[i * nProjs + j], bpts[i * nProjs + j + 1], r.bezierProjPcts[j], r.bezierProjPcts[j + 1]); + addSegment(cp, bpts[_i * nProjs + j], bpts[_i * nProjs + j + 1], r.bezierProjPcts[j], r.bezierProjPcts[j + 1]); } - addSegment(cp, bpts[i * nProjs + nProjs - 1], cp.p2, r.bezierProjPcts[nProjs - 1], 1); // last + addSegment(cp, bpts[_i * nProjs + nProjs - 1], cp.p2, r.bezierProjPcts[nProjs - 1], 1); // last } return createControlPointInfo.cache = ctrlpts; @@ -22554,89 +22668,95 @@ BRp$6.recalculateEdgeLabelProjections = function (edge) { case 'compound': case 'bezier': case 'multibezier': - var cps = createControlPointInfo(); - var selected; - var startDist = 0; - var totalDist = 0; // find the segment we're on - - for (var i = 0; i < cps.length; i++) { - var cp = cps[isSrc ? i : cps.length - 1 - i]; - - for (var j = 0; j < cp.segments.length; j++) { - var seg = cp.segments[isSrc ? j : cp.segments.length - 1 - j]; - var lastSeg = i === cps.length - 1 && j === cp.segments.length - 1; - startDist = totalDist; - totalDist += seg.length; - - if (totalDist >= offset || lastSeg) { - selected = { - cp: cp, - segment: seg - }; + { + var cps = createControlPointInfo(); + var selected; + var startDist = 0; + var totalDist = 0; // find the segment we're on + + for (var i = 0; i < cps.length; i++) { + var _cp = cps[isSrc ? i : cps.length - 1 - i]; + + for (var j = 0; j < _cp.segments.length; j++) { + var _seg = _cp.segments[isSrc ? j : _cp.segments.length - 1 - j]; + var lastSeg = i === cps.length - 1 && j === _cp.segments.length - 1; + startDist = totalDist; + totalDist += _seg.length; + + if (totalDist >= offset || lastSeg) { + selected = { + cp: _cp, + segment: _seg + }; + break; + } + } + + if (selected) { break; } } - if (selected) { - break; - } + var cp = selected.cp; + var seg = selected.segment; + var tSegment = (offset - startDist) / seg.length; + var segDt = seg.t1 - seg.t0; + var t = isSrc ? seg.t0 + segDt * tSegment : seg.t1 - segDt * tSegment; + t = bound(0, t, 1); + p = qbezierPtAt(cp.p0, cp.p1, cp.p2, t); + angle = bezierAngle(cp.p0, cp.p1, cp.p2, t); + break; } - var cp = selected.cp; - var seg = selected.segment; - var tSegment = (offset - startDist) / seg.length; - var segDt = seg.t1 - seg.t0; - var t = isSrc ? seg.t0 + segDt * tSegment : seg.t1 - segDt * tSegment; - t = bound(0, t, 1); - p = qbezierPtAt(cp.p0, cp.p1, cp.p2, t); - angle = bezierAngle(cp.p0, cp.p1, cp.p2, t, p); - break; - case 'straight': case 'segments': case 'haystack': - var d = 0, - di, - d0; - var p0, p1; - var l = rs.allpts.length; - - for (var i = 0; i + 3 < l; i += 2) { - if (isSrc) { - p0 = { - x: rs.allpts[i], - y: rs.allpts[i + 1] - }; - p1 = { - x: rs.allpts[i + 2], - y: rs.allpts[i + 3] - }; - } else { - p0 = { - x: rs.allpts[l - 2 - i], - y: rs.allpts[l - 1 - i] - }; - p1 = { - x: rs.allpts[l - 4 - i], - y: rs.allpts[l - 3 - i] - }; - } + { + var d = 0, + di, + d0; + var p0, p1; + var l = rs.allpts.length; + + for (var _i2 = 0; _i2 + 3 < l; _i2 += 2) { + if (isSrc) { + p0 = { + x: rs.allpts[_i2], + y: rs.allpts[_i2 + 1] + }; + p1 = { + x: rs.allpts[_i2 + 2], + y: rs.allpts[_i2 + 3] + }; + } else { + p0 = { + x: rs.allpts[l - 2 - _i2], + y: rs.allpts[l - 1 - _i2] + }; + p1 = { + x: rs.allpts[l - 4 - _i2], + y: rs.allpts[l - 3 - _i2] + }; + } - di = dist(p0, p1); - d0 = d; - d += di; + di = dist(p0, p1); + d0 = d; + d += di; - if (d >= offset) { - break; + if (d >= offset) { + break; + } } - } - var pD = offset - d0; - var t = pD / di; - t = bound(0, t, 1); - p = lineAt(p0, p1, t); - angle = lineAngle(p0, p1); - break; + var pD = offset - d0; + + var _t = pD / di; + + _t = bound(0, _t, 1); + p = lineAt(p0, p1, _t); + angle = lineAngle(p0, p1); + break; + } } setRs('labelX', prefix, p.x); @@ -22662,10 +22782,19 @@ BRp$6.applyPrefixedLabelDimensions = function (ele, prefix) { var _p = ele._private; var text = this.getLabelText(ele, prefix); var labelDims = this.calculateLabelDimensions(ele, text); - setPrefixedProperty(_p.rstyle, 'labelWidth', prefix, labelDims.width); - setPrefixedProperty(_p.rscratch, 'labelWidth', prefix, labelDims.width); - setPrefixedProperty(_p.rstyle, 'labelHeight', prefix, labelDims.height); - setPrefixedProperty(_p.rscratch, 'labelHeight', prefix, labelDims.height); + var lineHeight = ele.pstyle('line-height').pfValue; + var textWrap = ele.pstyle('text-wrap').strValue; + var lines = getPrefixedProperty(_p.rscratch, 'labelWrapCachedLines', prefix) || []; + var numLines = textWrap !== 'wrap' ? 1 : Math.max(lines.length, 1); + var normPerLineHeight = labelDims.height / numLines; + var labelLineHeight = normPerLineHeight * lineHeight; + var width = labelDims.width; + var height = labelDims.height + (numLines - 1) * (lineHeight - 1) * normPerLineHeight; + setPrefixedProperty(_p.rstyle, 'labelWidth', prefix, width); + setPrefixedProperty(_p.rscratch, 'labelWidth', prefix, width); + setPrefixedProperty(_p.rstyle, 'labelHeight', prefix, height); + setPrefixedProperty(_p.rscratch, 'labelHeight', prefix, height); + setPrefixedProperty(_p.rscratch, 'labelLineHeight', prefix, labelLineHeight); }; BRp$6.getLabelText = function (ele, prefix) { @@ -22697,48 +22826,54 @@ BRp$6.getLabelText = function (ele, prefix) { var wrapStyle = ele.pstyle('text-wrap').value; if (wrapStyle === 'wrap') { - //console.log('wrap'); var labelKey = rscratch('labelKey'); // save recalc if the label is the same as before if (labelKey != null && rscratch('labelWrapKey') === labelKey) { - // console.log('wrap cache hit'); return rscratch('labelWrapCachedText'); - } // console.log('wrap cache miss'); - + } + var zwsp = "\u200B"; var lines = text.split('\n'); var maxW = ele.pstyle('text-max-width').pfValue; + var overflow = ele.pstyle('text-overflow-wrap').value; + var overflowAny = overflow === 'anywhere'; var wrappedLines = []; + var wordsRegex = /[\s\u200b]+/; + var wordSeparator = overflowAny ? '' : ' '; for (var l = 0; l < lines.length; l++) { var line = lines[l]; var lineDims = this.calculateLabelDimensions(ele, line); var lineW = lineDims.width; + if (overflowAny) { + var processedLine = line.split('').join(zwsp); + line = processedLine; + } + if (lineW > maxW) { // line is too long - var words = line.split(/\s+/); // NB: assume collapsed whitespace into single space - + var words = line.split(wordsRegex); var subline = ''; for (var w = 0; w < words.length; w++) { var word = words[w]; - var testLine = subline.length === 0 ? word : subline + ' ' + word; + var testLine = subline.length === 0 ? word : subline + wordSeparator + word; var testDims = this.calculateLabelDimensions(ele, testLine); var testW = testDims.width; if (testW <= maxW) { // word fits on current line - subline += word + ' '; + subline += word + wordSeparator; } else { // word starts new line wrappedLines.push(subline); - subline = word + ' '; + subline = word + wordSeparator; } } // if there's remaining text, put it in a wrapped line - if (!subline.match(/^\s+$/)) { + if (!subline.match(/^[\s\u200b]+$/)) { wrappedLines.push(subline); } } else { @@ -22750,9 +22885,9 @@ BRp$6.getLabelText = function (ele, prefix) { rscratch('labelWrapCachedLines', wrappedLines); text = rscratch('labelWrapCachedText', wrappedLines.join('\n')); - rscratch('labelWrapKey', labelKey); // console.log(text) + rscratch('labelWrapKey', labelKey); } else if (wrapStyle === 'ellipsis') { - var maxW = ele.pstyle('text-max-width').pfValue; + var _maxW = ele.pstyle('text-max-width').pfValue; var ellipsized = ''; var ellipsis = "\u2026"; var incLastCh = false; @@ -22760,7 +22895,7 @@ BRp$6.getLabelText = function (ele, prefix) { for (var i = 0; i < text.length; i++) { var widthWithNextCh = this.calculateLabelDimensions(ele, ellipsized + text[i] + ellipsis).width; - if (widthWithNextCh > maxW) { + if (widthWithNextCh > _maxW) { break; } @@ -22782,6 +22917,30 @@ BRp$6.getLabelText = function (ele, prefix) { return text; }; +BRp$6.getLabelJustification = function (ele) { + var justification = ele.pstyle('text-justification').strValue; + var textHalign = ele.pstyle('text-halign').strValue; + + if (justification === 'auto') { + if (ele.isNode()) { + switch (textHalign) { + case 'left': + return 'right'; + + case 'right': + return 'left'; + + default: + return 'center'; + } + } else { + return 'center'; + } + } else { + return justification; + } +}; + BRp$6.calculateLabelDimensions = function (ele, text) { var r = this; var cacheKey = hashString(text, ele._private.labelDimsKey); @@ -22918,6 +23077,7 @@ BRp$8.registerCalculationListeners = function () { var _p = ele._private; var rstyle = _p.rstyle; rstyle.clean = false; + rstyle.cleanConnected = false; } } }; @@ -22936,9 +23096,11 @@ BRp$8.registerCalculationListeners = function () { for (var i = 0; i < elesToUpdate.length; i++) { var ele = elesToUpdate[i]; + var rstyle = ele._private.rstyle; - if (ele.isNode() && !ele._private.rstyle.clean) { + if (ele.isNode() && !rstyle.cleanConnected) { enqueue(ele.connectedEdges()); + rstyle.cleanConnected = true; } } @@ -23131,9 +23293,9 @@ BRp$b.getCachedImage = function (url, crossOrigin, onLoad) { }; var BRp$c = {}; -/* global document, window */ +/* global document, window, ResizeObserver, MutationObserver */ -BRp$c.registerBinding = function (target, event$$1, handler, useCapture) { +BRp$c.registerBinding = function (target, event, handler, useCapture) { // eslint-disable-line no-unused-vars var args = Array.prototype.slice.apply(arguments, [1]); // copy @@ -23163,7 +23325,7 @@ BRp$c.binder = function (tgt) { r.supportsPassiveEvents = supportsPassive; } - var on = function on(event$$1, handler, useCapture) { + var on = function on(event, handler, useCapture) { var args = Array.prototype.slice.call(arguments); if (tgtIsDom && r.supportsPassiveEvents) { @@ -23228,8 +23390,8 @@ BRp$c.load = function () { var allowPanningPassthrough = function allowPanningPassthrough(down, downs) { var allowPassthrough = true; - if (r.cy.hasCompoundNodes() && down && down.isEdge()) { - // a compound node below the edge => no passthrough panning + if (r.cy.hasCompoundNodes() && down && down.pannable()) { + // a grabbable compound node below the ele => no passthrough panning for (var i = 0; downs && i < downs.length; i++) { var down = downs[i]; @@ -23386,7 +23548,8 @@ BRp$c.load = function () { } }; - var haveMutationsApi = typeof MutationObserver !== 'undefined'; // watch for when the cy container is removed from the dom + var haveMutationsApi = typeof MutationObserver !== 'undefined'; + var haveResizeObserverApi = typeof ResizeObserver !== 'undefined'; // watch for when the cy container is removed from the dom if (haveMutationsApi) { r.removeObserver = new MutationObserver(function (mutns) { @@ -23435,9 +23598,15 @@ BRp$c.load = function () { r.registerBinding(window, 'resize', onResize); // eslint-disable-line no-undef - var forEachUp = function forEachUp(domEle, fn$$1) { + if (haveResizeObserverApi) { + r.resizeObserver = new ResizeObserver(onResize); // eslint-disable-line no-undef + + r.resizeObserver.observe(r.container); + } + + var forEachUp = function forEachUp(domEle, fn) { while (domEle != null) { - fn$$1(domEle); + fn(domEle); domEle = domEle.parentNode; } }; @@ -23646,7 +23815,7 @@ BRp$c.load = function () { }; r.redrawHint('select', true); r.redraw(); - } else if (near.isEdge()) { + } else if (near.pannable()) { select[4] = 1; // for future pan } @@ -23812,7 +23981,7 @@ BRp$c.load = function () { pos = r.projectIntoViewport(e.clientX, e.clientY); // Checks primary button down & out of time & mouse not moved much - } else if (select[4] == 1 && (down == null || down.isEdge())) { + } else if (select[4] == 1 && (down == null || down.pannable())) { if (isOverThresholdDrag) { if (!r.hoverData.dragging && cy.boxSelectionEnabled() && (multSelKeyDown || !cy.panningEnabled() || !cy.userPanningEnabled())) { goIntoBoxMode(); @@ -23829,12 +23998,12 @@ BRp$c.load = function () { } } - if (down && down.isEdge() && down.active()) { + if (down && down.pannable() && down.active()) { down.unactivate(); } } } else { - if (down && down.isEdge() && down.active()) { + if (down && down.pannable() && down.active()) { down.unactivate(); } @@ -24253,29 +24422,30 @@ BRp$c.load = function () { r.touchData.capture = true; r.data.bgActivePosistion = undefined; var cy = r.cy; - var now$$1 = r.touchData.now; + var now = r.touchData.now; var earlier = r.touchData.earlier; if (e.touches[0]) { var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY); - now$$1[0] = pos[0]; - now$$1[1] = pos[1]; + now[0] = pos[0]; + now[1] = pos[1]; } if (e.touches[1]) { var pos = r.projectIntoViewport(e.touches[1].clientX, e.touches[1].clientY); - now$$1[2] = pos[0]; - now$$1[3] = pos[1]; + now[2] = pos[0]; + now[3] = pos[1]; } if (e.touches[2]) { var pos = r.projectIntoViewport(e.touches[2].clientX, e.touches[2].clientY); - now$$1[4] = pos[0]; - now$$1[5] = pos[1]; + now[4] = pos[0]; + now[5] = pos[1]; } // record starting points for pinch-to-zoom if (e.touches[1]) { + r.touchData.singleTouchMoved = true; freeDraggedElements(r.dragData.touchDragEles); var offsets = r.findContainerClientCoords(); offsetLeft = offsets[0]; @@ -24298,16 +24468,16 @@ BRp$c.load = function () { var cxtDistThresholdSq = cxtDistThreshold * cxtDistThreshold; if (distance1Sq < cxtDistThresholdSq && !e.touches[2]) { - var near1 = r.findNearestElement(now$$1[0], now$$1[1], true, true); - var near2 = r.findNearestElement(now$$1[2], now$$1[3], true, true); + var near1 = r.findNearestElement(now[0], now[1], true, true); + var near2 = r.findNearestElement(now[2], now[3], true, true); if (near1 && near1.isNode()) { near1.activate().emit({ originalEvent: e, type: 'cxttapstart', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }); r.touchData.start = near1; @@ -24316,8 +24486,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxttapstart', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }); r.touchData.start = near2; @@ -24326,8 +24496,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxttapstart', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }); } @@ -24344,8 +24514,14 @@ BRp$c.load = function () { } } - if (e.touches[2]) ; else if (e.touches[1]) ; else if (e.touches[0]) { - var nears = r.findNearestElements(now$$1[0], now$$1[1], true, true); + if (e.touches[2]) { + // ignore + // safari on ios pans the page otherwise (normally you should be able to preventdefault on touchmove...) + if (cy.boxSelectionEnabled()) { + e.preventDefault(); + } + } else if (e.touches[1]) ; else if (e.touches[0]) { + var nears = r.findNearestElements(now[0], now[1], true, true); var near = nears[0]; if (near != null) { @@ -24380,8 +24556,8 @@ BRp$c.load = function () { originalEvent: e, type: type, position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }; }; @@ -24399,8 +24575,8 @@ BRp$c.load = function () { } triggerEvents(near, ['touchstart', 'tapstart', 'vmousedown'], e, { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] }); if (near == null) { @@ -24422,8 +24598,8 @@ BRp$c.load = function () { && !r.touchData.selecting // box selection shouldn't allow taphold through ) { triggerEvents(r.touchData.start, ['taphold'], e, { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] }); } }, r.tapholdDuration); @@ -24432,8 +24608,8 @@ BRp$c.load = function () { if (e.touches.length >= 1) { var sPos = r.touchData.startPosition = []; - for (var i = 0; i < now$$1.length; i++) { - sPos[i] = earlier[i] = now$$1[i]; + for (var i = 0; i < now.length; i++) { + sPos[i] = earlier[i] = now[i]; } var touch0 = e.touches[0]; @@ -24451,26 +24627,26 @@ BRp$c.load = function () { var select = r.selection; var cy = r.cy; - var now$$1 = r.touchData.now; + var now = r.touchData.now; var earlier = r.touchData.earlier; var zoom = cy.zoom(); if (e.touches[0]) { var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY); - now$$1[0] = pos[0]; - now$$1[1] = pos[1]; + now[0] = pos[0]; + now[1] = pos[1]; } if (e.touches[1]) { var pos = r.projectIntoViewport(e.touches[1].clientX, e.touches[1].clientY); - now$$1[2] = pos[0]; - now$$1[3] = pos[1]; + now[2] = pos[0]; + now[3] = pos[1]; } if (e.touches[2]) { var pos = r.projectIntoViewport(e.touches[2].clientX, e.touches[2].clientY); - now$$1[4] = pos[0]; - now$$1[5] = pos[1]; + now[4] = pos[0]; + now[5] = pos[1]; } var startGPos = r.touchData.startGPosition; @@ -24479,8 +24655,8 @@ BRp$c.load = function () { if (capture && e.touches[0] && startGPos) { var disp = []; - for (var j = 0; j < now$$1.length; j++) { - disp[j] = now$$1[j] - earlier[j]; + for (var j = 0; j < now.length; j++) { + disp[j] = now[j] - earlier[j]; } var dx = e.touches[0].clientX - startGPos[0]; @@ -24514,8 +24690,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxttapend', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }; @@ -24534,8 +24710,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxtdrag', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }; r.data.bgActivePosistion = undefined; @@ -24552,7 +24728,7 @@ BRp$c.load = function () { } r.touchData.cxtDragged = true; - var near = r.findNearestElement(now$$1[0], now$$1[1], true, true); + var near = r.findNearestElement(now[0], now[1], true, true); if (!r.touchData.cxtOver || near !== r.touchData.cxtOver) { if (r.touchData.cxtOver) { @@ -24560,8 +24736,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxtdragout', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }); } @@ -24573,8 +24749,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxtdragover', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }); } @@ -24590,29 +24766,30 @@ BRp$c.load = function () { originalEvent: e, type: 'boxstart', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }); } r.touchData.selecting = true; - r.redrawHint('select', true); + r.touchData.didSelect = true; + select[4] = 1; if (!select || select.length === 0 || select[0] === undefined) { - select[0] = (now$$1[0] + now$$1[2] + now$$1[4]) / 3; - select[1] = (now$$1[1] + now$$1[3] + now$$1[5]) / 3; - select[2] = (now$$1[0] + now$$1[2] + now$$1[4]) / 3 + 1; - select[3] = (now$$1[1] + now$$1[3] + now$$1[5]) / 3 + 1; + select[0] = (now[0] + now[2] + now[4]) / 3; + select[1] = (now[1] + now[3] + now[5]) / 3; + select[2] = (now[0] + now[2] + now[4]) / 3 + 1; + select[3] = (now[1] + now[3] + now[5]) / 3 + 1; } else { - select[2] = (now$$1[0] + now$$1[2] + now$$1[4]) / 3; - select[3] = (now$$1[1] + now$$1[3] + now$$1[5]) / 3; + select[2] = (now[0] + now[2] + now[4]) / 3; + select[3] = (now[1] + now[3] + now[5]) / 3; } - select[4] = 1; - r.touchData.selecting = true; + r.redrawHint('select', true); r.redraw(); // pinch to zoom - } else if (capture && e.touches[1] && cy.zoomingEnabled() && cy.panningEnabled() && cy.userZoomingEnabled() && cy.userPanningEnabled()) { + } else if (capture && e.touches[1] && !r.touchData.didSelect // don't allow box selection to degrade to pinch-to-zoom + && cy.zoomingEnabled() && cy.panningEnabled() && cy.userZoomingEnabled() && cy.userPanningEnabled()) { // two fingers => pinch to zoom e.preventDefault(); r.data.bgActivePosistion = undefined; @@ -24696,174 +24873,174 @@ BRp$c.load = function () { if (e.touches[0]) { var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY); - now$$1[0] = pos[0]; - now$$1[1] = pos[1]; + now[0] = pos[0]; + now[1] = pos[1]; } if (e.touches[1]) { var pos = r.projectIntoViewport(e.touches[1].clientX, e.touches[1].clientY); - now$$1[2] = pos[0]; - now$$1[3] = pos[1]; + now[2] = pos[0]; + now[3] = pos[1]; } if (e.touches[2]) { var pos = r.projectIntoViewport(e.touches[2].clientX, e.touches[2].clientY); - now$$1[4] = pos[0]; - now$$1[5] = pos[1]; + now[4] = pos[0]; + now[5] = pos[1]; } - } else if (e.touches[0]) { - var start = r.touchData.start; - var last = r.touchData.last; - var near; + } else if (e.touches[0] && !r.touchData.didSelect // don't allow box selection to degrade to single finger events like panning + ) { + var start = r.touchData.start; + var last = r.touchData.last; + var near; - if (!r.hoverData.draggingEles && !r.swipePanning) { - near = r.findNearestElement(now$$1[0], now$$1[1], true, true); - } + if (!r.hoverData.draggingEles && !r.swipePanning) { + near = r.findNearestElement(now[0], now[1], true, true); + } - if (capture && start != null) { - e.preventDefault(); - } // dragging nodes + if (capture && start != null) { + e.preventDefault(); + } // dragging nodes - if (capture && start != null && r.nodeIsDraggable(start)) { - if (isOverThresholdDrag) { - // then dragging can happen - var draggedEles = r.dragData.touchDragEles; - var justStartedDrag = !r.dragData.didDrag; + if (capture && start != null && r.nodeIsDraggable(start)) { + if (isOverThresholdDrag) { + // then dragging can happen + var draggedEles = r.dragData.touchDragEles; + var justStartedDrag = !r.dragData.didDrag; - if (justStartedDrag) { - addNodesToDrag(draggedEles, { - inDragLayer: true - }); - } + if (justStartedDrag) { + addNodesToDrag(draggedEles, { + inDragLayer: true + }); + } - r.dragData.didDrag = true; - var totalShift = { - x: 0, - y: 0 - }; + r.dragData.didDrag = true; + var totalShift = { + x: 0, + y: 0 + }; - if (number(disp[0]) && number(disp[1])) { - totalShift.x += disp[0]; - totalShift.y += disp[1]; + if (number(disp[0]) && number(disp[1])) { + totalShift.x += disp[0]; + totalShift.y += disp[1]; - if (justStartedDrag) { - r.redrawHint('eles', true); - var dragDelta = r.touchData.dragDelta; + if (justStartedDrag) { + r.redrawHint('eles', true); + var dragDelta = r.touchData.dragDelta; - if (dragDelta && number(dragDelta[0]) && number(dragDelta[1])) { - totalShift.x += dragDelta[0]; - totalShift.y += dragDelta[1]; + if (dragDelta && number(dragDelta[0]) && number(dragDelta[1])) { + totalShift.x += dragDelta[0]; + totalShift.y += dragDelta[1]; + } } } - } - - r.hoverData.draggingEles = true; - draggedEles.silentShift(totalShift).emit('position drag'); - r.redrawHint('drag', true); - if (r.touchData.startPosition[0] == earlier[0] && r.touchData.startPosition[1] == earlier[1]) { - r.redrawHint('eles', true); - } + r.hoverData.draggingEles = true; + draggedEles.silentShift(totalShift).emit('position drag'); + r.redrawHint('drag', true); - r.redraw(); - } else { - // otherise keep track of drag delta for later - var dragDelta = r.touchData.dragDelta = r.touchData.dragDelta || []; + if (r.touchData.startPosition[0] == earlier[0] && r.touchData.startPosition[1] == earlier[1]) { + r.redrawHint('eles', true); + } - if (dragDelta.length === 0) { - dragDelta.push(disp[0]); - dragDelta.push(disp[1]); + r.redraw(); } else { - dragDelta[0] += disp[0]; - dragDelta[1] += disp[1]; + // otherise keep track of drag delta for later + var dragDelta = r.touchData.dragDelta = r.touchData.dragDelta || []; + + if (dragDelta.length === 0) { + dragDelta.push(disp[0]); + dragDelta.push(disp[1]); + } else { + dragDelta[0] += disp[0]; + dragDelta[1] += disp[1]; + } } - } - } // touchmove + } // touchmove - { - triggerEvents(start || near, ['touchmove', 'tapdrag', 'vmousemove'], e, { - x: now$$1[0], - y: now$$1[1] - }); + { + triggerEvents(start || near, ['touchmove', 'tapdrag', 'vmousemove'], e, { + x: now[0], + y: now[1] + }); - if ((!start || !start.grabbed()) && near != last) { - if (last) { - last.emit({ - originalEvent: e, - type: 'tapdragout', - position: { - x: now$$1[0], - y: now$$1[1] - } - }); - } + if ((!start || !start.grabbed()) && near != last) { + if (last) { + last.emit({ + originalEvent: e, + type: 'tapdragout', + position: { + x: now[0], + y: now[1] + } + }); + } - if (near) { - near.emit({ - originalEvent: e, - type: 'tapdragover', - position: { - x: now$$1[0], - y: now$$1[1] - } - }); + if (near) { + near.emit({ + originalEvent: e, + type: 'tapdragover', + position: { + x: now[0], + y: now[1] + } + }); + } } - } - r.touchData.last = near; - } // check to cancel taphold + r.touchData.last = near; + } // check to cancel taphold - if (capture) { - for (var i = 0; i < now$$1.length; i++) { - if (now$$1[i] && r.touchData.startPosition[i] && isOverThresholdDrag) { - r.touchData.singleTouchMoved = true; + if (capture) { + for (var i = 0; i < now.length; i++) { + if (now[i] && r.touchData.startPosition[i] && isOverThresholdDrag) { + r.touchData.singleTouchMoved = true; + } } - } - } // panning + } // panning - if (capture && (start == null || start.isEdge()) && cy.panningEnabled() && cy.userPanningEnabled()) { - var allowPassthrough = allowPanningPassthrough(start, r.touchData.starts); + if (capture && (start == null || start.pannable()) && cy.panningEnabled() && cy.userPanningEnabled()) { + var allowPassthrough = allowPanningPassthrough(start, r.touchData.starts); - if (allowPassthrough) { - e.preventDefault(); + if (allowPassthrough) { + e.preventDefault(); - if (r.swipePanning) { - cy.panBy({ - x: disp[0] * zoom, - y: disp[1] * zoom - }); - } else if (isOverThresholdDrag) { - r.swipePanning = true; - cy.panBy({ - x: dx * zoom, - y: dy * zoom - }); + if (!r.data.bgActivePosistion) { + r.data.bgActivePosistion = array2point(r.touchData.startPosition); + } - if (start) { - start.unactivate(); + if (r.swipePanning) { + cy.panBy({ + x: disp[0] * zoom, + y: disp[1] * zoom + }); + } else if (isOverThresholdDrag) { + r.swipePanning = true; + cy.panBy({ + x: dx * zoom, + y: dy * zoom + }); - if (!r.data.bgActivePosistion) { - r.data.bgActivePosistion = array2point(r.touchData.startPosition); + if (start) { + start.unactivate(); + r.redrawHint('select', true); + r.touchData.start = null; } - - r.redrawHint('select', true); - r.touchData.start = null; } - } - } // Re-project + } // Re-project - var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY); - now$$1[0] = pos[0]; - now$$1[1] = pos[1]; + var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY); + now[0] = pos[0]; + now[1] = pos[1]; + } } - } - for (var j = 0; j < now$$1.length; j++) { - earlier[j] = now$$1[j]; + for (var j = 0; j < now.length; j++) { + earlier[j] = now[j]; } // the active bg indicator should be removed when making a swipe that is neither for dragging nodes or panning @@ -24904,25 +25081,25 @@ BRp$c.load = function () { r.hoverData.draggingEles = false; var cy = r.cy; var zoom = cy.zoom(); - var now$$1 = r.touchData.now; + var now = r.touchData.now; var earlier = r.touchData.earlier; if (e.touches[0]) { var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY); - now$$1[0] = pos[0]; - now$$1[1] = pos[1]; + now[0] = pos[0]; + now[1] = pos[1]; } if (e.touches[1]) { var pos = r.projectIntoViewport(e.touches[1].clientX, e.touches[1].clientY); - now$$1[2] = pos[0]; - now$$1[3] = pos[1]; + now[2] = pos[0]; + now[3] = pos[1]; } if (e.touches[2]) { var pos = r.projectIntoViewport(e.touches[2].clientX, e.touches[2].clientY); - now$$1[4] = pos[0]; - now$$1[5] = pos[1]; + now[4] = pos[0]; + now[5] = pos[1]; } if (start) { @@ -24936,8 +25113,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxttapend', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }; @@ -24952,8 +25129,8 @@ BRp$c.load = function () { originalEvent: e, type: 'cxttap', position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }; @@ -24988,8 +25165,8 @@ BRp$c.load = function () { type: 'boxend', originalEvent: e, position: { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] } }); @@ -25035,22 +25212,22 @@ BRp$c.load = function () { } triggerEvents(start, ['touchend', 'tapend', 'vmouseup', 'tapdragout'], e, { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] }); start.unactivate(); r.touchData.start = null; } else { - var near = r.findNearestElement(now$$1[0], now$$1[1], true, true); + var near = r.findNearestElement(now[0], now[1], true, true); triggerEvents(near, ['touchend', 'tapend', 'vmouseup', 'tapdragout'], e, { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] }); } - var dx = r.touchData.startPosition[0] - now$$1[0]; + var dx = r.touchData.startPosition[0] - now[0]; var dx2 = dx * dx; - var dy = r.touchData.startPosition[1] - now$$1[1]; + var dy = r.touchData.startPosition[1] - now[1]; var dy2 = dy * dy; var dist2 = dx2 + dy2; var rdist2 = dist2 * zoom * zoom; // Tap event, roughly same as mouse click event for touch @@ -25061,8 +25238,8 @@ BRp$c.load = function () { } triggerEvents(start, ['tap', 'vclick'], e, { - x: now$$1[0], - y: now$$1[1] + x: now[0], + y: now[1] }); } // Prepare to select the currently touched node, only if it hasn't been dragged past a certain distance @@ -25087,19 +25264,25 @@ BRp$c.load = function () { r.touchData.singleTouchMoved = true; } - for (var j = 0; j < now$$1.length; j++) { - earlier[j] = now$$1[j]; + for (var j = 0; j < now.length; j++) { + earlier[j] = now[j]; } - r.dragData.didDrag = false; // reset for next mousedown + r.dragData.didDrag = false; // reset for next touchstart if (e.touches.length === 0) { r.touchData.dragDelta = []; r.touchData.startPosition = null; r.touchData.startGPosition = null; + r.touchData.didSelect = false; } if (e.touches.length < 2) { + if (e.touches.length === 1) { + // the old start global pos'n may not be the same finger that remains + r.touchData.startGPosition = [e.touches[0].clientX, e.touches[0].clientY]; + } + r.pinching = false; r.redrawHint('eles', true); r.redraw(); @@ -25742,10 +25925,10 @@ BRp$f.init = function (options) { } if (!stylesheetAlreadyExists) { - var stylesheet$$1 = document.createElement('style'); - stylesheet$$1.id = stylesheetId; - stylesheet$$1.innerHTML = '.' + className + ' { position: relative; }'; - head.insertBefore(stylesheet$$1, head.children[0]); // first so lowest priority + var stylesheet = document.createElement('style'); + stylesheet.id = stylesheetId; + stylesheet.innerHTML = '.' + className + ' { position: relative; }'; + head.insertBefore(stylesheet, head.children[0]); // first so lowest priority } var computedStyle = window$1.getComputedStyle(ctr); @@ -25883,6 +26066,10 @@ BRp$f.destroy = function () { r.styleObserver.disconnect(); } + if (r.resizeObserver) { + r.resizeObserver.disconnect(); + } + if (r.labelCalcDiv) { try { document.body.removeChild(r.labelCalcDiv); // eslint-disable-line no-undef @@ -25934,9 +26121,9 @@ var defs = { while (true) { // eslint-disable-line no-constant-condition - var now$$1 = performanceNow(); - var duration = now$$1 - startTime; - var frameDuration = now$$1 - frameStartTime; + var now = performanceNow(); + var duration = now - startTime; + var frameDuration = now - frameStartTime; if (renderTime < fullFpsTime) { // if we're rendering faster than the ideal fps, then do dequeueing @@ -26734,8 +26921,8 @@ var LayeredTextureCache = function LayeredTextureCache(renderer) { self.refineElementTextures(self.eleTxrDeqs); self.eleTxrDeqs.unmerge(self.eleTxrDeqs); }, refineEleDebounceTime); - r.beforeRender(function (willDraw, now$$1) { - if (now$$1 - self.lastInvalidationTime <= invalidThreshold) { + r.beforeRender(function (willDraw, now) { + if (now - self.lastInvalidationTime <= invalidThreshold) { self.skipping = true; } else { self.skipping = false; @@ -26897,7 +27084,7 @@ LTCp.getLayers = function (eles, pxRatio, lvl) { var layer = null; var maxElesPerLayer = eles.length / defNumLayers; - var allowLazyQueueing = !firstGet; + var allowLazyQueueing = !firstGet; for (var i = 0; i < eles.length; i++) { var ele = eles[i]; @@ -27404,7 +27591,7 @@ CRp$1.drawElementOverlay = function (context, ele) { } }; -CRp$1.drawCachedElementPortion = function (context, ele, eleTxrCache, pxRatio, lvl, reason, getRotation) { +CRp$1.drawCachedElementPortion = function (context, ele, eleTxrCache, pxRatio, lvl, reason, getRotation, getOpacity) { var r = this; var bb = eleTxrCache.getBoundingBox(ele); @@ -27416,7 +27603,7 @@ CRp$1.drawCachedElementPortion = function (context, ele, eleTxrCache, pxRatio, l var eleCache = eleTxrCache.getElement(ele, bb, pxRatio, lvl, reason); if (eleCache != null) { - var opacity = ele.effectiveOpacity(); + var opacity = getOpacity(r, ele); if (opacity === 0) { return; @@ -27491,6 +27678,14 @@ var getTargetLabelRotation = function getTargetLabelRotation(r, ele) { return r.getTextAngle(ele, 'target'); }; +var getOpacity = function getOpacity(r, ele) { + return ele.effectiveOpacity(); +}; + +var getTextOpacity = function getTextOpacity(e, ele) { + return ele.pstyle('text-opacity').pfValue * ele.effectiveOpacity(); +}; + CRp$1.drawCachedElement = function (context, ele, pxRatio, extent, lvl, requestHighQuality) { var r = this; var _r$data = r.data, @@ -27506,12 +27701,12 @@ CRp$1.drawCachedElement = function (context, ele, pxRatio, extent, lvl, requestH } if (!extent || boundingBoxesIntersect(bb, extent)) { - r.drawCachedElementPortion(context, ele, eleTxrCache, pxRatio, lvl, reason, getZeroRotation); - r.drawCachedElementPortion(context, ele, lblTxrCache, pxRatio, lvl, reason, getLabelRotation); + r.drawCachedElementPortion(context, ele, eleTxrCache, pxRatio, lvl, reason, getZeroRotation, getOpacity); + r.drawCachedElementPortion(context, ele, lblTxrCache, pxRatio, lvl, reason, getLabelRotation, getTextOpacity); if (ele.isEdge()) { - r.drawCachedElementPortion(context, ele, slbTxrCache, pxRatio, lvl, reason, getSourceLabelRotation); - r.drawCachedElementPortion(context, ele, tlbTxrCache, pxRatio, lvl, reason, getTargetLabelRotation); + r.drawCachedElementPortion(context, ele, slbTxrCache, pxRatio, lvl, reason, getSourceLabelRotation, getTextOpacity); + r.drawCachedElementPortion(context, ele, tlbTxrCache, pxRatio, lvl, reason, getTargetLabelRotation, getTextOpacity); } r.drawElementOverlay(context, ele); @@ -27581,7 +27776,7 @@ CRp$2.drawEdge = function (context, edge, shiftToOriginWithBb) { var r = this; var rs = edge._private.rscratch; - if (!edge.visible()) { + if (shouldDrawOpacity && !edge.visible()) { return; } // if bezier ctrl pts can not be calculated, then die @@ -27932,7 +28127,7 @@ CRp$3.drawInscribedImage = function (context, img, node, index, nodeOpacity) { var nodeTW = nodeW + (getIndexedStyle(node, 'background-width-relative-to', 'value', index) === 'inner' ? 0 : paddingX2); var nodeTH = nodeH + (getIndexedStyle(node, 'background-height-relative-to', 'value', index) === 'inner' ? 0 : paddingX2); var rs = node._private.rscratch; - var clip = node.pstyle('background-clip').value; + var clip = getIndexedStyle(node, 'background-clip', 'value', index); var shouldClip = clip === 'node'; var imgOpacity = getIndexedStyle(node, 'background-image-opacity', 'value', index) * nodeOpacity; var imgW = img.width || img.cachedW; @@ -28084,7 +28279,7 @@ CRp$4.drawElementText = function (context, ele, shiftToOriginWithBb, force, pref var r = this; if (force == null) { - if (!r.eleTextBiggerThanMin(ele)) { + if (useEleOpacity && !r.eleTextBiggerThanMin(ele)) { return; } } else if (force === false) { @@ -28098,29 +28293,16 @@ CRp$4.drawElementText = function (context, ele, shiftToOriginWithBb, force, pref return; } - var textHalign = ele.pstyle('text-halign').strValue; - - switch (textHalign) { - case 'left': - context.textAlign = 'right'; - break; - - case 'right': - context.textAlign = 'left'; - break; - - default: - // e.g. center - context.textAlign = 'center'; - } - + var justification = r.getLabelJustification(ele); + context.textAlign = justification; context.textBaseline = 'bottom'; } else { - var label = ele.pstyle('label'); + var _label = ele.pstyle('label'); + var srcLabel = ele.pstyle('source-label'); var tgtLabel = ele.pstyle('target-label'); - if ((!label || !label.value) && (!srcLabel || !srcLabel.value) && (!tgtLabel || !tgtLabel.value)) { + if ((!_label || !_label.value) && (!srcLabel || !srcLabel.value) && (!tgtLabel || !tgtLabel.value)) { return; } @@ -28180,7 +28362,7 @@ CRp$4.setupTextStyle = function (context, ele) { var labelSize = ele.pstyle('font-size').pfValue + 'px'; var labelFamily = ele.pstyle('font-family').strValue; var labelWeight = ele.pstyle('font-weight').strValue; - var opacity = ele.pstyle('text-opacity').value * (useEleOpacity ? ele.effectiveOpacity() : 1); + var opacity = useEleOpacity ? ele.effectiveOpacity() * ele.pstyle('text-opacity').value : 1; var outlineOpacity = ele.pstyle('text-outline-opacity').value * opacity; var color = ele.pstyle('color').value; var outlineColor = ele.pstyle('text-outline-color').value; @@ -28192,8 +28374,8 @@ CRp$4.setupTextStyle = function (context, ele) { }; // TODO ensure re-used -function roundRect(ctx, x, y, width, height, radius) { - var radius = radius || 5; +function roundRect(ctx, x, y, width, height) { + var radius = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 5; ctx.beginPath(); ctx.moveTo(x + radius, y); ctx.lineTo(x + width - radius, y); @@ -28234,7 +28416,7 @@ CRp$4.drawText = function (context, ele, prefix) { var rscratch = _p.rscratch; var parentOpacity = useEleOpacity ? ele.effectiveOpacity() : 1; - if (parentOpacity === 0 || ele.pstyle('text-opacity').value === 0) { + if (useEleOpacity && (parentOpacity === 0 || ele.pstyle('text-opacity').value === 0)) { return; } // use 'main' as an alias for the main label (i.e. null prefix) @@ -28245,6 +28427,8 @@ CRp$4.drawText = function (context, ele, prefix) { var textX = getPrefixedProperty(rscratch, 'labelX', prefix); var textY = getPrefixedProperty(rscratch, 'labelY', prefix); + var orgTextX, orgTextY; // used for rotation + var text = this.getLabelText(ele, prefix); if (text != null && text !== '' && !isNaN(textX) && !isNaN(textY)) { @@ -28274,8 +28458,8 @@ CRp$4.drawText = function (context, ele, prefix) { } if (theta !== 0) { - var orgTextX = textX; - var orgTextY = textY; + orgTextX = textX; + orgTextY = textY; context.translate(orgTextX, orgTextY); context.rotate(theta); textX = 0; @@ -28391,7 +28575,35 @@ CRp$4.drawText = function (context, ele, prefix) { if (ele.pstyle('text-wrap').value === 'wrap') { var lines = getPrefixedProperty(rscratch, 'labelWrapCachedLines', prefix); - var lineHeight = textH / lines.length; + var lineHeight = getPrefixedProperty(rscratch, 'labelLineHeight', prefix); + var halfTextW = textW / 2; + var justification = this.getLabelJustification(ele); + + if (justification === 'auto') ; else if (halign === 'left') { + // auto justification : right + if (justification === 'left') { + textX += -textW; + } else if (justification === 'center') { + textX += -halfTextW; + } // else same as auto + + } else if (halign === 'center') { + // auto justfication : center + if (justification === 'left') { + textX += -halfTextW; + } else if (justification === 'right') { + textX += halfTextW; + } // else same as auto + + } else if (halign === 'right') { + // auto justification : left + if (justification === 'center') { + textX += halfTextW; + } else if (justification === 'right') { + textX += textW; + } // else same as auto + + } switch (valign) { case 'top': @@ -28444,7 +28656,7 @@ CRp$5.drawNode = function (context, node, shiftToOriginWithBb) { return; // can't draw node with undefined position } - if (!node.visible()) { + if (shouldDrawOpacity && !node.visible()) { return; } @@ -28835,7 +29047,7 @@ CRp$6.paintCache = function (context) { CRp$6.createGradientStyleFor = function (context, shapeStyleName, ele, fill, opacity) { var gradientStyle; var usePaths = this.usePaths(); - var colors$$1 = ele.pstyle(shapeStyleName + '-gradient-stop-colors').value, + var colors = ele.pstyle(shapeStyleName + '-gradient-stop-colors').value, positions = ele.pstyle(shapeStyleName + '-gradient-stop-positions').pfValue; if (fill === 'radial-gradient') { @@ -28915,11 +29127,11 @@ CRp$6.createGradientStyleFor = function (context, shapeStyleName, ele, fill, opa if (!gradientStyle) return null; // invalid gradient style - var hasPositions = positions.length === colors$$1.length; - var length = colors$$1.length; + var hasPositions = positions.length === colors.length; + var length = colors.length; for (var i = 0; i < length; i++) { - gradientStyle.addColorStop(hasPositions ? positions[i] : i / (length - 1), 'rgba(' + colors$$1[i][0] + ',' + colors$$1[i][1] + ',' + colors$$1[i][2] + ',' + opacity + ')'); + gradientStyle.addColorStop(hasPositions ? positions[i] : i / (length - 1), 'rgba(' + colors[i][0] + ',' + colors[i][1] + ',' + colors[i][2] + ',' + opacity + ')'); } return gradientStyle; @@ -29250,7 +29462,7 @@ CRp$6.render = function (options) { } var extent = cy.extent(); - var vpManip = r.pinching || r.hoverData.dragging || r.swipePanning || r.data.wheelZooming || r.hoverData.draggingEles; + var vpManip = r.pinching || r.hoverData.dragging || r.swipePanning || r.data.wheelZooming || r.hoverData.draggingEles || r.cy.animated(); var hideEdges = r.hideEdgesOnViewport && vpManip; var needMbClear = []; needMbClear[r.NODE] = !needDraw[r.NODE] && motionBlur && !r.clearedForMotionBlur[r.NODE] || r.clearingMotionBlur; @@ -29770,26 +29982,38 @@ function CanvasRenderer(options) { bufferCanvases: new Array(CRp$a.BUFFER_COUNT), bufferContexts: new Array(CRp$a.CANVAS_LAYERS) }; - var tapHlOff = '-webkit-tap-highlight-color: rgba(0,0,0,0);'; + var tapHlOffAttr = '-webkit-tap-highlight-color'; + var tapHlOffStyle = 'rgba(0,0,0,0)'; r.data.canvasContainer = document.createElement('div'); // eslint-disable-line no-undef var containerStyle = r.data.canvasContainer.style; - r.data.canvasContainer.setAttribute('style', tapHlOff); + r.data.canvasContainer.style[tapHlOffAttr] = tapHlOffStyle; containerStyle.position = 'relative'; containerStyle.zIndex = '0'; containerStyle.overflow = 'hidden'; var container = options.cy.container(); container.appendChild(r.data.canvasContainer); + container.style[tapHlOffAttr] = tapHlOffStyle; + var styleMap = { + '-webkit-user-select': 'none', + '-moz-user-select': '-moz-none', + 'user-select': 'none', + '-webkit-tap-highlight-color': 'rgba(0,0,0,0)', + 'outline-style': 'none' + }; - if ((container.getAttribute('style') || '').indexOf(tapHlOff) < 0) { - container.setAttribute('style', (container.getAttribute('style') || '') + tapHlOff); + if (ms()) { + styleMap['-ms-touch-action'] = 'none'; + styleMap['touch-action'] = 'none'; } for (var i = 0; i < CRp$a.CANVAS_LAYERS; i++) { var canvas = r.data.canvases[i] = document.createElement('canvas'); // eslint-disable-line no-undef r.data.contexts[i] = canvas.getContext('2d'); - canvas.setAttribute('style', '-webkit-user-select: none; -moz-user-select: -moz-none; user-select: none; -webkit-tap-highlight-color: rgba(0,0,0,0); outline-style: none;' + (ms() ? ' -ms-touch-action: none; touch-action: none; ' : '')); + Object.keys(styleMap).forEach(function (k) { + canvas.style[k] = styleMap[k]; + }); canvas.style.position = 'absolute'; canvas.setAttribute('data-id', 'layer' + i); canvas.style.zIndex = String(CRp$a.CANVAS_LAYERS - i); @@ -30025,20 +30249,20 @@ function CanvasRenderer(options) { tlbTxrCache.onDequeue(refineInLayers); } -CRp$a.redrawHint = function (group, bool$$1) { +CRp$a.redrawHint = function (group, bool) { var r = this; switch (group) { case 'eles': - r.data.canvasNeedsRedraw[CRp$a.NODE] = bool$$1; + r.data.canvasNeedsRedraw[CRp$a.NODE] = bool; break; case 'drag': - r.data.canvasNeedsRedraw[CRp$a.DRAG] = bool$$1; + r.data.canvasNeedsRedraw[CRp$a.DRAG] = bool; break; case 'select': - r.data.canvasNeedsRedraw[CRp$a.SELECT_BOX] = bool$$1; + r.data.canvasNeedsRedraw[CRp$a.SELECT_BOX] = bool; break; } }; // whether to use Path2D caching for drawing @@ -30058,13 +30282,13 @@ CRp$a.usePaths = function () { return pathsImpld && this.pathsEnabled; }; -CRp$a.setImgSmoothing = function (context, bool$$1) { +CRp$a.setImgSmoothing = function (context, bool) { if (context.imageSmoothingEnabled != null) { - context.imageSmoothingEnabled = bool$$1; + context.imageSmoothingEnabled = bool; } else { - context.webkitImageSmoothingEnabled = bool$$1; - context.mozImageSmoothingEnabled = bool$$1; - context.msImageSmoothingEnabled = bool$$1; + context.webkitImageSmoothingEnabled = bool; + context.mozImageSmoothingEnabled = bool; + context.msImageSmoothingEnabled = bool; } }; @@ -30079,7 +30303,7 @@ CRp$a.getImgSmoothing = function (context) { CRp$a.makeOffscreenCanvas = function (width, height) { var canvas; - if ((typeof OffscreenCanvas === "undefined" ? "undefined" : _typeof(OffscreenCanvas)) !== ("undefined")) { + if ((typeof OffscreenCanvas === "undefined" ? "undefined" : _typeof(OffscreenCanvas)) !== ( "undefined" )) { canvas = new OffscreenCanvas(width, height); } else { canvas = document.createElement('canvas'); // eslint-disable-line no-undef @@ -30251,6 +30475,10 @@ function setExtension(type, name, registrant) { this.emitter().removeListener(evt, cb); return this; }, + removeAllListeners: function removeAllListeners() { + this.emitter().removeAllListeners(); + return this; + }, emit: function emit(evt, params) { this.emitter().emit(evt, params); return this; @@ -30419,28 +30647,28 @@ sheetfn.css = function (name, value) { sheetfn.style = sheetfn.css; // generate a real style object from the dummy stylesheet sheetfn.generateStyle = function (cy) { - var style$$1 = new Style(cy); - return this.appendToStyle(style$$1); + var style = new Style(cy); + return this.appendToStyle(style); }; // append a dummy stylesheet object on a real style object -sheetfn.appendToStyle = function (style$$1) { +sheetfn.appendToStyle = function (style) { for (var i = 0; i < this.length; i++) { var context = this[i]; var selector = context.selector; var props = context.properties; - style$$1.selector(selector); // apply selector + style.selector(selector); // apply selector for (var j = 0; j < props.length; j++) { var prop = props[j]; - style$$1.css(prop.name, prop.value); // apply property + style.css(prop.name, prop.value); // apply property } } - return style$$1; + return style; }; -var version = "3.5.0"; +var version = "3.9.0"; var cytoscape = function cytoscape(options) { // if no options specified, use default @@ -30467,8 +30695,8 @@ cytoscape.use = function (ext) { return this; }; -cytoscape.warnings = function (bool$$1) { - return warnings(bool$$1); +cytoscape.warnings = function (bool) { + return warnings(bool); }; // replaced by build system diff --git a/dist/cytoscape.min.js b/dist/cytoscape.min.js index 056d225459..2239a01fdc 100644 --- a/dist/cytoscape.min.js +++ b/dist/cytoscape.min.js @@ -20,4 +20,4 @@ * SOFTWARE. */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).cytoscape=t()}(this,function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;nt?1:0},I=null!=Object.assign?Object.assign.bind(Object):function(e){for(var t=arguments,n=1;n255)return;t.push(Math.floor(a))}var o=r[1]||r[2]||r[3],s=r[1]&&r[2]&&r[3];if(o&&!s)return;var l=n[4];if(void 0!==l){if((l=parseFloat(l))<0||l>1)return;t.push(l)}}return t}(e)||function(e){var t,n,r,i,a,o,s,l;function u(e,t,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?e+6*(t-e)*n:n<.5?t:n<2/3?e+(t-e)*(2/3-n)*6:e}var c=new RegExp("^hsl[a]?\\(((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?)))\\s*,\\s*((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?))[%])\\s*,\\s*((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?))[%])(?:\\s*,\\s*((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?))))?\\)$").exec(e);if(c){if((n=parseInt(c[1]))<0?n=(360- -1*n%360)%360:n>360&&(n%=360),n/=360,(r=parseFloat(c[2]))<0||r>100)return;if(r/=100,(i=parseFloat(c[3]))<0||i>100)return;if(i/=100,void 0!==(a=c[4])&&((a=parseFloat(a))<0||a>1))return;if(0===r)o=s=l=Math.round(255*i);else{var h=i<.5?i*(1+r):i+r-i*r,d=2*i-h;o=Math.round(255*u(d,h,n+1/3)),s=Math.round(255*u(d,h,n)),l=Math.round(255*u(d,h,n-1/3))}t=[o,s,l,a]}return t}(e)},A={transparent:[0,0,0,0],aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],grey:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},L=function(e){for(var t=e.map,n=e.keys,r=n.length,i=0;i=t||n<0||h&&e-u>=a}function g(){var e=J();if(f(e))return v(e);s=setTimeout(g,function(e){var n=t-(e-l);return h?Q(n,a-(e-u)):n}(e))}function v(e){return s=void 0,d&&r?p(e):(r=i=void 0,o)}function y(){var e=J(),n=f(e);if(r=arguments,i=this,l=e,n){if(void 0===s)return function(e){return u=e,s=setTimeout(g,t),c?p(e):o}(l);if(h)return s=setTimeout(g,t),p(l)}return void 0===s&&(s=setTimeout(g,t)),o}return t=te(t)||0,ee(n)&&(c=!!n.leading,a=(h="maxWait"in n)?$(te(n.maxWait)||0,t):a,d="trailing"in n?!!n.trailing:d),y.cancel=function(){void 0!==s&&clearTimeout(s),u=0,r=l=i=s=void 0},y.flush=function(){return void 0===s?o:v(J())},y},re=a?a.performance:null,ie=re&&re.now?function(){return re.now()}:function(){return Date.now()},ae=function(){if(a){if(a.requestAnimationFrame)return function(e){a.requestAnimationFrame(e)};if(a.mozRequestAnimationFrame)return function(e){a.mozRequestAnimationFrame(e)};if(a.webkitRequestAnimationFrame)return function(e){a.webkitRequestAnimationFrame(e)};if(a.msRequestAnimationFrame)return function(e){a.msRequestAnimationFrame(e)}}return function(e){e&&setTimeout(function(){e(ie())},1e3/60)}}(),oe=function(e){return ae(e)},se=ie,le=function(e){for(var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5381;!(t=e.next()).done;)n=33*n^t.value;return n>>>0},ue=function(e){return(33*(arguments.length>1&&void 0!==arguments[1]?arguments[1]:5381)^e)>>>0},ce=function(e,t){var n={value:0,done:!1},r=0,i=e.length;return le({next:function(){return r=0&&(e[r]!==t||(e.splice(r,1),n));r--);},Be=function(e){e.splice(0,e.length)},Ne=function(e,t,n){return n&&(t=M(n,t)),e[t]},Ie=function(e,t,n,r){n&&(t=M(n,t)),e[t]=r},ze="undefined"!=typeof Map?Map:function(){function e(){t(this,e),this._obj={}}return r(e,[{key:"set",value:function(e,t){return this._obj[e]=t,this}},{key:"delete",value:function(e){return this._obj[e]=void 0,this}},{key:"clear",value:function(){this._obj={}}},{key:"has",value:function(e){return void 0!==this._obj[e]}},{key:"get",value:function(e){return this._obj[e]}}]),e}(),Ae=function(){function e(n){if(t(this,e),this._obj=Object.create(null),this.size=0,null!=n){var r;r=null!=n.instanceString&&n.instanceString()===this.instanceString()?n.toArray():n;for(var i=0;it?1:0},u=function(e,t,i,a,o){var s;if(null==i&&(i=0),null==o&&(o=n),i<0)throw new Error("lo must be non-negative");for(null==a&&(a=e.length);in;0<=n?t++:t--)u.push(t);return u}.apply(this).reverse()).length;ag;0<=g?++d:--d)v.push(a(e,r));return v},f=function(e,t,r,i){var a,o,s;for(null==i&&(i=n),a=e[r];r>t&&i(a,o=e[s=r-1>>1])<0;)e[r]=o,r=s;return e[r]=a},g=function(e,t,r){var i,a,o,s,l;for(null==r&&(r=n),a=e.length,l=t,o=e[t],i=2*t+1;i0;){var k=b.pop(),C=y(k),S=k.id();if(h[S]=C,C!==1/0)for(var D=k.neighborhood().intersect(f),P=0;P0)for(n.unshift(t);c[i];){var a=c[i];n.unshift(a.edge),n.unshift(a.node),i=(r=a.node).id()}return o.spawn(n)}}}},Xe={kruskal:function(e){e=e||function(e){return 1};for(var t=this.byGroup(),n=t.nodes,r=t.edges,i=n.length,a=new Array(i),o=n,s=function(e){for(var t=0;t0;){if(l=g.pop(),u=l.id(),v.delete(u),w++,u===h){for(var E=[],k=i,C=h,S=m[C];E.unshift(k),null!=S&&E.unshift(S),null!=(k=y[C]);)S=m[C=k.id()];return{found:!0,distance:d[u],path:this.spawn(E),steps:w}}f[u]=!0;for(var D=l._private.edges,P=0;PP&&(f[D]=P,m[D]=S,b[D]=w),!i){var T=S*u+C;!i&&f[T]>P&&(f[T]=P,m[T]=C,b[T]=w)}}}for(var M=0;M1&&void 0!==arguments[1]?arguments[1]:a,r=[],i=m(e);;){if(null==i)return t.spawn();var o=y(i),l=o.edge,u=o.pred;if(r.unshift(i[0]),i.same(n)&&r.length>0)break;null!=l&&r.unshift(l),i=u}return s.spawn(r)},hasNegativeWeightCycle:g,negativeWeightCycles:[]}}},Ue=Math.sqrt(2),$e=function(e,t,n){0===n.length&&Ee("Karger-Stein must be run on a connected (sub)graph");for(var r=n[e],i=r[1],a=r[2],o=t[i],s=t[a],l=n,u=l.length-1;u>=0;u--){var c=l[u],h=c[1],d=c[2];(t[h]===o&&t[d]===s||t[h]===s&&t[d]===o)&&l.splice(u,1)}for(var p=0;pr;){var i=Math.floor(Math.random()*t.length);t=$e(i,e,t),n--}return t},Je={kargerStein:function(){var e=this.byGroup(),t=e.nodes,n=e.edges;n.unmergeBy(function(e){return e.isLoop()});var r=t.length,i=n.length,a=Math.ceil(Math.pow(Math.log(r)/Math.LN2,2)),o=Math.floor(r/Ue);if(!(r<2)){for(var s=[],l=0;l0?1:e<0?-1:0},st=function(e,t){return Math.sqrt(lt(e,t))},lt=function(e,t){var n=t.x-e.x,r=t.y-e.y;return n*n+r*r},ut=function(e){for(var t=e.length,n=0,r=0;r=e.x1&&e.y2>=e.y1)return{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,w:e.x2-e.x1,h:e.y2-e.y1};if(null!=e.w&&null!=e.h&&e.w>=0&&e.h>=0)return{x1:e.x1,y1:e.y1,x2:e.x1+e.w,y2:e.y1+e.h,w:e.w,h:e.h}}},ft=function(e,t,n){e.x1=Math.min(e.x1,t),e.x2=Math.max(e.x2,t),e.w=e.x2-e.x1,e.y1=Math.min(e.y1,n),e.y2=Math.max(e.y2,n),e.h=e.y2-e.y1},gt=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return e.x1-=t,e.x2+=t,e.y1-=t,e.y2+=t,e.w=e.x2-e.x1,e.h=e.y2-e.y1,e},vt=function(e,t){e.x1=t.x1,e.y1=t.y1,e.x2=t.x2,e.y2=t.y2,e.w=e.x2-e.x1,e.h=e.y2-e.y1},yt=function(e,t){e.x1+=t.x,e.x2+=t.x,e.y1+=t.y,e.y2+=t.y},mt=function(e,t){return!(e.x1>t.x2)&&(!(t.x1>e.x2)&&(!(e.x2t.y2)&&!(t.y1>e.y2)))))))},bt=function(e,t,n){return e.x1<=t&&t<=e.x2&&e.y1<=n&&n<=e.y2},xt=function(e,t){return bt(e,t.x1,t.y1)&&bt(e,t.x2,t.y2)},wt=function(e,t,n,r,i,a,o){var s,l=Ft(i,a),u=i/2,c=a/2,h=r-c-o;if((s=It(e,t,n,r,n-u+l-o,h,n+u-l+o,h,!1)).length>0)return s;var d=n+u+o;if((s=It(e,t,n,r,d,r-c+l-o,d,r+c-l+o,!1)).length>0)return s;var p=r+c+o;if((s=It(e,t,n,r,n-u+l-o,p,n+u-l+o,p,!1)).length>0)return s;var f,g=n-u-o;if((s=It(e,t,n,r,g,r-c+l-o,g,r+c-l+o,!1)).length>0)return s;var v=n-u+l,y=r-c+l;if((f=Bt(e,t,n,r,v,y,l+o)).length>0&&f[0]<=v&&f[1]<=y)return[f[0],f[1]];var m=n+u-l,b=r-c+l;if((f=Bt(e,t,n,r,m,b,l+o)).length>0&&f[0]>=m&&f[1]<=b)return[f[0],f[1]];var x=n+u-l,w=r+c-l;if((f=Bt(e,t,n,r,x,w,l+o)).length>0&&f[0]>=x&&f[1]>=w)return[f[0],f[1]];var E=n-u+l,k=r+c-l;return(f=Bt(e,t,n,r,E,k,l+o)).length>0&&f[0]<=E&&f[1]>=k?[f[0],f[1]]:[]},Et=function(e,t,n,r,i,a,o){var s=o,l=Math.min(n,i),u=Math.max(n,i),c=Math.min(r,a),h=Math.max(r,a);return l-s<=e&&e<=u+s&&c-s<=t&&t<=h+s},kt=function(e,t,n,r,i,a,o,s,l){var u=Math.min(n,o,i)-l,c=Math.max(n,o,i)+l,h=Math.min(r,s,a)-l,d=Math.max(r,s,a)+l;return!(ec||td)},Ct=function(e,t,n,r,i,a,o,s){var l=[];!function(e,t,n,r,i){var a,o,s,l,u,c,h,d;s=-27*(r/=e)+(t/=e)*(9*(n/=e)-t*t*2),a=(o=(3*n-t*t)/9)*o*o+(s/=54)*s,i[1]=0,h=t/3,a>0?(u=(u=s+Math.sqrt(a))<0?-Math.pow(-u,1/3):Math.pow(u,1/3),c=(c=s-Math.sqrt(a))<0?-Math.pow(-c,1/3):Math.pow(c,1/3),i[0]=-h+u+c,h+=(u+c)/2,i[4]=i[2]=-h,h=Math.sqrt(3)*(-c+u)/2,i[3]=h,i[5]=-h):(i[5]=i[3]=0,0===a?(d=s<0?-Math.pow(-s,1/3):Math.pow(s,1/3),i[0]=2*d-h,i[4]=i[2]=-(d+h)):(l=(o=-o)*o*o,l=Math.acos(s/Math.sqrt(l)),d=2*Math.sqrt(o),i[0]=-h+d*Math.cos(l/3),i[2]=-h+d*Math.cos((l+2*Math.PI)/3),i[4]=-h+d*Math.cos((l+4*Math.PI)/3)))}(1*n*n-4*n*i+2*n*o+4*i*i-4*i*o+o*o+r*r-4*r*a+2*r*s+4*a*a-4*a*s+s*s,9*n*i-3*n*n-3*n*o-6*i*i+3*i*o+9*r*a-3*r*r-3*r*s-6*a*a+3*a*s,3*n*n-6*n*i+n*o-n*e+2*i*i+2*i*e-o*e+3*r*r-6*r*a+r*s-r*t+2*a*a+2*a*t-s*t,1*n*i-n*n+n*e-i*e+r*a-r*r+r*t-a*t,l);for(var u=[],c=0;c<6;c+=2)Math.abs(l[c+1])<1e-7&&l[c]>=0&&l[c]<=1&&u.push(l[c]);u.push(1),u.push(0);for(var h,d,p,f=-1,g=0;g=0?pl?(e-i)*(e-i)+(t-a)*(t-a):u-h},Dt=function(e,t,n){for(var r,i,a,o,s=0,l=0;l=e&&e>=a||r<=e&&e<=a))continue;(e-r)/(a-r)*(o-i)+i>t&&s++}return s%2!=0},Pt=function(e,t,n,r,i,a,o,s,l){var u,c=new Array(n.length);null!=s[0]?(u=Math.atan(s[1]/s[0]),s[0]<0?u+=Math.PI/2:u=-u-Math.PI/2):u=s;for(var h,d=Math.cos(-u),p=Math.sin(-u),f=0;f0){var g=Mt(c,-l);h=Tt(g)}else h=c;return Dt(e,t,h)},Tt=function(e){for(var t,n,r,i,a,o,s,l,u=new Array(e.length/2),c=0;c=0&&f<=1&&v.push(f),g>=0&&g<=1&&v.push(g),0===v.length)return[];var y=v[0]*s[0]+e,m=v[0]*s[1]+t;return v.length>1?v[0]==v[1]?[y,m]:[y,m,v[1]*s[0]+e,v[1]*s[1]+t]:[y,m]},Nt=function(e,t,n){return t<=e&&e<=n||n<=e&&e<=t?e:e<=t&&t<=n||n<=t&&t<=e?t:n},It=function(e,t,n,r,i,a,o,s,l){var u=e-i,c=n-e,h=o-i,d=t-a,p=r-t,f=s-a,g=h*d-f*u,v=c*d-p*u,y=f*c-h*p;if(0!==y){var m=g/y,b=v/y;return-.001<=m&&m<=1.001&&-.001<=b&&b<=1.001?[e+m*c,t+m*p]:l?[e+m*c,t+m*p]:[]}return 0===g||0===v?Nt(e,n,o)===o?[o,s]:Nt(e,n,i)===i?[i,a]:Nt(i,o,n)===n?[n,r]:[]:[]},zt=function(e,t,n,r,i,a,o,s){var l,u,c,h,d,p,f=[],g=new Array(n.length),v=!0;if(null==a&&(v=!1),v){for(var y=0;y0){var m=Mt(g,-s);u=Tt(m)}else u=g}else u=n;for(var b=0;bu&&(u=t)},h=function(e){return l[e]},d=0;d0?b.edgesTo(m)[0]:m.edgesTo(b)[0];var w=r(x);m=m.id(),d[m]>d[v]+w&&(d[m]=d[v]+w,p.nodes.indexOf(m)<0?p.push(m):p.updateItem(m),u[m]=0,l[m]=[]),d[m]==d[v]+w&&(u[m]=u[m]+u[v],l[m].push(v))}else for(var E=0;E0;)for(var D=n.pop(),P=0;P0&&o.push(n[s]);0!==o.length&&i.push(r.collection(o))}return i}(c,l,t,r);return b=function(e){for(var t=0;t5&&void 0!==arguments[5]?arguments[5]:on,o=r,s=0;s=2?dn(e,t,n,0,un,cn):dn(e,t,n,0,ln)},squaredEuclidean:function(e,t,n){return dn(e,t,n,0,un)},manhattan:function(e,t,n){return dn(e,t,n,0,ln)},max:function(e,t,n){return dn(e,t,n,-1/0,hn)}};function fn(e,t,n,r,i,a){var o;return o=p(e)?e:pn[e]||pn.euclidean,0===t&&p(e)?o(i,a):o(t,n,r,i,a)}pn["squared-euclidean"]=pn.squaredEuclidean,pn.squaredeuclidean=pn.squaredEuclidean;var gn=Me({k:2,m:2,sensitivityThreshold:1e-4,distance:"euclidean",maxIterations:10,attributes:[],testMode:!1,testCentroids:null}),vn=function(e){return gn(e)},yn=function(e,t,n,r,i){var a="kMedoids"===i?function(e){return r[e](n)}:function(e){return n[e]};return fn(e,r.length,a,function(e){return r[e](t)})},mn=function(e,t,n){for(var r=n.length,i=new Array(r),a=new Array(r),o=new Array(t),s=null,l=0;ln)return!1}return!0},En=function(e,t,n){for(var r=0;ri&&(i=t[l][u],a=u);o[a].push(e[l])}for(var c=0;c=i.threshold||"dendrogram"===i.mode&&1===e.length)return!1;var p,f=t[o],g=t[r[o]];p="dendrogram"===i.mode?{left:f,right:g,key:f.key}:{value:f.value.concat(g.value),key:f.key},e[f.index]=p,e.splice(g.index,1),t[f.key]=p;for(var v=0;vn[g.key][y.key]&&(a=n[g.key][y.key])):"max"===i.linkage?(a=n[f.key][y.key],n[f.key][y.key]1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],a=!(arguments.length>5&&void 0!==arguments[5])||arguments[5];r?e=e.slice(t,n):(n0&&e.splice(0,t));for(var o=0,s=e.length-1;s>=0;s--){var l=e[s];a?isFinite(l)||(e[s]=-1/0,o++):e.splice(s,1)}i&&e.sort(function(e,t){return e-t});var u=e.length,c=Math.floor(u/2);return u%2!=0?e[c+1+o]:(e[c-1+o]+e[c+o])/2}(e):"mean"===t?function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=0,i=0,a=t;a1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=1/0,i=t;i1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=-1/0,i=t;io&&(a=l,o=t[i*e+l])}a>0&&r.push(a)}for(var u=0;u=P?(T=P,P=_,M=B):_>T&&(T=_);for(var N=0;N0?1:0;C[k%u.minIterations*t+R]=F,O+=F}if(O>0&&(k>=u.minIterations-1||k==u.maxIterations-1)){for(var V=0,q=0;q0&&r.push(i);return r}(t,a,o),j=function(e,t,n){for(var r=Rn(e,t,n),i=0;il&&(s=u,l=c)}n[i]=a[s]}return r=Rn(e,t,n)}(t,r,X),W={},H=0;H0:void 0}},clearQueue:function(){return function(){var e=void 0!==this.length?this:[this];if(!(this._private.cy||this).styleEnabled())return this;for(var t=0;t0&&this.spawn(n).updateStyle().emit("class"),this},addClass:function(e){return this.toggleClass(e,!0)},hasClass:function(e){var t=this[0];return null!=t&&t._private.classes.has(e)},toggleClass:function(e,t){f(e)||(e=e.match(/\S+/g)||[]);for(var n=void 0===t,r=[],i=0,a=this.length;i0&&this.spawn(r).updateStyle().emit("class"),this},removeClass:function(e){return this.toggleClass(e,!1)},flashClass:function(e,t){var n=this;if(null==t)t=250;else if(0===t)return n;return n.addClass(e),setTimeout(function(){n.removeClass(e)},t),n}};Qn.className=Qn.classNames=Qn.classes;var Jn={metaChar:"[\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\]\\^\\`\\{\\|\\}\\~]",comparatorOp:"=|\\!=|>|>=|<|<=|\\$=|\\^=|\\*=",boolOp:"\\?|\\!|\\^",string:'"(?:\\\\"|[^"])*"|'+"'(?:\\\\'|[^'])*'",number:B,meta:"degree|indegree|outdegree",separator:"\\s*,\\s*",descendant:"\\s+",child:"\\s+>\\s+",subject:"\\$",group:"node|edge|\\*",directedEdge:"\\s+->\\s+",undirectedEdge:"\\s+<->\\s+"};Jn.variable="(?:[\\w-]|(?:\\\\"+Jn.metaChar+"))+",Jn.value=Jn.string+"|"+Jn.number,Jn.className=Jn.variable,Jn.id=Jn.variable,function(){var e,t,n;for(e=Jn.comparatorOp.split("|"),n=0;n=0||"="!==t&&(Jn.comparatorOp+="|\\!"+t)}();var er=0,tr=1,nr=2,rr=3,ir=4,ar=5,or=6,sr=7,lr=8,ur=9,cr=10,hr=11,dr=12,pr=13,fr=14,gr=15,vr=16,yr=17,mr=18,br=19,xr=20,wr=[{selector:":selected",matches:function(e){return e.selected()}},{selector:":unselected",matches:function(e){return!e.selected()}},{selector:":selectable",matches:function(e){return e.selectable()}},{selector:":unselectable",matches:function(e){return!e.selectable()}},{selector:":locked",matches:function(e){return e.locked()}},{selector:":unlocked",matches:function(e){return!e.locked()}},{selector:":visible",matches:function(e){return e.visible()}},{selector:":hidden",matches:function(e){return!e.visible()}},{selector:":transparent",matches:function(e){return e.transparent()}},{selector:":grabbed",matches:function(e){return e.grabbed()}},{selector:":free",matches:function(e){return!e.grabbed()}},{selector:":removed",matches:function(e){return e.removed()}},{selector:":inside",matches:function(e){return!e.removed()}},{selector:":grabbable",matches:function(e){return e.grabbable()}},{selector:":ungrabbable",matches:function(e){return!e.grabbable()}},{selector:":animated",matches:function(e){return e.animated()}},{selector:":unanimated",matches:function(e){return!e.animated()}},{selector:":parent",matches:function(e){return e.isParent()}},{selector:":childless",matches:function(e){return e.isChildless()}},{selector:":child",matches:function(e){return e.isChild()}},{selector:":orphan",matches:function(e){return e.isOrphan()}},{selector:":nonorphan",matches:function(e){return e.isChild()}},{selector:":compound",matches:function(e){return e.isNode()?e.isParent():e.source().isParent()||e.target().isParent()}},{selector:":loop",matches:function(e){return e.isLoop()}},{selector:":simple",matches:function(e){return e.isSimple()}},{selector:":active",matches:function(e){return e.active()}},{selector:":inactive",matches:function(e){return!e.active()}},{selector:":backgrounding",matches:function(e){return e.backgrounding()}},{selector:":nonbackgrounding",matches:function(e){return!e.backgrounding()}}].sort(function(e,t){return function(e,t){return-1*N(e,t)}(e.selector,t.selector)}),Er=function(){for(var e,t={},n=0;n0&&l.edgeCount>0)return Ce("The selector `"+e+"` is invalid because it uses both a compound selector and an edge selector"),!1;if(l.edgeCount>1)return Ce("The selector `"+e+"` is invalid because it uses multiple edge selectors"),!1;1===l.edgeCount&&Ce("The selector `"+e+"` is deprecated. Edge selectors do not take effect on changes to source and target nodes after an edge is added, for performance reasons. Use a class or data selector on edges instead, updating the class or data of an edge when your app detects a change in source or target nodes.")}return!0},toString:function(){if(null!=this.toStringCache)return this.toStringCache;for(var e=function(e){return null==e?"":e},t=function(t){return d(t)?'"'+t+'"':e(t)},n=function(e){return" "+e+" "},r=function(r,a){var o=r.type,s=r.value;switch(o){case er:var l=e(s);return l.substring(0,l.length-1);case rr:var u=r.field,c=r.operator;return"["+u+n(e(c))+t(s)+"]";case ar:var h=r.operator,d=r.field;return"["+e(h)+d+"]";case ir:return"["+r.field+"]";case or:var p=r.operator;return"[["+r.field+n(e(p))+t(s)+"]]";case sr:return s;case lr:return"#"+s;case ur:return"."+s;case yr:case gr:return i(r.parent,a)+n(">")+i(r.child,a);case mr:case vr:return i(r.ancestor,a)+" "+i(r.descendant,a);case br:var f=i(r.left,a),g=i(r.subject,a),v=i(r.right,a);return f+(f.length>0?" ":"")+g+v;case xr:return""}},i=function(e,t){return e.checks.reduce(function(n,i,a){return n+(t===e&&0===a?"$":"")+r(i,t)},"")},a="",o=0;o1&&o=0&&(t=t.replace("!",""),c=!0),t.indexOf("@")>=0&&(t=t.replace("@",""),u=!0),(o||l||u)&&(i=o||s?""+e:"",a=""+n),u&&(e=i=i.toLowerCase(),n=a=a.toLowerCase()),t){case"*=":r=i.indexOf(a)>=0;break;case"$=":r=i.indexOf(a,i.length-a.length)>=0;break;case"^=":r=0===i.indexOf(a);break;case"=":r=e===n;break;case">":h=!0,r=e>n;break;case">=":h=!0,r=e>=n;break;case"<":h=!0,r=e0;){var u=i.shift();t(u),a.add(u.id()),o&&r(i,a,u)}return e}function qr(e,t,n){if(n.isParent())for(var r=n._private.children,i=0;i1&&void 0!==arguments[1])||arguments[1],qr)},Fr.forEachUp=function(e){return Vr(this,e,!(arguments.length>1&&void 0!==arguments[1])||arguments[1],Yr)},Fr.forEachUpAndDown=function(e){return Vr(this,e,!(arguments.length>1&&void 0!==arguments[1])||arguments[1],Xr)},Fr.ancestors=Fr.parents,(Lr=Or={data:Un.data({field:"data",bindingEvent:"data",allowBinding:!0,allowSetting:!0,settingEvent:"data",settingTriggersEvent:!0,triggerFnName:"trigger",allowGetting:!0,immutableKeys:{id:!0,source:!0,target:!0,parent:!0},updateStyle:!0}),removeData:Un.removeData({field:"data",event:"data",triggerFnName:"trigger",triggerEvent:!0,immutableKeys:{id:!0,source:!0,target:!0,parent:!0},updateStyle:!0}),scratch:Un.data({field:"scratch",bindingEvent:"scratch",allowBinding:!0,allowSetting:!0,settingEvent:"scratch",settingTriggersEvent:!0,triggerFnName:"trigger",allowGetting:!0,updateStyle:!0}),removeScratch:Un.removeData({field:"scratch",event:"scratch",triggerFnName:"trigger",triggerEvent:!0,updateStyle:!0}),rscratch:Un.data({field:"rscratch",allowBinding:!1,allowSetting:!0,settingTriggersEvent:!1,allowGetting:!0}),removeRscratch:Un.removeData({field:"rscratch",triggerEvent:!1}),id:function(){var e=this[0];if(e)return e._private.data.id}}).attr=Lr.data,Lr.removeAttr=Lr.removeData;var jr,Wr,Hr=Or,Kr={};function Gr(e){return function(t){if(void 0===t&&(t=!0),0!==this.length&&this.isNode()&&!this.removed()){for(var n=0,r=this[0],i=r._private.edges,a=0;at}),minIndegree:Zr("indegree",function(e,t){return et}),minOutdegree:Zr("outdegree",function(e,t){return et})}),I(Kr,{totalDegree:function(e){for(var t=0,n=this.nodes(),r=0;r0,c=u;u&&(l=l[0]);var h=c?l.position():{x:0,y:0};return i={x:s.x-h.x,y:s.y-h.y},void 0===e?i:i[e]}for(var p=0;p0,m=y;y&&(v=v[0]);var b=m?v.position():{x:0,y:0};void 0!==t?f.position(e,t+b[e]):void 0!==i&&f.position({x:i.x+b.x,y:i.y+b.y})}}else if(!a)return;return this}}).modelPosition=jr.point=jr.position,jr.modelPositions=jr.points=jr.positions,jr.renderedPoint=jr.renderedPosition,jr.relativePoint=jr.relativePosition;var Qr,Jr,ei=Wr;Qr=Jr={},Jr.renderedBoundingBox=function(e){var t=this.boundingBox(e),n=this.cy(),r=n.zoom(),i=n.pan(),a=t.x1*r+i.x,o=t.x2*r+i.x,s=t.y1*r+i.y,l=t.y2*r+i.y;return{x1:a,x2:o,y1:s,y2:l,w:o-a,h:l-s}},Jr.dirtyCompoundBoundsCache=function(){var e=this.cy();return e.styleEnabled()&&e.hasCompoundNodes()?(this.forEachUp(function(e){if(e.isParent()){var t=e._private;t.compoundBoundsClean=!1,t.bbCache=null,e.emitAndNotify("bounds")}}),this):this},Jr.updateCompoundBounds=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.cy();if(!t.styleEnabled()||!t.hasCompoundNodes())return this;if(!e&&t.batching())return this;function n(e){if(e.isParent()){var t=e._private,n=e.children(),r="include"===e.pstyle("compound-sizing-wrt-labels").value,i={width:{val:e.pstyle("min-width").pfValue,left:e.pstyle("min-width-bias-left"),right:e.pstyle("min-width-bias-right")},height:{val:e.pstyle("min-height").pfValue,top:e.pstyle("min-height-bias-top"),bottom:e.pstyle("min-height-bias-bottom")}},a=n.boundingBox({includeLabels:r,includeOverlays:!1,useCache:!1}),o=t.position;0!==a.w&&0!==a.h||((a={w:e.pstyle("width").pfValue,h:e.pstyle("height").pfValue}).x1=o.x-a.w/2,a.x2=o.x+a.w/2,a.y1=o.y-a.h/2,a.y2=o.y+a.h/2);var s=i.width.left.value;"px"===i.width.left.units&&i.width.val>0&&(s=100*s/i.width.val);var l=i.width.right.value;"px"===i.width.right.units&&i.width.val>0&&(l=100*l/i.width.val);var u=i.height.top.value;"px"===i.height.top.units&&i.height.val>0&&(u=100*u/i.height.val);var c=i.height.bottom.value;"px"===i.height.bottom.units&&i.height.val>0&&(c=100*c/i.height.val);var h=y(i.width.val-a.w,s,l),d=h.biasDiff,p=h.biasComplementDiff,f=y(i.height.val-a.h,u,c),g=f.biasDiff,v=f.biasComplementDiff;t.autoPadding=function(e,t,n,r){if("%"!==n.units)return"px"===n.units?n.pfValue:0;switch(r){case"width":return e>0?n.pfValue*e:0;case"height":return t>0?n.pfValue*t:0;case"average":return e>0&&t>0?n.pfValue*(e+t)/2:0;case"min":return e>0&&t>0?e>t?n.pfValue*t:n.pfValue*e:0;case"max":return e>0&&t>0?e>t?n.pfValue*e:n.pfValue*t:0;default:return 0}}(a.w,a.h,e.pstyle("padding"),e.pstyle("padding-relative-to").value),t.autoWidth=Math.max(a.w,i.width.val),o.x=(-d+a.x1+a.x2+p)/2,t.autoHeight=Math.max(a.h,i.height.val),o.y=(-g+a.y1+a.y2+v)/2}function y(e,t,n){var r=0,i=0,a=t+n;return e>0&&a>0&&(r=t/a*e,i=n/a*e),{biasDiff:r,biasComplementDiff:i}}}for(var r=0;re.x2?r:e.x2,e.y1=ne.y2?i:e.y2,e.w=e.x2-e.x1,e.h=e.y2-e.y1)},ri=function(e,t){return ni(e,t.x1,t.y1,t.x2,t.y2)},ii=function(e,t,n){return Ne(e,t,n)},ai=function(e,t,n){if(!t.cy().headless()){var r,i,a=t._private,o=a.rstyle,s=o.arrowWidth/2;if("none"!==t.pstyle(n+"-arrow-shape").value){"source"===n?(r=o.srcX,i=o.srcY):"target"===n?(r=o.tgtX,i=o.tgtY):(r=o.midX,i=o.midY);var l=a.arrowBounds=a.arrowBounds||{},u=l[n]=l[n]||{};u.x1=r-s,u.y1=i-s,u.x2=r+s,u.y2=i+s,u.w=u.x2-u.x1,u.h=u.y2-u.y1,gt(u,1),ni(e,u.x1,u.y1,u.x2,u.y2)}}},oi=function(e,t,n){if(!t.cy().headless()){var r;r=n?n+"-":"";var i=t._private,a=i.rstyle;if(t.pstyle(r+"label").strValue){var o,s,l,u,c=t.pstyle("text-halign"),h=t.pstyle("text-valign"),d=ii(a,"labelWidth",n),p=ii(a,"labelHeight",n),f=ii(a,"labelX",n),g=ii(a,"labelY",n),v=t.pstyle(r+"text-margin-x").pfValue,y=t.pstyle(r+"text-margin-y").pfValue,m=t.isEdge(),b=t.pstyle(r+"text-rotation"),x=t.pstyle("text-outline-width").pfValue,w=t.pstyle("text-border-width").pfValue/2,E=t.pstyle("text-background-padding").pfValue,k=p+2*E,C=d+2*E,S=C/2,D=k/2;if(m)o=f-S,s=f+S,l=g-D,u=g+D;else{switch(c.value){case"left":o=f-C,s=f;break;case"center":o=f-S,s=f+S;break;case"right":o=f,s=f+C}switch(h.value){case"top":l=g-k,u=g;break;case"center":l=g-D,u=g+D;break;case"bottom":l=g,u=g+k}}o+=v-Math.max(x,w),s+=v+Math.max(x,w),l+=y-Math.max(x,w),u+=y+Math.max(x,w);var P=n||"main",T=i.labelBounds,M=T[P]=T[P]||{};M.x1=o,M.y1=l,M.x2=s,M.y2=u,M.w=s-o,M.h=u-l,gt(M,1);var _=m&&"autorotate"===b.strValue,B=null!=b.pfValue&&0!==b.pfValue;if(_||B){var N=_?ii(i.rstyle,"labelAngle",n):b.pfValue,I=Math.cos(N),z=Math.sin(N),A=(o+s)/2,L=(l+u)/2;if(!m){switch(c.value){case"left":A=s;break;case"right":A=o}switch(h.value){case"top":L=u;break;case"bottom":L=l}}var O=function(e,t){return{x:(e-=A)*I-(t-=L)*z+A,y:e*z+t*I+L}},R=O(o,l),F=O(o,u),V=O(s,l),q=O(s,u);o=Math.min(R.x,F.x,V.x,q.x),s=Math.max(R.x,F.x,V.x,q.x),l=Math.min(R.y,F.y,V.y,q.y),u=Math.max(R.y,F.y,V.y,q.y)}ni(e,o,l,s,u),ni(i.labelBounds.all,o,l,s,u)}return e}},si=function(e){var t=0,n=function(e){return(e?1:0)<(r=S[1].x)){var D=n;n=r,r=D}if(i>(a=S[1].y)){var P=i;i=a,a=P}ni(d,n-w,i-w,r+w,a+w)}else{for(var T=m.bezierPts||m.linePts||[],M=0;M(r=N.x)){var I=n;n=r,r=I}if((i=B.y)>(a=N.y)){var z=i;i=a,a=z}ni(d,n-=w,i-=w,r+=w,a+=w)}}if(c&&t.includeEdges&&v&&(ai(d,e,"mid-source"),ai(d,e,"mid-target"),ai(d,e,"source"),ai(d,e,"target")),c&&"yes"===e.pstyle("ghost").value){var A=e.pstyle("ghost-offset-x").pfValue,L=e.pstyle("ghost-offset-y").pfValue;ni(d,d.x1+A,d.y1+L,d.x2+A,d.y2+L)}var O=p.bodyBounds=p.bodyBounds||{};vt(O,d),gt(O,b),gt(O,1),c&&(n=d.x1,r=d.x2,i=d.y1,a=d.y2,ni(d,n-x,i-x,r+x,a+x));var R=p.overlayBounds=p.overlayBounds||{};vt(R,d),gt(R,b),gt(R,1);var F=p.labelBounds=p.labelBounds||{};null!=F.all?((l=F.all).x1=1/0,l.y1=1/0,l.x2=-1/0,l.y2=-1/0,l.w=0,l.h=0):F.all=pt(),c&&t.includeLabels&&(oi(d,e,null),v&&(oi(d,e,"source"),oi(d,e,"target")))}return d.x1=ti(d.x1),d.y1=ti(d.y1),d.x2=ti(d.x2),d.y2=ti(d.y2),d.w=ti(d.x2-d.x1),d.h=ti(d.y2-d.y1),d.w>0&&d.h>0&&y&&(gt(d,b),gt(d,1)),d}(e,ci),r.bbCache=n,r.bbCacheShift.x=r.bbCacheShift.y=0,r.bbCachePosKey=a):n=r.bbCache,!s&&(0!==r.bbCacheShift.x||0!==r.bbCacheShift.y)){var l=yt,u=r.bbCacheShift,c=function(e,t){null!=e&&l(e,t)};l(n,u);var h=r.bodyBounds,d=r.overlayBounds,p=r.labelBounds,f=r.arrowBounds;c(h,u),c(d,u),null!=f&&(c(f.source,u),c(f.target,u),c(f["mid-source"],u),c(f["mid-target"],u)),null!=p&&(c(p.main,u),c(p.all,u),c(p.source,u),c(p.target,u))}if(r.bbCacheShift.x=r.bbCacheShift.y=0,!i){var g=e.isNode();n=pt(),(t.includeNodes&&g||t.includeEdges&&!g)&&(t.includeOverlays?ri(n,r.overlayBounds):ri(n,r.bodyBounds)),t.includeLabels&&ri(n,r.labelBounds.all),n.w=n.x2-n.x1,n.h=n.y2-n.y1}return n},ci={includeNodes:!0,includeEdges:!0,includeLabels:!0,includeOverlays:!0,useCache:!0},hi=si(ci),di=Me(ci);Jr.boundingBox=function(e){if(1===this.length&&null!=this[0]._private.bbCache&&(void 0===e||void 0===e.useCache||!0===e.useCache))return e=void 0===e?ci:di(e),ui(this[0],e);var t=pt(),n=di(e=e||ci);if(this.cy().styleEnabled())for(var r=0;r=0;s--)o(s);return this},Ti.emit=Ti.trigger=function(e,t,n){var r=this.listeners,i=r.length;return this.emitting++,f(t)||(t=[t]),Bi(this,function(e,a){null!=n&&(r=[{event:a.event,type:a.type,namespace:a.namespace,callback:n}],i=r.length);for(var o=function(n){var i=r[n];if(i.type===a.type&&(!i.namespace||i.namespace===a.namespace||".*"===i.namespace)&&e.eventMatches(e.context,i,a)){var o=[a];null!=t&&function(e,t){for(var n=0;n1&&!r){var i=this.length-1,a=this[i],o=a._private.data.id;this[i]=void 0,this[e]=a,n.set(o,{ele:a,index:e})}return this.length--,this},unmergeOne:function(e){e=e[0];var t=this._private,n=e._private.data.id,r=t.map.get(n);if(!r)return this;var i=r.index;return this.unmergeAt(i),this},unmerge:function(e){var t=this._private.cy;if(!e)return this;if(e&&d(e)){var n=e;e=t.mutableElements().filter(n)}for(var r=0;r=0;t--){e(this[t])&&this.unmergeAt(t)}return this},map:function(e,t){for(var n=[],r=0;rr&&(r=o,n=a)}return{value:r,ele:n}},min:function(e,t){for(var n,r=1/0,i=0;i=0&&i1&&void 0!==arguments[1])||arguments[1],n=this[0],r=n.cy();if(r.styleEnabled()&&n){var i=n._private.style[e];return null!=i?i:t?r.style().getDefaultProperty(e):null}},numericStyle:function(e){var t=this[0];if(t.cy().styleEnabled()&&t){var n=t.pstyle(e);return void 0!==n.pfValue?n.pfValue:n.value}},numericStyleUnits:function(e){var t=this[0];if(t.cy().styleEnabled())return t?t.pstyle(e).units:void 0},renderedStyle:function(e){var t=this.cy();if(!t.styleEnabled())return this;var n=this[0];return n?t.style().getRenderedStyle(n,e):void 0},style:function(e,t){var n=this.cy();if(!n.styleEnabled())return this;var r=n.style();if(g(e)){var i=e;r.applyBypass(this,i,!1),this.emitAndNotify("style")}else if(d(e)){if(void 0===t){var a=this[0];return a?r.getStylePropertyValue(a,e):void 0}r.applyBypass(this,e,t,!1),this.emitAndNotify("style")}else if(void 0===e){var o=this[0];return o?r.getRawStyle(o):void 0}return this},removeStyle:function(e){var t=this.cy();if(!t.styleEnabled())return this;var n=t.style();if(void 0===e)for(var r=0;r0&&t.push(c[0]),t.push(s[0])}return this.spawn(t,{unique:!0}).filter(e)},"neighborhood"),closedNeighborhood:function(e){return this.neighborhood().add(this).filter(e)},openNeighborhood:function(e){return this.neighborhood(e)}}),ta.neighbourhood=ta.neighborhood,ta.closedNeighbourhood=ta.closedNeighborhood,ta.openNeighbourhood=ta.openNeighborhood,I(ta,{source:Rr(function(e){var t,n=this[0];return n&&(t=n._private.source||n.cy().collection()),t&&e?t.filter(e):t},"source"),target:Rr(function(e){var t,n=this[0];return n&&(t=n._private.target||n.cy().collection()),t&&e?t.filter(e):t},"target"),sources:aa({attr:"source"}),targets:aa({attr:"target"})}),I(ta,{edgesWith:Rr(oa(),"edgesWith"),edgesTo:Rr(oa({thisIsSrc:!0}),"edgesTo")}),I(ta,{connectedEdges:Rr(function(e){for(var t=[],n=0;n0);return a},component:function(){var e=this[0];return e.cy().mutableElements().components(e)[0]}}),ta.componentsOf=ta.components;var la=function(e,t,n){for(var r=null!=n?n:De();e.hasElementWithId(r);)r=De();return r},ua=function(e,t,n){if(void 0!==e&&w(e)){var r=new ze,i=!1;if(t){if(t.length>0&&g(t[0])&&!b(t[0])){i=!0;for(var a=[],o=new Le,s=0,l=t.length;s0&&void 0!==arguments[0])||arguments[0],r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],i=this.cy(),a=i._private,o=[],s=[],l=0,u=this.length;l0){for(var L=new ua(i,e),O=0;O0&&void 0!==arguments[0])||arguments[0],t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=[],r={},i=this._private.cy;function a(e){var i=r[e.id()];t&&e.removed()||i||(r[e.id()]=!0,e.isNode()?(n.push(e),function(e){for(var t=e._private.edges,n=0;n0&&(e?E.emitAndNotify("remove"):t&&E.emit("remove"));for(var k=0;k=a?function(t,r){for(var a=0;a0?i=l:r=l}while(Math.abs(a)>o&&++u1e-4&&Math.abs(s.v)>1e-4;);return a?function(e){return u[e*(u.length-1)|0]}:c}}(),fa=function(e,t,n,r){var i=da(e,t,n,r);return function(e,t,n){return e+(t-e)*i(n)}},ga={linear:function(e,t,n){return e+(t-e)*n},ease:fa(.25,.1,.25,1),"ease-in":fa(.42,0,1,1),"ease-out":fa(0,0,.58,1),"ease-in-out":fa(.42,0,.58,1),"ease-in-sine":fa(.47,0,.745,.715),"ease-out-sine":fa(.39,.575,.565,1),"ease-in-out-sine":fa(.445,.05,.55,.95),"ease-in-quad":fa(.55,.085,.68,.53),"ease-out-quad":fa(.25,.46,.45,.94),"ease-in-out-quad":fa(.455,.03,.515,.955),"ease-in-cubic":fa(.55,.055,.675,.19),"ease-out-cubic":fa(.215,.61,.355,1),"ease-in-out-cubic":fa(.645,.045,.355,1),"ease-in-quart":fa(.895,.03,.685,.22),"ease-out-quart":fa(.165,.84,.44,1),"ease-in-out-quart":fa(.77,0,.175,1),"ease-in-quint":fa(.755,.05,.855,.06),"ease-out-quint":fa(.23,1,.32,1),"ease-in-out-quint":fa(.86,0,.07,1),"ease-in-expo":fa(.95,.05,.795,.035),"ease-out-expo":fa(.19,1,.22,1),"ease-in-out-expo":fa(1,0,0,1),"ease-in-circ":fa(.6,.04,.98,.335),"ease-out-circ":fa(.075,.82,.165,1),"ease-in-out-circ":fa(.785,.135,.15,.86),spring:function(e,t,n){if(0===n)return ga.linear;var r=pa(e,t,n);return function(e,t,n){return e+(t-e)*r(n)}},"cubic-bezier":fa};function va(e,t,n,r,i){if(1===r)return n;var a=i(t,n,r);return null==e?a:((e.roundValue||e.color)&&(a=Math.round(a)),void 0!==e.min&&(a=Math.max(a,e.min)),void 0!==e.max&&(a=Math.min(a,e.max)),a)}function ya(e,t){return null!=e.pfValue||null!=e.value?null==e.pfValue||null!=t&&"%"===t.type.units?e.value:e.pfValue:e}function ma(e,t,n,r,i){var a=null!=i?i.type:null;n<0?n=0:n>1&&(n=1);var o=ya(e,i),s=ya(t,i);if(v(o)&&v(s))return va(a,o,s,n,r);if(f(o)&&f(s)){for(var l=[],u=0;u0?("spring"===h&&p.push(o.duration),o.easingImpl=ga[h].apply(null,p)):o.easingImpl=ga[h]}var f,g=o.easingImpl;if(f=0===o.duration?1:(n-l)/o.duration,o.applying&&(f=o.progress),f<0?f=0:f>1&&(f=1),null==o.delay){var v=o.startPosition,y=o.position;if(y&&i&&!e.locked()){var m={};xa(v.x,y.x)&&(m.x=ma(v.x,y.x,f,g)),xa(v.y,y.y)&&(m.y=ma(v.y,y.y,f,g)),e.position(m)}var b=o.startPan,x=o.pan,w=a.pan,E=null!=x&&r;E&&(xa(b.x,x.x)&&(w.x=ma(b.x,x.x,f,g)),xa(b.y,x.y)&&(w.y=ma(b.y,x.y,f,g)),e.emit("pan"));var k=o.startZoom,C=o.zoom,S=null!=C&&r;S&&(xa(k,C)&&(a.zoom=ma(k,C,f,g)),e.emit("zoom")),(E||S)&&e.emit("viewport");var D=o.style;if(D&&D.length>0&&i){for(var P=0;P=0;t--){(0,e[t])()}e.splice(0,e.length)},h=a.length-1;h>=0;h--){var d=a[h],p=d._private;p.stopped?(a.splice(h,1),p.hooked=!1,p.playing=!1,p.started=!1,c(p.frames)):(p.playing||p.applying)&&(p.playing&&p.applying&&(p.applying=!1),p.started||wa(0,d,e),ba(t,d,e,n),p.applying&&(p.applying=!1),c(p.frames),null!=p.step&&p.step(e),d.completed()&&(a.splice(h,1),p.hooked=!1,p.playing=!1,p.started=!1,c(p.completes)),s=!0)}return n||0!==a.length||0!==o.length||r.push(t),s}for(var a=!1,o=0;o0?t.notify("draw",n):t.notify("draw")),n.unmerge(r),t.emit("step")}var ka={animate:Un.animate(),animation:Un.animation(),animated:Un.animated(),clearQueue:Un.clearQueue(),delay:Un.delay(),delayAnimation:Un.delayAnimation(),stop:Un.stop(),addToAnimationPool:function(e){this.styleEnabled()&&this._private.aniEles.merge(e)},stopAnimationLoop:function(){this._private.animationsRunning=!1},startAnimationLoop:function(){var e=this;if(e._private.animationsRunning=!0,e.styleEnabled()){var t=e.renderer();t&&t.beforeRender?t.beforeRender(function(t,n){Ea(n,e)},t.beforeRenderPriorities.animations):function t(){e._private.animationsRunning&&oe(function(n){Ea(n,e),t()})}()}}},Ca={qualifierCompare:function(e,t){return null==e||null==t?null==e&&null==t:e.sameText(t)},eventMatches:function(e,t,n){var r=t.qualifier;return null==r||e!==n.target&&b(n.target)&&r.matches(n.target)},addEventFields:function(e,t){t.cy=e,t.target=e},callbackContext:function(e,t,n){return null!=t.qualifier?n.target:e}},Sa=function(e){return d(e)?new Ir(e):e},Da={createEmitter:function(){var e=this._private;return e.emitter||(e.emitter=new Pi(Ca,this)),this},emitter:function(){return this._private.emitter},on:function(e,t,n){return this.emitter().on(e,Sa(t),n),this},removeListener:function(e,t,n){return this.emitter().removeListener(e,Sa(t),n),this},one:function(e,t,n){return this.emitter().one(e,Sa(t),n),this},once:function(e,t,n){return this.emitter().one(e,Sa(t),n),this},emit:function(e,t){return this.emitter().emit(e,t),this},emitAndNotify:function(e,t){return this.emit(e),this.notify(e,t),this}};Un.eventAliasesOn(Da);var Pa={png:function(e){return e=e||{},this._private.renderer.png(e)},jpg:function(e){var t=this._private.renderer;return(e=e||{}).bg=e.bg||"#fff",t.jpg(e)}};Pa.jpeg=Pa.jpg;var Ta={layout:function(e){if(null!=e)if(null!=e.name){var t=e.name,n=this.extension("layout",t);if(null!=n){var r;r=d(e.eles)?this.$(e.eles):null!=e.eles?e.eles:this.$();var i=new n(I({},e,{cy:this,eles:r}));return i}Ee("No such layout `"+t+"` found. Did you forget to import it and `cytoscape.use()` it?")}else Ee("A `name` must be specified to make a layout");else Ee("Layout options must be specified to make a layout")}};Ta.createLayout=Ta.makeLayout=Ta.layout;var Ma={notify:function(e,t){var n=this._private;if(this.batching()){n.batchNotifications=n.batchNotifications||{};var r=n.batchNotifications[e]=n.batchNotifications[e]||this.collection();null!=t&&r.merge(t)}else if(n.notificationsEnabled){var i=this.renderer();!this.isDestroyed()&&i&&i.notify(e,t)}},notifications:function(e){var t=this._private;return void 0===e?t.notificationsEnabled:(t.notificationsEnabled=!!e,this)},noNotifications:function(e){this.notifications(!1),e(),this.notifications(!0)},batching:function(){return this._private.batchCount>0},startBatch:function(){var e=this._private;return null==e.batchCount&&(e.batchCount=0),0===e.batchCount&&(e.batchStyleEles=this.collection(),e.batchNotifications={}),e.batchCount++,this},endBatch:function(){var e=this._private;if(0===e.batchCount)return this;if(e.batchCount--,0===e.batchCount){e.batchStyleEles.updateStyle();var t=this.renderer();Object.keys(e.batchNotifications).forEach(function(n){var r=e.batchNotifications[n];r.empty()?t.notify(n):t.notify(n,r)})}return this},batch:function(e){return this.startBatch(),e(),this.endBatch(),this},batchData:function(e){var t=this;return this.batch(function(){for(var n=Object.keys(e),r=0;r0;)e.removeChild(e.childNodes[0]);this._private.renderer=null,this.mutableElements().forEach(function(e){var t=e._private;t.rscratch={},t.rstyle={},t.animation.current=[],t.animation.queue=[]})},onRender:function(e){return this.on("render",e)},offRender:function(e){return this.off("render",e)}};Ba.invalidateDimensions=Ba.resize;var Na={collection:function(e,t){return d(e)?this.$(e):m(e)?e.collection():f(e)?new ua(this,e,t):new ua(this)},nodes:function(e){var t=this.$(function(e){return e.isNode()});return e?t.filter(e):t},edges:function(e){var t=this.$(function(e){return e.isEdge()});return e?t.filter(e):t},$:function(e){var t=this._private.elements;return e?t.filter(e):t.spawnSelf()},mutableElements:function(){return this._private.elements}};Na.elements=Na.filter=Na.$;var Ia={};Ia.apply=function(e){var t=this._private,n=t.cy.collection();t.newStyle&&(t.contextStyles={},t.propDiffs={},this.cleanElements(e,!0));for(var r=0;r0;if(h||c&&d){var p=void 0;h&&d?p=l.properties:h?p=l.properties:d&&(p=l.mappedProperties);for(var f=0;f1&&(g=1),s.color){var w=i.valueMin[0],E=i.valueMax[0],k=i.valueMin[1],C=i.valueMax[1],S=i.valueMin[2],D=i.valueMax[2],P=null==i.valueMin[3]?1:i.valueMin[3],T=null==i.valueMax[3]?1:i.valueMax[3],M=[Math.round(w+(E-w)*g),Math.round(k+(C-k)*g),Math.round(S+(D-S)*g),Math.round(P+(T-P)*g)];n={bypass:i.bypass,name:i.name,value:M,strValue:"rgb("+M[0]+", "+M[1]+", "+M[2]+")"}}else{if(!s.number)return!1;var _=i.valueMin+(i.valueMax-i.valueMin)*g;n=this.parse(i.name,_,i.bypass,"mapping")}if(!n)return f(),!1;n.mapping=i,i=n;break;case o.data:for(var B=i.field.split("."),N=h.data,I=0;I0&&a>0){for(var s={},l=!1,u=0;u0?e.delayAnimation(o).play().promise().then(t):t()}).then(function(){return e.animation({style:s,duration:a,easing:e.pstyle("transition-timing-function").value,queue:!1}).play().promise()}).then(function(){n.removeBypasses(e,i),e.emitAndNotify("style"),r.transitioning=!1})}else r.transitioning&&(this.removeBypasses(e,i),e.emitAndNotify("style"),r.transitioning=!1)},Ia.checkTrigger=function(e,t,n,r,i,a){var o=this.properties[t],s=i(o);null!=s&&s(n,r)&&a(o)},Ia.checkZOrderTrigger=function(e,t,n,r){var i=this;this.checkTrigger(e,t,n,r,function(e){return e.triggersZOrder},function(){i._private.cy.notify("zorder",e)})},Ia.checkBoundsTrigger=function(e,t,n,r){this.checkTrigger(e,t,n,r,function(e){return e.triggersBounds},function(i){e.dirtyCompoundBoundsCache(),e.dirtyBoundingBoxCache(),"bezier"!==e.pstyle("curve-style").value&&("curve-style"!==t||"bezier"!==n&&"bezier"!==r)||!i.triggersBoundsOfParallelBeziers||e.parallelEdges().forEach(function(e){e.isBundledBezier()&&e.dirtyBoundingBoxCache()})})},Ia.checkTriggers=function(e,t,n,r){e.dirtyStyleCache(),this.checkZOrderTrigger(e,t,n,r),this.checkBoundsTrigger(e,t,n,r)};var za={applyBypass:function(e,t,n,r){var i=[];if("*"===t||"**"===t){if(void 0!==n)for(var a=0;at.length?i.substr(t.length):""}function o(){n=n.length>r.length?n.substr(r.length):""}for(i=i.replace(/[\/][*](\s|.)+?[*][\/]/g,"");;){if(i.match(/^\s*$/))break;var s=i.match(/^\s*((?:.|\s)+?)\s*\{((?:.|\s)+?)\}/);if(!s){Ce("Halting stylesheet parsing: String stylesheet contains more to parse but no selector and block found in: "+i);break}t=s[0];var l=s[1];if("core"!==l)if(new Ir(l).invalid){Ce("Skipping parsing of block: Invalid selector found in string stylesheet: "+l),a();continue}var u=s[2],c=!1;n=u;for(var h=[];;){if(n.match(/^\s*$/))break;var d=n.match(/^\s*(.+?)\s*:\s*(.+?)\s*;/);if(!d){Ce("Skipping parsing of block: Invalid formatting of style property and value definitions found in:"+u),c=!0;break}r=d[0];var p=d[1],f=d[2];if(this.properties[p])this.parse(p,f)?(h.push({name:p,val:f}),o()):(Ce("Skipping property: Invalid property definition in: "+r),o());else Ce("Skipping property: Invalid property name in: "+r),o()}if(c){a();break}this.selector(l);for(var g=0;g=7&&"d"===t[0]&&(l=new RegExp(o.data.regex).exec(t))){if(n)return!1;var h=o.data;return{name:e,value:l,strValue:""+t,mapped:h,field:l[1],bypass:n}}if(t.length>=10&&"m"===t[0]&&(u=new RegExp(o.mapData.regex).exec(t))){if(n)return!1;if(c.multiple)return!1;var g=o.mapData;if(!c.color&&!c.number)return!1;var y=this.parse(e,u[4]);if(!y||y.mapped)return!1;var m=this.parse(e,u[5]);if(!m||m.mapped)return!1;if(y.pfValue===m.pfValue||y.strValue===m.strValue)return Ce("`"+e+": "+t+"` is not a valid mapper because the output range is zero; converting to `"+e+": "+y.strValue+"`"),this.parse(e,y.strValue);if(c.color){var b=y.value,x=m.value;if(!(b[0]!==x[0]||b[1]!==x[1]||b[2]!==x[2]||b[3]!==x[3]&&(null!=b[3]&&1!==b[3]||null!=x[3]&&1!==x[3])))return!1}return{name:e,value:u,strValue:""+t,mapped:g,field:u[1],fieldMin:parseFloat(u[2]),fieldMax:parseFloat(u[3]),valueMin:y.value,valueMax:m.value,bypass:n}}}if(c.multiple&&"multiple"!==r){var w;if(w=s?t.split(/\s+/):f(t)?t:[t],c.evenMultiple&&w.length%2!=0)return null;for(var E=[],k=[],C=[],S="",D=!1,T=0;T0?" ":"")+M.strValue}return c.validate&&!c.validate(E,k)?null:c.singleEnum&&D?1===E.length&&d(E[0])?{name:e,value:E[0],strValue:E[0],bypass:n}:null:{name:e,value:E,pfValue:C,strValue:S,bypass:n,units:k}}var _,N,I=function(){for(var r=0;rc.max||c.strictMax&&t===c.max))return null;var F={name:e,value:t,strValue:""+t+(A||""),units:A,bypass:n};return c.unitless||"px"!==A&&"em"!==A?F.pfValue=t:F.pfValue="px"!==A&&A?this.getEmSizeInPixels()*t:t,"ms"!==A&&"s"!==A||(F.pfValue="ms"===A?t:1e3*t),"deg"!==A&&"rad"!==A||(F.pfValue="rad"===A?t:(_=t,Math.PI*_/180)),"%"===A&&(F.pfValue=t/100),F}if(c.propList){var V=[],q=""+t;if("none"===q);else{for(var Y=q.split(/\s*,\s*|\s+/),X=0;X0&&l>0&&!isNaN(n.w)&&!isNaN(n.h)&&n.w>0&&n.h>0)return{zoom:o=(o=(o=Math.min((s-2*t)/n.w,(l-2*t)/n.h))>this._private.maxZoom?this._private.maxZoom:o)=n.minZoom&&(n.maxZoom=t),this},minZoom:function(e){return void 0===e?this._private.minZoom:this.zoomRange({min:e})},maxZoom:function(e){return void 0===e?this._private.maxZoom:this.zoomRange({max:e})},getZoomedViewport:function(e){var t,n,r=this._private,i=r.pan,a=r.zoom,o=!1;if(r.zoomingEnabled||(o=!0),v(e)?n=e:g(e)&&(n=e.level,null!=e.position?t=tt(e.position,a,i):null!=e.renderedPosition&&(t=e.renderedPosition),null==t||r.panningEnabled||(o=!0)),n=(n=n>r.maxZoom?r.maxZoom:n)t.maxZoom||!t.zoomingEnabled?a=!0:(t.zoom=s,i.push("zoom"))}if(r&&(!a||!e.cancelOnFailedZoom)&&t.panningEnabled){var l=e.pan;v(l.x)&&(t.pan.x=l.x,o=!1),v(l.y)&&(t.pan.y=l.y,o=!1),o||i.push("pan")}return i.length>0&&(i.push("viewport"),this.emit(i.join(" ")),this.notify("viewport")),this},center:function(e){var t=this.getCenterPan(e);return t&&(this._private.pan=t,this.emit("pan viewport"),this.notify("viewport")),this},getCenterPan:function(e,t){if(this._private.panningEnabled){if(d(e)){var n=e;e=this.mutableElements().filter(n)}else m(e)||(e=this.mutableElements());if(0!==e.length){var r=e.boundingBox(),i=this.width(),a=this.height();return{x:(i-(t=void 0===t?this._private.zoom:t)*(r.x1+r.x2))/2,y:(a-t*(r.y1+r.y2))/2}}}},reset:function(){return this._private.panningEnabled&&this._private.zoomingEnabled?(this.viewport({pan:{x:0,y:0},zoom:1}),this):this},invalidateSize:function(){this._private.sizeCache=null},size:function(){var e,t,n=this._private,r=n.container;return n.sizeCache=n.sizeCache||(r?(e=a.getComputedStyle(r),t=function(t){return parseFloat(e.getPropertyValue(t))},{width:r.clientWidth-t("padding-left")-t("padding-right"),height:r.clientHeight-t("padding-top")-t("padding-bottom")}):{width:1,height:1})},width:function(){return this.size().width},height:function(){return this.size().height},extent:function(){var e=this._private.pan,t=this._private.zoom,n=this.renderedExtent(),r={x1:(n.x1-e.x)/t,x2:(n.x2-e.x)/t,y1:(n.y1-e.y)/t,y2:(n.y2-e.y)/t};return r.w=r.x2-r.x1,r.h=r.y2-r.y1,r},renderedExtent:function(){var e=this.width(),t=this.height();return{x1:0,y1:0,x2:e,y2:t,w:e,h:t}}};ja.centre=ja.center,ja.autolockNodes=ja.autolock,ja.autoungrabifyNodes=ja.autoungrabify;var Wa=function(e){var t=this,n=(e=I({},e)).container;n&&!y(n)&&y(n[0])&&(n=n[0]);var r=n?n._cyreg:null;(r=r||{})&&r.cy&&(r.cy.destroy(),r={});var i=r.readies=r.readies||[];n&&(n._cyreg=r),r.cy=t;var o=void 0!==a&&void 0!==n&&!e.headless,s=e;s.layout=I({name:o?"grid":"null"},s.layout),s.renderer=I({name:o?"canvas":"null"},s.renderer);var l=function(e,t,n){return void 0!==t?t:void 0!==n?n:e},u=this._private={container:n,ready:!1,options:s,elements:new ua(this),listeners:[],aniEles:new ua(this),scratch:{},layout:null,renderer:null,destroyed:!1,notificationsEnabled:!0,minZoom:1e-50,maxZoom:1e50,zoomingEnabled:l(!0,s.zoomingEnabled),userZoomingEnabled:l(!0,s.userZoomingEnabled),panningEnabled:l(!0,s.panningEnabled),userPanningEnabled:l(!0,s.userPanningEnabled),boxSelectionEnabled:l(!0,s.boxSelectionEnabled),autolock:l(!1,s.autolock,s.autolockNodes),autoungrabify:l(!1,s.autoungrabify,s.autoungrabifyNodes),autounselectify:l(!1,s.autounselectify),styleEnabled:void 0===s.styleEnabled?o:s.styleEnabled,zoom:v(s.zoom)?s.zoom:1,pan:{x:g(s.pan)&&v(s.pan.x)?s.pan.x:0,y:g(s.pan)&&v(s.pan.y)?s.pan.y:0},animation:{current:[],queue:[]},hasCompoundNodes:!1};this.createEmitter(),this.selectionType(s.selectionType),this.zoomRange({min:s.minZoom,max:s.maxZoom});u.styleEnabled&&t.setStyle([]);var c=I({},s,s.renderer);t.initRenderer(c);!function(e,t){if(e.some(C))return Kn.all(e).then(t);t(e)}([s.style,s.elements],function(e){var n=e[0],a=e[1];u.styleEnabled&&t.style().append(n),function(e,n,r){t.notifications(!1);var i=t.mutableElements();i.length>0&&i.remove(),null!=e&&(g(e)||f(e))&&t.add(e),t.one("layoutready",function(e){t.notifications(!0),t.emit(e),t.one("load",n),t.emitAndNotify("load")}).one("layoutstop",function(){t.one("done",r),t.emit("done")});var a=I({},t._private.options.layout);a.eles=t.elements(),t.layout(a).run()}(a,function(){t.startAnimationLoop(),u.ready=!0,p(s.ready)&&t.on("ready",s.ready);for(var e=0;e0,u=pt(n.boundingBox?n.boundingBox:{x1:0,y1:0,w:r.width(),h:r.height()});if(m(n.roots))e=n.roots;else if(f(n.roots)){for(var c=[],h=0;h0;){var I=M.shift(),z=T(I,_);if(z)I.outgoers().filter(function(e){return e.isNode()&&i.has(e)}).forEach(B);else if(null===z){Ce("Detected double maximal shift for node `"+I.id()+"`. Bailing maximal adjustment due to cycle. Use `options.maximal: true` only on DAGs.");break}}}P();var A=0;if(n.avoidOverlap)for(var L=0;L0&&x[0].length<=3?l/2:0),h=2*Math.PI/x[r].length*i;return 0===r&&1===x[0].length&&(c=1),{x:G+c*Math.cos(h),y:Z+c*Math.sin(h)}}return{x:G+(i+1-(a+1)/2)*o,y:(r+1)*s}}),this};var $a={fit:!0,padding:30,boundingBox:void 0,avoidOverlap:!0,nodeDimensionsIncludeLabels:!1,spacingFactor:void 0,radius:void 0,startAngle:1.5*Math.PI,sweep:void 0,clockwise:!0,sort:void 0,animate:!1,animationDuration:500,animationEasing:void 0,animateFilter:function(e,t){return!0},ready:void 0,stop:void 0,transform:function(e,t){return t}};function Qa(e){this.options=I({},$a,e)}Qa.prototype.run=function(){var e=this.options,t=e,n=e.cy,r=t.eles,i=void 0!==t.counterclockwise?!t.counterclockwise:t.clockwise,a=r.nodes().not(":parent");t.sort&&(a=a.sort(t.sort));for(var o,s=pt(t.boundingBox?t.boundingBox:{x1:0,y1:0,w:n.width(),h:n.height()}),l=s.x1+s.w/2,u=s.y1+s.h/2,c=(void 0===t.sweep?2*Math.PI-2*Math.PI/a.length:t.sweep)/Math.max(1,a.length-1),h=0,d=0;d1&&t.avoidOverlap){h*=1.75;var y=Math.cos(c)-Math.cos(0),m=Math.sin(c)-Math.sin(0),b=Math.sqrt(h*h/(y*y+m*m));o=Math.max(b,o)}return a.layoutPositions(this,t,function(e,n){var r=t.startAngle+n*c*(i?1:-1),a=o*Math.cos(r),s=o*Math.sin(r);return{x:l+a,y:u+s}}),this};var Ja,eo={fit:!0,padding:30,startAngle:1.5*Math.PI,sweep:void 0,clockwise:!0,equidistant:!1,minNodeSpacing:10,boundingBox:void 0,avoidOverlap:!0,nodeDimensionsIncludeLabels:!1,height:void 0,width:void 0,spacingFactor:void 0,concentric:function(e){return e.degree()},levelWidth:function(e){return e.maxDegree()/4},animate:!1,animationDuration:500,animationEasing:void 0,animateFilter:function(e,t){return!0},ready:void 0,stop:void 0,transform:function(e,t){return t}};function to(e){this.options=I({},eo,e)}to.prototype.run=function(){for(var e=this.options,t=e,n=void 0!==t.counterclockwise?!t.counterclockwise:t.clockwise,r=e.cy,i=t.eles.nodes().not(":parent"),a=pt(t.boundingBox?t.boundingBox:{x1:0,y1:0,w:r.width(),h:r.height()}),o=a.x1+a.w/2,s=a.y1+a.h/2,l=[],u=0,c=0;c0)Math.abs(y[0].value-b.value)>=g&&(y=[],v.push(y));y.push(b)}var x=u+t.minNodeSpacing;if(!t.avoidOverlap){var w=v.length>0&&v[0].length>1,E=(Math.min(a.w,a.h)/2-x)/(v.length+w?1:0);x=Math.min(x,E)}for(var k=0,C=0;C1&&t.avoidOverlap){var T=Math.cos(P)-Math.cos(0),M=Math.sin(P)-Math.sin(0),_=Math.sqrt(x*x/(T*T+M*M));k=Math.max(_,k)}S.r=k,k+=x}if(t.equidistant){for(var B=0,N=0,I=0;I0)var l=(d=r.nodeOverlap*o)*i/(m=Math.sqrt(i*i+a*a)),h=d*a/m;else{var d,p=c(e,i,a),f=c(t,-1*i,-1*a),g=f.x-p.x,v=f.y-p.y,y=g*g+v*v,m=Math.sqrt(y);l=(d=(e.nodeRepulsion+t.nodeRepulsion)/y)*g/m,h=d*v/m}e.isLocked||(e.offsetX-=l,e.offsetY-=h),t.isLocked||(t.offsetX+=l,t.offsetY+=h)}},u=function(e,t,n,r){if(n>0)var i=e.maxX-t.minX;else i=t.maxX-e.minX;if(r>0)var a=e.maxY-t.minY;else a=t.maxY-e.minY;return i>=0&&a>=0?Math.sqrt(i*i+a*a):0},c=function(e,t,n){var r=e.positionX,i=e.positionY,a=e.height||1,o=e.width||1,s=n/t,l=a/o,u={};return 0===t&&0n?(u.x=r,u.y=i+a/2,u):0t&&-1*l<=s&&s<=l?(u.x=r-o/2,u.y=i-o*n/2/t,u):0=l)?(u.x=r+a*t/2/n,u.y=i+a/2,u):0>n&&(s<=-1*l||s>=l)?(u.x=r-a*t/2/n,u.y=i-a/2,u):u},h=function(e,t){for(var n=0;n1){var f=t.gravity*h/p,g=t.gravity*d/p;c.offsetX+=f,c.offsetY+=g}}}}},p=function(e,t){var n=[],r=0,i=-1;for(n.push.apply(n,e.graphSet[0]),i+=e.graphSet[0].length;r<=i;){var a=n[r++],o=e.idToIndex[a],s=e.layoutNodes[o],l=s.children;if(0n)var i={x:n*e/r,y:n*t/r};else i={x:e,y:t};return i},v=function e(t,n){var r=t.parentId;if(null!=r){var i=n.layoutNodes[n.idToIndex[r]],a=!1;return(null==i.maxX||t.maxX+i.padRight>i.maxX)&&(i.maxX=t.maxX+i.padRight,a=!0),(null==i.minX||t.minX-i.padLefti.maxY)&&(i.maxY=t.maxY+i.padBottom,a=!0),(null==i.minY||t.minY-i.padTopg&&(d+=f+t.componentSpacing,h=0,p=0,f=0)}}}(0,i),r}).then(function(e){o.layoutNodes=e.layoutNodes,r.stop(),c()});var c=function(){!0===e.animate||!1===e.animate?u({force:!0,next:function(){n.one("layoutstop",e.stop),n.emit({type:"layoutstop",layout:n})}}):e.eles.nodes().layoutPositions(n,e,function(e){var t=o.layoutNodes[o.idToIndex[e.data("id")]];return{x:t.positionX,y:t.positionY}})};return this},ro.prototype.stop=function(){return this.stopped=!0,this.thread&&this.thread.stop(),this.emit("layoutstop"),this},ro.prototype.destroy=function(){return this.thread&&this.thread.stop(),this};var io=function(e,t,n){for(var r=n.eles.edges(),i=n.eles.nodes(),a={isCompound:e.hasCompoundNodes(),layoutNodes:[],idToIndex:{},nodeSize:i.size(),graphSet:[],indexToGraph:[],layoutEdges:[],edgeSize:r.size(),temperature:n.initialTemp,clientWidth:e.width(),clientHeight:e.width(),boundingBox:pt(n.boundingBox?n.boundingBox:{x1:0,y1:0,w:e.width(),h:e.height()})},o=n.eles.components(),s={},l=0;l0){a.graphSet.push(w);for(l=0;lr.count?0:r.graph},oo=function e(t,n,r,i){var a=i.graphSet[r];if(-1a){var p=u(),f=c();(p-1)*f>=a?u(p-1):(f-1)*p>=a&&c(f-1)}else for(;l*s=a?c(v+1):u(g+1)}var y=i.w/l,m=i.h/s;if(t.condense&&(y=0,m=0),t.avoidOverlap)for(var b=0;b=l&&(_=0,M++)},N={},I=0;I(r=St(e,t,x[w],x[w+1],x[w+2],x[w+3])))return v(n,r),!0}else if("bezier"===a.edgeType||"multibezier"===a.edgeType||"self"===a.edgeType||"compound"===a.edgeType)for(x=a.allpts,w=0;w+5(r=Ct(e,t,x[w],x[w+1],x[w+2],x[w+3],x[w+4],x[w+5])))return v(n,r),!0;m=m||i.source,b=b||i.target;var E=o.getArrowWidth(l,c),k=[{name:"source",x:a.arrowStartX,y:a.arrowStartY,angle:a.srcArrowAngle},{name:"target",x:a.arrowEndX,y:a.arrowEndY,angle:a.tgtArrowAngle},{name:"mid-source",x:a.midX,y:a.midY,angle:a.midsrcArrowAngle},{name:"mid-target",x:a.midX,y:a.midY,angle:a.midtgtArrowAngle}];for(w=0;w0&&(y(m),y(b))}function b(e,t,n){return Ne(e,t,n)}function x(n,r){var i,a=n._private,o=f;i=r?r+"-":"";var s=n.pstyle(i+"label").value;if("yes"===n.pstyle("text-events").strValue&&s){var l=a.rstyle,u=n.pstyle("text-border-width").pfValue,c=n.pstyle("text-background-padding").pfValue,h=b(l,"labelWidth",r)+u+2*o+2*c,d=b(l,"labelHeight",r)+u+2*o+2*c,p=b(l,"labelX",r),g=b(l,"labelY",r),y=b(a.rscratch,"labelAngle",r),m=p-h/2,x=p+h/2,w=g-d/2,E=g+d/2;if(y){var k=Math.cos(y),C=Math.sin(y),S=function(e,t){return{x:(e-=p)*k-(t-=g)*C+p,y:e*C+t*k+g}},D=S(m,w),P=S(m,E),T=S(x,w),M=S(x,E),_=[D.x,D.y,T.x,T.y,M.x,M.y,P.x,P.y];if(Dt(e,t,_))return v(n),!0}else{if(bt({w:h,h:d,x1:m,x2:x,y1:w,y2:E},e,t))return v(n),!0}}}n&&(l=l.interactive);for(var w=l.length-1;w>=0;w--){var E=l[w];E.isNode()?y(E)||x(E):m(E)||x(E)||x(E,"source")||x(E,"target")}return u},getAllInBox:function(e,t,n,r){for(var i,a,o=this.getCachedZSortedEles().interactive,s=[],l=Math.min(e,n),u=Math.max(e,n),c=Math.min(t,r),h=Math.max(t,r),d=pt({x1:e=l,y1:t=c,x2:n=u,y2:r=h}),p=0;p0?Math.max(e-t,0):Math.min(e+t,0)},x=b(y,g),w=b(m,v),E=!1;"auto"===u?u=Math.abs(x)>Math.abs(w)?"horizontal":"vertical":"upward"===u||"downward"===u?(u="vertical",E=!0):"leftward"!==u&&"rightward"!==u||(u="horizontal",E=!0);var k="vertical"===u,C=k?w:x,S=k?m:y,D=ot(S),P=!1;E&&f||!("downward"===c&&S<0||"upward"===c&&S>0||"leftward"===c&&S>0||"rightward"===c&&S<0)||(C=(D*=-1)*Math.abs(C),P=!0);var T=f?d*C:d*D,M=function(e){return Math.abs(e)=Math.abs(C)},_=M(T),B=M(C-T);if((_||B)&&!P)if(k){var N=Math.abs(S)<=a/2,I=Math.abs(y)<=o/2;if(N){var z=(r.x1+r.x2)/2,A=r.y1,L=r.y2;n.segpts=[z,A,z,L]}else if(I){var O=(r.y1+r.y2)/2,R=r.x1,F=r.x2;n.segpts=[R,O,F,O]}else n.segpts=[r.x1,r.y2]}else{var V=Math.abs(S)<=i/2,q=Math.abs(m)<=s/2;if(V){var Y=(r.y1+r.y2)/2,X=r.x1,j=r.x2;n.segpts=[X,Y,j,Y]}else if(q){var W=(r.x1+r.x2)/2,H=r.y1,K=r.y2;n.segpts=[W,H,W,K]}else n.segpts=[r.x2,r.y1]}else if(k){var G=r.y1+T+(l?a/2*D:0),Z=r.x1,U=r.x2;n.segpts=[Z,G,U,G]}else{var $=r.x1+T+(l?i/2*D:0),Q=r.y1,J=r.y2;n.segpts=[$,Q,$,J]}},Co.tryToCorrectInvalidPoints=function(e,t){var n=e._private.rscratch;if("bezier"===n.edgeType){var r=t.srcPos,i=t.tgtPos,a=t.srcW,o=t.srcH,s=t.tgtW,l=t.tgtH,u=t.srcShape,c=t.tgtShape,h=!v(n.startX)||!v(n.startY),d=!v(n.arrowStartX)||!v(n.arrowStartY),p=!v(n.endX)||!v(n.endY),f=!v(n.arrowEndX)||!v(n.arrowEndY),g=3*(this.getArrowWidth(e.pstyle("width").pfValue,e.pstyle("arrow-scale").value)*this.arrowShapeWidth),y=st({x:n.ctrlpts[0],y:n.ctrlpts[1]},{x:n.startX,y:n.startY}),m=yd.poolIndex()){var p=h;h=d,d=p}var f=s.srcPos=h.position(),g=s.tgtPos=d.position(),y=s.srcW=h.outerWidth(),m=s.srcH=h.outerHeight(),b=s.tgtW=d.outerWidth(),x=s.tgtH=d.outerHeight(),w=s.srcShape=n.nodeShapes[t.getNodeShape(h)],E=s.tgtShape=n.nodeShapes[t.getNodeShape(d)];s.dirCounts={north:0,west:0,south:0,east:0,northwest:0,southwest:0,northeast:0,southeast:0};for(var k=0;k=c||b){h={cp:v,segment:m};break}}if(h)break}v=h.cp;var x=(c-p)/(m=h.segment).length,w=m.t1-m.t0,E=u?m.t0+w*x:m.t1-w*x;E=dt(0,E,1),t=ht(v.p0,v.p1,v.p2,E),l=function(e,t,n,r){var i=dt(0,r-.001,1),a=dt(0,r+.001,1),o=ht(e,t,n,i),s=ht(e,t,n,a);return Bo(o,s)}(v.p0,v.p1,v.p2,E);break;case"straight":case"segments":case"haystack":var k,C,S,D,P=0,T=r.allpts.length;for(g=0;g+3=c));g+=2);E=dt(0,E=(c-C)/k,1),t=function(e,t,n,r){var i=t.x-e.x,a=t.y-e.y,o=st(e,t),s=i/o,l=a/o;return n=null==n?0:n,r=null!=r?r:n*o,{x:e.x+s*r,y:e.y+l*r}}(S,D,E),l=Bo(S,D)}o("labelX",s,t.x),o("labelY",s,t.y),o("labelAutoAngle",s,l)}};l("source"),l("target"),this.applyLabelDimensions(e)}},Mo.applyLabelDimensions=function(e){this.applyPrefixedLabelDimensions(e),e.isEdge()&&(this.applyPrefixedLabelDimensions(e,"source"),this.applyPrefixedLabelDimensions(e,"target"))},Mo.applyPrefixedLabelDimensions=function(e,t){var n=e._private,r=this.getLabelText(e,t),i=this.calculateLabelDimensions(e,r);Ie(n.rstyle,"labelWidth",t,i.width),Ie(n.rscratch,"labelWidth",t,i.width),Ie(n.rstyle,"labelHeight",t,i.height),Ie(n.rscratch,"labelHeight",t,i.height)},Mo.getLabelText=function(e,t){var n=e._private,r=t?t+"-":"",i=e.pstyle(r+"label").strValue,a=e.pstyle("text-transform").value,o=function(e,r){return r?(Ie(n.rscratch,e,t,r),r):Ne(n.rscratch,e,t)};if(!i)return"";"none"==a||("uppercase"==a?i=i.toUpperCase():"lowercase"==a&&(i=i.toLowerCase()));var s=e.pstyle("text-wrap").value;if("wrap"===s){var l=o("labelKey");if(null!=l&&o("labelWrapKey")===l)return o("labelWrapCachedText");for(var u=i.split("\n"),c=e.pstyle("text-max-width").pfValue,h=[],d=0;dc){for(var f=p.split(/\s+/),g="",v=0;vc)break;b+=i[w],w===i.length-1&&(x=!0)}return x||(b+="…"),b}return i},Mo.calculateLabelDimensions=function(e,t){var n=he(t,e._private.labelDimsKey),r=this.labelDimCache||(this.labelDimCache=[]),i=r[n];if(null!=i)return i;var a=e.pstyle("font-style").strValue,o=1*e.pstyle("font-size").pfValue+"px",s=e.pstyle("font-family").strValue,l=e.pstyle("font-weight").strValue,u=this.labelCalcDiv;u||(u=this.labelCalcDiv=document.createElement("div"),document.body.appendChild(u));var c=u.style;return c.fontFamily=s,c.fontStyle=a,c.fontSize=o,c.fontWeight=l,c.position="absolute",c.left="-9999px",c.top="-9999px",c.zIndex="-1",c.visibility="hidden",c.pointerEvents="none",c.padding="0",c.lineHeight="1","wrap"===e.pstyle("text-wrap").value?c.whiteSpace="pre":c.whiteSpace="normal",u.textContent=t,r[n]={width:Math.ceil(u.clientWidth/1),height:Math.ceil(u.clientHeight/1)}},Mo.calculateLabelAngle=function(e,t){var n=e._private.rscratch,r=e.isEdge(),i=t?t+"-":"",a=e.pstyle(i+"text-rotation"),o=a.strValue;return"none"===o?0:r&&"autorotate"===o?n.labelAutoAngle:"autorotate"===o?0:a.pfValue},Mo.calculateLabelAngles=function(e){var t=this,n=e.isEdge(),r=e._private.rscratch;r.labelAngle=t.calculateLabelAngle(e),n&&(r.sourceLabelAngle=t.calculateLabelAngle(e,"source"),r.targetLabelAngle=t.calculateLabelAngle(e,"target"))};var No={},Io=!1;No.getNodeShape=function(e){var t=e.pstyle("shape").value;if("cutrectangle"===t&&(e.width()<28||e.height()<28))return Io||(Ce("The `cutrectangle` node shape can not be used at small sizes so `rectangle` is used instead"),Io=!0),"rectangle";if(e.isParent())return"rectangle"===t||"roundrectangle"===t||"cutrectangle"===t||"barrel"===t?t:"rectangle";if("polygon"===t){var n=e.pstyle("shape-polygon-points").value;return this.nodeShapes.makePolygon(n).name}return t};var zo={registerCalculationListeners:function(){var e=this.cy,t=e.collection(),n=this,r=function(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(t.merge(e),n)for(var r=0;r=e.desktopTapThreshold2}var P=r(t);m&&(e.hoverData.tapholdCancelled=!0);a=!0,n(g,["mousemove","vmousemove","tapdrag"],t,{x:h[0],y:h[1]});var T=function(){e.data.bgActivePosistion=void 0,e.hoverData.selecting||o.emit({originalEvent:t,type:"boxstart",position:{x:h[0],y:h[1]}}),f[4]=1,e.hoverData.selecting=!0,e.redrawHint("select",!0),e.redraw()};if(3===e.hoverData.which){if(m){var M={originalEvent:t,type:"cxtdrag",position:{x:h[0],y:h[1]}};x?x.emit(M):o.emit(M),e.hoverData.cxtDragged=!0,e.hoverData.cxtOver&&g===e.hoverData.cxtOver||(e.hoverData.cxtOver&&e.hoverData.cxtOver.emit({originalEvent:t,type:"cxtdragout",position:{x:h[0],y:h[1]}}),e.hoverData.cxtOver=g,g&&g.emit({originalEvent:t,type:"cxtdragover",position:{x:h[0],y:h[1]}}))}}else if(e.hoverData.dragging){if(a=!0,o.panningEnabled()&&o.userPanningEnabled()){var _;if(e.hoverData.justStartedPan){var B=e.hoverData.mdownPos;_={x:(h[0]-B[0])*s,y:(h[1]-B[1])*s},e.hoverData.justStartedPan=!1}else _={x:w[0]*s,y:w[1]*s};o.panBy(_),e.hoverData.dragged=!0}h=e.projectIntoViewport(t.clientX,t.clientY)}else if(1!=f[4]||null!=x&&!x.isEdge()){if(x&&x.isEdge()&&x.active()&&x.unactivate(),x&&x.grabbed()||g==b||(b&&n(b,["mouseout","tapdragout"],t,{x:h[0],y:h[1]}),g&&n(g,["mouseover","tapdragover"],t,{x:h[0],y:h[1]}),e.hoverData.last=g),x)if(m){if(o.boxSelectionEnabled()&&P)x&&x.grabbed()&&(c(E),x.emit("freeon"),E.emit("free"),e.dragData.didDrag&&(x.emit("dragfreeon"),E.emit("dragfree"))),T();else if(x&&x.grabbed()&&e.nodeIsDraggable(x)){var N=!e.dragData.didDrag;N&&e.redrawHint("eles",!0),e.dragData.didDrag=!0;var I=o.collection();e.hoverData.draggingEles||l(E,{inDragLayer:!0});var z={x:0,y:0};if(v(w[0])&&v(w[1])&&(z.x+=w[0],z.y+=w[1],N)){var A=e.hoverData.dragDelta;A&&v(A[0])&&v(A[1])&&(z.x+=A[0],z.y+=A[1])}for(var L=0;L0&&e.redrawHint("eles",!0),e.dragData.possibleDragElements=u=a.collection()),l!=h||e.dragData.didDrag||e.hoverData.selecting||null!=l&&l._private.selectable&&(e.hoverData.dragging||("additive"===a.selectionType()||d?l.selected()?l.unselect(["tapunselect"]):l.select(["tapselect"]):d||(a.$(t).unmerge(l).unselect(["tapunselect"]),l.select(["tapselect"]))),e.redrawHint("eles",!0)),e.hoverData.selecting){var g=a.collection(e.getAllInBox(s[0],s[1],s[2],s[3]));e.redrawHint("select",!0),g.length>0&&e.redrawHint("eles",!0),a.emit({type:"boxend",originalEvent:i,position:{x:o[0],y:o[1]}});var v=function(e){return e.selectable()&&!e.selected()};"additive"===a.selectionType()?g.emit("box").stdFilter(v).select().emit("boxselect"):(d||a.$(t).unmerge(g).unselect(),g.emit("box").stdFilter(v).select().emit("boxselect")),e.redraw()}if(e.hoverData.dragging&&(e.hoverData.dragging=!1,e.redrawHint("select",!0),e.redrawHint("eles",!0),e.redraw()),!s[4]){e.redrawHint("drag",!0),e.redrawHint("eles",!0);var y=h&&h.grabbed();c(u),y&&(h.emit("freeon"),u.emit("free"),e.dragData.didDrag&&(h.emit("dragfreeon"),u.emit("dragfree")))}}s[4]=0,e.hoverData.down=null,e.hoverData.cxtStarted=!1,e.hoverData.draggingEles=!1,e.hoverData.selecting=!1,e.hoverData.isOverThresholdDrag=!1,e.dragData.didDrag=!1,e.hoverData.dragged=!1,e.hoverData.dragDelta=[],e.hoverData.mdownPos=null,e.hoverData.mdownGPos=null}},!1);var m,b,x,w,E,k,C,S,D,P,T,M,_;e.registerBinding(e.container,"wheel",function(t){if(!e.scrollingPage){var n,r=e.cy,i=e.projectIntoViewport(t.clientX,t.clientY),a=[i[0]*r.zoom()+r.pan().x,i[1]*r.zoom()+r.pan().y];e.hoverData.draggingEles||e.hoverData.dragging||e.hoverData.cxtStarted||0!==e.selection[4]?t.preventDefault():r.panningEnabled()&&r.userPanningEnabled()&&r.zoomingEnabled()&&r.userZoomingEnabled()&&(t.preventDefault(),e.data.wheelZooming=!0,clearTimeout(e.data.wheelTimeout),e.data.wheelTimeout=setTimeout(function(){e.data.wheelZooming=!1,e.redrawHint("eles",!0),e.redraw()},150),n=null!=t.deltaY?t.deltaY/-250:null!=t.wheelDeltaY?t.wheelDeltaY/1e3:t.wheelDelta/1e3,n*=e.wheelSensitivity,1===t.deltaMode&&(n*=33),r.zoom({level:r.zoom()*Math.pow(10,n),renderedPosition:{x:a[0],y:a[1]}}))}},!0),e.registerBinding(window,"scroll",function(t){e.scrollingPage=!0,clearTimeout(e.scrollingPageTimeout),e.scrollingPageTimeout=setTimeout(function(){e.scrollingPage=!1},250)},!0),e.registerBinding(e.container,"mouseout",function(t){var n=e.projectIntoViewport(t.clientX,t.clientY);e.cy.emit({originalEvent:t,type:"mouseout",position:{x:n[0],y:n[1]}})},!1),e.registerBinding(e.container,"mouseover",function(t){var n=e.projectIntoViewport(t.clientX,t.clientY);e.cy.emit({originalEvent:t,type:"mouseover",position:{x:n[0],y:n[1]}})},!1);var B,N,I,z,A=function(e,t,n,r){return Math.sqrt((n-e)*(n-e)+(r-t)*(r-t))},L=function(e,t,n,r){return(n-e)*(n-e)+(r-t)*(r-t)};if(e.registerBinding(e.container,"touchstart",B=function(t){if(y(t)){d(),e.touchData.capture=!0,e.data.bgActivePosistion=void 0;var r=e.cy,i=e.touchData.now,a=e.touchData.earlier;if(t.touches[0]){var s=e.projectIntoViewport(t.touches[0].clientX,t.touches[0].clientY);i[0]=s[0],i[1]=s[1]}if(t.touches[1]){s=e.projectIntoViewport(t.touches[1].clientX,t.touches[1].clientY);i[2]=s[0],i[3]=s[1]}if(t.touches[2]){s=e.projectIntoViewport(t.touches[2].clientX,t.touches[2].clientY);i[4]=s[0],i[5]=s[1]}if(t.touches[1]){c(e.dragData.touchDragEles);var h=e.findContainerClientCoords();D=h[0],P=h[1],T=h[2],M=h[3],m=t.touches[0].clientX-D,b=t.touches[0].clientY-P,x=t.touches[1].clientX-D,w=t.touches[1].clientY-P,_=0<=m&&m<=T&&0<=x&&x<=T&&0<=b&&b<=M&&0<=w&&w<=M;var p=r.pan(),f=r.zoom();E=A(m,b,x,w),k=L(m,b,x,w),S=[((C=[(m+x)/2,(b+w)/2])[0]-p.x)/f,(C[1]-p.y)/f];if(k<4e4&&!t.touches[2]){var g=e.findNearestElement(i[0],i[1],!0,!0),v=e.findNearestElement(i[2],i[3],!0,!0);return g&&g.isNode()?(g.activate().emit({originalEvent:t,type:"cxttapstart",position:{x:i[0],y:i[1]}}),e.touchData.start=g):v&&v.isNode()?(v.activate().emit({originalEvent:t,type:"cxttapstart",position:{x:i[0],y:i[1]}}),e.touchData.start=v):r.emit({originalEvent:t,type:"cxttapstart",position:{x:i[0],y:i[1]}}),e.touchData.start&&(e.touchData.start._private.grabbed=!1),e.touchData.cxt=!0,e.touchData.cxtDragged=!1,e.data.bgActivePosistion=void 0,void e.redraw()}}if(t.touches[2]);else if(t.touches[1]);else if(t.touches[0]){var B=e.findNearestElements(i[0],i[1],!0,!0),N=B[0];if(null!=N&&(N.activate(),e.touchData.start=N,e.touchData.starts=B,e.nodeIsGrabbable(N))){var I=e.dragData.touchDragEles=r.collection(),z=null;e.redrawHint("eles",!0),e.redrawHint("drag",!0),N.selected()?(z=r.$(function(t){return t.selected()&&e.nodeIsGrabbable(t)}),l(z,{addToList:I})):u(N,{addToList:I}),o(N);var O=function(e){return{originalEvent:t,type:e,position:{x:i[0],y:i[1]}}};N.emit(O("grabon")),z?z.forEach(function(e){e.emit(O("grab"))}):N.emit(O("grab"))}n(N,["touchstart","tapstart","vmousedown"],t,{x:i[0],y:i[1]}),null==N&&(e.data.bgActivePosistion={x:s[0],y:s[1]},e.redrawHint("select",!0),e.redraw()),e.touchData.singleTouchMoved=!1,e.touchData.singleTouchStartTime=+new Date,clearTimeout(e.touchData.tapholdTimeout),e.touchData.tapholdTimeout=setTimeout(function(){!1!==e.touchData.singleTouchMoved||e.pinching||e.touchData.selecting||n(e.touchData.start,["taphold"],t,{x:i[0],y:i[1]})},e.tapholdDuration)}if(t.touches.length>=1){for(var R=e.touchData.startPosition=[],F=0;F=e.touchTapThreshold2}if(r&&e.touchData.cxt){t.preventDefault();var N=t.touches[0].clientX-D,I=t.touches[0].clientY-P,z=t.touches[1].clientX-D,O=t.touches[1].clientY-P,R=L(N,I,z,O);if(R/k>=2.25||R>=22500){e.touchData.cxt=!1,e.data.bgActivePosistion=void 0,e.redrawHint("select",!0);var F={originalEvent:t,type:"cxttapend",position:{x:s[0],y:s[1]}};e.touchData.start?(e.touchData.start.unactivate().emit(F),e.touchData.start=null):o.emit(F)}}if(r&&e.touchData.cxt){F={originalEvent:t,type:"cxtdrag",position:{x:s[0],y:s[1]}};e.data.bgActivePosistion=void 0,e.redrawHint("select",!0),e.touchData.start?e.touchData.start.emit(F):o.emit(F),e.touchData.start&&(e.touchData.start._private.grabbed=!1),e.touchData.cxtDragged=!0;var V=e.findNearestElement(s[0],s[1],!0,!0);e.touchData.cxtOver&&V===e.touchData.cxtOver||(e.touchData.cxtOver&&e.touchData.cxtOver.emit({originalEvent:t,type:"cxtdragout",position:{x:s[0],y:s[1]}}),e.touchData.cxtOver=V,V&&V.emit({originalEvent:t,type:"cxtdragover",position:{x:s[0],y:s[1]}}))}else if(r&&t.touches[2]&&o.boxSelectionEnabled())t.preventDefault(),e.data.bgActivePosistion=void 0,this.lastThreeTouch=+new Date,e.touchData.selecting||o.emit({originalEvent:t,type:"boxstart",position:{x:s[0],y:s[1]}}),e.touchData.selecting=!0,e.redrawHint("select",!0),a&&0!==a.length&&void 0!==a[0]?(a[2]=(s[0]+s[2]+s[4])/3,a[3]=(s[1]+s[3]+s[5])/3):(a[0]=(s[0]+s[2]+s[4])/3,a[1]=(s[1]+s[3]+s[5])/3,a[2]=(s[0]+s[2]+s[4])/3+1,a[3]=(s[1]+s[3]+s[5])/3+1),a[4]=1,e.touchData.selecting=!0,e.redraw();else if(r&&t.touches[1]&&o.zoomingEnabled()&&o.panningEnabled()&&o.userZoomingEnabled()&&o.userPanningEnabled()){if(t.preventDefault(),e.data.bgActivePosistion=void 0,e.redrawHint("select",!0),ee=e.dragData.touchDragEles){e.redrawHint("drag",!0);for(var q=0;q0&&!e.hoverData.draggingEles&&!e.swipePanning&&null!=e.data.bgActivePosistion&&(e.data.bgActivePosistion=void 0,e.redrawHint("select",!0),e.redraw())}},!1),e.registerBinding(window,"touchcancel",I=function(t){var n=e.touchData.start;e.touchData.capture=!1,n&&n.unactivate()}),e.registerBinding(window,"touchend",z=function(r){var i=e.touchData.start;if(e.touchData.capture){0===r.touches.length&&(e.touchData.capture=!1),r.preventDefault();var a=e.selection;e.swipePanning=!1,e.hoverData.draggingEles=!1;var o,s=e.cy,l=s.zoom(),u=e.touchData.now,h=e.touchData.earlier;if(r.touches[0]){var d=e.projectIntoViewport(r.touches[0].clientX,r.touches[0].clientY);u[0]=d[0],u[1]=d[1]}if(r.touches[1]){d=e.projectIntoViewport(r.touches[1].clientX,r.touches[1].clientY);u[2]=d[0],u[3]=d[1]}if(r.touches[2]){d=e.projectIntoViewport(r.touches[2].clientX,r.touches[2].clientY);u[4]=d[0],u[5]=d[1]}if(i&&i.unactivate(),e.touchData.cxt){if(o={originalEvent:r,type:"cxttapend",position:{x:u[0],y:u[1]}},i?i.emit(o):s.emit(o),!e.touchData.cxtDragged){var p={originalEvent:r,type:"cxttap",position:{x:u[0],y:u[1]}};i?i.emit(p):s.emit(p)}return e.touchData.start&&(e.touchData.start._private.grabbed=!1),e.touchData.cxt=!1,e.touchData.start=null,void e.redraw()}if(!r.touches[2]&&s.boxSelectionEnabled()&&e.touchData.selecting){e.touchData.selecting=!1;var f=s.collection(e.getAllInBox(a[0],a[1],a[2],a[3]));a[0]=void 0,a[1]=void 0,a[2]=void 0,a[3]=void 0,a[4]=0,e.redrawHint("select",!0),s.emit({type:"boxend",originalEvent:r,position:{x:u[0],y:u[1]}});f.emit("box").stdFilter(function(e){return e.selectable()&&!e.selected()}).select().emit("boxselect"),f.nonempty()&&e.redrawHint("eles",!0),e.redraw()}if(null!=i&&i.unactivate(),r.touches[2])e.data.bgActivePosistion=void 0,e.redrawHint("select",!0);else if(r.touches[1]);else if(r.touches[0]);else if(!r.touches[0]){e.data.bgActivePosistion=void 0,e.redrawHint("select",!0);var g=e.dragData.touchDragEles;if(null!=i){var v=i._private.grabbed;c(g),e.redrawHint("drag",!0),e.redrawHint("eles",!0),v&&(i.emit("freeon"),g.emit("free"),e.dragData.didDrag&&(i.emit("dragfreeon"),g.emit("dragfree"))),n(i,["touchend","tapend","vmouseup","tapdragout"],r,{x:u[0],y:u[1]}),i.unactivate(),e.touchData.start=null}else{var y=e.findNearestElement(u[0],u[1],!0,!0);n(y,["touchend","tapend","vmouseup","tapdragout"],r,{x:u[0],y:u[1]})}var m=e.touchData.startPosition[0]-u[0],b=m*m,x=e.touchData.startPosition[1]-u[1],w=(b+x*x)*l*l;e.touchData.singleTouchMoved||(i||s.$(":selected").unselect(["tapunselect"]),n(i,["tap","vclick"],r,{x:u[0],y:u[1]})),null!=i&&!e.dragData.didDrag&&i._private.selectable&&w0)return g[0]}return null},d=Object.keys(c),p=0;p0?l:wt(i,a,e,t,n,r,o)},checkPoint:function(e,t,n,r,i,a,o){var s=Ft(r,i),l=2*s;if(Pt(e,t,this.points,a,o,r,i-l,[0,-1],n))return!0;if(Pt(e,t,this.points,a,o,r-l,i,[0,-1],n))return!0;var u=r/2+2*n,c=i/2+2*n;return!!Dt(e,t,[a-u,o-c,a-u,o,a+u,o,a+u,o-c])||(!!_t(e,t,l,l,a+r/2-s,o+i/2-s,n)||!!_t(e,t,l,l,a-r/2+s,o+i/2-s,n))}}},Fo.registerNodeShapes=function(){var e=this.nodeShapes={},t=this;this.generateEllipse(),this.generatePolygon("triangle",Lt(3,0)),this.generatePolygon("rectangle",Lt(4,0)),e.square=e.rectangle,this.generateRoundRectangle(),this.generateCutRectangle(),this.generateBarrel(),this.generateBottomRoundrectangle(),this.generatePolygon("diamond",[0,1,1,0,0,-1,-1,0]),this.generatePolygon("pentagon",Lt(5,0)),this.generatePolygon("hexagon",Lt(6,0)),this.generatePolygon("heptagon",Lt(7,0)),this.generatePolygon("octagon",Lt(8,0));var n=new Array(20),r=Rt(5,0),i=Rt(5,Math.PI/5),a=.5*(3-Math.sqrt(5));a*=1.57;for(var o=0;o=e.deqFastCost*g)break}else if(i){if(p>=e.deqCost*l||p>=e.deqAvgCost*s)break}else if(f>=e.deqNoDrawCost*(1e3/60))break;var v=e.deq(t,h,c);if(!(v.length>0))break;for(var y=0;y0&&(e.onDeqd(t,u),!i&&e.shouldRedraw(t,u,h,c)&&r())},i(t))}}},Wo=function(){function e(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:be;t(this,e),this.idsByKey=new ze,this.keyForId=new ze,this.cachesByLvl=new ze,this.lvls=[],this.getKey=n,this.doesEleInvalidateKey=r}return r(e,[{key:"getIdsFor",value:function(e){null==e&&Ee("Can not get id list for null key");var t=this.idsByKey,n=this.idsByKey.get(e);return n||(n=new Le,t.set(e,n)),n}},{key:"addIdForKey",value:function(e,t){null!=e&&this.getIdsFor(e).add(t)}},{key:"deleteIdForKey",value:function(e,t){null!=e&&this.getIdsFor(e).delete(t)}},{key:"getNumberOfIdsForKey",value:function(e){return null==e?0:this.getIdsFor(e).size}},{key:"updateKeyMappingFor",value:function(e){var t=e.id(),n=this.keyForId.get(t),r=this.getKey(e);this.deleteIdForKey(n,t),this.addIdForKey(r,t),this.keyForId.set(t,r)}},{key:"deleteKeyMappingFor",value:function(e){var t=e.id(),n=this.keyForId.get(t);this.deleteIdForKey(n,t),this.keyForId.delete(t)}},{key:"keyHasChangedFor",value:function(e){var t=e.id();return this.keyForId.get(t)!==this.getKey(e)}},{key:"isInvalid",value:function(e){return this.keyHasChangedFor(e)||this.doesEleInvalidateKey(e)}},{key:"getCachesAt",value:function(e){var t=this.cachesByLvl,n=this.lvls,r=t.get(e);return r||(r=new ze,t.set(e,r),n.push(e)),r}},{key:"getCache",value:function(e,t){return this.getCachesAt(t).get(e)}},{key:"get",value:function(e,t){var n=this.getKey(e),r=this.getCache(n,t);return null!=r&&this.updateKeyMappingFor(e),r}},{key:"getForCachedKey",value:function(e,t){var n=this.keyForId.get(e.id());return this.getCache(n,t)}},{key:"hasCache",value:function(e,t){return this.getCachesAt(t).has(e)}},{key:"has",value:function(e,t){var n=this.getKey(e);return this.hasCache(n,t)}},{key:"setCache",value:function(e,t,n){n.key=e,this.getCachesAt(t).set(e,n)}},{key:"set",value:function(e,t,n){var r=this.getKey(e);this.setCache(r,t,n),this.updateKeyMappingFor(e)}},{key:"deleteCache",value:function(e,t){this.getCachesAt(t).delete(e)}},{key:"delete",value:function(e,t){var n=this.getKey(e);this.deleteCache(n,t)}},{key:"invalidateKey",value:function(e){var t=this;this.lvls.forEach(function(n){return t.deleteCache(e,n)})}},{key:"invalidate",value:function(e){var t=e.id(),n=this.keyForId.get(t);this.deleteKeyMappingFor(e);var r=this.doesEleInvalidateKey(e);return r&&this.invalidateKey(n),r||0===this.getNumberOfIdsForKey(n)}}]),e}(),Ho={dequeue:"dequeue",downscale:"downscale",highQuality:"highQuality"},Ko=Me({getKey:null,doesEleInvalidateKey:be,drawElement:null,getBoundingBox:null,getRotationPoint:null,getRotationOffset:null,isVisible:me,allowEdgeTxrCaching:!0,allowParentTxrCaching:!0}),Go=function(e,t){this.renderer=e,this.onDequeues=[];var n=Ko(t);I(this,n),this.lookup=new Wo(n.getKey,n.doesEleInvalidateKey),this.setupDequeueing()},Zo=Go.prototype;Zo.reasons=Ho,Zo.getTextureQueue=function(e){return this.eleImgCaches=this.eleImgCaches||{},this.eleImgCaches[e]=this.eleImgCaches[e]||[]},Zo.getRetiredTextureQueue=function(e){var t=this.eleImgCaches.retired=this.eleImgCaches.retired||{};return t[e]=t[e]||[]},Zo.getElementQueue=function(){return this.eleCacheQueue=this.eleCacheQueue||new Ve(function(e,t){return t.reqs-e.reqs})},Zo.getElementKeyToQueue=function(){return this.eleKeyToCacheQueue=this.eleKeyToCacheQueue||{}},Zo.getElement=function(e,t,n,r,i){var a=this,o=this.renderer,s=o.cy.zoom(),l=this.lookup;if(0===t.w||0===t.h||isNaN(t.w)||isNaN(t.h)||!e.visible())return null;if(!a.allowEdgeTxrCaching&&e.isEdge()||!a.allowParentTxrCaching&&e.isParent())return null;if(null==r&&(r=Math.ceil(at(s*n))),r<-4)r=-4;else if(s>=7.99||r>3)return null;var u=Math.pow(2,r),c=t.h*u,h=t.w*u,d=o.eleTextBiggerThanMin(e,u);if(!this.isVisible(e,d))return null;var p,f=l.get(e,r);if(f&&f.invalidated&&(f.invalidated=!1,f.texture.invalidatedWidth-=f.width),f)return f;if(p=c<=25?25:c<=50?50:50*Math.ceil(c/50),c>1024||h>1024)return null;var g=a.getTextureQueue(p),v=g[g.length-2],y=function(){return a.recycleTexture(p,h)||a.addTexture(p,h)};v||(v=g[g.length-1]),v||(v=y()),v.width-v.usedWidthr;P--)S=a.getElement(e,t,n,P,Ho.downscale);D()}else{var T;if(!x&&!w&&!E)for(var M=r-1;M>=-4;M--){var _=l.get(e,M);if(_){T=_;break}}if(b(T))return a.queueElement(e,r),T;v.context.translate(v.usedWidth,0),v.context.scale(u,u),this.drawElement(v.context,e,t,d,!1),v.context.scale(1/u,1/u),v.context.translate(-v.usedWidth,0)}return f={x:v.usedWidth,texture:v,level:r,scale:u,width:h,height:c,scaledLabelShown:d},v.usedWidth+=Math.ceil(h+8),v.eleCaches.push(f),l.set(e,r,f),a.checkTextureFullness(v),f},Zo.invalidateElements=function(e){for(var t=0;t=.2*e.width&&this.retireTexture(e)},Zo.checkTextureFullness=function(e){var t=this.getTextureQueue(e.height);e.usedWidth/e.width>.8&&e.fullnessChecks>=10?_e(t,e):e.fullnessChecks++},Zo.retireTexture=function(e){var t=e.height,n=this.getTextureQueue(t),r=this.lookup;_e(n,e),e.retired=!0;for(var i=e.eleCaches,a=0;a=t)return a.retired=!1,a.usedWidth=0,a.invalidatedWidth=0,a.fullnessChecks=0,Be(a.eleCaches),a.context.setTransform(1,0,0,1,0,0),a.context.clearRect(0,0,a.width,a.height),_e(r,a),n.push(a),a}},Zo.queueElement=function(e,t){var n=this.getElementQueue(),r=this.getElementKeyToQueue(),i=this.getKey(e),a=r[i];if(a)a.level=Math.max(a.level,t),a.eles.merge(e),a.reqs++,n.updateItem(a);else{var o={eles:e.spawn().merge(e),level:t,reqs:1,key:i};n.push(o),r[i]=o}},Zo.dequeue=function(e){for(var t=this.getElementQueue(),n=this.getElementKeyToQueue(),r=[],i=this.lookup,a=0;a<1&&t.size()>0;a++){var o=t.pop(),s=o.key,l=o.eles[0],u=i.hasCache(l,o.level);if(n[s]=null,!u){r.push(o);var c=this.getBoundingBox(l);this.getElement(l,c,e,o.level,Ho.dequeue)}}return r},Zo.removeFromQueue=function(e){var t=this.getElementQueue(),n=this.getElementKeyToQueue(),r=this.getKey(e),i=n[r];null!=i&&(1===i.eles.length?(i.reqs=ye,t.updateItem(i),t.pop(),n[r]=null):i.eles.unmerge(e))},Zo.onDequeue=function(e){this.onDequeues.push(e)},Zo.offDequeue=function(e){_e(this.onDequeues,e)},Zo.setupDequeueing=jo({deqRedrawThreshold:100,deqCost:.15,deqAvgCost:.1,deqNoDrawCost:.9,deqFastCost:.9,deq:function(e,t,n){return e.dequeue(t,n)},onDeqd:function(e,t){for(var n=0;n=3.99||n>2)return null;r.validateLayersElesOrdering(n,e);var o,s,l=r.layersByLevel,u=Math.pow(2,n),c=l[n]=l[n]||[];if(r.levelIsComplete(n,e))return c;!function(){var t=function(t){if(r.validateLayersElesOrdering(t,e),r.levelIsComplete(t,e))return s=l[t],!0},i=function(e){if(!s)for(var r=n+e;-4<=r&&r<=2&&!t(r);r+=e);};i(1),i(-1);for(var a=c.length-1;a>=0;a--){var o=c[a];o.invalid&&_e(c,o)}}();var h=function(t){var i=(t=t||{}).after;if(function(){if(!o){o=pt();for(var t=0;t16e6)return null;var a=r.makeLayer(o,n);if(null!=i){var s=c.indexOf(i)+1;c.splice(s,0,a)}else(void 0===t.insert||t.insert)&&c.unshift(a);return a};if(r.skipping&&!a)return null;for(var d=null,p=e.length/1,f=!a,g=0;g=p||!xt(d.bb,v.boundingBox()))&&!(d=h({insert:!0,after:d})))return null;s||f?r.queueLayer(d,v):r.drawEleInLayer(d,v,n,t),d.eles.push(v),m[n]=d}}return s||(f?null:c)},$o.getEleLevelForLayerLevel=function(e,t){return e},$o.drawEleInLayer=function(e,t,n,r){var i=this.renderer,a=e.context,o=t.boundingBox();0!==o.w&&0!==o.h&&t.visible()&&(n=this.getEleLevelForLayerLevel(n,r),i.setImgSmoothing(a,!1),i.drawCachedElement(a,t,null,null,n,!0),i.setImgSmoothing(a,!0))},$o.levelIsComplete=function(e,t){var n=this.layersByLevel[e];if(!n||0===n.length)return!1;for(var r=0,i=0;i0)return!1;if(a.invalid)return!1;r+=a.eles.length}return r===t.length},$o.validateLayersElesOrdering=function(e,t){var n=this.layersByLevel[e];if(n)for(var r=0;r0){e=!0;break}}return e},$o.invalidateElements=function(e){var t=this;0!==e.length&&(t.lastInvalidationTime=se(),0!==e.length&&t.haveLayers()&&t.updateElementsInLayers(e,function(e,n,r){t.invalidateLayer(e)}))},$o.invalidateLayer=function(e){if(this.lastInvalidationTime=se(),!e.invalid){var t=e.level,n=e.eles,r=this.layersByLevel[t];_e(r,e),e.elesQueue=[],e.invalid=!0,e.replacement&&(e.replacement.invalid=!0);for(var i=0;i3&&void 0!==arguments[3])||arguments[3],i=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],a=!(arguments.length>5&&void 0!==arguments[5])||arguments[5],o=this,s=t._private.rscratch;if(t.visible()&&!s.badLine&&null!=s.allpts&&!isNaN(s.allpts[0])){var l;n&&(l=n,e.translate(-l.x1,-l.y1));var u=a?t.pstyle("opacity").value:1,c=t.pstyle("line-style").value,h=t.pstyle("width").pfValue,d=t.pstyle("line-cap").value,p=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u;e.lineWidth=h,e.lineCap=d,o.eleStrokeStyle(e,t,n),o.drawEdgePath(t,e,s.allpts,c),e.lineCap="butt"},f=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u;o.drawArrowheads(e,t,n)};if(e.lineJoin="round","yes"===t.pstyle("ghost").value){var g=t.pstyle("ghost-offset-x").pfValue,v=t.pstyle("ghost-offset-y").pfValue,y=t.pstyle("ghost-opacity").value,m=u*y;e.translate(g,v),p(m),f(m),e.translate(-g,-v)}p(),f(),i&&o.drawEdgeOverlay(e,t),o.drawElementText(e,t,null,r),n&&e.translate(l.x1,l.y1)}},drawEdgeOverlay:function(e,t){if(t.visible()){var n=t.pstyle("overlay-opacity").value;if(0!==n){var r=this,i=r.usePaths(),a=t._private.rscratch,o=2*t.pstyle("overlay-padding").pfValue,s=t.pstyle("overlay-color").value;e.lineWidth=o,"self"!==a.edgeType||i?e.lineCap="round":e.lineCap="butt",r.colorStrokeStyle(e,s[0],s[1],s[2],n),r.drawEdgePath(t,e,a.allpts,"solid")}}},drawEdgePath:function(e,t,n,r){var i,a=e._private.rscratch,o=t,s=!1,l=this.usePaths(),u=e.pstyle("line-dash-pattern").pfValue,c=e.pstyle("line-dash-offset").pfValue;if(l){var h=n.join("$");a.pathCacheKey&&a.pathCacheKey===h?(i=t=a.pathCache,s=!0):(i=t=new Path2D,a.pathCacheKey=h,a.pathCache=i)}if(o.setLineDash)switch(r){case"dotted":o.setLineDash([1,1]);break;case"dashed":o.setLineDash(u),o.lineDashOffset=c;break;case"solid":o.setLineDash([])}if(!s&&!a.badLine)switch(t.beginPath&&t.beginPath(),t.moveTo(n[0],n[1]),a.edgeType){case"bezier":case"self":case"compound":case"multibezier":for(var d=2;d+35&&void 0!==arguments[5])||arguments[5],o=this;if(null==r){if(!o.eleTextBiggerThanMin(t))return}else if(!1===r)return;if(t.isNode()){if(!(s=t.pstyle("label"))||!s.value)return;switch(t.pstyle("text-halign").strValue){case"left":e.textAlign="right";break;case"right":e.textAlign="left";break;default:e.textAlign="center"}e.textBaseline="bottom"}else{var s=t.pstyle("label"),l=t.pstyle("source-label"),u=t.pstyle("target-label");if(!(s&&s.value||l&&l.value||u&&u.value))return;e.textAlign="center",e.textBaseline="bottom"}var c,h=!n;n&&(c=n,e.translate(-c.x1,-c.y1)),null==i?(o.drawText(e,t,null,h,a),t.isEdge()&&(o.drawText(e,t,"source",h,a),o.drawText(e,t,"target",h,a))):o.drawText(e,t,i,h,a),n&&e.translate(c.x1,c.y1)},ps.getFontCache=function(e){var t;this.fontCaches=this.fontCaches||[];for(var n=0;n2&&void 0!==arguments[2])||arguments[2],r=t.pstyle("font-style").strValue,i=t.pstyle("font-size").pfValue+"px",a=t.pstyle("font-family").strValue,o=t.pstyle("font-weight").strValue,s=t.pstyle("text-opacity").value*(n?t.effectiveOpacity():1),l=t.pstyle("text-outline-opacity").value*s,u=t.pstyle("color").value,c=t.pstyle("text-outline-color").value;e.font=r+" "+o+" "+i+" "+a,e.lineJoin="round",this.colorFillStyle(e,u[0],u[1],u[2],s),this.colorStrokeStyle(e,c[0],c[1],c[2],l)},ps.getTextAngle=function(e,t){var n=e._private.rscratch,r=t?t+"-":"",i=e.pstyle(r+"text-rotation"),a=Ne(n,"labelAngle",t);return"autorotate"===i.strValue?e.isEdge()?a:0:"none"===i.strValue?0:i.pfValue},ps.drawText=function(e,t,n){var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],a=t._private.rscratch,o=i?t.effectiveOpacity():1;if(0!==o&&0!==t.pstyle("text-opacity").value){"main"===n&&(n=null);var s,l,u,c,h,d,p=Ne(a,"labelX",n),f=Ne(a,"labelY",n),g=this.getLabelText(t,n);if(null!=g&&""!==g&&!isNaN(p)&&!isNaN(f)){this.setupTextStyle(e,t,i);var v,y=n?n+"-":"",m=Ne(a,"labelWidth",n),b=Ne(a,"labelHeight",n),x=t.pstyle(y+"text-margin-x").pfValue,w=t.pstyle(y+"text-margin-y").pfValue,E=t.isEdge(),k=t.pstyle("text-halign").value,C=t.pstyle("text-valign").value;if(E&&(k="center",C="center"),p+=x,f+=w,0!==(v=r?this.getTextAngle(t,n):0)){var S=p,D=f;e.translate(S,D),e.rotate(v),p=0,f=0}switch(C){case"top":break;case"center":f+=b/2;break;case"bottom":f+=b}var P=t.pstyle("text-background-opacity").value,T=t.pstyle("text-border-opacity").value,M=t.pstyle("text-border-width").pfValue,_=t.pstyle("text-background-padding").pfValue;if(P>0||M>0&&T>0){var B=p-_;switch(k){case"left":B-=m;break;case"center":B-=m/2}var N=f-b-_,I=m+2*_,z=b+2*_;if(P>0){var A=e.fillStyle,L=t.pstyle("text-background-color").value;e.fillStyle="rgba("+L[0]+","+L[1]+","+L[2]+","+P*o+")","roundrectangle"==t.pstyle("text-background-shape").strValue?(l=B,u=N,c=I,h=z,d=(d=2)||5,(s=e).beginPath(),s.moveTo(l+d,u),s.lineTo(l+c-d,u),s.quadraticCurveTo(l+c,u,l+c,u+d),s.lineTo(l+c,u+h-d),s.quadraticCurveTo(l+c,u+h,l+c-d,u+h),s.lineTo(l+d,u+h),s.quadraticCurveTo(l,u+h,l,u+h-d),s.lineTo(l,u+d),s.quadraticCurveTo(l,u,l+d,u),s.closePath(),s.fill()):e.fillRect(B,N,I,z),e.fillStyle=A}if(M>0&&T>0){var O=e.strokeStyle,R=e.lineWidth,F=t.pstyle("text-border-color").value,V=t.pstyle("text-border-style").value;if(e.strokeStyle="rgba("+F[0]+","+F[1]+","+F[2]+","+T*o+")",e.lineWidth=M,e.setLineDash)switch(V){case"dotted":e.setLineDash([1,1]);break;case"dashed":e.setLineDash([4,2]);break;case"double":e.lineWidth=M/4,e.setLineDash([]);break;case"solid":e.setLineDash([])}if(e.strokeRect(B,N,I,z),"double"===V){var q=M/2;e.strokeRect(B+q,N+q,I-2*q,z-2*q)}e.setLineDash&&e.setLineDash([]),e.lineWidth=R,e.strokeStyle=O}}var Y=2*t.pstyle("text-outline-width").pfValue;if(Y>0&&(e.lineWidth=Y),"wrap"===t.pstyle("text-wrap").value){var X=Ne(a,"labelWrapCachedLines",n),j=b/X.length;switch(C){case"top":f-=(X.length-1)*j;break;case"center":case"bottom":f-=(X.length-1)*j}for(var W=0;W0&&e.strokeText(X[W],p,f),e.fillText(X[W],p,f),f+=j}else Y>0&&e.strokeText(g,p,f),e.fillText(g,p,f);0!==v&&(e.rotate(-v),e.translate(-S,-D))}}};var fs={drawNode:function(e,t,n){var r,i,a=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],s=!(arguments.length>5&&void 0!==arguments[5])||arguments[5],l=this,u=t._private,c=u.rscratch,h=t.position();if(v(h.x)&&v(h.y)&&t.visible()){var d,p,f=s?t.effectiveOpacity():1,g=l.usePaths(),y=!1,m=t.padding();r=t.width()+2*m,i=t.height()+2*m,n&&(p=n,e.translate(-p.x1,-p.y1));for(var b=t.pstyle("background-image").value,x=new Array(b.length),w=new Array(b.length),E=0,k=0;k0&&void 0!==arguments[0]?arguments[0]:T;l.eleFillStyle(e,t,n)},I=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:B;l.colorStrokeStyle(e,M[0],M[1],M[2],t)},z=t.pstyle("shape").strValue,A=t.pstyle("shape-polygon-points").pfValue;if(g){e.translate(h.x,h.y);var L=l.nodePathCache=l.nodePathCache||[],O=de("polygon"===z?z+","+A.join(","):z,""+i,""+r),R=L[O];null!=R?(d=R,y=!0,c.pathCache=d):(d=new Path2D,L[O]=c.pathCache=d)}var F=function(){if(!y){var n=h;g&&(n={x:0,y:0}),l.nodeShapes[l.getNodeShape(t)].draw(d||e,n.x,n.y,r,i)}g?e.fill(d):e.fill()},V=function(){for(var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:f,r=u.backgrounding,i=0,a=0;a0&&void 0!==arguments[0]&&arguments[0],a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:f;l.hasPie(t)&&(l.drawPie(e,t,a),n&&(g||l.nodeShapes[l.getNodeShape(t)].draw(e,h.x,h.y,r,i)))},Y=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:f,n=(D>0?D:-D)*t,r=D>0?0:255;0!==D&&(l.colorFillStyle(e,r,r,r,n),g?e.fill(d):e.fill())},X=function(){if(P>0){if(e.lineWidth=P,e.lineCap="butt",e.setLineDash)switch(_){case"dotted":e.setLineDash([1,1]);break;case"dashed":e.setLineDash([4,2]);break;case"solid":case"double":e.setLineDash([])}if(g?e.stroke(d):e.stroke(),"double"===_){e.lineWidth=P/3;var t=e.globalCompositeOperation;e.globalCompositeOperation="destination-out",g?e.stroke(d):e.stroke(),e.globalCompositeOperation=t}e.setLineDash&&e.setLineDash([])}};if("yes"===t.pstyle("ghost").value){var j=t.pstyle("ghost-offset-x").pfValue,W=t.pstyle("ghost-offset-y").pfValue,H=t.pstyle("ghost-opacity").value,K=H*f;e.translate(j,W),N(H*T),F(),V(K),q(0!==D||0!==P),Y(K),I(H*B),X(),e.translate(-j,-W)}N(),F(),V(),q(0!==D||0!==P),Y(),I(),X(),g&&e.translate(-h.x,-h.y),l.drawElementText(e,t,null,a),o&&l.drawNodeOverlay(e,t,h,r,i),n&&e.translate(p.x1,p.y1)}},drawNodeOverlay:function(e,t,n,r,i){if(t.visible()){var a=t.pstyle("overlay-padding").pfValue,o=t.pstyle("overlay-opacity").value,s=t.pstyle("overlay-color").value;if(o>0){if(n=n||t.position(),null==r||null==i){var l=t.padding();r=t.width()+2*l,i=t.height()+2*l}this.colorFillStyle(e,s[0],s[1],s[2],o),this.nodeShapes.roundrectangle.draw(e,n.x,n.y,r+2*a,i+2*a),e.fill()}}},hasPie:function(e){return(e=e[0])._private.hasPie},drawPie:function(e,t,n,r){t=t[0],r=r||t.position();var i=t.cy().style(),a=t.pstyle("pie-size"),o=r.x,s=r.y,l=t.width(),u=t.height(),c=Math.min(l,u)/2,h=0;this.usePaths()&&(o=0,s=0),"%"===a.units?c*=a.pfValue:void 0!==a.pfValue&&(c=a.pfValue/2);for(var d=1;d<=i.pieBackgroundN;d++){var p=t.pstyle("pie-"+d+"-background-size").value,f=t.pstyle("pie-"+d+"-background-color").value,g=t.pstyle("pie-"+d+"-background-opacity").value*n,v=p/100;v+h>1&&(v=1-h);var y=1.5*Math.PI+2*Math.PI*h,m=y+2*Math.PI*v;0===p||h>=1||h+v>1||(e.beginPath(),e.moveTo(o,s),e.arc(o,s,c,y,m),e.closePath(),this.colorFillStyle(e,f[0],f[1],f[2],g),e.fill(),h+=v)}}},gs={};gs.getPixelRatio=function(){var e=this.data.contexts[0];if(null!=this.forcedPixelRatio)return this.forcedPixelRatio;var t=e.backingStorePixelRatio||e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1;return(window.devicePixelRatio||1)/t},gs.paintCache=function(e){for(var t,n=this.paintCaches=this.paintCaches||[],r=!0,i=0;io.minMbLowQualFrames&&(o.motionBlurPxRatio=o.mbPxRBlurry)),o.clearingMotionBlur&&(o.motionBlurPxRatio=1),o.textureDrawLastFrame&&!h&&(c[o.NODE]=!0,c[o.SELECT_BOX]=!0);var m=l.style(),b=l.zoom(),x=void 0!==i?i:b,w=l.pan(),E={x:w.x,y:w.y},k={zoom:b,pan:{x:w.x,y:w.y}},C=o.prevViewport;void 0===C||k.zoom!==C.zoom||k.pan.x!==C.pan.x||k.pan.y!==C.pan.y||g&&!f||(o.motionBlurPxRatio=1),a&&(E=a),x*=s,E.x*=s,E.y*=s;var S=o.getCachedZSortedEles();function D(e,t,n,r,i){var a=e.globalCompositeOperation;e.globalCompositeOperation="destination-out",o.colorFillStyle(e,255,255,255,o.motionBlurTransparency),e.fillRect(t,n,r,i),e.globalCompositeOperation=a}function P(e,r){var s,l,c,h;o.clearingMotionBlur||e!==u.bufferContexts[o.MOTIONBLUR_BUFFER_NODE]&&e!==u.bufferContexts[o.MOTIONBLUR_BUFFER_DRAG]?(s=E,l=x,c=o.canvasWidth,h=o.canvasHeight):(s={x:w.x*p,y:w.y*p},l=b*p,c=o.canvasWidth*p,h=o.canvasHeight*p),e.setTransform(1,0,0,1,0,0),"motionBlur"===r?D(e,0,0,c,h):t||void 0!==r&&!r||e.clearRect(0,0,c,h),n||(e.translate(s.x,s.y),e.scale(l,l)),a&&e.translate(a.x,a.y),i&&e.scale(i,i)}if(h||(o.textureDrawLastFrame=!1),h){if(o.textureDrawLastFrame=!0,!o.textureCache){o.textureCache={},o.textureCache.bb=l.mutableElements().boundingBox(),o.textureCache.texture=o.data.bufferCanvases[o.TEXTURE_BUFFER];var T=o.data.bufferContexts[o.TEXTURE_BUFFER];T.setTransform(1,0,0,1,0,0),T.clearRect(0,0,o.canvasWidth*o.textureMult,o.canvasHeight*o.textureMult),o.render({forcedContext:T,drawOnlyNodeLayer:!0,forcedPxRatio:s*o.textureMult}),(k=o.textureCache.viewport={zoom:l.zoom(),pan:l.pan(),width:o.canvasWidth,height:o.canvasHeight}).mpan={x:(0-k.pan.x)/k.zoom,y:(0-k.pan.y)/k.zoom}}c[o.DRAG]=!1,c[o.NODE]=!1;var M=u.contexts[o.NODE],_=o.textureCache.texture;k=o.textureCache.viewport;M.setTransform(1,0,0,1,0,0),d?D(M,0,0,k.width,k.height):M.clearRect(0,0,k.width,k.height);var B=m.core("outside-texture-bg-color").value,N=m.core("outside-texture-bg-opacity").value;o.colorFillStyle(M,B[0],B[1],B[2],N),M.fillRect(0,0,k.width,k.height);b=l.zoom();P(M,!1),M.clearRect(k.mpan.x,k.mpan.y,k.width/k.zoom/s,k.height/k.zoom/s),M.drawImage(_,k.mpan.x,k.mpan.y,k.width/k.zoom/s,k.height/k.zoom/s)}else o.textureOnViewport&&!t&&(o.textureCache=null);var I=l.extent(),z=o.pinching||o.hoverData.dragging||o.swipePanning||o.data.wheelZooming||o.hoverData.draggingEles,A=o.hideEdgesOnViewport&&z,L=[];if(L[o.NODE]=!c[o.NODE]&&d&&!o.clearedForMotionBlur[o.NODE]||o.clearingMotionBlur,L[o.NODE]&&(o.clearedForMotionBlur[o.NODE]=!0),L[o.DRAG]=!c[o.DRAG]&&d&&!o.clearedForMotionBlur[o.DRAG]||o.clearingMotionBlur,L[o.DRAG]&&(o.clearedForMotionBlur[o.DRAG]=!0),c[o.NODE]||n||r||L[o.NODE]){var O=d&&!L[o.NODE]&&1!==p;P(M=t||(O?o.data.bufferContexts[o.MOTIONBLUR_BUFFER_NODE]:u.contexts[o.NODE]),d&&!O?"motionBlur":void 0),A?o.drawCachedNodes(M,S.nondrag,s,I):o.drawLayeredElements(M,S.nondrag,s,I),o.debug&&o.drawDebugPoints(M,S.nondrag),n||d||(c[o.NODE]=!1)}if(!r&&(c[o.DRAG]||n||L[o.DRAG])){O=d&&!L[o.DRAG]&&1!==p;P(M=t||(O?o.data.bufferContexts[o.MOTIONBLUR_BUFFER_DRAG]:u.contexts[o.DRAG]),d&&!O?"motionBlur":void 0),A?o.drawCachedNodes(M,S.drag,s,I):o.drawCachedElements(M,S.drag,s,I),o.debug&&o.drawDebugPoints(M,S.drag),n||d||(c[o.DRAG]=!1)}if(o.showFps||!r&&c[o.SELECT_BOX]&&!n){if(P(M=t||u.contexts[o.SELECT_BOX]),1==o.selection[4]&&(o.hoverData.selecting||o.touchData.selecting)){b=o.cy.zoom();var R=m.core("selection-box-border-width").value/b;M.lineWidth=R,M.fillStyle="rgba("+m.core("selection-box-color").value[0]+","+m.core("selection-box-color").value[1]+","+m.core("selection-box-color").value[2]+","+m.core("selection-box-opacity").value+")",M.fillRect(o.selection[0],o.selection[1],o.selection[2]-o.selection[0],o.selection[3]-o.selection[1]),R>0&&(M.strokeStyle="rgba("+m.core("selection-box-border-color").value[0]+","+m.core("selection-box-border-color").value[1]+","+m.core("selection-box-border-color").value[2]+","+m.core("selection-box-opacity").value+")",M.strokeRect(o.selection[0],o.selection[1],o.selection[2]-o.selection[0],o.selection[3]-o.selection[1]))}if(u.bgActivePosistion&&!o.hoverData.selecting){b=o.cy.zoom();var F=u.bgActivePosistion;M.fillStyle="rgba("+m.core("active-bg-color").value[0]+","+m.core("active-bg-color").value[1]+","+m.core("active-bg-color").value[2]+","+m.core("active-bg-opacity").value+")",M.beginPath(),M.arc(F.x,F.y,m.core("active-bg-size").pfValue/b,0,2*Math.PI),M.fill()}var V=o.lastRedrawTime;if(o.showFps&&V){V=Math.round(V);var q=Math.round(1e3/V);M.setTransform(1,0,0,1,0,0),M.fillStyle="rgba(255, 0, 0, 0.75)",M.strokeStyle="rgba(255, 0, 0, 0.75)",M.lineWidth=1,M.fillText("1 frame = "+V+" ms = "+q+" fps",0,20);M.strokeRect(0,30,250,20),M.fillRect(0,30,250*Math.min(q/60,1),20)}n||(c[o.SELECT_BOX]=!1)}if(d&&1!==p){var Y=u.contexts[o.NODE],X=o.data.bufferCanvases[o.MOTIONBLUR_BUFFER_NODE],j=u.contexts[o.DRAG],W=o.data.bufferCanvases[o.MOTIONBLUR_BUFFER_DRAG],H=function(e,t,n){e.setTransform(1,0,0,1,0,0),n||!y?e.clearRect(0,0,o.canvasWidth,o.canvasHeight):D(e,0,0,o.canvasWidth,o.canvasHeight);var r=p;e.drawImage(t,0,0,o.canvasWidth*r,o.canvasHeight*r,0,0,o.canvasWidth,o.canvasHeight)};(c[o.NODE]||L[o.NODE])&&(H(Y,X,L[o.NODE]),c[o.NODE]=!1),(c[o.DRAG]||L[o.DRAG])&&(H(j,W,L[o.DRAG]),c[o.DRAG]=!1)}o.prevViewport=k,o.clearingMotionBlur&&(o.clearingMotionBlur=!1,o.motionBlurCleared=!0,o.motionBlur=!0),d&&(o.motionBlurTimeout=setTimeout(function(){o.motionBlurTimeout=null,o.clearedForMotionBlur[o.NODE]=!1,o.clearedForMotionBlur[o.DRAG]=!1,o.motionBlur=!1,o.clearingMotionBlur=!h,o.mbFrames=0,c[o.NODE]=!0,c[o.DRAG]=!0,o.redraw()},100)),t||l.emit("render")};for(var vs={drawPolygonPath:function(e,t,n,r,i,a){var o=r/2,s=i/2;e.beginPath&&e.beginPath(),e.moveTo(t+o*a[0],n+s*a[1]);for(var l=1;l0&&a>0){d.clearRect(0,0,i,a),d.globalCompositeOperation="source-over";var p=this.getCachedZSortedEles();if(e.full)d.translate(-n.x1*l,-n.y1*l),d.scale(l,l),this.drawElements(d,p),d.scale(1/l,1/l),d.translate(n.x1*l,n.y1*l);else{var f=t.pan(),g={x:f.x*l,y:f.y*l};l*=t.zoom(),d.translate(g.x,g.y),d.scale(l,l),this.drawElements(d,p),d.scale(1/l,1/l),d.translate(-g.x,-g.y)}e.bg&&(d.globalCompositeOperation="destination-over",d.fillStyle=e.bg,d.rect(0,0,i,a),d.fill())}return h},ks.png=function(e){return Ss(e,this.bufferCanvasImage(e),"image/png")},ks.jpg=function(e){return Ss(e,this.bufferCanvasImage(e),"image/jpeg")};var Ds={nodeShapeImpl:function(e,t,n,r,i,a,o){switch(e){case"ellipse":return this.drawEllipsePath(t,n,r,i,a);case"polygon":return this.drawPolygonPath(t,n,r,i,a,o);case"roundrectangle":case"round-rectangle":return this.drawRoundRectanglePath(t,n,r,i,a);case"cutrectangle":case"cut-rectangle":return this.drawCutRectanglePath(t,n,r,i,a);case"bottomroundrectangle":case"bottom-round-rectangle":return this.drawBottomRoundRectanglePath(t,n,r,i,a);case"barrel":return this.drawBarrelPath(t,n,r,i,a)}}},Ps=Ms,Ts=Ms.prototype;function Ms(e){var t=this;t.data={canvases:new Array(Ts.CANVAS_LAYERS),contexts:new Array(Ts.CANVAS_LAYERS),canvasNeedsRedraw:new Array(Ts.CANVAS_LAYERS),bufferCanvases:new Array(Ts.BUFFER_COUNT),bufferContexts:new Array(Ts.CANVAS_LAYERS)};var n="-webkit-tap-highlight-color: rgba(0,0,0,0);";t.data.canvasContainer=document.createElement("div");var r=t.data.canvasContainer.style;t.data.canvasContainer.setAttribute("style",n),r.position="relative",r.zIndex="0",r.overflow="hidden";var i=e.cy.container();i.appendChild(t.data.canvasContainer),(i.getAttribute("style")||"").indexOf(n)<0&&i.setAttribute("style",(i.getAttribute("style")||"")+n);for(var a=0;at?1:0},z=null!=Object.assign?Object.assign.bind(Object):function(e){for(var t=arguments,n=1;n255)return;t.push(Math.floor(a))}var o=r[1]||r[2]||r[3],s=r[1]&&r[2]&&r[3];if(o&&!s)return;var l=n[4];if(void 0!==l){if((l=parseFloat(l))<0||l>1)return;t.push(l)}}return t}(e)||function(e){var t,n,r,i,a,o,s,l;function u(e,t,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?e+6*(t-e)*n:n<.5?t:n<2/3?e+(t-e)*(2/3-n)*6:e}var c=new RegExp("^hsl[a]?\\(((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?)))\\s*,\\s*((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?))[%])\\s*,\\s*((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?))[%])(?:\\s*,\\s*((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?))))?\\)$").exec(e);if(c){if((n=parseInt(c[1]))<0?n=(360- -1*n%360)%360:n>360&&(n%=360),n/=360,(r=parseFloat(c[2]))<0||r>100)return;if(r/=100,(i=parseFloat(c[3]))<0||i>100)return;if(i/=100,void 0!==(a=c[4])&&((a=parseFloat(a))<0||a>1))return;if(0===r)o=s=l=Math.round(255*i);else{var h=i<.5?i*(1+r):i+r-i*r,d=2*i-h;o=Math.round(255*u(d,h,n+1/3)),s=Math.round(255*u(d,h,n)),l=Math.round(255*u(d,h,n-1/3))}t=[o,s,l,a]}return t}(e)},L={transparent:[0,0,0,0],aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],grey:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},A=function(e){for(var t=e.map,n=e.keys,r=n.length,i=0;i=t||n<0||h&&e-u>=a}function g(){var e=J();if(f(e))return v(e);s=setTimeout(g,function(e){var n=t-(e-l);return h?Q(n,a-(e-u)):n}(e))}function v(e){return s=void 0,d&&r?p(e):(r=i=void 0,o)}function y(){var e=J(),n=f(e);if(r=arguments,i=this,l=e,n){if(void 0===s)return function(e){return u=e,s=setTimeout(g,t),c?p(e):o}(l);if(h)return s=setTimeout(g,t),p(l)}return void 0===s&&(s=setTimeout(g,t)),o}return t=te(t)||0,ee(n)&&(c=!!n.leading,a=(h="maxWait"in n)?$(te(n.maxWait)||0,t):a,d="trailing"in n?!!n.trailing:d),y.cancel=function(){void 0!==s&&clearTimeout(s),u=0,r=l=i=s=void 0},y.flush=function(){return void 0===s?o:v(J())},y},re=a?a.performance:null,ie=re&&re.now?function(){return re.now()}:function(){return Date.now()},ae=function(){if(a){if(a.requestAnimationFrame)return function(e){a.requestAnimationFrame(e)};if(a.mozRequestAnimationFrame)return function(e){a.mozRequestAnimationFrame(e)};if(a.webkitRequestAnimationFrame)return function(e){a.webkitRequestAnimationFrame(e)};if(a.msRequestAnimationFrame)return function(e){a.msRequestAnimationFrame(e)}}return function(e){e&&setTimeout(function(){e(ie())},1e3/60)}}(),oe=function(e){return ae(e)},se=ie,le=function(e){for(var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5381;!(t=e.next()).done;)n=33*n^t.value;return n>>>0},ue=function(e){return(33*(arguments.length>1&&void 0!==arguments[1]?arguments[1]:5381)^e)>>>0},ce=function(e,t){var n={value:0,done:!1},r=0,i=e.length;return le({next:function(){return r=0&&(e[r]!==t||(e.splice(r,1),n));r--);},_e=function(e){e.splice(0,e.length)},Ne=function(e,t,n){return n&&(t=B(n,t)),e[t]},ze=function(e,t,n,r){n&&(t=B(n,t)),e[t]=r},Ie="undefined"!=typeof Map?Map:function(){function e(){t(this,e),this._obj={}}return r(e,[{key:"set",value:function(e,t){return this._obj[e]=t,this}},{key:"delete",value:function(e){return this._obj[e]=void 0,this}},{key:"clear",value:function(){this._obj={}}},{key:"has",value:function(e){return void 0!==this._obj[e]}},{key:"get",value:function(e){return this._obj[e]}}]),e}(),Le=function(){function e(n){if(t(this,e),this._obj=Object.create(null),this.size=0,null!=n){var r;r=null!=n.instanceString&&n.instanceString()===this.instanceString()?n.toArray():n;for(var i=0;it?1:0},u=function(e,t,i,a,o){var s;if(null==i&&(i=0),null==o&&(o=n),i<0)throw new Error("lo must be non-negative");for(null==a&&(a=e.length);in;0<=n?t++:t--)u.push(t);return u}.apply(this).reverse()).length;ag;0<=g?++d:--d)v.push(a(e,r));return v},f=function(e,t,r,i){var a,o,s;for(null==i&&(i=n),a=e[r];r>t&&i(a,o=e[s=r-1>>1])<0;)e[r]=o,r=s;return e[r]=a},g=function(e,t,r){var i,a,o,s,l;for(null==r&&(r=n),a=e.length,l=t,o=e[t],i=2*t+1;i0;){var k=b.pop(),C=y(k),S=k.id();if(h[S]=C,C!==1/0)for(var D=k.neighborhood().intersect(f),P=0;P0)for(n.unshift(t);c[i];){var a=c[i];n.unshift(a.edge),n.unshift(a.node),i=(r=a.node).id()}return o.spawn(n)}}}},je={kruskal:function(e){e=e||function(e){return 1};for(var t=this.byGroup(),n=t.nodes,r=t.edges,i=n.length,a=new Array(i),o=n,s=function(e){for(var t=0;t0;){if(l=g.pop(),u=l.id(),v.delete(u),w++,u===h){for(var E=[],k=i,C=h,S=m[C];E.unshift(k),null!=S&&E.unshift(S),null!=(k=y[C]);)S=m[C=k.id()];return{found:!0,distance:d[u],path:this.spawn(E),steps:w}}f[u]=!0;for(var D=l._private.edges,P=0;PP&&(f[D]=P,m[D]=S,b[D]=w),!i){var T=S*u+C;!i&&f[T]>P&&(f[T]=P,m[T]=C,b[T]=w)}}}for(var B=0;B1&&void 0!==arguments[1]?arguments[1]:a,r=[],i=m(e);;){if(null==i)return t.spawn();var o=y(i),l=o.edge,u=o.pred;if(r.unshift(i[0]),i.same(n)&&r.length>0)break;null!=l&&r.unshift(l),i=u}return s.spawn(r)},hasNegativeWeightCycle:g,negativeWeightCycles:[]}}},Ue=Math.sqrt(2),$e=function(e,t,n){0===n.length&&Ee("Karger-Stein must be run on a connected (sub)graph");for(var r=n[e],i=r[1],a=r[2],o=t[i],s=t[a],l=n,u=l.length-1;u>=0;u--){var c=l[u],h=c[1],d=c[2];(t[h]===o&&t[d]===s||t[h]===s&&t[d]===o)&&l.splice(u,1)}for(var p=0;pr;){var i=Math.floor(Math.random()*t.length);t=$e(i,e,t),n--}return t},Je={kargerStein:function(){var e=this.byGroup(),t=e.nodes,n=e.edges;n.unmergeBy(function(e){return e.isLoop()});var r=t.length,i=n.length,a=Math.ceil(Math.pow(Math.log(r)/Math.LN2,2)),o=Math.floor(r/Ue);if(!(r<2)){for(var s=[],l=0;l0?1:e<0?-1:0},st=function(e,t){return Math.sqrt(lt(e,t))},lt=function(e,t){var n=t.x-e.x,r=t.y-e.y;return n*n+r*r},ut=function(e){for(var t=e.length,n=0,r=0;r=e.x1&&e.y2>=e.y1)return{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,w:e.x2-e.x1,h:e.y2-e.y1};if(null!=e.w&&null!=e.h&&e.w>=0&&e.h>=0)return{x1:e.x1,y1:e.y1,x2:e.x1+e.w,y2:e.y1+e.h,w:e.w,h:e.h}}},ft=function(e,t,n){e.x1=Math.min(e.x1,t),e.x2=Math.max(e.x2,t),e.w=e.x2-e.x1,e.y1=Math.min(e.y1,n),e.y2=Math.max(e.y2,n),e.h=e.y2-e.y1},gt=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return e.x1-=t,e.x2+=t,e.y1-=t,e.y2+=t,e.w=e.x2-e.x1,e.h=e.y2-e.y1,e},vt=function(e,t){e.x1=t.x1,e.y1=t.y1,e.x2=t.x2,e.y2=t.y2,e.w=e.x2-e.x1,e.h=e.y2-e.y1},yt=function(e,t){e.x1+=t.x,e.x2+=t.x,e.y1+=t.y,e.y2+=t.y},mt=function(e,t){return!(e.x1>t.x2)&&(!(t.x1>e.x2)&&(!(e.x2t.y2)&&!(t.y1>e.y2)))))))},bt=function(e,t,n){return e.x1<=t&&t<=e.x2&&e.y1<=n&&n<=e.y2},xt=function(e,t){return bt(e,t.x1,t.y1)&&bt(e,t.x2,t.y2)},wt=function(e,t,n,r,i,a,o){var s,l=Vt(i,a),u=i/2,c=a/2,h=r-c-o;if((s=zt(e,t,n,r,n-u+l-o,h,n+u-l+o,h,!1)).length>0)return s;var d=n+u+o;if((s=zt(e,t,n,r,d,r-c+l-o,d,r+c-l+o,!1)).length>0)return s;var p=r+c+o;if((s=zt(e,t,n,r,n-u+l-o,p,n+u-l+o,p,!1)).length>0)return s;var f,g=n-u-o;if((s=zt(e,t,n,r,g,r-c+l-o,g,r+c-l+o,!1)).length>0)return s;var v=n-u+l,y=r-c+l;if((f=_t(e,t,n,r,v,y,l+o)).length>0&&f[0]<=v&&f[1]<=y)return[f[0],f[1]];var m=n+u-l,b=r-c+l;if((f=_t(e,t,n,r,m,b,l+o)).length>0&&f[0]>=m&&f[1]<=b)return[f[0],f[1]];var x=n+u-l,w=r+c-l;if((f=_t(e,t,n,r,x,w,l+o)).length>0&&f[0]>=x&&f[1]>=w)return[f[0],f[1]];var E=n-u+l,k=r+c-l;return(f=_t(e,t,n,r,E,k,l+o)).length>0&&f[0]<=E&&f[1]>=k?[f[0],f[1]]:[]},Et=function(e,t,n,r,i,a,o){var s=o,l=Math.min(n,i),u=Math.max(n,i),c=Math.min(r,a),h=Math.max(r,a);return l-s<=e&&e<=u+s&&c-s<=t&&t<=h+s},kt=function(e,t,n,r,i,a,o,s,l){var u=Math.min(n,o,i)-l,c=Math.max(n,o,i)+l,h=Math.min(r,s,a)-l,d=Math.max(r,s,a)+l;return!(ec||td)},Ct=function(e,t,n,r,i,a,o,s){var l=[];!function(e,t,n,r,i){var a,o,s,l,u,c,h,d;s=-27*(r/=e)+(t/=e)*(9*(n/=e)-t*t*2),a=(o=(3*n-t*t)/9)*o*o+(s/=54)*s,i[1]=0,h=t/3,a>0?(u=(u=s+Math.sqrt(a))<0?-Math.pow(-u,1/3):Math.pow(u,1/3),c=(c=s-Math.sqrt(a))<0?-Math.pow(-c,1/3):Math.pow(c,1/3),i[0]=-h+u+c,h+=(u+c)/2,i[4]=i[2]=-h,h=Math.sqrt(3)*(-c+u)/2,i[3]=h,i[5]=-h):(i[5]=i[3]=0,0===a?(d=s<0?-Math.pow(-s,1/3):Math.pow(s,1/3),i[0]=2*d-h,i[4]=i[2]=-(d+h)):(l=(o=-o)*o*o,l=Math.acos(s/Math.sqrt(l)),d=2*Math.sqrt(o),i[0]=-h+d*Math.cos(l/3),i[2]=-h+d*Math.cos((l+2*Math.PI)/3),i[4]=-h+d*Math.cos((l+4*Math.PI)/3)))}(1*n*n-4*n*i+2*n*o+4*i*i-4*i*o+o*o+r*r-4*r*a+2*r*s+4*a*a-4*a*s+s*s,9*n*i-3*n*n-3*n*o-6*i*i+3*i*o+9*r*a-3*r*r-3*r*s-6*a*a+3*a*s,3*n*n-6*n*i+n*o-n*e+2*i*i+2*i*e-o*e+3*r*r-6*r*a+r*s-r*t+2*a*a+2*a*t-s*t,1*n*i-n*n+n*e-i*e+r*a-r*r+r*t-a*t,l);for(var u=[],c=0;c<6;c+=2)Math.abs(l[c+1])<1e-7&&l[c]>=0&&l[c]<=1&&u.push(l[c]);u.push(1),u.push(0);for(var h,d,p,f=-1,g=0;g=0?pl?(e-i)*(e-i)+(t-a)*(t-a):u-h},Dt=function(e,t,n){for(var r,i,a,o,s=0,l=0;l=e&&e>=a||r<=e&&e<=a))continue;(e-r)/(a-r)*(o-i)+i>t&&s++}return s%2!=0},Pt=function(e,t,n,r,i,a,o,s,l){var u,c=new Array(n.length);null!=s[0]?(u=Math.atan(s[1]/s[0]),s[0]<0?u+=Math.PI/2:u=-u-Math.PI/2):u=s;for(var h,d=Math.cos(-u),p=Math.sin(-u),f=0;f0){var g=Bt(c,-l);h=Tt(g)}else h=c;return Dt(e,t,h)},Tt=function(e){for(var t,n,r,i,a,o,s,l,u=new Array(e.length/2),c=0;c=0&&f<=1&&v.push(f),g>=0&&g<=1&&v.push(g),0===v.length)return[];var y=v[0]*s[0]+e,m=v[0]*s[1]+t;return v.length>1?v[0]==v[1]?[y,m]:[y,m,v[1]*s[0]+e,v[1]*s[1]+t]:[y,m]},Nt=function(e,t,n){return t<=e&&e<=n||n<=e&&e<=t?e:e<=t&&t<=n||n<=t&&t<=e?t:n},zt=function(e,t,n,r,i,a,o,s,l){var u=e-i,c=n-e,h=o-i,d=t-a,p=r-t,f=s-a,g=h*d-f*u,v=c*d-p*u,y=f*c-h*p;if(0!==y){var m=g/y,b=v/y;return-.001<=m&&m<=1.001&&-.001<=b&&b<=1.001?[e+m*c,t+m*p]:l?[e+m*c,t+m*p]:[]}return 0===g||0===v?Nt(e,n,o)===o?[o,s]:Nt(e,n,i)===i?[i,a]:Nt(i,o,n)===n?[n,r]:[]:[]},It=function(e,t,n,r,i,a,o,s){var l,u,c,h,d,p,f=[],g=new Array(n.length),v=!0;if(null==a&&(v=!1),v){for(var y=0;y0){var m=Bt(g,-s);u=Tt(m)}else u=g}else u=n;for(var b=0;bu&&(u=t)},h=function(e){return l[e]},d=0;d0?b.edgesTo(m)[0]:m.edgesTo(b)[0];var w=r(x);m=m.id(),d[m]>d[v]+w&&(d[m]=d[v]+w,p.nodes.indexOf(m)<0?p.push(m):p.updateItem(m),u[m]=0,l[m]=[]),d[m]==d[v]+w&&(u[m]=u[m]+u[v],l[m].push(v))}else for(var E=0;E0;)for(var D=n.pop(),P=0;P0&&o.push(n[s]);0!==o.length&&i.push(r.collection(o))}return i}(c,l,t,r);return b=function(e){for(var t=0;t5&&void 0!==arguments[5]?arguments[5]:on,o=r,s=0;s=2?dn(e,t,n,0,un,cn):dn(e,t,n,0,ln)},squaredEuclidean:function(e,t,n){return dn(e,t,n,0,un)},manhattan:function(e,t,n){return dn(e,t,n,0,ln)},max:function(e,t,n){return dn(e,t,n,-1/0,hn)}};function fn(e,t,n,r,i,a){var o;return o=p(e)?e:pn[e]||pn.euclidean,0===t&&p(e)?o(i,a):o(t,n,r,i,a)}pn["squared-euclidean"]=pn.squaredEuclidean,pn.squaredeuclidean=pn.squaredEuclidean;var gn=Be({k:2,m:2,sensitivityThreshold:1e-4,distance:"euclidean",maxIterations:10,attributes:[],testMode:!1,testCentroids:null}),vn=function(e){return gn(e)},yn=function(e,t,n,r,i){var a="kMedoids"!==i?function(e){return n[e]}:function(e){return r[e](n)},o=n,s=t;return fn(e,r.length,a,function(e){return r[e](t)},o,s)},mn=function(e,t,n){for(var r=n.length,i=new Array(r),a=new Array(r),o=new Array(t),s=null,l=0;ln)return!1}return!0},En=function(e,t,n){for(var r=0;ri&&(i=t[l][u],a=u);o[a].push(e[l])}for(var c=0;c=i.threshold||"dendrogram"===i.mode&&1===e.length)return!1;var p,f=t[o],g=t[r[o]];p="dendrogram"===i.mode?{left:f,right:g,key:f.key}:{value:f.value.concat(g.value),key:f.key},e[f.index]=p,e.splice(g.index,1),t[f.key]=p;for(var v=0;vn[g.key][y.key]&&(a=n[g.key][y.key])):"max"===i.linkage?(a=n[f.key][y.key],n[f.key][y.key]1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],a=!(arguments.length>5&&void 0!==arguments[5])||arguments[5];r?e=e.slice(t,n):(n0&&e.splice(0,t));for(var o=0,s=e.length-1;s>=0;s--){var l=e[s];a?isFinite(l)||(e[s]=-1/0,o++):e.splice(s,1)}i&&e.sort(function(e,t){return e-t});var u=e.length,c=Math.floor(u/2);return u%2!=0?e[c+1+o]:(e[c-1+o]+e[c+o])/2}(e):"mean"===t?function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=0,i=0,a=t;a1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=1/0,i=t;i1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=-1/0,i=t;io&&(a=l,o=t[i*e+l])}a>0&&r.push(a)}for(var u=0;u=P?(T=P,P=M,B=_):M>T&&(T=M);for(var N=0;N0?1:0;C[k%u.minIterations*t+R]=V,O+=V}if(O>0&&(k>=u.minIterations-1||k==u.maxIterations-1)){for(var F=0,q=0;q0&&r.push(i);return r}(t,a,o),X=function(e,t,n){for(var r=Rn(e,t,n),i=0;il&&(s=u,l=c)}n[i]=a[s]}return r=Rn(e,t,n)}(t,r,j),W={},H=0;H0:void 0}},clearQueue:function(){return function(){var e=void 0!==this.length?this:[this];if(!(this._private.cy||this).styleEnabled())return this;for(var t=0;t0&&this.spawn(n).updateStyle().emit("class"),this},addClass:function(e){return this.toggleClass(e,!0)},hasClass:function(e){var t=this[0];return null!=t&&t._private.classes.has(e)},toggleClass:function(e,t){f(e)||(e=e.match(/\S+/g)||[]);for(var n=void 0===t,r=[],i=0,a=this.length;i0&&this.spawn(r).updateStyle().emit("class"),this},removeClass:function(e){return this.toggleClass(e,!1)},flashClass:function(e,t){var n=this;if(null==t)t=250;else if(0===t)return n;return n.addClass(e),setTimeout(function(){n.removeClass(e)},t),n}};Qn.className=Qn.classNames=Qn.classes;var Jn={metaChar:"[\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\]\\^\\`\\{\\|\\}\\~]",comparatorOp:"=|\\!=|>|>=|<|<=|\\$=|\\^=|\\*=",boolOp:"\\?|\\!|\\^",string:'"(?:\\\\"|[^"])*"|'+"'(?:\\\\'|[^'])*'",number:_,meta:"degree|indegree|outdegree",separator:"\\s*,\\s*",descendant:"\\s+",child:"\\s+>\\s+",subject:"\\$",group:"node|edge|\\*",directedEdge:"\\s+->\\s+",undirectedEdge:"\\s+<->\\s+"};Jn.variable="(?:[\\w-]|(?:\\\\"+Jn.metaChar+"))+",Jn.value=Jn.string+"|"+Jn.number,Jn.className=Jn.variable,Jn.id=Jn.variable,function(){var e,t,n;for(e=Jn.comparatorOp.split("|"),n=0;n=0||"="!==t&&(Jn.comparatorOp+="|\\!"+t)}();var er=0,tr=1,nr=2,rr=3,ir=4,ar=5,or=6,sr=7,lr=8,ur=9,cr=10,hr=11,dr=12,pr=13,fr=14,gr=15,vr=16,yr=17,mr=18,br=19,xr=20,wr=[{selector:":selected",matches:function(e){return e.selected()}},{selector:":unselected",matches:function(e){return!e.selected()}},{selector:":selectable",matches:function(e){return e.selectable()}},{selector:":unselectable",matches:function(e){return!e.selectable()}},{selector:":locked",matches:function(e){return e.locked()}},{selector:":unlocked",matches:function(e){return!e.locked()}},{selector:":visible",matches:function(e){return e.visible()}},{selector:":hidden",matches:function(e){return!e.visible()}},{selector:":transparent",matches:function(e){return e.transparent()}},{selector:":grabbed",matches:function(e){return e.grabbed()}},{selector:":free",matches:function(e){return!e.grabbed()}},{selector:":removed",matches:function(e){return e.removed()}},{selector:":inside",matches:function(e){return!e.removed()}},{selector:":grabbable",matches:function(e){return e.grabbable()}},{selector:":ungrabbable",matches:function(e){return!e.grabbable()}},{selector:":animated",matches:function(e){return e.animated()}},{selector:":unanimated",matches:function(e){return!e.animated()}},{selector:":parent",matches:function(e){return e.isParent()}},{selector:":childless",matches:function(e){return e.isChildless()}},{selector:":child",matches:function(e){return e.isChild()}},{selector:":orphan",matches:function(e){return e.isOrphan()}},{selector:":nonorphan",matches:function(e){return e.isChild()}},{selector:":compound",matches:function(e){return e.isNode()?e.isParent():e.source().isParent()||e.target().isParent()}},{selector:":loop",matches:function(e){return e.isLoop()}},{selector:":simple",matches:function(e){return e.isSimple()}},{selector:":active",matches:function(e){return e.active()}},{selector:":inactive",matches:function(e){return!e.active()}},{selector:":backgrounding",matches:function(e){return e.backgrounding()}},{selector:":nonbackgrounding",matches:function(e){return!e.backgrounding()}}].sort(function(e,t){return function(e,t){return-1*N(e,t)}(e.selector,t.selector)}),Er=function(){for(var e,t={},n=0;n0&&l.edgeCount>0)return Ce("The selector `"+e+"` is invalid because it uses both a compound selector and an edge selector"),!1;if(l.edgeCount>1)return Ce("The selector `"+e+"` is invalid because it uses multiple edge selectors"),!1;1===l.edgeCount&&Ce("The selector `"+e+"` is deprecated. Edge selectors do not take effect on changes to source and target nodes after an edge is added, for performance reasons. Use a class or data selector on edges instead, updating the class or data of an edge when your app detects a change in source or target nodes.")}return!0},toString:function(){if(null!=this.toStringCache)return this.toStringCache;for(var e=function(e){return null==e?"":e},t=function(t){return d(t)?'"'+t+'"':e(t)},n=function(e){return" "+e+" "},r=function(r,a){var o=r.type,s=r.value;switch(o){case er:var l=e(s);return l.substring(0,l.length-1);case rr:var u=r.field,c=r.operator;return"["+u+n(e(c))+t(s)+"]";case ar:var h=r.operator,d=r.field;return"["+e(h)+d+"]";case ir:return"["+r.field+"]";case or:var p=r.operator;return"[["+r.field+n(e(p))+t(s)+"]]";case sr:return s;case lr:return"#"+s;case ur:return"."+s;case yr:case gr:return i(r.parent,a)+n(">")+i(r.child,a);case mr:case vr:return i(r.ancestor,a)+" "+i(r.descendant,a);case br:var f=i(r.left,a),g=i(r.subject,a),v=i(r.right,a);return f+(f.length>0?" ":"")+g+v;case xr:return""}},i=function(e,t){return e.checks.reduce(function(n,i,a){return n+(t===e&&0===a?"$":"")+r(i,t)},"")},a="",o=0;o1&&o=0&&(t=t.replace("!",""),c=!0),t.indexOf("@")>=0&&(t=t.replace("@",""),u=!0),(o||l||u)&&(i=o||s?""+e:"",a=""+n),u&&(e=i=i.toLowerCase(),n=a=a.toLowerCase()),t){case"*=":r=i.indexOf(a)>=0;break;case"$=":r=i.indexOf(a,i.length-a.length)>=0;break;case"^=":r=0===i.indexOf(a);break;case"=":r=e===n;break;case">":h=!0,r=e>n;break;case">=":h=!0,r=e>=n;break;case"<":h=!0,r=e0;){var u=i.shift();t(u),a.add(u.id()),o&&r(i,a,u)}return e}function qr(e,t,n){if(n.isParent())for(var r=n._private.children,i=0;i1&&void 0!==arguments[1])||arguments[1],qr)},Vr.forEachUp=function(e){return Fr(this,e,!(arguments.length>1&&void 0!==arguments[1])||arguments[1],Yr)},Vr.forEachUpAndDown=function(e){return Fr(this,e,!(arguments.length>1&&void 0!==arguments[1])||arguments[1],jr)},Vr.ancestors=Vr.parents,(Ar=Or={data:Un.data({field:"data",bindingEvent:"data",allowBinding:!0,allowSetting:!0,settingEvent:"data",settingTriggersEvent:!0,triggerFnName:"trigger",allowGetting:!0,immutableKeys:{id:!0,source:!0,target:!0,parent:!0},updateStyle:!0}),removeData:Un.removeData({field:"data",event:"data",triggerFnName:"trigger",triggerEvent:!0,immutableKeys:{id:!0,source:!0,target:!0,parent:!0},updateStyle:!0}),scratch:Un.data({field:"scratch",bindingEvent:"scratch",allowBinding:!0,allowSetting:!0,settingEvent:"scratch",settingTriggersEvent:!0,triggerFnName:"trigger",allowGetting:!0,updateStyle:!0}),removeScratch:Un.removeData({field:"scratch",event:"scratch",triggerFnName:"trigger",triggerEvent:!0,updateStyle:!0}),rscratch:Un.data({field:"rscratch",allowBinding:!1,allowSetting:!0,settingTriggersEvent:!1,allowGetting:!0}),removeRscratch:Un.removeData({field:"rscratch",triggerEvent:!1}),id:function(){var e=this[0];if(e)return e._private.data.id}}).attr=Ar.data,Ar.removeAttr=Ar.removeData;var Xr,Wr,Hr=Or,Kr={};function Gr(e){return function(t){if(void 0===t&&(t=!0),0!==this.length&&this.isNode()&&!this.removed()){for(var n=0,r=this[0],i=r._private.edges,a=0;at}),minIndegree:Zr("indegree",function(e,t){return et}),minOutdegree:Zr("outdegree",function(e,t){return et})}),z(Kr,{totalDegree:function(e){for(var t=0,n=this.nodes(),r=0;r0,c=u;u&&(l=l[0]);var h=c?l.position():{x:0,y:0};return i={x:s.x-h.x,y:s.y-h.y},void 0===e?i:i[e]}for(var p=0;p0,m=y;y&&(v=v[0]);var b=m?v.position():{x:0,y:0};void 0!==t?f.position(e,t+b[e]):void 0!==i&&f.position({x:i.x+b.x,y:i.y+b.y})}}else if(!a)return;return this}}).modelPosition=Xr.point=Xr.position,Xr.modelPositions=Xr.points=Xr.positions,Xr.renderedPoint=Xr.renderedPosition,Xr.relativePoint=Xr.relativePosition;var Qr,Jr,ei=Wr;Qr=Jr={},Jr.renderedBoundingBox=function(e){var t=this.boundingBox(e),n=this.cy(),r=n.zoom(),i=n.pan(),a=t.x1*r+i.x,o=t.x2*r+i.x,s=t.y1*r+i.y,l=t.y2*r+i.y;return{x1:a,x2:o,y1:s,y2:l,w:o-a,h:l-s}},Jr.dirtyCompoundBoundsCache=function(){var e=this.cy();return e.styleEnabled()&&e.hasCompoundNodes()?(this.forEachUp(function(e){if(e.isParent()){var t=e._private;t.compoundBoundsClean=!1,t.bbCache=null,e.emitAndNotify("bounds")}}),this):this},Jr.updateCompoundBounds=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.cy();if(!t.styleEnabled()||!t.hasCompoundNodes())return this;if(!e&&t.batching())return this;function n(e){if(e.isParent()){var t=e._private,n=e.children(),r="include"===e.pstyle("compound-sizing-wrt-labels").value,i={width:{val:e.pstyle("min-width").pfValue,left:e.pstyle("min-width-bias-left"),right:e.pstyle("min-width-bias-right")},height:{val:e.pstyle("min-height").pfValue,top:e.pstyle("min-height-bias-top"),bottom:e.pstyle("min-height-bias-bottom")}},a=n.boundingBox({includeLabels:r,includeOverlays:!1,useCache:!1}),o=t.position;0!==a.w&&0!==a.h||((a={w:e.pstyle("width").pfValue,h:e.pstyle("height").pfValue}).x1=o.x-a.w/2,a.x2=o.x+a.w/2,a.y1=o.y-a.h/2,a.y2=o.y+a.h/2);var s=i.width.left.value;"px"===i.width.left.units&&i.width.val>0&&(s=100*s/i.width.val);var l=i.width.right.value;"px"===i.width.right.units&&i.width.val>0&&(l=100*l/i.width.val);var u=i.height.top.value;"px"===i.height.top.units&&i.height.val>0&&(u=100*u/i.height.val);var c=i.height.bottom.value;"px"===i.height.bottom.units&&i.height.val>0&&(c=100*c/i.height.val);var h=y(i.width.val-a.w,s,l),d=h.biasDiff,p=h.biasComplementDiff,f=y(i.height.val-a.h,u,c),g=f.biasDiff,v=f.biasComplementDiff;t.autoPadding=function(e,t,n,r){if("%"!==n.units)return"px"===n.units?n.pfValue:0;switch(r){case"width":return e>0?n.pfValue*e:0;case"height":return t>0?n.pfValue*t:0;case"average":return e>0&&t>0?n.pfValue*(e+t)/2:0;case"min":return e>0&&t>0?e>t?n.pfValue*t:n.pfValue*e:0;case"max":return e>0&&t>0?e>t?n.pfValue*e:n.pfValue*t:0;default:return 0}}(a.w,a.h,e.pstyle("padding"),e.pstyle("padding-relative-to").value),t.autoWidth=Math.max(a.w,i.width.val),o.x=(-d+a.x1+a.x2+p)/2,t.autoHeight=Math.max(a.h,i.height.val),o.y=(-g+a.y1+a.y2+v)/2}function y(e,t,n){var r=0,i=0,a=t+n;return e>0&&a>0&&(r=t/a*e,i=n/a*e),{biasDiff:r,biasComplementDiff:i}}}for(var r=0;re.x2?r:e.x2,e.y1=ne.y2?i:e.y2,e.w=e.x2-e.x1,e.h=e.y2-e.y1)},ri=function(e,t){return null==t?e:ni(e,t.x1,t.y1,t.x2,t.y2)},ii=function(e,t,n){return Ne(e,t,n)},ai=function(e,t,n){if(!t.cy().headless()){var r,i,a=t._private,o=a.rstyle,s=o.arrowWidth/2;if("none"!==t.pstyle(n+"-arrow-shape").value){"source"===n?(r=o.srcX,i=o.srcY):"target"===n?(r=o.tgtX,i=o.tgtY):(r=o.midX,i=o.midY);var l=a.arrowBounds=a.arrowBounds||{},u=l[n]=l[n]||{};u.x1=r-s,u.y1=i-s,u.x2=r+s,u.y2=i+s,u.w=u.x2-u.x1,u.h=u.y2-u.y1,gt(u,1),ni(e,u.x1,u.y1,u.x2,u.y2)}}},oi=function(e,t,n){if(!t.cy().headless()){var r;r=n?n+"-":"";var i=t._private,a=i.rstyle;if(t.pstyle(r+"label").strValue){var o,s,l,u,c=t.pstyle("text-halign"),h=t.pstyle("text-valign"),d=ii(a,"labelWidth",n),p=ii(a,"labelHeight",n),f=ii(a,"labelX",n),g=ii(a,"labelY",n),v=t.pstyle(r+"text-margin-x").pfValue,y=t.pstyle(r+"text-margin-y").pfValue,m=t.isEdge(),b=t.pstyle(r+"text-rotation"),x=t.pstyle("text-outline-width").pfValue,w=t.pstyle("text-border-width").pfValue/2,E=t.pstyle("text-background-padding").pfValue,k=p,C=d,S=C/2,D=k/2;if(m)o=f-S,s=f+S,l=g-D,u=g+D;else{switch(c.value){case"left":o=f-C,s=f;break;case"center":o=f-S,s=f+S;break;case"right":o=f,s=f+C}switch(h.value){case"top":l=g-k,u=g;break;case"center":l=g-D,u=g+D;break;case"bottom":l=g,u=g+k}}o+=v-Math.max(x,w)-E,s+=v+Math.max(x,w)+E,l+=y-Math.max(x,w)-E,u+=y+Math.max(x,w)+E;var P=n||"main",T=i.labelBounds,B=T[P]=T[P]||{};B.x1=o,B.y1=l,B.x2=s,B.y2=u,B.w=s-o,B.h=u-l,gt(B,1);var M=m&&"autorotate"===b.strValue,_=null!=b.pfValue&&0!==b.pfValue;if(M||_){var N=M?ii(i.rstyle,"labelAngle",n):b.pfValue,z=Math.cos(N),I=Math.sin(N),L=(o+s)/2,A=(l+u)/2;if(!m){switch(c.value){case"left":L=s;break;case"right":L=o}switch(h.value){case"top":A=u;break;case"bottom":A=l}}var O=function(e,t){return{x:(e-=L)*z-(t-=A)*I+L,y:e*I+t*z+A}},R=O(o,l),V=O(o,u),F=O(s,l),q=O(s,u);o=Math.min(R.x,V.x,F.x,q.x),s=Math.max(R.x,V.x,F.x,q.x),l=Math.min(R.y,V.y,F.y,q.y),u=Math.max(R.y,V.y,F.y,q.y)}ni(e,o,l,s,u),ni(i.labelBounds.all,o,l,s,u)}return e}},si=function(e){var t=0,n=function(e){return(e?1:0)<(r=S[1].x)){var D=n;n=r,r=D}if(i>(a=S[1].y)){var P=i;i=a,a=P}ni(d,n-w,i-w,r+w,a+w)}else{for(var T=v.bezierPts||v.linePts||[],B=0;B(r=N.x)){var z=n;n=r,r=z}if((i=_.y)>(a=N.y)){var I=i;i=a,a=I}ni(d,n-=w,i-=w,r+=w,a+=w)}}if(c&&t.includeEdges&&g&&(ai(d,e,"mid-source"),ai(d,e,"mid-target"),ai(d,e,"source"),ai(d,e,"target")),c&&"yes"===e.pstyle("ghost").value){var L=e.pstyle("ghost-offset-x").pfValue,A=e.pstyle("ghost-offset-y").pfValue;ni(d,d.x1+L,d.y1+A,d.x2+L,d.y2+A)}var O=p.bodyBounds=p.bodyBounds||{};vt(O,d),gt(O,y),gt(O,1),c&&(n=d.x1,r=d.x2,i=d.y1,a=d.y2,ni(d,n-x,i-x,r+x,a+x));var R=p.overlayBounds=p.overlayBounds||{};vt(R,d),gt(R,y),gt(R,1);var V=p.labelBounds=p.labelBounds||{};null!=V.all?((l=V.all).x1=1/0,l.y1=1/0,l.x2=-1/0,l.y2=-1/0,l.w=0,l.h=0):V.all=pt(),c&&t.includeLabels&&(oi(d,e,null),g&&(oi(d,e,"source"),oi(d,e,"target")))}return d.x1=ti(d.x1),d.y1=ti(d.y1),d.x2=ti(d.x2),d.y2=ti(d.y2),d.w=ti(d.x2-d.x1),d.h=ti(d.y2-d.y1),d.w>0&&d.h>0&&b&&(gt(d,y),gt(d,1)),d}(e,ci),r.bbCache=n,r.bbCacheShift.x=r.bbCacheShift.y=0,r.bbCachePosKey=a):n=r.bbCache,!s&&(0!==r.bbCacheShift.x||0!==r.bbCacheShift.y)){var l=yt,u=r.bbCacheShift,c=function(e,t){null!=e&&l(e,t)};l(n,u);var h=r.bodyBounds,d=r.overlayBounds,p=r.labelBounds,f=r.arrowBounds;c(h,u),c(d,u),null!=f&&(c(f.source,u),c(f.target,u),c(f["mid-source"],u),c(f["mid-target"],u)),null!=p&&(c(p.main,u),c(p.all,u),c(p.source,u),c(p.target,u))}if(r.bbCacheShift.x=r.bbCacheShift.y=0,!i){var g=e.isNode();n=pt(),(t.includeNodes&&g||t.includeEdges&&!g)&&(t.includeOverlays?ri(n,r.overlayBounds):ri(n,r.bodyBounds)),t.includeLabels&&ri(n,r.labelBounds.all),n.w=n.x2-n.x1,n.h=n.y2-n.y1}return n},ci={includeNodes:!0,includeEdges:!0,includeLabels:!0,includeOverlays:!0,useCache:!0},hi=si(ci),di=Be(ci);Jr.boundingBox=function(e){var t;if(1!==this.length||null==this[0]._private.bbCache||void 0!==e&&void 0!==e.useCache&&!0!==e.useCache){t=pt();var n=di(e=e||ci);if(this.cy().styleEnabled())for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:Pi,t=arguments.length>1?arguments[1]:void 0,n=0;n=0;s--)o(s);return this},Bi.removeAllListeners=function(){return this.removeListener("*")},Bi.emit=Bi.trigger=function(e,t,n){var r=this.listeners,i=r.length;return this.emitting++,f(t)||(t=[t]),Ni(this,function(e,a){null!=n&&(r=[{event:a.event,type:a.type,namespace:a.namespace,callback:n}],i=r.length);for(var o=function(n){var i=r[n];if(i.type===a.type&&(!i.namespace||i.namespace===a.namespace||".*"===i.namespace)&&e.eventMatches(e.context,i,a)){var o=[a];null!=t&&function(e,t){for(var n=0;n1&&!r){var i=this.length-1,a=this[i],o=a._private.data.id;this[i]=void 0,this[e]=a,n.set(o,{ele:a,index:e})}return this.length--,this},unmergeOne:function(e){e=e[0];var t=this._private,n=e._private.data.id,r=t.map.get(n);if(!r)return this;var i=r.index;return this.unmergeAt(i),this},unmerge:function(e){var t=this._private.cy;if(!e)return this;if(e&&d(e)){var n=e;e=t.mutableElements().filter(n)}for(var r=0;r=0;t--){e(this[t])&&this.unmergeAt(t)}return this},map:function(e,t){for(var n=[],r=0;rr&&(r=o,n=a)}return{value:r,ele:n}},min:function(e,t){for(var n,r=1/0,i=0;i=0&&i1&&void 0!==arguments[1])||arguments[1],n=this[0],r=n.cy();if(r.styleEnabled()&&n){var i=n._private.style[e];return null!=i?i:t?r.style().getDefaultProperty(e):null}},numericStyle:function(e){var t=this[0];if(t.cy().styleEnabled()&&t){var n=t.pstyle(e);return void 0!==n.pfValue?n.pfValue:n.value}},numericStyleUnits:function(e){var t=this[0];if(t.cy().styleEnabled())return t?t.pstyle(e).units:void 0},renderedStyle:function(e){var t=this.cy();if(!t.styleEnabled())return this;var n=this[0];return n?t.style().getRenderedStyle(n,e):void 0},style:function(e,t){var n=this.cy();if(!n.styleEnabled())return this;var r=n.style();if(g(e)){var i=e;r.applyBypass(this,i,!1),this.emitAndNotify("style")}else if(d(e)){if(void 0===t){var a=this[0];return a?r.getStylePropertyValue(a,e):void 0}r.applyBypass(this,e,t,!1),this.emitAndNotify("style")}else if(void 0===e){var o=this[0];return o?r.getRawStyle(o):void 0}return this},removeStyle:function(e){var t=this.cy();if(!t.styleEnabled())return this;var n=t.style();if(void 0===e)for(var r=0;r0&&t.push(c[0]),t.push(s[0])}return this.spawn(t,{unique:!0}).filter(e)},"neighborhood"),closedNeighborhood:function(e){return this.neighborhood().add(this).filter(e)},openNeighborhood:function(e){return this.neighborhood(e)}}),na.neighbourhood=na.neighborhood,na.closedNeighbourhood=na.closedNeighborhood,na.openNeighbourhood=na.openNeighborhood,z(na,{source:Rr(function(e){var t,n=this[0];return n&&(t=n._private.source||n.cy().collection()),t&&e?t.filter(e):t},"source"),target:Rr(function(e){var t,n=this[0];return n&&(t=n._private.target||n.cy().collection()),t&&e?t.filter(e):t},"target"),sources:oa({attr:"source"}),targets:oa({attr:"target"})}),z(na,{edgesWith:Rr(sa(),"edgesWith"),edgesTo:Rr(sa({thisIsSrc:!0}),"edgesTo")}),z(na,{connectedEdges:Rr(function(e){for(var t=[],n=0;n0);return a},component:function(){var e=this[0];return e.cy().mutableElements().components(e)[0]}}),na.componentsOf=na.components;var ua=function(e,t,n){for(var r=null!=n?n:De();e.hasElementWithId(r);)r=De();return r},ca=function(e,t,n){if(void 0!==e&&w(e)){var r=new Ie,i=!1;if(t){if(t.length>0&&g(t[0])&&!b(t[0])){i=!0;for(var a=[],o=new Ae,s=0,l=t.length;s0&&void 0!==arguments[0])||arguments[0],r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],i=this.cy(),a=i._private,o=[],s=[],l=0,u=this.length;l0){for(var A=new ca(i,e),O=0;O0&&void 0!==arguments[0])||arguments[0],t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=[],r={},i=this._private.cy;function a(e){var i=r[e.id()];t&&e.removed()||i||(r[e.id()]=!0,e.isNode()?(n.push(e),function(e){for(var t=e._private.edges,n=0;n0&&(e?E.emitAndNotify("remove"):t&&E.emit("remove"));for(var k=0;k=a?function(t,r){for(var a=0;a0?i=l:r=l}while(Math.abs(a)>o&&++u1e-4&&Math.abs(s.v)>1e-4;);return a?function(e){return u[e*(u.length-1)|0]}:c}}(),ga=function(e,t,n,r){var i=pa(e,t,n,r);return function(e,t,n){return e+(t-e)*i(n)}},va={linear:function(e,t,n){return e+(t-e)*n},ease:ga(.25,.1,.25,1),"ease-in":ga(.42,0,1,1),"ease-out":ga(0,0,.58,1),"ease-in-out":ga(.42,0,.58,1),"ease-in-sine":ga(.47,0,.745,.715),"ease-out-sine":ga(.39,.575,.565,1),"ease-in-out-sine":ga(.445,.05,.55,.95),"ease-in-quad":ga(.55,.085,.68,.53),"ease-out-quad":ga(.25,.46,.45,.94),"ease-in-out-quad":ga(.455,.03,.515,.955),"ease-in-cubic":ga(.55,.055,.675,.19),"ease-out-cubic":ga(.215,.61,.355,1),"ease-in-out-cubic":ga(.645,.045,.355,1),"ease-in-quart":ga(.895,.03,.685,.22),"ease-out-quart":ga(.165,.84,.44,1),"ease-in-out-quart":ga(.77,0,.175,1),"ease-in-quint":ga(.755,.05,.855,.06),"ease-out-quint":ga(.23,1,.32,1),"ease-in-out-quint":ga(.86,0,.07,1),"ease-in-expo":ga(.95,.05,.795,.035),"ease-out-expo":ga(.19,1,.22,1),"ease-in-out-expo":ga(1,0,0,1),"ease-in-circ":ga(.6,.04,.98,.335),"ease-out-circ":ga(.075,.82,.165,1),"ease-in-out-circ":ga(.785,.135,.15,.86),spring:function(e,t,n){if(0===n)return va.linear;var r=fa(e,t,n);return function(e,t,n){return e+(t-e)*r(n)}},"cubic-bezier":ga};function ya(e,t,n,r,i){if(1===r)return n;var a=i(t,n,r);return null==e?a:((e.roundValue||e.color)&&(a=Math.round(a)),void 0!==e.min&&(a=Math.max(a,e.min)),void 0!==e.max&&(a=Math.min(a,e.max)),a)}function ma(e,t){return null!=e.pfValue||null!=e.value?null==e.pfValue||null!=t&&"%"===t.type.units?e.value:e.pfValue:e}function ba(e,t,n,r,i){var a=null!=i?i.type:null;n<0?n=0:n>1&&(n=1);var o=ma(e,i),s=ma(t,i);if(v(o)&&v(s))return ya(a,o,s,n,r);if(f(o)&&f(s)){for(var l=[],u=0;u0?("spring"===h&&p.push(o.duration),o.easingImpl=va[h].apply(null,p)):o.easingImpl=va[h]}var f,g=o.easingImpl;if(f=0===o.duration?1:(n-l)/o.duration,o.applying&&(f=o.progress),f<0?f=0:f>1&&(f=1),null==o.delay){var v=o.startPosition,y=o.position;if(y&&i&&!e.locked()){var m={};wa(v.x,y.x)&&(m.x=ba(v.x,y.x,f,g)),wa(v.y,y.y)&&(m.y=ba(v.y,y.y,f,g)),e.position(m)}var b=o.startPan,x=o.pan,w=a.pan,E=null!=x&&r;E&&(wa(b.x,x.x)&&(w.x=ba(b.x,x.x,f,g)),wa(b.y,x.y)&&(w.y=ba(b.y,x.y,f,g)),e.emit("pan"));var k=o.startZoom,C=o.zoom,S=null!=C&&r;S&&(wa(k,C)&&(a.zoom=dt(a.minZoom,ba(k,C,f,g),a.maxZoom)),e.emit("zoom")),(E||S)&&e.emit("viewport");var D=o.style;if(D&&D.length>0&&i){for(var P=0;P=0;t--){(0,e[t])()}e.splice(0,e.length)},h=a.length-1;h>=0;h--){var d=a[h],p=d._private;p.stopped?(a.splice(h,1),p.hooked=!1,p.playing=!1,p.started=!1,c(p.frames)):(p.playing||p.applying)&&(p.playing&&p.applying&&(p.applying=!1),p.started||Ea(0,d,e),xa(t,d,e,n),p.applying&&(p.applying=!1),c(p.frames),null!=p.step&&p.step(e),d.completed()&&(a.splice(h,1),p.hooked=!1,p.playing=!1,p.started=!1,c(p.completes)),s=!0)}return n||0!==a.length||0!==o.length||r.push(t),s}for(var a=!1,o=0;o0?t.notify("draw",n):t.notify("draw")),n.unmerge(r),t.emit("step")}var Ca={animate:Un.animate(),animation:Un.animation(),animated:Un.animated(),clearQueue:Un.clearQueue(),delay:Un.delay(),delayAnimation:Un.delayAnimation(),stop:Un.stop(),addToAnimationPool:function(e){this.styleEnabled()&&this._private.aniEles.merge(e)},stopAnimationLoop:function(){this._private.animationsRunning=!1},startAnimationLoop:function(){var e=this;if(e._private.animationsRunning=!0,e.styleEnabled()){var t=e.renderer();t&&t.beforeRender?t.beforeRender(function(t,n){ka(n,e)},t.beforeRenderPriorities.animations):function t(){e._private.animationsRunning&&oe(function(n){ka(n,e),t()})}()}}},Sa={qualifierCompare:function(e,t){return null==e||null==t?null==e&&null==t:e.sameText(t)},eventMatches:function(e,t,n){var r=t.qualifier;return null==r||e!==n.target&&b(n.target)&&r.matches(n.target)},addEventFields:function(e,t){t.cy=e,t.target=e},callbackContext:function(e,t,n){return null!=t.qualifier?n.target:e}},Da=function(e){return d(e)?new zr(e):e},Pa={createEmitter:function(){var e=this._private;return e.emitter||(e.emitter=new Ti(Sa,this)),this},emitter:function(){return this._private.emitter},on:function(e,t,n){return this.emitter().on(e,Da(t),n),this},removeListener:function(e,t,n){return this.emitter().removeListener(e,Da(t),n),this},removeAllListeners:function(){return this.emitter().removeAllListeners(),this},one:function(e,t,n){return this.emitter().one(e,Da(t),n),this},once:function(e,t,n){return this.emitter().one(e,Da(t),n),this},emit:function(e,t){return this.emitter().emit(e,t),this},emitAndNotify:function(e,t){return this.emit(e),this.notify(e,t),this}};Un.eventAliasesOn(Pa);var Ta={png:function(e){return e=e||{},this._private.renderer.png(e)},jpg:function(e){var t=this._private.renderer;return(e=e||{}).bg=e.bg||"#fff",t.jpg(e)}};Ta.jpeg=Ta.jpg;var Ba={layout:function(e){if(null!=e)if(null!=e.name){var t=e.name,n=this.extension("layout",t);if(null!=n){var r;r=d(e.eles)?this.$(e.eles):null!=e.eles?e.eles:this.$();var i=new n(z({},e,{cy:this,eles:r}));return i}Ee("No such layout `"+t+"` found. Did you forget to import it and `cytoscape.use()` it?")}else Ee("A `name` must be specified to make a layout");else Ee("Layout options must be specified to make a layout")}};Ba.createLayout=Ba.makeLayout=Ba.layout;var Ma={notify:function(e,t){var n=this._private;if(this.batching()){n.batchNotifications=n.batchNotifications||{};var r=n.batchNotifications[e]=n.batchNotifications[e]||this.collection();null!=t&&r.merge(t)}else if(n.notificationsEnabled){var i=this.renderer();!this.destroyed()&&i&&i.notify(e,t)}},notifications:function(e){var t=this._private;return void 0===e?t.notificationsEnabled:(t.notificationsEnabled=!!e,this)},noNotifications:function(e){this.notifications(!1),e(),this.notifications(!0)},batching:function(){return this._private.batchCount>0},startBatch:function(){var e=this._private;return null==e.batchCount&&(e.batchCount=0),0===e.batchCount&&(e.batchStyleEles=this.collection(),e.batchNotifications={}),e.batchCount++,this},endBatch:function(){var e=this._private;if(0===e.batchCount)return this;if(e.batchCount--,0===e.batchCount){e.batchStyleEles.updateStyle();var t=this.renderer();Object.keys(e.batchNotifications).forEach(function(n){var r=e.batchNotifications[n];r.empty()?t.notify(n):t.notify(n,r)})}return this},batch:function(e){return this.startBatch(),e(),this.endBatch(),this},batchData:function(e){var t=this;return this.batch(function(){for(var n=Object.keys(e),r=0;r0;)e.removeChild(e.childNodes[0]);this._private.renderer=null,this.mutableElements().forEach(function(e){var t=e._private;t.rscratch={},t.rstyle={},t.animation.current=[],t.animation.queue=[]})},onRender:function(e){return this.on("render",e)},offRender:function(e){return this.off("render",e)}};Na.invalidateDimensions=Na.resize;var za={collection:function(e,t){return d(e)?this.$(e):m(e)?e.collection():f(e)?new ca(this,e,t):new ca(this)},nodes:function(e){var t=this.$(function(e){return e.isNode()});return e?t.filter(e):t},edges:function(e){var t=this.$(function(e){return e.isEdge()});return e?t.filter(e):t},$:function(e){var t=this._private.elements;return e?t.filter(e):t.spawnSelf()},mutableElements:function(){return this._private.elements}};za.elements=za.filter=za.$;var Ia={};Ia.apply=function(e){var t=this._private,n=t.cy.collection();t.newStyle&&(t.contextStyles={},t.propDiffs={},this.cleanElements(e,!0));for(var r=0;r0;if(h||c&&d){var p=void 0;h&&d?p=l.properties:h?p=l.properties:d&&(p=l.mappedProperties);for(var f=0;f1&&(g=1),s.color){var w=i.valueMin[0],E=i.valueMax[0],k=i.valueMin[1],C=i.valueMax[1],S=i.valueMin[2],D=i.valueMax[2],P=null==i.valueMin[3]?1:i.valueMin[3],T=null==i.valueMax[3]?1:i.valueMax[3],B=[Math.round(w+(E-w)*g),Math.round(k+(C-k)*g),Math.round(S+(D-S)*g),Math.round(P+(T-P)*g)];n={bypass:i.bypass,name:i.name,value:B,strValue:"rgb("+B[0]+", "+B[1]+", "+B[2]+")"}}else{if(!s.number)return!1;var M=i.valueMin+(i.valueMax-i.valueMin)*g;n=this.parse(i.name,M,i.bypass,"mapping")}if(!n)return f(),!1;n.mapping=i,i=n;break;case o.data:for(var _=i.field.split("."),N=h.data,z=0;z<_.length&&N;z++){N=N[_[z]]}if(null!=N&&(n=this.parse(i.name,N,i.bypass,"mapping")),!n)return f(),!1;n.mapping=i,i=n;break;case o.fn:var I=i.value,L=null!=i.fnValue?i.fnValue:I(e);if(i.prevFnValue=L,null==L)return Ce("Custom function mappers may not return null (i.e. `"+i.name+"` for ele `"+e.id()+"` is null)"),!1;if(!(n=this.parse(i.name,L,i.bypass,"mapping")))return Ce("Custom function mappers may not return invalid values for the property type (i.e. `"+i.name+"` for ele `"+e.id()+"` is invalid)"),!1;n.mapping=Se(i),i=n;break;case void 0:break;default:return!1}return l?(i.bypassed=c?u.bypassed:u,a[i.name]=i):c?u.bypassed=i:a[i.name]=i,p(),!0},Ia.cleanElements=function(e,t){for(var n=0;n0&&a>0){for(var s={},l=!1,u=0;u0?e.delayAnimation(o).play().promise().then(t):t()}).then(function(){return e.animation({style:s,duration:a,easing:e.pstyle("transition-timing-function").value,queue:!1}).play().promise()}).then(function(){n.removeBypasses(e,i),e.emitAndNotify("style"),r.transitioning=!1})}else r.transitioning&&(this.removeBypasses(e,i),e.emitAndNotify("style"),r.transitioning=!1)},Ia.checkTrigger=function(e,t,n,r,i,a){var o=this.properties[t],s=i(o);null!=s&&s(n,r)&&a(o)},Ia.checkZOrderTrigger=function(e,t,n,r){var i=this;this.checkTrigger(e,t,n,r,function(e){return e.triggersZOrder},function(){i._private.cy.notify("zorder",e)})},Ia.checkBoundsTrigger=function(e,t,n,r){this.checkTrigger(e,t,n,r,function(e){return e.triggersBounds},function(i){e.dirtyCompoundBoundsCache(),e.dirtyBoundingBoxCache(),"bezier"!==e.pstyle("curve-style").value&&("curve-style"!==t||"bezier"!==n&&"bezier"!==r)||!i.triggersBoundsOfParallelBeziers||e.parallelEdges().forEach(function(e){e.isBundledBezier()&&e.dirtyBoundingBoxCache()})})},Ia.checkTriggers=function(e,t,n,r){e.dirtyStyleCache(),this.checkZOrderTrigger(e,t,n,r),this.checkBoundsTrigger(e,t,n,r)};var La={applyBypass:function(e,t,n,r){var i=[];if("*"===t||"**"===t){if(void 0!==n)for(var a=0;at.length?i.substr(t.length):""}function o(){n=n.length>r.length?n.substr(r.length):""}for(i=i.replace(/[\/][*](\s|.)+?[*][\/]/g,"");;){if(i.match(/^\s*$/))break;var s=i.match(/^\s*((?:.|\s)+?)\s*\{((?:.|\s)+?)\}/);if(!s){Ce("Halting stylesheet parsing: String stylesheet contains more to parse but no selector and block found in: "+i);break}t=s[0];var l=s[1];if("core"!==l)if(new zr(l).invalid){Ce("Skipping parsing of block: Invalid selector found in string stylesheet: "+l),a();continue}var u=s[2],c=!1;n=u;for(var h=[];;){if(n.match(/^\s*$/))break;var d=n.match(/^\s*(.+?)\s*:\s*(.+?)\s*;/);if(!d){Ce("Skipping parsing of block: Invalid formatting of style property and value definitions found in:"+u),c=!0;break}r=d[0];var p=d[1],f=d[2];if(this.properties[p])this.parse(p,f)?(h.push({name:p,val:f}),o()):(Ce("Skipping property: Invalid property definition in: "+r),o());else Ce("Skipping property: Invalid property name in: "+r),o()}if(c){a();break}this.selector(l);for(var g=0;g=7&&"d"===t[0]&&(l=new RegExp(o.data.regex).exec(t))){if(n)return!1;var h=o.data;return{name:e,value:l,strValue:""+t,mapped:h,field:l[1],bypass:n}}if(t.length>=10&&"m"===t[0]&&(u=new RegExp(o.mapData.regex).exec(t))){if(n)return!1;if(c.multiple)return!1;var g=o.mapData;if(!c.color&&!c.number)return!1;var y=this.parse(e,u[4]);if(!y||y.mapped)return!1;var m=this.parse(e,u[5]);if(!m||m.mapped)return!1;if(y.pfValue===m.pfValue||y.strValue===m.strValue)return Ce("`"+e+": "+t+"` is not a valid mapper because the output range is zero; converting to `"+e+": "+y.strValue+"`"),this.parse(e,y.strValue);if(c.color){var b=y.value,x=m.value;if(!(b[0]!==x[0]||b[1]!==x[1]||b[2]!==x[2]||b[3]!==x[3]&&(null!=b[3]&&1!==b[3]||null!=x[3]&&1!==x[3])))return!1}return{name:e,value:u,strValue:""+t,mapped:g,field:u[1],fieldMin:parseFloat(u[2]),fieldMax:parseFloat(u[3]),valueMin:y.value,valueMax:m.value,bypass:n}}}if(c.multiple&&"multiple"!==r){var w;if(w=s?t.split(/\s+/):f(t)?t:[t],c.evenMultiple&&w.length%2!=0)return null;for(var E=[],k=[],C=[],S="",D=!1,T=0;T0?" ":"")+B.strValue}return c.validate&&!c.validate(E,k)?null:c.singleEnum&&D?1===E.length&&d(E[0])?{name:e,value:E[0],strValue:E[0],bypass:n}:null:{name:e,value:E,pfValue:C,strValue:S,bypass:n,units:k}}var M,N,z=function(){for(var r=0;rc.max||c.strictMax&&t===c.max))return null;var V={name:e,value:t,strValue:""+t+(L||""),units:L,bypass:n};return c.unitless||"px"!==L&&"em"!==L?V.pfValue=t:V.pfValue="px"!==L&&L?this.getEmSizeInPixels()*t:t,"ms"!==L&&"s"!==L||(V.pfValue="ms"===L?t:1e3*t),"deg"!==L&&"rad"!==L||(V.pfValue="rad"===L?t:(M=t,Math.PI*M/180)),"%"===L&&(V.pfValue=t/100),V}if(c.propList){var F=[],q=""+t;if("none"===q);else{for(var Y=q.split(/\s*,\s*|\s+/),j=0;j0&&l>0&&!isNaN(n.w)&&!isNaN(n.h)&&n.w>0&&n.h>0)return{zoom:o=(o=(o=Math.min((s-2*t)/n.w,(l-2*t)/n.h))>this._private.maxZoom?this._private.maxZoom:o)=n.minZoom&&(n.maxZoom=t),this},minZoom:function(e){return void 0===e?this._private.minZoom:this.zoomRange({min:e})},maxZoom:function(e){return void 0===e?this._private.maxZoom:this.zoomRange({max:e})},getZoomedViewport:function(e){var t,n,r=this._private,i=r.pan,a=r.zoom,o=!1;if(r.zoomingEnabled||(o=!0),v(e)?n=e:g(e)&&(n=e.level,null!=e.position?t=tt(e.position,a,i):null!=e.renderedPosition&&(t=e.renderedPosition),null==t||r.panningEnabled||(o=!0)),n=(n=n>r.maxZoom?r.maxZoom:n)t.maxZoom||!t.zoomingEnabled?a=!0:(t.zoom=s,i.push("zoom"))}if(r&&(!a||!e.cancelOnFailedZoom)&&t.panningEnabled){var l=e.pan;v(l.x)&&(t.pan.x=l.x,o=!1),v(l.y)&&(t.pan.y=l.y,o=!1),o||i.push("pan")}return i.length>0&&(i.push("viewport"),this.emit(i.join(" ")),this.notify("viewport")),this},center:function(e){var t=this.getCenterPan(e);return t&&(this._private.pan=t,this.emit("pan viewport"),this.notify("viewport")),this},getCenterPan:function(e,t){if(this._private.panningEnabled){if(d(e)){var n=e;e=this.mutableElements().filter(n)}else m(e)||(e=this.mutableElements());if(0!==e.length){var r=e.boundingBox(),i=this.width(),a=this.height();return{x:(i-(t=void 0===t?this._private.zoom:t)*(r.x1+r.x2))/2,y:(a-t*(r.y1+r.y2))/2}}}},reset:function(){return this._private.panningEnabled&&this._private.zoomingEnabled?(this.viewport({pan:{x:0,y:0},zoom:1}),this):this},invalidateSize:function(){this._private.sizeCache=null},size:function(){var e,t,n=this._private,r=n.container;return n.sizeCache=n.sizeCache||(r?(e=a.getComputedStyle(r),t=function(t){return parseFloat(e.getPropertyValue(t))},{width:r.clientWidth-t("padding-left")-t("padding-right"),height:r.clientHeight-t("padding-top")-t("padding-bottom")}):{width:1,height:1})},width:function(){return this.size().width},height:function(){return this.size().height},extent:function(){var e=this._private.pan,t=this._private.zoom,n=this.renderedExtent(),r={x1:(n.x1-e.x)/t,x2:(n.x2-e.x)/t,y1:(n.y1-e.y)/t,y2:(n.y2-e.y)/t};return r.w=r.x2-r.x1,r.h=r.y2-r.y1,r},renderedExtent:function(){var e=this.width(),t=this.height();return{x1:0,y1:0,x2:e,y2:t,w:e,h:t}}};Wa.centre=Wa.center,Wa.autolockNodes=Wa.autolock,Wa.autoungrabifyNodes=Wa.autoungrabify;var Ha={data:Un.data({field:"data",bindingEvent:"data",allowBinding:!0,allowSetting:!0,settingEvent:"data",settingTriggersEvent:!0,triggerFnName:"trigger",allowGetting:!0}),removeData:Un.removeData({field:"data",event:"data",triggerFnName:"trigger",triggerEvent:!0}),scratch:Un.data({field:"scratch",bindingEvent:"scratch",allowBinding:!0,allowSetting:!0,settingEvent:"scratch",settingTriggersEvent:!0,triggerFnName:"trigger",allowGetting:!0}),removeScratch:Un.removeData({field:"scratch",event:"scratch",triggerFnName:"trigger",triggerEvent:!0})};Ha.attr=Ha.data,Ha.removeAttr=Ha.removeData;var Ka=function(e){var t=this,n=(e=z({},e)).container;n&&!y(n)&&y(n[0])&&(n=n[0]);var r=n?n._cyreg:null;(r=r||{})&&r.cy&&(r.cy.destroy(),r={});var i=r.readies=r.readies||[];n&&(n._cyreg=r),r.cy=t;var o=void 0!==a&&void 0!==n&&!e.headless,s=e;s.layout=z({name:o?"grid":"null"},s.layout),s.renderer=z({name:o?"canvas":"null"},s.renderer);var l=function(e,t,n){return void 0!==t?t:void 0!==n?n:e},u=this._private={container:n,ready:!1,options:s,elements:new ca(this),listeners:[],aniEles:new ca(this),data:{},scratch:{},layout:null,renderer:null,destroyed:!1,notificationsEnabled:!0,minZoom:1e-50,maxZoom:1e50,zoomingEnabled:l(!0,s.zoomingEnabled),userZoomingEnabled:l(!0,s.userZoomingEnabled),panningEnabled:l(!0,s.panningEnabled),userPanningEnabled:l(!0,s.userPanningEnabled),boxSelectionEnabled:l(!0,s.boxSelectionEnabled),autolock:l(!1,s.autolock,s.autolockNodes),autoungrabify:l(!1,s.autoungrabify,s.autoungrabifyNodes),autounselectify:l(!1,s.autounselectify),styleEnabled:void 0===s.styleEnabled?o:s.styleEnabled,zoom:v(s.zoom)?s.zoom:1,pan:{x:g(s.pan)&&v(s.pan.x)?s.pan.x:0,y:g(s.pan)&&v(s.pan.y)?s.pan.y:0},animation:{current:[],queue:[]},hasCompoundNodes:!1};this.createEmitter(),this.selectionType(s.selectionType),this.zoomRange({min:s.minZoom,max:s.maxZoom});u.styleEnabled&&t.setStyle([]);var c=z({},s,s.renderer);t.initRenderer(c);!function(e,t){if(e.some(C))return Kn.all(e).then(t);t(e)}([s.style,s.elements],function(e){var n=e[0],a=e[1];u.styleEnabled&&t.style().append(n),function(e,n,r){t.notifications(!1);var i=t.mutableElements();i.length>0&&i.remove(),null!=e&&(g(e)||f(e))&&t.add(e),t.one("layoutready",function(e){t.notifications(!0),t.emit(e),t.one("load",n),t.emitAndNotify("load")}).one("layoutstop",function(){t.one("done",r),t.emit("done")});var a=z({},t._private.options.layout);a.eles=t.elements(),t.layout(a).run()}(a,function(){t.startAnimationLoop(),u.ready=!0,p(s.ready)&&t.on("ready",s.ready);for(var e=0;e0,u=pt(n.boundingBox?n.boundingBox:{x1:0,y1:0,w:r.width(),h:r.height()});if(m(n.roots))e=n.roots;else if(f(n.roots)){for(var c=[],h=0;h0;){var z=B.shift(),I=T(z,M);if(I)z.outgoers().filter(function(e){return e.isNode()&&i.has(e)}).forEach(_);else if(null===I){Ce("Detected double maximal shift for node `"+z.id()+"`. Bailing maximal adjustment due to cycle. Use `options.maximal: true` only on DAGs.");break}}}P();var L=0;if(n.avoidOverlap)for(var A=0;A0&&x[0].length<=3?l/2:0),h=2*Math.PI/x[r].length*i;return 0===r&&1===x[0].length&&(c=1),{x:G+c*Math.cos(h),y:Z+c*Math.sin(h)}}return{x:G+(i+1-(a+1)/2)*o,y:(r+1)*s}}),this};var Ja={fit:!0,padding:30,boundingBox:void 0,avoidOverlap:!0,nodeDimensionsIncludeLabels:!1,spacingFactor:void 0,radius:void 0,startAngle:1.5*Math.PI,sweep:void 0,clockwise:!0,sort:void 0,animate:!1,animationDuration:500,animationEasing:void 0,animateFilter:function(e,t){return!0},ready:void 0,stop:void 0,transform:function(e,t){return t}};function eo(e){this.options=z({},Ja,e)}eo.prototype.run=function(){var e=this.options,t=e,n=e.cy,r=t.eles,i=void 0!==t.counterclockwise?!t.counterclockwise:t.clockwise,a=r.nodes().not(":parent");t.sort&&(a=a.sort(t.sort));for(var o,s=pt(t.boundingBox?t.boundingBox:{x1:0,y1:0,w:n.width(),h:n.height()}),l=s.x1+s.w/2,u=s.y1+s.h/2,c=(void 0===t.sweep?2*Math.PI-2*Math.PI/a.length:t.sweep)/Math.max(1,a.length-1),h=0,d=0;d1&&t.avoidOverlap){h*=1.75;var y=Math.cos(c)-Math.cos(0),m=Math.sin(c)-Math.sin(0),b=Math.sqrt(h*h/(y*y+m*m));o=Math.max(b,o)}return a.layoutPositions(this,t,function(e,n){var r=t.startAngle+n*c*(i?1:-1),a=o*Math.cos(r),s=o*Math.sin(r);return{x:l+a,y:u+s}}),this};var to,no={fit:!0,padding:30,startAngle:1.5*Math.PI,sweep:void 0,clockwise:!0,equidistant:!1,minNodeSpacing:10,boundingBox:void 0,avoidOverlap:!0,nodeDimensionsIncludeLabels:!1,height:void 0,width:void 0,spacingFactor:void 0,concentric:function(e){return e.degree()},levelWidth:function(e){return e.maxDegree()/4},animate:!1,animationDuration:500,animationEasing:void 0,animateFilter:function(e,t){return!0},ready:void 0,stop:void 0,transform:function(e,t){return t}};function ro(e){this.options=z({},no,e)}ro.prototype.run=function(){for(var e=this.options,t=e,n=void 0!==t.counterclockwise?!t.counterclockwise:t.clockwise,r=e.cy,i=t.eles.nodes().not(":parent"),a=pt(t.boundingBox?t.boundingBox:{x1:0,y1:0,w:r.width(),h:r.height()}),o=a.x1+a.w/2,s=a.y1+a.h/2,l=[],u=0,c=0;c0)Math.abs(y[0].value-b.value)>=g&&(y=[],v.push(y));y.push(b)}var x=u+t.minNodeSpacing;if(!t.avoidOverlap){var w=v.length>0&&v[0].length>1,E=(Math.min(a.w,a.h)/2-x)/(v.length+w?1:0);x=Math.min(x,E)}for(var k=0,C=0;C1&&t.avoidOverlap){var T=Math.cos(P)-Math.cos(0),B=Math.sin(P)-Math.sin(0),M=Math.sqrt(x*x/(T*T+B*B));k=Math.max(M,k)}S.r=k,k+=x}if(t.equidistant){for(var _=0,N=0,z=0;z=e.numIter)&&(po(r,e),r.temperature=r.temperature*e.coolingFactor,!(r.temperature=e.animationThreshold&&a(),oe(t)):(So(r,e),s())}()}else{for(;u;)u=o(l),l++;So(r,e),s()}return this},ao.prototype.stop=function(){return this.stopped=!0,this.thread&&this.thread.stop(),this.emit("layoutstop"),this},ao.prototype.destroy=function(){return this.thread&&this.thread.stop(),this};var oo=function(e,t,n){for(var r=n.eles.edges(),i=n.eles.nodes(),a={isCompound:e.hasCompoundNodes(),layoutNodes:[],idToIndex:{},nodeSize:i.size(),graphSet:[],indexToGraph:[],layoutEdges:[],edgeSize:r.size(),temperature:n.initialTemp,clientWidth:e.width(),clientHeight:e.width(),boundingBox:pt(n.boundingBox?n.boundingBox:{x1:0,y1:0,w:e.width(),h:e.height()})},o=n.eles.components(),s={},l=0;l0){a.graphSet.push(w);for(l=0;lr.count?0:r.graph},lo=function e(t,n,r,i){var a=i.graphSet[r];if(-10)var s=(u=r.nodeOverlap*o)*i/(g=Math.sqrt(i*i+a*a)),l=u*a/g;else{var u,c=mo(e,i,a),h=mo(t,-1*i,-1*a),d=h.x-c.x,p=h.y-c.y,f=d*d+p*p,g=Math.sqrt(f);s=(u=(e.nodeRepulsion+t.nodeRepulsion)/f)*d/g,l=u*p/g}e.isLocked||(e.offsetX-=s,e.offsetY-=l),t.isLocked||(t.offsetX+=s,t.offsetY+=l)}},yo=function(e,t,n,r){if(n>0)var i=e.maxX-t.minX;else i=t.maxX-e.minX;if(r>0)var a=e.maxY-t.minY;else a=t.maxY-e.minY;return i>=0&&a>=0?Math.sqrt(i*i+a*a):0},mo=function(e,t,n){var r=e.positionX,i=e.positionY,a=e.height||1,o=e.width||1,s=n/t,l=a/o,u={};return 0===t&&0n?(u.x=r,u.y=i+a/2,u):0t&&-1*l<=s&&s<=l?(u.x=r-o/2,u.y=i-o*n/2/t,u):0=l)?(u.x=r+a*t/2/n,u.y=i+a/2,u):0>n&&(s<=-1*l||s>=l)?(u.x=r-a*t/2/n,u.y=i-a/2,u):u},bo=function(e,t){for(var n=0;n1){var f=t.gravity*h/p,g=t.gravity*d/p;c.offsetX+=f,c.offsetY+=g}}}}},wo=function(e,t){var n=[],r=0,i=-1;for(n.push.apply(n,e.graphSet[0]),i+=e.graphSet[0].length;r<=i;){var a=n[r++],o=e.idToIndex[a],s=e.layoutNodes[o],l=s.children;if(0n)var i={x:n*e/r,y:n*t/r};else i={x:e,y:t};return i},Co=function e(t,n){var r=t.parentId;if(null!=r){var i=n.layoutNodes[n.idToIndex[r]],a=!1;return(null==i.maxX||t.maxX+i.padRight>i.maxX)&&(i.maxX=t.maxX+i.padRight,a=!0),(null==i.minX||t.minX-i.padLefti.maxY)&&(i.maxY=t.maxY+i.padBottom,a=!0),(null==i.minY||t.minY-i.padTopf&&(h+=p+t.componentSpacing,c=0,d=0,p=0)}}},Do={fit:!0,padding:30,boundingBox:void 0,avoidOverlap:!0,avoidOverlapPadding:10,nodeDimensionsIncludeLabels:!1,spacingFactor:void 0,condense:!1,rows:void 0,cols:void 0,position:function(e){},sort:void 0,animate:!1,animationDuration:500,animationEasing:void 0,animateFilter:function(e,t){return!0},ready:void 0,stop:void 0,transform:function(e,t){return t}};function Po(e){this.options=z({},Do,e)}Po.prototype.run=function(){var e=this.options,t=e,n=e.cy,r=t.eles.nodes().not(":parent");t.sort&&(r=r.sort(t.sort));var i=pt(t.boundingBox?t.boundingBox:{x1:0,y1:0,w:n.width(),h:n.height()});if(0===i.h||0===i.w)r.layoutPositions(this,t,function(e){return{x:i.x1,y:i.y1}});else{var a=r.size(),o=Math.sqrt(a*i.h/i.w),s=Math.round(o),l=Math.round(i.w/i.h*o),u=function(e){if(null==e)return Math.min(s,l);Math.min(s,l)==s?s=e:l=e},c=function(e){if(null==e)return Math.max(s,l);Math.max(s,l)==s?s=e:l=e},h=t.rows,d=null!=t.cols?t.cols:t.columns;if(null!=h&&null!=d)s=h,l=d;else if(null!=h&&null==d)s=h,l=Math.ceil(a/s);else if(null==h&&null!=d)l=d,s=Math.ceil(a/l);else if(l*s>a){var p=u(),f=c();(p-1)*f>=a?u(p-1):(f-1)*p>=a&&c(f-1)}else for(;l*s=a?c(v+1):u(g+1)}var y=i.w/l,m=i.h/s;if(t.condense&&(y=0,m=0),t.avoidOverlap)for(var b=0;b=l&&(M=0,B++)},N={},z=0;z(r=St(e,t,x[w],x[w+1],x[w+2],x[w+3])))return v(n,r),!0}else if("bezier"===a.edgeType||"multibezier"===a.edgeType||"self"===a.edgeType||"compound"===a.edgeType)for(x=a.allpts,w=0;w+5(r=Ct(e,t,x[w],x[w+1],x[w+2],x[w+3],x[w+4],x[w+5])))return v(n,r),!0;m=m||i.source,b=b||i.target;var E=o.getArrowWidth(l,c),k=[{name:"source",x:a.arrowStartX,y:a.arrowStartY,angle:a.srcArrowAngle},{name:"target",x:a.arrowEndX,y:a.arrowEndY,angle:a.tgtArrowAngle},{name:"mid-source",x:a.midX,y:a.midY,angle:a.midsrcArrowAngle},{name:"mid-target",x:a.midX,y:a.midY,angle:a.midtgtArrowAngle}];for(w=0;w0&&(y(m),y(b))}function b(e,t,n){return Ne(e,t,n)}function x(n,r){var i,a=n._private,o=f;i=r?r+"-":"";var s=a.labelBounds[r||"main"],l=n.pstyle(i+"label").value;if("yes"===n.pstyle("text-events").strValue&&l){var u=a.rstyle,c=b(u,"labelX",r),h=b(u,"labelY",r),d=b(a.rscratch,"labelAngle",r),p=s.x1-o,g=s.x2+o,y=s.y1-o,m=s.y2+o;if(d){var x=Math.cos(d),w=Math.sin(d),E=function(e,t){return{x:(e-=c)*x-(t-=h)*w+c,y:e*w+t*x+h}},k=E(p,y),C=E(p,m),S=E(g,y),D=E(g,m),P=[k.x,k.y,S.x,S.y,D.x,D.y,C.x,C.y];if(Dt(e,t,P))return v(n),!0}else if(bt(s,e,t))return v(n),!0}}n&&(l=l.interactive);for(var w=l.length-1;w>=0;w--){var E=l[w];E.isNode()?y(E)||x(E):m(E)||x(E)||x(E,"source")||x(E,"target")}return u},getAllInBox:function(e,t,n,r){for(var i,a,o=this.getCachedZSortedEles().interactive,s=[],l=Math.min(e,n),u=Math.max(e,n),c=Math.min(t,r),h=Math.max(t,r),d=pt({x1:e=l,y1:t=c,x2:n=u,y2:r=h}),p=0;p0?Math.max(e-t,0):Math.min(e+t,0)},x=b(y,g),w=b(m,v),E=!1;"auto"===u?u=Math.abs(x)>Math.abs(w)?"horizontal":"vertical":"upward"===u||"downward"===u?(u="vertical",E=!0):"leftward"!==u&&"rightward"!==u||(u="horizontal",E=!0);var k="vertical"===u,C=k?w:x,S=k?m:y,D=ot(S),P=!1;E&&f||!("downward"===c&&S<0||"upward"===c&&S>0||"leftward"===c&&S>0||"rightward"===c&&S<0)||(C=(D*=-1)*Math.abs(C),P=!0);var T=f?d*C:d*D,B=function(e){return Math.abs(e)=Math.abs(C)},M=B(T),_=B(C-T);if((M||_)&&!P)if(k){var N=Math.abs(S)<=a/2,z=Math.abs(y)<=o/2;if(N){var I=(r.x1+r.x2)/2,L=r.y1,A=r.y2;n.segpts=[I,L,I,A]}else if(z){var O=(r.y1+r.y2)/2,R=r.x1,V=r.x2;n.segpts=[R,O,V,O]}else n.segpts=[r.x1,r.y2]}else{var F=Math.abs(S)<=i/2,q=Math.abs(m)<=s/2;if(F){var Y=(r.y1+r.y2)/2,j=r.x1,X=r.x2;n.segpts=[j,Y,X,Y]}else if(q){var W=(r.x1+r.x2)/2,H=r.y1,K=r.y2;n.segpts=[W,H,W,K]}else n.segpts=[r.x2,r.y1]}else if(k){var G=r.y1+T+(l?a/2*D:0),Z=r.x1,U=r.x2;n.segpts=[Z,G,U,G]}else{var $=r.x1+T+(l?i/2*D:0),Q=r.y1,J=r.y2;n.segpts=[$,Q,$,J]}},Fo.tryToCorrectInvalidPoints=function(e,t){var n=e._private.rscratch;if("bezier"===n.edgeType){var r=t.srcPos,i=t.tgtPos,a=t.srcW,o=t.srcH,s=t.tgtW,l=t.tgtH,u=t.srcShape,c=t.tgtShape,h=!v(n.startX)||!v(n.startY),d=!v(n.arrowStartX)||!v(n.arrowStartY),p=!v(n.endX)||!v(n.endY),f=!v(n.arrowEndX)||!v(n.arrowEndY),g=3*(this.getArrowWidth(e.pstyle("width").pfValue,e.pstyle("arrow-scale").value)*this.arrowShapeWidth),y=st({x:n.ctrlpts[0],y:n.ctrlpts[1]},{x:n.startX,y:n.startY}),m=yd.poolIndex()){var p=h;h=d,d=p}var f=s.srcPos=h.position(),g=s.tgtPos=d.position(),y=s.srcW=h.outerWidth(),m=s.srcH=h.outerHeight(),b=s.tgtW=d.outerWidth(),x=s.tgtH=d.outerHeight(),w=s.srcShape=n.nodeShapes[t.getNodeShape(h)],E=s.tgtShape=n.nodeShapes[t.getNodeShape(d)];s.dirCounts={north:0,west:0,south:0,east:0,northwest:0,southwest:0,northeast:0,southeast:0};for(var k=0;k=c||b){h={cp:v,segment:m};break}}if(h)break}var x=h.cp,w=h.segment,E=(c-p)/w.length,k=w.t1-w.t0,C=u?w.t0+k*E:w.t1-k*E;C=dt(0,C,1),t=ht(x.p0,x.p1,x.p2,C),l=function(e,t,n,r){var i=dt(0,r-.001,1),a=dt(0,r+.001,1),o=ht(e,t,n,i),s=ht(e,t,n,a);return Ko(o,s)}(x.p0,x.p1,x.p2,C);break;case"straight":case"segments":case"haystack":for(var S,D,P,T,B=0,M=r.allpts.length,_=0;_+3=c));_+=2);var N=(c-D)/S;N=dt(0,N,1),t=function(e,t,n,r){var i=t.x-e.x,a=t.y-e.y,o=st(e,t),s=i/o,l=a/o;return n=null==n?0:n,r=null!=r?r:n*o,{x:e.x+s*r,y:e.y+l*r}}(P,T,N),l=Ko(P,T)}o("labelX",s,t.x),o("labelY",s,t.y),o("labelAutoAngle",s,l)}};l("source"),l("target"),this.applyLabelDimensions(e)}},Wo.applyLabelDimensions=function(e){this.applyPrefixedLabelDimensions(e),e.isEdge()&&(this.applyPrefixedLabelDimensions(e,"source"),this.applyPrefixedLabelDimensions(e,"target"))},Wo.applyPrefixedLabelDimensions=function(e,t){var n=e._private,r=this.getLabelText(e,t),i=this.calculateLabelDimensions(e,r),a=e.pstyle("line-height").pfValue,o=e.pstyle("text-wrap").strValue,s=Ne(n.rscratch,"labelWrapCachedLines",t)||[],l="wrap"!==o?1:Math.max(s.length,1),u=i.height/l,c=u*a,h=i.width,d=i.height+(l-1)*(a-1)*u;ze(n.rstyle,"labelWidth",t,h),ze(n.rscratch,"labelWidth",t,h),ze(n.rstyle,"labelHeight",t,d),ze(n.rscratch,"labelHeight",t,d),ze(n.rscratch,"labelLineHeight",t,c)},Wo.getLabelText=function(e,t){var n=e._private,r=t?t+"-":"",i=e.pstyle(r+"label").strValue,a=e.pstyle("text-transform").value,o=function(e,r){return r?(ze(n.rscratch,e,t,r),r):Ne(n.rscratch,e,t)};if(!i)return"";"none"==a||("uppercase"==a?i=i.toUpperCase():"lowercase"==a&&(i=i.toLowerCase()));var s=e.pstyle("text-wrap").value;if("wrap"===s){var l=o("labelKey");if(null!=l&&o("labelWrapKey")===l)return o("labelWrapCachedText");for(var u=i.split("\n"),c=e.pstyle("text-max-width").pfValue,h="anywhere"===e.pstyle("text-overflow-wrap").value,d=[],p=/[\s\u200b]+/,f=h?"":" ",g=0;gc){for(var b=v.split(p),x="",w=0;wC)break;S+=i[P],P===i.length-1&&(D=!0)}return D||(S+="…"),S}return i},Wo.getLabelJustification=function(e){var t=e.pstyle("text-justification").strValue,n=e.pstyle("text-halign").strValue;if("auto"!==t)return t;if(!e.isNode())return"center";switch(n){case"left":return"right";case"right":return"left";default:return"center"}},Wo.calculateLabelDimensions=function(e,t){var n=he(t,e._private.labelDimsKey),r=this.labelDimCache||(this.labelDimCache=[]),i=r[n];if(null!=i)return i;var a=e.pstyle("font-style").strValue,o=1*e.pstyle("font-size").pfValue+"px",s=e.pstyle("font-family").strValue,l=e.pstyle("font-weight").strValue,u=this.labelCalcDiv;u||(u=this.labelCalcDiv=document.createElement("div"),document.body.appendChild(u));var c=u.style;return c.fontFamily=s,c.fontStyle=a,c.fontSize=o,c.fontWeight=l,c.position="absolute",c.left="-9999px",c.top="-9999px",c.zIndex="-1",c.visibility="hidden",c.pointerEvents="none",c.padding="0",c.lineHeight="1","wrap"===e.pstyle("text-wrap").value?c.whiteSpace="pre":c.whiteSpace="normal",u.textContent=t,r[n]={width:Math.ceil(u.clientWidth/1),height:Math.ceil(u.clientHeight/1)}},Wo.calculateLabelAngle=function(e,t){var n=e._private.rscratch,r=e.isEdge(),i=t?t+"-":"",a=e.pstyle(i+"text-rotation"),o=a.strValue;return"none"===o?0:r&&"autorotate"===o?n.labelAutoAngle:"autorotate"===o?0:a.pfValue},Wo.calculateLabelAngles=function(e){var t=this,n=e.isEdge(),r=e._private.rscratch;r.labelAngle=t.calculateLabelAngle(e),n&&(r.sourceLabelAngle=t.calculateLabelAngle(e,"source"),r.targetLabelAngle=t.calculateLabelAngle(e,"target"))};var Go={},Zo=!1;Go.getNodeShape=function(e){var t=e.pstyle("shape").value;if("cutrectangle"===t&&(e.width()<28||e.height()<28))return Zo||(Ce("The `cutrectangle` node shape can not be used at small sizes so `rectangle` is used instead"),Zo=!0),"rectangle";if(e.isParent())return"rectangle"===t||"roundrectangle"===t||"cutrectangle"===t||"barrel"===t?t:"rectangle";if("polygon"===t){var n=e.pstyle("shape-polygon-points").value;return this.nodeShapes.makePolygon(n).name}return t};var Uo={registerCalculationListeners:function(){var e=this.cy,t=e.collection(),n=this,r=function(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(t.merge(e),n)for(var r=0;r=e.desktopTapThreshold2}var P=r(t);y&&(e.hoverData.tapholdCancelled=!0);a=!0,n(g,["mousemove","vmousemove","tapdrag"],t,{x:h[0],y:h[1]});var T=function(){e.data.bgActivePosistion=void 0,e.hoverData.selecting||o.emit({originalEvent:t,type:"boxstart",position:{x:h[0],y:h[1]}}),f[4]=1,e.hoverData.selecting=!0,e.redrawHint("select",!0),e.redraw()};if(3===e.hoverData.which){if(y){var B={originalEvent:t,type:"cxtdrag",position:{x:h[0],y:h[1]}};x?x.emit(B):o.emit(B),e.hoverData.cxtDragged=!0,e.hoverData.cxtOver&&g===e.hoverData.cxtOver||(e.hoverData.cxtOver&&e.hoverData.cxtOver.emit({originalEvent:t,type:"cxtdragout",position:{x:h[0],y:h[1]}}),e.hoverData.cxtOver=g,g&&g.emit({originalEvent:t,type:"cxtdragover",position:{x:h[0],y:h[1]}}))}}else if(e.hoverData.dragging){if(a=!0,o.panningEnabled()&&o.userPanningEnabled()){var M;if(e.hoverData.justStartedPan){var _=e.hoverData.mdownPos;M={x:(h[0]-_[0])*s,y:(h[1]-_[1])*s},e.hoverData.justStartedPan=!1}else M={x:w[0]*s,y:w[1]*s};o.panBy(M),e.hoverData.dragged=!0}h=e.projectIntoViewport(t.clientX,t.clientY)}else if(1!=f[4]||null!=x&&!x.pannable()){if(x&&x.pannable()&&x.active()&&x.unactivate(),x&&x.grabbed()||g==b||(b&&n(b,["mouseout","tapdragout"],t,{x:h[0],y:h[1]}),g&&n(g,["mouseover","tapdragover"],t,{x:h[0],y:h[1]}),e.hoverData.last=g),x)if(y){if(o.boxSelectionEnabled()&&P)x&&x.grabbed()&&(c(E),x.emit("freeon"),E.emit("free"),e.dragData.didDrag&&(x.emit("dragfreeon"),E.emit("dragfree"))),T();else if(x&&x.grabbed()&&e.nodeIsDraggable(x)){var N=!e.dragData.didDrag;N&&e.redrawHint("eles",!0),e.dragData.didDrag=!0;var z=o.collection();e.hoverData.draggingEles||l(E,{inDragLayer:!0});var I={x:0,y:0};if(v(w[0])&&v(w[1])&&(I.x+=w[0],I.y+=w[1],N)){var L=e.hoverData.dragDelta;L&&v(L[0])&&v(L[1])&&(I.x+=L[0],I.y+=L[1])}for(var A=0;A0&&e.redrawHint("eles",!0),e.dragData.possibleDragElements=u=a.collection()),l!=h||e.dragData.didDrag||e.hoverData.selecting||null!=l&&l._private.selectable&&(e.hoverData.dragging||("additive"===a.selectionType()||d?l.selected()?l.unselect(["tapunselect"]):l.select(["tapselect"]):d||(a.$(t).unmerge(l).unselect(["tapunselect"]),l.select(["tapselect"]))),e.redrawHint("eles",!0)),e.hoverData.selecting){var g=a.collection(e.getAllInBox(s[0],s[1],s[2],s[3]));e.redrawHint("select",!0),g.length>0&&e.redrawHint("eles",!0),a.emit({type:"boxend",originalEvent:i,position:{x:o[0],y:o[1]}});var v=function(e){return e.selectable()&&!e.selected()};"additive"===a.selectionType()?g.emit("box").stdFilter(v).select().emit("boxselect"):(d||a.$(t).unmerge(g).unselect(),g.emit("box").stdFilter(v).select().emit("boxselect")),e.redraw()}if(e.hoverData.dragging&&(e.hoverData.dragging=!1,e.redrawHint("select",!0),e.redrawHint("eles",!0),e.redraw()),!s[4]){e.redrawHint("drag",!0),e.redrawHint("eles",!0);var y=h&&h.grabbed();c(u),y&&(h.emit("freeon"),u.emit("free"),e.dragData.didDrag&&(h.emit("dragfreeon"),u.emit("dragfree")))}}s[4]=0,e.hoverData.down=null,e.hoverData.cxtStarted=!1,e.hoverData.draggingEles=!1,e.hoverData.selecting=!1,e.hoverData.isOverThresholdDrag=!1,e.dragData.didDrag=!1,e.hoverData.dragged=!1,e.hoverData.dragDelta=[],e.hoverData.mdownPos=null,e.hoverData.mdownGPos=null}},!1);var b,x,w,E,k,C,S,D,P,T,B,M,_;e.registerBinding(e.container,"wheel",function(t){if(!e.scrollingPage){var n,r=e.cy,i=e.projectIntoViewport(t.clientX,t.clientY),a=[i[0]*r.zoom()+r.pan().x,i[1]*r.zoom()+r.pan().y];e.hoverData.draggingEles||e.hoverData.dragging||e.hoverData.cxtStarted||0!==e.selection[4]?t.preventDefault():r.panningEnabled()&&r.userPanningEnabled()&&r.zoomingEnabled()&&r.userZoomingEnabled()&&(t.preventDefault(),e.data.wheelZooming=!0,clearTimeout(e.data.wheelTimeout),e.data.wheelTimeout=setTimeout(function(){e.data.wheelZooming=!1,e.redrawHint("eles",!0),e.redraw()},150),n=null!=t.deltaY?t.deltaY/-250:null!=t.wheelDeltaY?t.wheelDeltaY/1e3:t.wheelDelta/1e3,n*=e.wheelSensitivity,1===t.deltaMode&&(n*=33),r.zoom({level:r.zoom()*Math.pow(10,n),renderedPosition:{x:a[0],y:a[1]}}))}},!0),e.registerBinding(window,"scroll",function(t){e.scrollingPage=!0,clearTimeout(e.scrollingPageTimeout),e.scrollingPageTimeout=setTimeout(function(){e.scrollingPage=!1},250)},!0),e.registerBinding(e.container,"mouseout",function(t){var n=e.projectIntoViewport(t.clientX,t.clientY);e.cy.emit({originalEvent:t,type:"mouseout",position:{x:n[0],y:n[1]}})},!1),e.registerBinding(e.container,"mouseover",function(t){var n=e.projectIntoViewport(t.clientX,t.clientY);e.cy.emit({originalEvent:t,type:"mouseover",position:{x:n[0],y:n[1]}})},!1);var N,z,I,L,A=function(e,t,n,r){return Math.sqrt((n-e)*(n-e)+(r-t)*(r-t))},O=function(e,t,n,r){return(n-e)*(n-e)+(r-t)*(r-t)};if(e.registerBinding(e.container,"touchstart",N=function(t){if(m(t)){d(),e.touchData.capture=!0,e.data.bgActivePosistion=void 0;var r=e.cy,i=e.touchData.now,a=e.touchData.earlier;if(t.touches[0]){var s=e.projectIntoViewport(t.touches[0].clientX,t.touches[0].clientY);i[0]=s[0],i[1]=s[1]}if(t.touches[1]){s=e.projectIntoViewport(t.touches[1].clientX,t.touches[1].clientY);i[2]=s[0],i[3]=s[1]}if(t.touches[2]){s=e.projectIntoViewport(t.touches[2].clientX,t.touches[2].clientY);i[4]=s[0],i[5]=s[1]}if(t.touches[1]){e.touchData.singleTouchMoved=!0,c(e.dragData.touchDragEles);var h=e.findContainerClientCoords();P=h[0],T=h[1],B=h[2],M=h[3],b=t.touches[0].clientX-P,x=t.touches[0].clientY-T,w=t.touches[1].clientX-P,E=t.touches[1].clientY-T,_=0<=b&&b<=B&&0<=w&&w<=B&&0<=x&&x<=M&&0<=E&&E<=M;var p=r.pan(),f=r.zoom();k=A(b,x,w,E),C=O(b,x,w,E),D=[((S=[(b+w)/2,(x+E)/2])[0]-p.x)/f,(S[1]-p.y)/f];if(C<4e4&&!t.touches[2]){var g=e.findNearestElement(i[0],i[1],!0,!0),v=e.findNearestElement(i[2],i[3],!0,!0);return g&&g.isNode()?(g.activate().emit({originalEvent:t,type:"cxttapstart",position:{x:i[0],y:i[1]}}),e.touchData.start=g):v&&v.isNode()?(v.activate().emit({originalEvent:t,type:"cxttapstart",position:{x:i[0],y:i[1]}}),e.touchData.start=v):r.emit({originalEvent:t,type:"cxttapstart",position:{x:i[0],y:i[1]}}),e.touchData.start&&(e.touchData.start._private.grabbed=!1),e.touchData.cxt=!0,e.touchData.cxtDragged=!1,e.data.bgActivePosistion=void 0,void e.redraw()}}if(t.touches[2])r.boxSelectionEnabled()&&t.preventDefault();else if(t.touches[1]);else if(t.touches[0]){var y=e.findNearestElements(i[0],i[1],!0,!0),N=y[0];if(null!=N&&(N.activate(),e.touchData.start=N,e.touchData.starts=y,e.nodeIsGrabbable(N))){var z=e.dragData.touchDragEles=r.collection(),I=null;e.redrawHint("eles",!0),e.redrawHint("drag",!0),N.selected()?(I=r.$(function(t){return t.selected()&&e.nodeIsGrabbable(t)}),l(I,{addToList:z})):u(N,{addToList:z}),o(N);var L=function(e){return{originalEvent:t,type:e,position:{x:i[0],y:i[1]}}};N.emit(L("grabon")),I?I.forEach(function(e){e.emit(L("grab"))}):N.emit(L("grab"))}n(N,["touchstart","tapstart","vmousedown"],t,{x:i[0],y:i[1]}),null==N&&(e.data.bgActivePosistion={x:s[0],y:s[1]},e.redrawHint("select",!0),e.redraw()),e.touchData.singleTouchMoved=!1,e.touchData.singleTouchStartTime=+new Date,clearTimeout(e.touchData.tapholdTimeout),e.touchData.tapholdTimeout=setTimeout(function(){!1!==e.touchData.singleTouchMoved||e.pinching||e.touchData.selecting||n(e.touchData.start,["taphold"],t,{x:i[0],y:i[1]})},e.tapholdDuration)}if(t.touches.length>=1){for(var R=e.touchData.startPosition=[],V=0;V=e.touchTapThreshold2}if(r&&e.touchData.cxt){t.preventDefault();var N=t.touches[0].clientX-P,z=t.touches[0].clientY-T,I=t.touches[1].clientX-P,L=t.touches[1].clientY-T,R=O(N,z,I,L);if(R/C>=2.25||R>=22500){e.touchData.cxt=!1,e.data.bgActivePosistion=void 0,e.redrawHint("select",!0);var V={originalEvent:t,type:"cxttapend",position:{x:s[0],y:s[1]}};e.touchData.start?(e.touchData.start.unactivate().emit(V),e.touchData.start=null):o.emit(V)}}if(r&&e.touchData.cxt){V={originalEvent:t,type:"cxtdrag",position:{x:s[0],y:s[1]}};e.data.bgActivePosistion=void 0,e.redrawHint("select",!0),e.touchData.start?e.touchData.start.emit(V):o.emit(V),e.touchData.start&&(e.touchData.start._private.grabbed=!1),e.touchData.cxtDragged=!0;var F=e.findNearestElement(s[0],s[1],!0,!0);e.touchData.cxtOver&&F===e.touchData.cxtOver||(e.touchData.cxtOver&&e.touchData.cxtOver.emit({originalEvent:t,type:"cxtdragout",position:{x:s[0],y:s[1]}}),e.touchData.cxtOver=F,F&&F.emit({originalEvent:t,type:"cxtdragover",position:{x:s[0],y:s[1]}}))}else if(r&&t.touches[2]&&o.boxSelectionEnabled())t.preventDefault(),e.data.bgActivePosistion=void 0,this.lastThreeTouch=+new Date,e.touchData.selecting||o.emit({originalEvent:t,type:"boxstart",position:{x:s[0],y:s[1]}}),e.touchData.selecting=!0,e.touchData.didSelect=!0,a[4]=1,a&&0!==a.length&&void 0!==a[0]?(a[2]=(s[0]+s[2]+s[4])/3,a[3]=(s[1]+s[3]+s[5])/3):(a[0]=(s[0]+s[2]+s[4])/3,a[1]=(s[1]+s[3]+s[5])/3,a[2]=(s[0]+s[2]+s[4])/3+1,a[3]=(s[1]+s[3]+s[5])/3+1),e.redrawHint("select",!0),e.redraw();else if(r&&t.touches[1]&&!e.touchData.didSelect&&o.zoomingEnabled()&&o.panningEnabled()&&o.userZoomingEnabled()&&o.userPanningEnabled()){if(t.preventDefault(),e.data.bgActivePosistion=void 0,e.redrawHint("select",!0),ee=e.dragData.touchDragEles){e.redrawHint("drag",!0);for(var q=0;q0&&!e.hoverData.draggingEles&&!e.swipePanning&&null!=e.data.bgActivePosistion&&(e.data.bgActivePosistion=void 0,e.redrawHint("select",!0),e.redraw())}},!1),e.registerBinding(window,"touchcancel",I=function(t){var n=e.touchData.start;e.touchData.capture=!1,n&&n.unactivate()}),e.registerBinding(window,"touchend",L=function(r){var i=e.touchData.start;if(e.touchData.capture){0===r.touches.length&&(e.touchData.capture=!1),r.preventDefault();var a=e.selection;e.swipePanning=!1,e.hoverData.draggingEles=!1;var o,s=e.cy,l=s.zoom(),u=e.touchData.now,h=e.touchData.earlier;if(r.touches[0]){var d=e.projectIntoViewport(r.touches[0].clientX,r.touches[0].clientY);u[0]=d[0],u[1]=d[1]}if(r.touches[1]){d=e.projectIntoViewport(r.touches[1].clientX,r.touches[1].clientY);u[2]=d[0],u[3]=d[1]}if(r.touches[2]){d=e.projectIntoViewport(r.touches[2].clientX,r.touches[2].clientY);u[4]=d[0],u[5]=d[1]}if(i&&i.unactivate(),e.touchData.cxt){if(o={originalEvent:r,type:"cxttapend",position:{x:u[0],y:u[1]}},i?i.emit(o):s.emit(o),!e.touchData.cxtDragged){var p={originalEvent:r,type:"cxttap",position:{x:u[0],y:u[1]}};i?i.emit(p):s.emit(p)}return e.touchData.start&&(e.touchData.start._private.grabbed=!1),e.touchData.cxt=!1,e.touchData.start=null,void e.redraw()}if(!r.touches[2]&&s.boxSelectionEnabled()&&e.touchData.selecting){e.touchData.selecting=!1;var f=s.collection(e.getAllInBox(a[0],a[1],a[2],a[3]));a[0]=void 0,a[1]=void 0,a[2]=void 0,a[3]=void 0,a[4]=0,e.redrawHint("select",!0),s.emit({type:"boxend",originalEvent:r,position:{x:u[0],y:u[1]}});f.emit("box").stdFilter(function(e){return e.selectable()&&!e.selected()}).select().emit("boxselect"),f.nonempty()&&e.redrawHint("eles",!0),e.redraw()}if(null!=i&&i.unactivate(),r.touches[2])e.data.bgActivePosistion=void 0,e.redrawHint("select",!0);else if(r.touches[1]);else if(r.touches[0]);else if(!r.touches[0]){e.data.bgActivePosistion=void 0,e.redrawHint("select",!0);var g=e.dragData.touchDragEles;if(null!=i){var v=i._private.grabbed;c(g),e.redrawHint("drag",!0),e.redrawHint("eles",!0),v&&(i.emit("freeon"),g.emit("free"),e.dragData.didDrag&&(i.emit("dragfreeon"),g.emit("dragfree"))),n(i,["touchend","tapend","vmouseup","tapdragout"],r,{x:u[0],y:u[1]}),i.unactivate(),e.touchData.start=null}else{var y=e.findNearestElement(u[0],u[1],!0,!0);n(y,["touchend","tapend","vmouseup","tapdragout"],r,{x:u[0],y:u[1]})}var m=e.touchData.startPosition[0]-u[0],b=m*m,x=e.touchData.startPosition[1]-u[1],w=(b+x*x)*l*l;e.touchData.singleTouchMoved||(i||s.$(":selected").unselect(["tapunselect"]),n(i,["tap","vclick"],r,{x:u[0],y:u[1]})),null!=i&&!e.dragData.didDrag&&i._private.selectable&&w0)return g[0]}return null},d=Object.keys(c),p=0;p0?l:wt(i,a,e,t,n,r,o)},checkPoint:function(e,t,n,r,i,a,o){var s=Vt(r,i),l=2*s;if(Pt(e,t,this.points,a,o,r,i-l,[0,-1],n))return!0;if(Pt(e,t,this.points,a,o,r-l,i,[0,-1],n))return!0;var u=r/2+2*n,c=i/2+2*n;return!!Dt(e,t,[a-u,o-c,a-u,o,a+u,o,a+u,o-c])||(!!Mt(e,t,l,l,a+r/2-s,o+i/2-s,n)||!!Mt(e,t,l,l,a-r/2+s,o+i/2-s,n))}}},ts.registerNodeShapes=function(){var e=this.nodeShapes={},t=this;this.generateEllipse(),this.generatePolygon("triangle",At(3,0)),this.generatePolygon("rectangle",At(4,0)),e.square=e.rectangle,this.generateRoundRectangle(),this.generateCutRectangle(),this.generateBarrel(),this.generateBottomRoundrectangle(),this.generatePolygon("diamond",[0,1,1,0,0,-1,-1,0]),this.generatePolygon("pentagon",At(5,0)),this.generatePolygon("hexagon",At(6,0)),this.generatePolygon("heptagon",At(7,0)),this.generatePolygon("octagon",At(8,0));var n=new Array(20),r=Rt(5,0),i=Rt(5,Math.PI/5),a=.5*(3-Math.sqrt(5));a*=1.57;for(var o=0;o=e.deqFastCost*g)break}else if(i){if(p>=e.deqCost*l||p>=e.deqAvgCost*s)break}else if(f>=e.deqNoDrawCost*(1e3/60))break;var v=e.deq(t,h,c);if(!(v.length>0))break;for(var y=0;y0&&(e.onDeqd(t,u),!i&&e.shouldRedraw(t,u,h,c)&&r())},i(t))}}},ss=function(){function e(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:be;t(this,e),this.idsByKey=new Ie,this.keyForId=new Ie,this.cachesByLvl=new Ie,this.lvls=[],this.getKey=n,this.doesEleInvalidateKey=r}return r(e,[{key:"getIdsFor",value:function(e){null==e&&Ee("Can not get id list for null key");var t=this.idsByKey,n=this.idsByKey.get(e);return n||(n=new Ae,t.set(e,n)),n}},{key:"addIdForKey",value:function(e,t){null!=e&&this.getIdsFor(e).add(t)}},{key:"deleteIdForKey",value:function(e,t){null!=e&&this.getIdsFor(e).delete(t)}},{key:"getNumberOfIdsForKey",value:function(e){return null==e?0:this.getIdsFor(e).size}},{key:"updateKeyMappingFor",value:function(e){var t=e.id(),n=this.keyForId.get(t),r=this.getKey(e);this.deleteIdForKey(n,t),this.addIdForKey(r,t),this.keyForId.set(t,r)}},{key:"deleteKeyMappingFor",value:function(e){var t=e.id(),n=this.keyForId.get(t);this.deleteIdForKey(n,t),this.keyForId.delete(t)}},{key:"keyHasChangedFor",value:function(e){var t=e.id();return this.keyForId.get(t)!==this.getKey(e)}},{key:"isInvalid",value:function(e){return this.keyHasChangedFor(e)||this.doesEleInvalidateKey(e)}},{key:"getCachesAt",value:function(e){var t=this.cachesByLvl,n=this.lvls,r=t.get(e);return r||(r=new Ie,t.set(e,r),n.push(e)),r}},{key:"getCache",value:function(e,t){return this.getCachesAt(t).get(e)}},{key:"get",value:function(e,t){var n=this.getKey(e),r=this.getCache(n,t);return null!=r&&this.updateKeyMappingFor(e),r}},{key:"getForCachedKey",value:function(e,t){var n=this.keyForId.get(e.id());return this.getCache(n,t)}},{key:"hasCache",value:function(e,t){return this.getCachesAt(t).has(e)}},{key:"has",value:function(e,t){var n=this.getKey(e);return this.hasCache(n,t)}},{key:"setCache",value:function(e,t,n){n.key=e,this.getCachesAt(t).set(e,n)}},{key:"set",value:function(e,t,n){var r=this.getKey(e);this.setCache(r,t,n),this.updateKeyMappingFor(e)}},{key:"deleteCache",value:function(e,t){this.getCachesAt(t).delete(e)}},{key:"delete",value:function(e,t){var n=this.getKey(e);this.deleteCache(n,t)}},{key:"invalidateKey",value:function(e){var t=this;this.lvls.forEach(function(n){return t.deleteCache(e,n)})}},{key:"invalidate",value:function(e){var t=e.id(),n=this.keyForId.get(t);this.deleteKeyMappingFor(e);var r=this.doesEleInvalidateKey(e);return r&&this.invalidateKey(n),r||0===this.getNumberOfIdsForKey(n)}}]),e}(),ls={dequeue:"dequeue",downscale:"downscale",highQuality:"highQuality"},us=Be({getKey:null,doesEleInvalidateKey:be,drawElement:null,getBoundingBox:null,getRotationPoint:null,getRotationOffset:null,isVisible:me,allowEdgeTxrCaching:!0,allowParentTxrCaching:!0}),cs=function(e,t){this.renderer=e,this.onDequeues=[];var n=us(t);z(this,n),this.lookup=new ss(n.getKey,n.doesEleInvalidateKey),this.setupDequeueing()},hs=cs.prototype;hs.reasons=ls,hs.getTextureQueue=function(e){return this.eleImgCaches=this.eleImgCaches||{},this.eleImgCaches[e]=this.eleImgCaches[e]||[]},hs.getRetiredTextureQueue=function(e){var t=this.eleImgCaches.retired=this.eleImgCaches.retired||{};return t[e]=t[e]||[]},hs.getElementQueue=function(){return this.eleCacheQueue=this.eleCacheQueue||new Fe(function(e,t){return t.reqs-e.reqs})},hs.getElementKeyToQueue=function(){return this.eleKeyToCacheQueue=this.eleKeyToCacheQueue||{}},hs.getElement=function(e,t,n,r,i){var a=this,o=this.renderer,s=o.cy.zoom(),l=this.lookup;if(0===t.w||0===t.h||isNaN(t.w)||isNaN(t.h)||!e.visible())return null;if(!a.allowEdgeTxrCaching&&e.isEdge()||!a.allowParentTxrCaching&&e.isParent())return null;if(null==r&&(r=Math.ceil(at(s*n))),r<-4)r=-4;else if(s>=7.99||r>3)return null;var u=Math.pow(2,r),c=t.h*u,h=t.w*u,d=o.eleTextBiggerThanMin(e,u);if(!this.isVisible(e,d))return null;var p,f=l.get(e,r);if(f&&f.invalidated&&(f.invalidated=!1,f.texture.invalidatedWidth-=f.width),f)return f;if(p=c<=25?25:c<=50?50:50*Math.ceil(c/50),c>1024||h>1024)return null;var g=a.getTextureQueue(p),v=g[g.length-2],y=function(){return a.recycleTexture(p,h)||a.addTexture(p,h)};v||(v=g[g.length-1]),v||(v=y()),v.width-v.usedWidthr;P--)S=a.getElement(e,t,n,P,ls.downscale);D()}else{var T;if(!x&&!w&&!E)for(var B=r-1;B>=-4;B--){var M=l.get(e,B);if(M){T=M;break}}if(b(T))return a.queueElement(e,r),T;v.context.translate(v.usedWidth,0),v.context.scale(u,u),this.drawElement(v.context,e,t,d,!1),v.context.scale(1/u,1/u),v.context.translate(-v.usedWidth,0)}return f={x:v.usedWidth,texture:v,level:r,scale:u,width:h,height:c,scaledLabelShown:d},v.usedWidth+=Math.ceil(h+8),v.eleCaches.push(f),l.set(e,r,f),a.checkTextureFullness(v),f},hs.invalidateElements=function(e){for(var t=0;t=.2*e.width&&this.retireTexture(e)},hs.checkTextureFullness=function(e){var t=this.getTextureQueue(e.height);e.usedWidth/e.width>.8&&e.fullnessChecks>=10?Me(t,e):e.fullnessChecks++},hs.retireTexture=function(e){var t=e.height,n=this.getTextureQueue(t),r=this.lookup;Me(n,e),e.retired=!0;for(var i=e.eleCaches,a=0;a=t)return a.retired=!1,a.usedWidth=0,a.invalidatedWidth=0,a.fullnessChecks=0,_e(a.eleCaches),a.context.setTransform(1,0,0,1,0,0),a.context.clearRect(0,0,a.width,a.height),Me(r,a),n.push(a),a}},hs.queueElement=function(e,t){var n=this.getElementQueue(),r=this.getElementKeyToQueue(),i=this.getKey(e),a=r[i];if(a)a.level=Math.max(a.level,t),a.eles.merge(e),a.reqs++,n.updateItem(a);else{var o={eles:e.spawn().merge(e),level:t,reqs:1,key:i};n.push(o),r[i]=o}},hs.dequeue=function(e){for(var t=this.getElementQueue(),n=this.getElementKeyToQueue(),r=[],i=this.lookup,a=0;a<1&&t.size()>0;a++){var o=t.pop(),s=o.key,l=o.eles[0],u=i.hasCache(l,o.level);if(n[s]=null,!u){r.push(o);var c=this.getBoundingBox(l);this.getElement(l,c,e,o.level,ls.dequeue)}}return r},hs.removeFromQueue=function(e){var t=this.getElementQueue(),n=this.getElementKeyToQueue(),r=this.getKey(e),i=n[r];null!=i&&(1===i.eles.length?(i.reqs=ye,t.updateItem(i),t.pop(),n[r]=null):i.eles.unmerge(e))},hs.onDequeue=function(e){this.onDequeues.push(e)},hs.offDequeue=function(e){Me(this.onDequeues,e)},hs.setupDequeueing=os({deqRedrawThreshold:100,deqCost:.15,deqAvgCost:.1,deqNoDrawCost:.9,deqFastCost:.9,deq:function(e,t,n){return e.dequeue(t,n)},onDeqd:function(e,t){for(var n=0;n=3.99||n>2)return null;r.validateLayersElesOrdering(n,e);var o,s,l=r.layersByLevel,u=Math.pow(2,n),c=l[n]=l[n]||[];if(r.levelIsComplete(n,e))return c;!function(){var t=function(t){if(r.validateLayersElesOrdering(t,e),r.levelIsComplete(t,e))return s=l[t],!0},i=function(e){if(!s)for(var r=n+e;-4<=r&&r<=2&&!t(r);r+=e);};i(1),i(-1);for(var a=c.length-1;a>=0;a--){var o=c[a];o.invalid&&Me(c,o)}}();var h=function(t){var i=(t=t||{}).after;if(function(){if(!o){o=pt();for(var t=0;t16e6)return null;var a=r.makeLayer(o,n);if(null!=i){var s=c.indexOf(i)+1;c.splice(s,0,a)}else(void 0===t.insert||t.insert)&&c.unshift(a);return a};if(r.skipping&&!a)return null;for(var d=null,p=e.length/1,f=!a,g=0;g=p||!xt(d.bb,v.boundingBox()))&&!(d=h({insert:!0,after:d})))return null;s||f?r.queueLayer(d,v):r.drawEleInLayer(d,v,n,t),d.eles.push(v),m[n]=d}}return s||(f?null:c)},ps.getEleLevelForLayerLevel=function(e,t){return e},ps.drawEleInLayer=function(e,t,n,r){var i=this.renderer,a=e.context,o=t.boundingBox();0!==o.w&&0!==o.h&&t.visible()&&(n=this.getEleLevelForLayerLevel(n,r),i.setImgSmoothing(a,!1),i.drawCachedElement(a,t,null,null,n,!0),i.setImgSmoothing(a,!0))},ps.levelIsComplete=function(e,t){var n=this.layersByLevel[e];if(!n||0===n.length)return!1;for(var r=0,i=0;i0)return!1;if(a.invalid)return!1;r+=a.eles.length}return r===t.length},ps.validateLayersElesOrdering=function(e,t){var n=this.layersByLevel[e];if(n)for(var r=0;r0){e=!0;break}}return e},ps.invalidateElements=function(e){var t=this;0!==e.length&&(t.lastInvalidationTime=se(),0!==e.length&&t.haveLayers()&&t.updateElementsInLayers(e,function(e,n,r){t.invalidateLayer(e)}))},ps.invalidateLayer=function(e){if(this.lastInvalidationTime=se(),!e.invalid){var t=e.level,n=e.eles,r=this.layersByLevel[t];Me(r,e),e.elesQueue=[],e.invalid=!0,e.replacement&&(e.replacement.invalid=!0);for(var i=0;i3&&void 0!==arguments[3])||arguments[3],i=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],a=!(arguments.length>5&&void 0!==arguments[5])||arguments[5],o=this,s=t._private.rscratch;if((!a||t.visible())&&!s.badLine&&null!=s.allpts&&!isNaN(s.allpts[0])){var l;n&&(l=n,e.translate(-l.x1,-l.y1));var u=a?t.pstyle("opacity").value:1,c=t.pstyle("line-style").value,h=t.pstyle("width").pfValue,d=t.pstyle("line-cap").value,p=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u;e.lineWidth=h,e.lineCap=d,o.eleStrokeStyle(e,t,n),o.drawEdgePath(t,e,s.allpts,c),e.lineCap="butt"},f=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u;o.drawArrowheads(e,t,n)};if(e.lineJoin="round","yes"===t.pstyle("ghost").value){var g=t.pstyle("ghost-offset-x").pfValue,v=t.pstyle("ghost-offset-y").pfValue,y=t.pstyle("ghost-opacity").value,m=u*y;e.translate(g,v),p(m),f(m),e.translate(-g,-v)}p(),f(),i&&o.drawEdgeOverlay(e,t),o.drawElementText(e,t,null,r),n&&e.translate(l.x1,l.y1)}},drawEdgeOverlay:function(e,t){if(t.visible()){var n=t.pstyle("overlay-opacity").value;if(0!==n){var r=this,i=r.usePaths(),a=t._private.rscratch,o=2*t.pstyle("overlay-padding").pfValue,s=t.pstyle("overlay-color").value;e.lineWidth=o,"self"!==a.edgeType||i?e.lineCap="round":e.lineCap="butt",r.colorStrokeStyle(e,s[0],s[1],s[2],n),r.drawEdgePath(t,e,a.allpts,"solid")}}},drawEdgePath:function(e,t,n,r){var i,a=e._private.rscratch,o=t,s=!1,l=this.usePaths(),u=e.pstyle("line-dash-pattern").pfValue,c=e.pstyle("line-dash-offset").pfValue;if(l){var h=n.join("$");a.pathCacheKey&&a.pathCacheKey===h?(i=t=a.pathCache,s=!0):(i=t=new Path2D,a.pathCacheKey=h,a.pathCache=i)}if(o.setLineDash)switch(r){case"dotted":o.setLineDash([1,1]);break;case"dashed":o.setLineDash(u),o.lineDashOffset=c;break;case"solid":o.setLineDash([])}if(!s&&!a.badLine)switch(t.beginPath&&t.beginPath(),t.moveTo(n[0],n[1]),a.edgeType){case"bezier":case"self":case"compound":case"multibezier":for(var d=2;d+35&&void 0!==arguments[5])||arguments[5],o=this;if(null==r){if(a&&!o.eleTextBiggerThanMin(t))return}else if(!1===r)return;if(t.isNode()){var s=t.pstyle("label");if(!s||!s.value)return;var l=o.getLabelJustification(t);e.textAlign=l,e.textBaseline="bottom"}else{var u=t.pstyle("label"),c=t.pstyle("source-label"),h=t.pstyle("target-label");if(!(u&&u.value||c&&c.value||h&&h.value))return;e.textAlign="center",e.textBaseline="bottom"}var d,p=!n;n&&(d=n,e.translate(-d.x1,-d.y1)),null==i?(o.drawText(e,t,null,p,a),t.isEdge()&&(o.drawText(e,t,"source",p,a),o.drawText(e,t,"target",p,a))):o.drawText(e,t,i,p,a),n&&e.translate(d.x1,d.y1)},_s.getFontCache=function(e){var t;this.fontCaches=this.fontCaches||[];for(var n=0;n2&&void 0!==arguments[2])||arguments[2],r=t.pstyle("font-style").strValue,i=t.pstyle("font-size").pfValue+"px",a=t.pstyle("font-family").strValue,o=t.pstyle("font-weight").strValue,s=n?t.effectiveOpacity()*t.pstyle("text-opacity").value:1,l=t.pstyle("text-outline-opacity").value*s,u=t.pstyle("color").value,c=t.pstyle("text-outline-color").value;e.font=r+" "+o+" "+i+" "+a,e.lineJoin="round",this.colorFillStyle(e,u[0],u[1],u[2],s),this.colorStrokeStyle(e,c[0],c[1],c[2],l)},_s.getTextAngle=function(e,t){var n=e._private.rscratch,r=t?t+"-":"",i=e.pstyle(r+"text-rotation"),a=Ne(n,"labelAngle",t);return"autorotate"===i.strValue?e.isEdge()?a:0:"none"===i.strValue?0:i.pfValue},_s.drawText=function(e,t,n){var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],a=t._private.rscratch,o=i?t.effectiveOpacity():1;if(!i||0!==o&&0!==t.pstyle("text-opacity").value){"main"===n&&(n=null);var s,l,u=Ne(a,"labelX",n),c=Ne(a,"labelY",n),h=this.getLabelText(t,n);if(null!=h&&""!==h&&!isNaN(u)&&!isNaN(c)){this.setupTextStyle(e,t,i);var d,p=n?n+"-":"",f=Ne(a,"labelWidth",n),g=Ne(a,"labelHeight",n),v=t.pstyle(p+"text-margin-x").pfValue,y=t.pstyle(p+"text-margin-y").pfValue,m=t.isEdge(),b=t.pstyle("text-halign").value,x=t.pstyle("text-valign").value;switch(m&&(b="center",x="center"),u+=v,c+=y,0!==(d=r?this.getTextAngle(t,n):0)&&(s=u,l=c,e.translate(s,l),e.rotate(d),u=0,c=0),x){case"top":break;case"center":c+=g/2;break;case"bottom":c+=g}var w=t.pstyle("text-background-opacity").value,E=t.pstyle("text-border-opacity").value,k=t.pstyle("text-border-width").pfValue,C=t.pstyle("text-background-padding").pfValue;if(w>0||k>0&&E>0){var S=u-C;switch(b){case"left":S-=f;break;case"center":S-=f/2}var D=c-g-C,P=f+2*C,T=g+2*C;if(w>0){var B=e.fillStyle,M=t.pstyle("text-background-color").value;e.fillStyle="rgba("+M[0]+","+M[1]+","+M[2]+","+w*o+")","roundrectangle"==t.pstyle("text-background-shape").strValue?function(e,t,n,r,i){var a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:5;e.beginPath(),e.moveTo(t+a,n),e.lineTo(t+r-a,n),e.quadraticCurveTo(t+r,n,t+r,n+a),e.lineTo(t+r,n+i-a),e.quadraticCurveTo(t+r,n+i,t+r-a,n+i),e.lineTo(t+a,n+i),e.quadraticCurveTo(t,n+i,t,n+i-a),e.lineTo(t,n+a),e.quadraticCurveTo(t,n,t+a,n),e.closePath(),e.fill()}(e,S,D,P,T,2):e.fillRect(S,D,P,T),e.fillStyle=B}if(k>0&&E>0){var _=e.strokeStyle,N=e.lineWidth,z=t.pstyle("text-border-color").value,I=t.pstyle("text-border-style").value;if(e.strokeStyle="rgba("+z[0]+","+z[1]+","+z[2]+","+E*o+")",e.lineWidth=k,e.setLineDash)switch(I){case"dotted":e.setLineDash([1,1]);break;case"dashed":e.setLineDash([4,2]);break;case"double":e.lineWidth=k/4,e.setLineDash([]);break;case"solid":e.setLineDash([])}if(e.strokeRect(S,D,P,T),"double"===I){var L=k/2;e.strokeRect(S+L,D+L,P-2*L,T-2*L)}e.setLineDash&&e.setLineDash([]),e.lineWidth=N,e.strokeStyle=_}}var A=2*t.pstyle("text-outline-width").pfValue;if(A>0&&(e.lineWidth=A),"wrap"===t.pstyle("text-wrap").value){var O=Ne(a,"labelWrapCachedLines",n),R=Ne(a,"labelLineHeight",n),V=f/2,F=this.getLabelJustification(t);switch("auto"===F||("left"===b?"left"===F?u+=-f:"center"===F&&(u+=-V):"center"===b?"left"===F?u+=-V:"right"===F&&(u+=V):"right"===b&&("center"===F?u+=V:"right"===F&&(u+=f))),x){case"top":c-=(O.length-1)*R;break;case"center":case"bottom":c-=(O.length-1)*R}for(var q=0;q0&&e.strokeText(O[q],u,c),e.fillText(O[q],u,c),c+=R}else A>0&&e.strokeText(h,u,c),e.fillText(h,u,c);0!==d&&(e.rotate(-d),e.translate(-s,-l))}}};var Ns={drawNode:function(e,t,n){var r,i,a=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],s=!(arguments.length>5&&void 0!==arguments[5])||arguments[5],l=this,u=t._private,c=u.rscratch,h=t.position();if(v(h.x)&&v(h.y)&&(!s||t.visible())){var d,p,f=s?t.effectiveOpacity():1,g=l.usePaths(),y=!1,m=t.padding();r=t.width()+2*m,i=t.height()+2*m,n&&(p=n,e.translate(-p.x1,-p.y1));for(var b=t.pstyle("background-image").value,x=new Array(b.length),w=new Array(b.length),E=0,k=0;k0&&void 0!==arguments[0]?arguments[0]:T;l.eleFillStyle(e,t,n)},z=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:_;l.colorStrokeStyle(e,B[0],B[1],B[2],t)},I=t.pstyle("shape").strValue,L=t.pstyle("shape-polygon-points").pfValue;if(g){e.translate(h.x,h.y);var A=l.nodePathCache=l.nodePathCache||[],O=de("polygon"===I?I+","+L.join(","):I,""+i,""+r),R=A[O];null!=R?(d=R,y=!0,c.pathCache=d):(d=new Path2D,A[O]=c.pathCache=d)}var V=function(){if(!y){var n=h;g&&(n={x:0,y:0}),l.nodeShapes[l.getNodeShape(t)].draw(d||e,n.x,n.y,r,i)}g?e.fill(d):e.fill()},F=function(){for(var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:f,r=u.backgrounding,i=0,a=0;a0&&void 0!==arguments[0]&&arguments[0],a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:f;l.hasPie(t)&&(l.drawPie(e,t,a),n&&(g||l.nodeShapes[l.getNodeShape(t)].draw(e,h.x,h.y,r,i)))},Y=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:f,n=(D>0?D:-D)*t,r=D>0?0:255;0!==D&&(l.colorFillStyle(e,r,r,r,n),g?e.fill(d):e.fill())},j=function(){if(P>0){if(e.lineWidth=P,e.lineCap="butt",e.setLineDash)switch(M){case"dotted":e.setLineDash([1,1]);break;case"dashed":e.setLineDash([4,2]);break;case"solid":case"double":e.setLineDash([])}if(g?e.stroke(d):e.stroke(),"double"===M){e.lineWidth=P/3;var t=e.globalCompositeOperation;e.globalCompositeOperation="destination-out",g?e.stroke(d):e.stroke(),e.globalCompositeOperation=t}e.setLineDash&&e.setLineDash([])}};if("yes"===t.pstyle("ghost").value){var X=t.pstyle("ghost-offset-x").pfValue,W=t.pstyle("ghost-offset-y").pfValue,H=t.pstyle("ghost-opacity").value,K=H*f;e.translate(X,W),N(H*T),V(),F(K),q(0!==D||0!==P),Y(K),z(H*_),j(),e.translate(-X,-W)}N(),V(),F(),q(0!==D||0!==P),Y(),z(),j(),g&&e.translate(-h.x,-h.y),l.drawElementText(e,t,null,a),o&&l.drawNodeOverlay(e,t,h,r,i),n&&e.translate(p.x1,p.y1)}},drawNodeOverlay:function(e,t,n,r,i){if(t.visible()){var a=t.pstyle("overlay-padding").pfValue,o=t.pstyle("overlay-opacity").value,s=t.pstyle("overlay-color").value;if(o>0){if(n=n||t.position(),null==r||null==i){var l=t.padding();r=t.width()+2*l,i=t.height()+2*l}this.colorFillStyle(e,s[0],s[1],s[2],o),this.nodeShapes.roundrectangle.draw(e,n.x,n.y,r+2*a,i+2*a),e.fill()}}},hasPie:function(e){return(e=e[0])._private.hasPie},drawPie:function(e,t,n,r){t=t[0],r=r||t.position();var i=t.cy().style(),a=t.pstyle("pie-size"),o=r.x,s=r.y,l=t.width(),u=t.height(),c=Math.min(l,u)/2,h=0;this.usePaths()&&(o=0,s=0),"%"===a.units?c*=a.pfValue:void 0!==a.pfValue&&(c=a.pfValue/2);for(var d=1;d<=i.pieBackgroundN;d++){var p=t.pstyle("pie-"+d+"-background-size").value,f=t.pstyle("pie-"+d+"-background-color").value,g=t.pstyle("pie-"+d+"-background-opacity").value*n,v=p/100;v+h>1&&(v=1-h);var y=1.5*Math.PI+2*Math.PI*h,m=y+2*Math.PI*v;0===p||h>=1||h+v>1||(e.beginPath(),e.moveTo(o,s),e.arc(o,s,c,y,m),e.closePath(),this.colorFillStyle(e,f[0],f[1],f[2],g),e.fill(),h+=v)}}},zs={};zs.getPixelRatio=function(){var e=this.data.contexts[0];if(null!=this.forcedPixelRatio)return this.forcedPixelRatio;var t=e.backingStorePixelRatio||e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1;return(window.devicePixelRatio||1)/t},zs.paintCache=function(e){for(var t,n=this.paintCaches=this.paintCaches||[],r=!0,i=0;io.minMbLowQualFrames&&(o.motionBlurPxRatio=o.mbPxRBlurry)),o.clearingMotionBlur&&(o.motionBlurPxRatio=1),o.textureDrawLastFrame&&!h&&(c[o.NODE]=!0,c[o.SELECT_BOX]=!0);var m=l.style(),b=l.zoom(),x=void 0!==i?i:b,w=l.pan(),E={x:w.x,y:w.y},k={zoom:b,pan:{x:w.x,y:w.y}},C=o.prevViewport;void 0===C||k.zoom!==C.zoom||k.pan.x!==C.pan.x||k.pan.y!==C.pan.y||g&&!f||(o.motionBlurPxRatio=1),a&&(E=a),x*=s,E.x*=s,E.y*=s;var S=o.getCachedZSortedEles();function D(e,t,n,r,i){var a=e.globalCompositeOperation;e.globalCompositeOperation="destination-out",o.colorFillStyle(e,255,255,255,o.motionBlurTransparency),e.fillRect(t,n,r,i),e.globalCompositeOperation=a}function P(e,r){var s,l,c,h;o.clearingMotionBlur||e!==u.bufferContexts[o.MOTIONBLUR_BUFFER_NODE]&&e!==u.bufferContexts[o.MOTIONBLUR_BUFFER_DRAG]?(s=E,l=x,c=o.canvasWidth,h=o.canvasHeight):(s={x:w.x*p,y:w.y*p},l=b*p,c=o.canvasWidth*p,h=o.canvasHeight*p),e.setTransform(1,0,0,1,0,0),"motionBlur"===r?D(e,0,0,c,h):t||void 0!==r&&!r||e.clearRect(0,0,c,h),n||(e.translate(s.x,s.y),e.scale(l,l)),a&&e.translate(a.x,a.y),i&&e.scale(i,i)}if(h||(o.textureDrawLastFrame=!1),h){if(o.textureDrawLastFrame=!0,!o.textureCache){o.textureCache={},o.textureCache.bb=l.mutableElements().boundingBox(),o.textureCache.texture=o.data.bufferCanvases[o.TEXTURE_BUFFER];var T=o.data.bufferContexts[o.TEXTURE_BUFFER];T.setTransform(1,0,0,1,0,0),T.clearRect(0,0,o.canvasWidth*o.textureMult,o.canvasHeight*o.textureMult),o.render({forcedContext:T,drawOnlyNodeLayer:!0,forcedPxRatio:s*o.textureMult}),(k=o.textureCache.viewport={zoom:l.zoom(),pan:l.pan(),width:o.canvasWidth,height:o.canvasHeight}).mpan={x:(0-k.pan.x)/k.zoom,y:(0-k.pan.y)/k.zoom}}c[o.DRAG]=!1,c[o.NODE]=!1;var B=u.contexts[o.NODE],M=o.textureCache.texture;k=o.textureCache.viewport;B.setTransform(1,0,0,1,0,0),d?D(B,0,0,k.width,k.height):B.clearRect(0,0,k.width,k.height);var _=m.core("outside-texture-bg-color").value,N=m.core("outside-texture-bg-opacity").value;o.colorFillStyle(B,_[0],_[1],_[2],N),B.fillRect(0,0,k.width,k.height);b=l.zoom();P(B,!1),B.clearRect(k.mpan.x,k.mpan.y,k.width/k.zoom/s,k.height/k.zoom/s),B.drawImage(M,k.mpan.x,k.mpan.y,k.width/k.zoom/s,k.height/k.zoom/s)}else o.textureOnViewport&&!t&&(o.textureCache=null);var z=l.extent(),I=o.pinching||o.hoverData.dragging||o.swipePanning||o.data.wheelZooming||o.hoverData.draggingEles||o.cy.animated(),L=o.hideEdgesOnViewport&&I,A=[];if(A[o.NODE]=!c[o.NODE]&&d&&!o.clearedForMotionBlur[o.NODE]||o.clearingMotionBlur,A[o.NODE]&&(o.clearedForMotionBlur[o.NODE]=!0),A[o.DRAG]=!c[o.DRAG]&&d&&!o.clearedForMotionBlur[o.DRAG]||o.clearingMotionBlur,A[o.DRAG]&&(o.clearedForMotionBlur[o.DRAG]=!0),c[o.NODE]||n||r||A[o.NODE]){var O=d&&!A[o.NODE]&&1!==p;P(B=t||(O?o.data.bufferContexts[o.MOTIONBLUR_BUFFER_NODE]:u.contexts[o.NODE]),d&&!O?"motionBlur":void 0),L?o.drawCachedNodes(B,S.nondrag,s,z):o.drawLayeredElements(B,S.nondrag,s,z),o.debug&&o.drawDebugPoints(B,S.nondrag),n||d||(c[o.NODE]=!1)}if(!r&&(c[o.DRAG]||n||A[o.DRAG])){O=d&&!A[o.DRAG]&&1!==p;P(B=t||(O?o.data.bufferContexts[o.MOTIONBLUR_BUFFER_DRAG]:u.contexts[o.DRAG]),d&&!O?"motionBlur":void 0),L?o.drawCachedNodes(B,S.drag,s,z):o.drawCachedElements(B,S.drag,s,z),o.debug&&o.drawDebugPoints(B,S.drag),n||d||(c[o.DRAG]=!1)}if(o.showFps||!r&&c[o.SELECT_BOX]&&!n){if(P(B=t||u.contexts[o.SELECT_BOX]),1==o.selection[4]&&(o.hoverData.selecting||o.touchData.selecting)){b=o.cy.zoom();var R=m.core("selection-box-border-width").value/b;B.lineWidth=R,B.fillStyle="rgba("+m.core("selection-box-color").value[0]+","+m.core("selection-box-color").value[1]+","+m.core("selection-box-color").value[2]+","+m.core("selection-box-opacity").value+")",B.fillRect(o.selection[0],o.selection[1],o.selection[2]-o.selection[0],o.selection[3]-o.selection[1]),R>0&&(B.strokeStyle="rgba("+m.core("selection-box-border-color").value[0]+","+m.core("selection-box-border-color").value[1]+","+m.core("selection-box-border-color").value[2]+","+m.core("selection-box-opacity").value+")",B.strokeRect(o.selection[0],o.selection[1],o.selection[2]-o.selection[0],o.selection[3]-o.selection[1]))}if(u.bgActivePosistion&&!o.hoverData.selecting){b=o.cy.zoom();var V=u.bgActivePosistion;B.fillStyle="rgba("+m.core("active-bg-color").value[0]+","+m.core("active-bg-color").value[1]+","+m.core("active-bg-color").value[2]+","+m.core("active-bg-opacity").value+")",B.beginPath(),B.arc(V.x,V.y,m.core("active-bg-size").pfValue/b,0,2*Math.PI),B.fill()}var F=o.lastRedrawTime;if(o.showFps&&F){F=Math.round(F);var q=Math.round(1e3/F);B.setTransform(1,0,0,1,0,0),B.fillStyle="rgba(255, 0, 0, 0.75)",B.strokeStyle="rgba(255, 0, 0, 0.75)",B.lineWidth=1,B.fillText("1 frame = "+F+" ms = "+q+" fps",0,20);B.strokeRect(0,30,250,20),B.fillRect(0,30,250*Math.min(q/60,1),20)}n||(c[o.SELECT_BOX]=!1)}if(d&&1!==p){var Y=u.contexts[o.NODE],j=o.data.bufferCanvases[o.MOTIONBLUR_BUFFER_NODE],X=u.contexts[o.DRAG],W=o.data.bufferCanvases[o.MOTIONBLUR_BUFFER_DRAG],H=function(e,t,n){e.setTransform(1,0,0,1,0,0),n||!y?e.clearRect(0,0,o.canvasWidth,o.canvasHeight):D(e,0,0,o.canvasWidth,o.canvasHeight);var r=p;e.drawImage(t,0,0,o.canvasWidth*r,o.canvasHeight*r,0,0,o.canvasWidth,o.canvasHeight)};(c[o.NODE]||A[o.NODE])&&(H(Y,j,A[o.NODE]),c[o.NODE]=!1),(c[o.DRAG]||A[o.DRAG])&&(H(X,W,A[o.DRAG]),c[o.DRAG]=!1)}o.prevViewport=k,o.clearingMotionBlur&&(o.clearingMotionBlur=!1,o.motionBlurCleared=!0,o.motionBlur=!0),d&&(o.motionBlurTimeout=setTimeout(function(){o.motionBlurTimeout=null,o.clearedForMotionBlur[o.NODE]=!1,o.clearedForMotionBlur[o.DRAG]=!1,o.motionBlur=!1,o.clearingMotionBlur=!h,o.mbFrames=0,c[o.NODE]=!0,c[o.DRAG]=!0,o.redraw()},100)),t||l.emit("render")};for(var Is={drawPolygonPath:function(e,t,n,r,i,a){var o=r/2,s=i/2;e.beginPath&&e.beginPath(),e.moveTo(t+o*a[0],n+s*a[1]);for(var l=1;l0&&a>0){d.clearRect(0,0,i,a),d.globalCompositeOperation="source-over";var p=this.getCachedZSortedEles();if(e.full)d.translate(-n.x1*l,-n.y1*l),d.scale(l,l),this.drawElements(d,p),d.scale(1/l,1/l),d.translate(n.x1*l,n.y1*l);else{var f=t.pan(),g={x:f.x*l,y:f.y*l};l*=t.zoom(),d.translate(g.x,g.y),d.scale(l,l),this.drawElements(d,p),d.scale(1/l,1/l),d.translate(-g.x,-g.y)}e.bg&&(d.globalCompositeOperation="destination-over",d.fillStyle=e.bg,d.rect(0,0,i,a),d.fill())}return h},qs.png=function(e){return js(e,this.bufferCanvasImage(e),"image/png")},qs.jpg=function(e){return js(e,this.bufferCanvasImage(e),"image/jpeg")};var Xs={nodeShapeImpl:function(e,t,n,r,i,a,o){switch(e){case"ellipse":return this.drawEllipsePath(t,n,r,i,a);case"polygon":return this.drawPolygonPath(t,n,r,i,a,o);case"roundrectangle":case"round-rectangle":return this.drawRoundRectanglePath(t,n,r,i,a);case"cutrectangle":case"cut-rectangle":return this.drawCutRectanglePath(t,n,r,i,a);case"bottomroundrectangle":case"bottom-round-rectangle":return this.drawBottomRoundRectanglePath(t,n,r,i,a);case"barrel":return this.drawBarrelPath(t,n,r,i,a)}}},Ws=Ks,Hs=Ks.prototype;function Ks(e){var t=this;t.data={canvases:new Array(Hs.CANVAS_LAYERS),contexts:new Array(Hs.CANVAS_LAYERS),canvasNeedsRedraw:new Array(Hs.CANVAS_LAYERS),bufferCanvases:new Array(Hs.BUFFER_COUNT),bufferContexts:new Array(Hs.CANVAS_LAYERS)};t.data.canvasContainer=document.createElement("div");var n=t.data.canvasContainer.style;t.data.canvasContainer.style["-webkit-tap-highlight-color"]="rgba(0,0,0,0)",n.position="relative",n.zIndex="0",n.overflow="hidden";var r=e.cy.container();r.appendChild(t.data.canvasContainer),r.style["-webkit-tap-highlight-color"]="rgba(0,0,0,0)";var i={"-webkit-user-select":"none","-moz-user-select":"-moz-none","user-select":"none","-webkit-tap-highlight-color":"rgba(0,0,0,0)","outline-style":"none"};S()&&(i["-ms-touch-action"]="none",i["touch-action"]="none");for(var a=0;a max$$1) { + if (S[i * n + e] > max) { index = e; - max$$1 = S[i * n + e]; + max = S[i * n + e]; } } @@ -5852,7 +5873,7 @@ // main algorithmic loop // Update R responsibility matrix for (var _i8 = 0; _i8 < n; _i8++) { - var max$$1 = -Infinity, + var max = -Infinity, max2 = -Infinity, maxI = -1, AS = 0.0; @@ -5861,9 +5882,9 @@ old[_j] = R[_i8 * n + _j]; AS = A[_i8 * n + _j] + S[_i8 * n + _j]; - if (AS >= max$$1) { - max2 = max$$1; - max$$1 = AS; + if (AS >= max) { + max2 = max; + max = AS; maxI = _j; } else if (AS > max2) { max2 = AS; @@ -5871,7 +5892,7 @@ } for (var _j2 = 0; _j2 < n; _j2++) { - R[_i8 * n + _j2] = (1 - opts.damping) * (S[_i8 * n + _j2] - max$$1) + opts.damping * old[_j2]; + R[_i8 * n + _j2] = (1 - opts.damping) * (S[_i8 * n + _j2] - max) + opts.damping * old[_j2]; } R[_i8 * n + maxI] = (1 - opts.damping) * (S[_i8 * n + maxI] - max2) + opts.damping * old[maxI]; @@ -5932,7 +5953,7 @@ var exemplarsIndices = findExemplars(n, R, A); // Assign nodes to clusters - var clusterIndices = assign$2(n, S, exemplarsIndices, nodes, id2position); + var clusterIndices = assign$2(n, S, exemplarsIndices); var clusters = {}; for (var c = 0; c < exemplarsIndices.length; c++) { @@ -6460,7 +6481,7 @@ return this; }, - promise: function promise$$1(type) { + promise: function promise(type) { var _p = this._private; var arr; @@ -6574,7 +6595,7 @@ return this; } - var style$$1 = cy.style(); + var style = cy.style(); properties = extend({}, properties, params); var propertiesEmpty = Object.keys(properties).length === 0; @@ -6597,7 +6618,7 @@ } if (isEles) { - properties.style = style$$1.getPropsList(properties.style || properties.css); + properties.style = style.getPropsList(properties.style || properties.css); properties.css = undefined; } @@ -6738,7 +6759,7 @@ var define$1 = { // access data field data: function data(params) { - var defaults$$1 = { + var defaults = { field: 'data', bindingEvent: 'data', allowBinding: false, @@ -6757,7 +6778,7 @@ return true; } }; - params = extend({}, defaults$$1, params); + params = extend({}, defaults, params); return function dataImpl(name, value) { var p = params; var self = this; @@ -6848,8 +6869,8 @@ } else if (p.allowBinding && fn(name)) { // bind to event - var fn$$1 = name; - self.on(p.bindingEvent, fn$$1); // .data() + var fn$1 = name; + self.on(p.bindingEvent, fn$1); // .data() } else if (p.allowGetting && name === undefined) { // get whole object var _ret; @@ -6868,7 +6889,7 @@ // data // remove data field removeData: function removeData(params) { - var defaults$$1 = { + var defaults = { field: 'data', event: 'data', triggerFnName: 'trigger', @@ -6876,7 +6897,7 @@ immutableKeys: {} // key => true if immutable }; - params = extend({}, defaults$$1, params); + params = extend({}, defaults, params); return function removeDataImpl(names) { var p = params; var self = this; @@ -8269,7 +8290,7 @@ match[Type.DATA_EXIST] = function (check, ele) { var field = check.field, operator = check.operator; - return existCmp(data(ele, field), operator); + return existCmp(data(ele, field)); }; match[Type.UNDIRECTED_EDGE] = function (check, ele) { @@ -8372,7 +8393,7 @@ // does selector match a single element? - var matches$1 = function matches$$1(ele) { + var matches$1 = function matches$1(ele) { var self = this; for (var j = 0; j < self.length; j++) { @@ -8418,7 +8439,7 @@ this.invalid = true; } } else { - error('A selector must be created from a string; found ', selector); + error('A selector must be created from a string; found '); } }; @@ -8532,7 +8553,7 @@ elesfn$e.has = elesfn$e.contains; elesfn$e.equal = elesfn$e.equals = elesfn$e.same; - var cache = function cache(fn$$1, name) { + var cache = function cache(fn, name) { return function traversalCache(arg1, arg2, arg3, arg4) { var selectorOrEles = arg1; var eles = this; @@ -8554,10 +8575,10 @@ if (cacheHit) { return cacheHit; } else { - return ch[hash] = fn$$1.call(eles, arg1, arg2, arg3, arg4); + return ch[hash] = fn.call(eles, arg1, arg2, arg3, arg4); } } else { - return fn$$1.call(eles, arg1, arg2, arg3, arg4); + return fn.call(eles, arg1, arg2, arg3, arg4); } }; }; @@ -9285,7 +9306,7 @@ var _p = parent._private; var children = parent.children(); var includeLabels = parent.pstyle('compound-sizing-wrt-labels').value === 'include'; - var min$$1 = { + var min = { width: { val: parent.pstyle('min-width').pfValue, left: parent.pstyle('min-width-bias-left'), @@ -9362,40 +9383,40 @@ } } - var leftVal = min$$1.width.left.value; + var leftVal = min.width.left.value; - if (min$$1.width.left.units === 'px' && min$$1.width.val > 0) { - leftVal = leftVal * 100 / min$$1.width.val; + if (min.width.left.units === 'px' && min.width.val > 0) { + leftVal = leftVal * 100 / min.width.val; } - var rightVal = min$$1.width.right.value; + var rightVal = min.width.right.value; - if (min$$1.width.right.units === 'px' && min$$1.width.val > 0) { - rightVal = rightVal * 100 / min$$1.width.val; + if (min.width.right.units === 'px' && min.width.val > 0) { + rightVal = rightVal * 100 / min.width.val; } - var topVal = min$$1.height.top.value; + var topVal = min.height.top.value; - if (min$$1.height.top.units === 'px' && min$$1.height.val > 0) { - topVal = topVal * 100 / min$$1.height.val; + if (min.height.top.units === 'px' && min.height.val > 0) { + topVal = topVal * 100 / min.height.val; } - var bottomVal = min$$1.height.bottom.value; + var bottomVal = min.height.bottom.value; - if (min$$1.height.bottom.units === 'px' && min$$1.height.val > 0) { - bottomVal = bottomVal * 100 / min$$1.height.val; + if (min.height.bottom.units === 'px' && min.height.val > 0) { + bottomVal = bottomVal * 100 / min.height.val; } - var widthBiasDiffs = computeBiasValues(min$$1.width.val - bb.w, leftVal, rightVal); + var widthBiasDiffs = computeBiasValues(min.width.val - bb.w, leftVal, rightVal); var diffLeft = widthBiasDiffs.biasDiff; var diffRight = widthBiasDiffs.biasComplementDiff; - var heightBiasDiffs = computeBiasValues(min$$1.height.val - bb.h, topVal, bottomVal); + var heightBiasDiffs = computeBiasValues(min.height.val - bb.h, topVal, bottomVal); var diffTop = heightBiasDiffs.biasDiff; var diffBottom = heightBiasDiffs.biasComplementDiff; _p.autoPadding = computePaddingValues(bb.w, bb.h, parent.pstyle('padding'), parent.pstyle('padding-relative-to').value); - _p.autoWidth = Math.max(bb.w, min$$1.width.val); + _p.autoWidth = Math.max(bb.w, min.width.val); pos.x = (-diffLeft + bb.x1 + bb.x2 + diffRight) / 2; - _p.autoHeight = Math.max(bb.h, min$$1.height.val); + _p.autoHeight = Math.max(bb.h, min.height.val); pos.y = (-diffTop + bb.y1 + bb.y2 + diffBottom) / 2; } @@ -9443,6 +9464,10 @@ }; var updateBoundsFromBox = function updateBoundsFromBox(b, b2) { + if (b2 == null) { + return b; + } + return updateBounds(b, b2.x1, b2.y1, b2.x2, b2.y2); }; @@ -9520,8 +9545,8 @@ var borderWidth = ele.pstyle('text-border-width').pfValue; var halfBorderWidth = borderWidth / 2; var padding = ele.pstyle('text-background-padding').pfValue; - var lh = labelHeight + 2 * padding; - var lw = labelWidth + 2 * padding; + var lh = labelHeight; + var lw = labelWidth; var lw_2 = lw / 2; var lh_2 = lh / 2; var lx1, lx2, ly1, ly2; @@ -9568,10 +9593,10 @@ } // shift by margin and expand by outline and border - lx1 += marginX - Math.max(outlineWidth, halfBorderWidth); - lx2 += marginX + Math.max(outlineWidth, halfBorderWidth); - ly1 += marginY - Math.max(outlineWidth, halfBorderWidth); - ly2 += marginY + Math.max(outlineWidth, halfBorderWidth); // always store the unrotated label bounds separately + lx1 += marginX - Math.max(outlineWidth, halfBorderWidth) - padding; + lx2 += marginX + Math.max(outlineWidth, halfBorderWidth) + padding; + ly1 += marginY - Math.max(outlineWidth, halfBorderWidth) - padding; + ly2 += marginY + Math.max(outlineWidth, halfBorderWidth) + padding; // always store the unrotated label bounds separately var bbPrefix = prefix || 'main'; var bbs = _p.labelBounds; @@ -9650,18 +9675,25 @@ var headless = cy.headless(); var bounds = makeBoundingBox(); var _p = ele._private; - var display = styleEnabled ? ele.pstyle('display').value : 'element'; var isNode = ele.isNode(); var isEdge = ele.isEdge(); var ex1, ex2, ey1, ey2; // extrema of body / lines var x, y; // node pos - var displayed = display !== 'none'; var rstyle = _p.rstyle; - var manualExpansion = isNode && styleEnabled ? ele.pstyle('bounds-expansion').pfValue : 0; + var manualExpansion = isNode && styleEnabled ? ele.pstyle('bounds-expansion').pfValue : 0; // must use `display` prop only, as reading `compound.width()` causes recursion + // (other factors like width values will be considered later in this function anyway) + + var isDisplayed = function isDisplayed(ele) { + return ele.pstyle('display').value !== 'none'; + }; + + var displayed = !styleEnabled || isDisplayed(ele) // must take into account connected nodes b/c of implicit edge hiding on display:none node + && (!isEdge || isDisplayed(ele.source()) && isDisplayed(ele.target())); if (displayed) { + // displayed suffices, since we will find zero area eles anyway var overlayOpacity = 0; var overlayPadding = 0; @@ -9787,10 +9819,10 @@ if (styleEnabled && options.includeEdges && isEdge) { - updateBoundsFromArrow(bounds, ele, 'mid-source', options); - updateBoundsFromArrow(bounds, ele, 'mid-target', options); - updateBoundsFromArrow(bounds, ele, 'source', options); - updateBoundsFromArrow(bounds, ele, 'target', options); + updateBoundsFromArrow(bounds, ele, 'mid-source'); + updateBoundsFromArrow(bounds, ele, 'mid-target'); + updateBoundsFromArrow(bounds, ele, 'source'); + updateBoundsFromArrow(bounds, ele, 'target'); } // ghost //////// @@ -9838,11 +9870,11 @@ } if (styleEnabled && options.includeLabels) { - updateBoundsFromLabel(bounds, ele, null, options); + updateBoundsFromLabel(bounds, ele, null); if (isEdge) { - updateBoundsFromLabel(bounds, ele, 'source', options); - updateBoundsFromLabel(bounds, ele, 'target', options); + updateBoundsFromLabel(bounds, ele, 'source'); + updateBoundsFromLabel(bounds, ele, 'target'); } } // style enabled for labels @@ -9988,9 +10020,10 @@ var filledBbOpts = defaults(defBbOpts); elesfn$j.boundingBox = function (options) { - // the main usecase is ele.boundingBox() for a single element with no/def options + var bounds; // the main usecase is ele.boundingBox() for a single element with no/def options // specified s.t. the cache is used, so check for this case to make it faster by // avoiding the overhead of the rest of the function + if (this.length === 1 && this[0]._private.bbCache != null && (options === undefined || options.useCache === undefined || options.useCache === true)) { if (options === undefined) { options = defBbOpts; @@ -9998,32 +10031,32 @@ options = filledBbOpts(options); } - return cachedBoundingBoxImpl(this[0], options); - } - - var bounds = makeBoundingBox(); - options = options || defBbOpts; - var opts = filledBbOpts(options); - var eles = this; - var cy = eles.cy(); - var styleEnabled = cy.styleEnabled(); + bounds = cachedBoundingBoxImpl(this[0], options); + } else { + bounds = makeBoundingBox(); + options = options || defBbOpts; + var opts = filledBbOpts(options); + var eles = this; + var cy = eles.cy(); + var styleEnabled = cy.styleEnabled(); - if (styleEnabled) { - for (var i = 0; i < eles.length; i++) { - var ele = eles[i]; - var _p = ele._private; - var currPosKey = getBoundingBoxPosKey(ele); - var isPosKeySame = _p.bbCachePosKey === currPosKey; - var useCache = opts.useCache && isPosKeySame; - ele.recalculateRenderedStyle(useCache); + if (styleEnabled) { + for (var i = 0; i < eles.length; i++) { + var ele = eles[i]; + var _p = ele._private; + var currPosKey = getBoundingBoxPosKey(ele); + var isPosKeySame = _p.bbCachePosKey === currPosKey; + var useCache = opts.useCache && isPosKeySame; + ele.recalculateRenderedStyle(useCache); + } } - } - this.updateCompoundBounds(); + this.updateCompoundBounds(); - for (var _i = 0; _i < eles.length; _i++) { - var _ele = eles[_i]; - updateBoundsFromBox(bounds, cachedBoundingBoxImpl(_ele, opts)); + for (var _i = 0; _i < eles.length; _i++) { + var _ele = eles[_i]; + updateBoundsFromBox(bounds, cachedBoundingBoxImpl(_ele, opts)); + } } bounds.x1 = noninf(bounds.x1); @@ -10041,6 +10074,16 @@ _p.bbCache = null; _p.bbCacheShift.x = _p.bbCacheShift.y = 0; _p.bbCachePosKey = null; + _p.bodyBounds = null; + _p.overlayBounds = null; + _p.labelBounds.all = null; + _p.labelBounds.source = null; + _p.labelBounds.target = null; + _p.labelBounds.main = null; + _p.arrowBounds.source = null; + _p.arrowBounds.target = null; + _p.arrowBounds['mid-source'] = null; + _p.arrowBounds['mid-target'] = null; } this.emitAndNotify('bounds'); @@ -10067,7 +10110,7 @@ // - try to use for only things like discrete layouts where the node position would change anyway - elesfn$j.boundingBoxAt = function (fn$$1) { + elesfn$j.boundingBoxAt = function (fn) { var nodes = this.nodes(); var cy = this.cy(); var hasCompoundNodes = cy.hasCompoundNodes(); @@ -10078,16 +10121,16 @@ }); } - if (plainObject(fn$$1)) { - var obj = fn$$1; + if (plainObject(fn)) { + var obj = fn; - fn$$1 = function fn$$1() { + fn = function fn() { return obj; }; } var storeOldPos = function storeOldPos(node, i) { - return node._private.bbAtOldPos = fn$$1(node, i); + return node._private.bbAtOldPos = fn(node, i); }; var getOldPos = function getOldPos(node) { @@ -10095,7 +10138,7 @@ }; cy.startBatch(); - nodes.forEach(storeOldPos).silentPositions(fn$$1); + nodes.forEach(storeOldPos).silentPositions(fn); if (hasCompoundNodes) { this.updateCompoundBounds(true); // force update b/c we're inside a batch cycle @@ -10450,8 +10493,12 @@ context: null }; var defaultsKeys = Object.keys(defaults$8); + var emptyOpts = {}; + + function Emitter() { + var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : emptyOpts; + var context = arguments.length > 1 ? arguments[1] : undefined; - function Emitter(opts, context) { // micro-optimisation vs Object.assign() -- reduces Element instantiation time for (var i = 0; i < defaultsKeys.length; i++) { var key = defaultsKeys[i]; @@ -10542,10 +10589,10 @@ }; p.on = p.addListener = function (events, qualifier, callback, conf, confOverrides) { - forEachEvent(this, function (self, event$$1, type, namespace, qualifier, callback, conf) { + forEachEvent(this, function (self, event, type, namespace, qualifier, callback, conf) { if (fn(callback)) { self.listeners.push({ - event: event$$1, + event: event, // full event string callback: callback, // callback to run @@ -10580,10 +10627,10 @@ var _loop = function _loop(i) { var listener = listeners[i]; - forEachEvent(_this, function (self, event$$1, type, namespace, qualifier, callback + forEachEvent(_this, function (self, event, type, namespace, qualifier, callback /*, conf*/ ) { - if (listener.type === type && (!namespace || listener.namespace === namespace) && (!qualifier || self.qualifierCompare(listener.qualifier, qualifier)) && (!callback || listener.callback === callback)) { + if ((listener.type === type || events === '*') && (!namespace && listener.namespace !== '.*' || listener.namespace === namespace) && (!qualifier || self.qualifierCompare(listener.qualifier, qualifier)) && (!callback || listener.callback === callback)) { listeners.splice(i, 1); return false; } @@ -10597,6 +10644,10 @@ return this; }; + p.removeAllListeners = function () { + return this.removeListener('*'); + }; + p.emit = p.trigger = function (events, extraParams, manualCallback) { var listeners = this.listeners; var numListenersBeforeEmit = listeners.length; @@ -10743,6 +10794,14 @@ return this; }, + removeAllListeners: function removeAllListeners() { + for (var i = 0; i < this.length; i++) { + var ele = this[i]; + ele.emitter().removeAllListeners(); + } + + return this; + }, one: function one(events, selector, callback) { var argSel = argSelector(selector); @@ -10772,7 +10831,7 @@ return this; }, - emitAndNotify: function emitAndNotify(event$$1, extraParams) { + emitAndNotify: function emitAndNotify(event, extraParams) { // for internal use only if (this.length === 0) { return; @@ -10780,8 +10839,8 @@ // notify renderer - this.cy().notify(event$$1, this); - this.emit(event$$1, extraParams); + this.cy().notify(event, this); + this.emit(event, extraParams); return this; } }; @@ -10854,11 +10913,11 @@ var rMap = toRemove._private.map; for (var i = 0; i < this.length; i++) { - var element$$1 = this[i]; - var remove = rMap.has(element$$1.id()); + var element = this[i]; + var remove = rMap.has(element.id()); if (!remove) { - elements.push(element$$1); + elements.push(element); } } @@ -11117,12 +11176,12 @@ return arr; }, - reduce: function reduce(fn$$1, initialValue) { + reduce: function reduce(fn, initialValue) { var val = initialValue; var eles = this; for (var i = 0; i < eles.length; i++) { - val = fn$$1(val, eles[i], i, eles); + val = fn(val, eles[i], i, eles); } return val; @@ -11265,13 +11324,13 @@ }; var elesfn$o = { - forEach: function forEach(fn$$1, thisArg) { - if (fn(fn$$1)) { + forEach: function forEach(fn$1, thisArg) { + if (fn(fn$1)) { var N = this.length; for (var i = 0; i < N; i++) { var ele = this[i]; - var ret = thisArg ? fn$$1.apply(thisArg, [ele, i, this]) : fn$$1(ele, i, this); + var ret = thisArg ? fn$1.apply(thisArg, [ele, i, this]) : fn$1(ele, i, this); if (ret === false) { break; @@ -11283,16 +11342,16 @@ return this; }, toArray: function toArray() { - var array$$1 = []; + var array = []; for (var i = 0; i < this.length; i++) { - array$$1.push(this[i]); + array.push(this[i]); } - return array$$1; + return array; }, slice: function slice(start, end) { - var array$$1 = []; + var array = []; var thisSize = this.length; if (end == null) { @@ -11312,10 +11371,10 @@ } for (var i = start; i >= 0 && i < end && i < thisSize; i++) { - array$$1.push(this[i]); + array.push(this[i]); } - return this.spawn(array$$1); + return this.spawn(array); }, size: function size() { return this.length; @@ -11335,7 +11394,7 @@ nonempty: function nonempty() { return !this.empty(); }, - sort: function sort$$1(sortFn) { + sort: function sort(sortFn) { if (!fn(sortFn)) { return this; } @@ -11383,19 +11442,32 @@ // Calculates and returns node dimensions { x, y } based on options given layoutDimensions: function layoutDimensions(options) { options = getLayoutDimensionOptions(options); + var dims; - if (options.nodeDimensionsIncludeLabels) { + if (!this.takesUpSpace()) { + dims = { + w: 0, + h: 0 + }; + } else if (options.nodeDimensionsIncludeLabels) { var bbDim = this.boundingBox(); - return { + dims = { w: bbDim.w, h: bbDim.h }; } else { - return { + dims = { w: this.outerWidth(), h: this.outerHeight() }; + } // sanitise the dimensions for external layouts (avoid division by zero) + + + if (dims.w === 0 || dims.h === 0) { + dims.w = dims.h = 1; } + + return dims; }, // using standard layout options, apply position function (w/ or w/o animation) layoutPositions: function layoutPositions(layout, options, fn) { @@ -11559,7 +11631,7 @@ elesfn$p.createLayout = elesfn$p.makeLayout = elesfn$p.layout; - function styleCache(key, fn$$1, ele) { + function styleCache(key, fn, ele) { var _p = ele._private; var cache = _p.styleCache = _p.styleCache || []; var val; @@ -11567,23 +11639,23 @@ if ((val = cache[key]) != null) { return val; } else { - val = cache[key] = fn$$1(ele); + val = cache[key] = fn(ele); return val; } } - function cacheStyleFunction(key, fn$$1) { + function cacheStyleFunction(key, fn) { key = hashString(key); return function cachedStyleFunction(ele) { - return styleCache(key, fn$$1, ele); + return styleCache(key, fn, ele); }; } - function cachePrototypeStyleFunction(key, fn$$1) { + function cachePrototypeStyleFunction(key, fn) { key = hashString(key); var selfFn = function selfFn(ele) { - return fn$$1.call(ele); + return fn.call(ele); }; return function cachedPrototypeStyleFunction() { @@ -11643,7 +11715,7 @@ } var hasCompounds = cy.hasCompoundNodes(); - var style$$1 = cy.style(); + var style = cy.style(); var updatedEles = this; notifyRenderer = notifyRenderer || notifyRenderer === undefined ? true : false; @@ -11652,7 +11724,7 @@ updatedEles = this.spawnSelf().merge(this.descendants()).merge(this.parents()); } - var changedEles = style$$1.apply(updatedEles); + var changedEles = style.apply(updatedEles); if (notifyRenderer) { changedEles.emitAndNotify('style'); // let renderer know we changed style @@ -11723,7 +11795,7 @@ } }, // read the calculated css style of the element or override the style (via a bypass) - style: function style$$1(name, value) { + style: function style(name, value) { var cy = this.cy(); if (!cy.styleEnabled()) { @@ -11731,12 +11803,12 @@ } var updateTransitions = false; - var style$$1 = cy.style(); + var style = cy.style(); if (plainObject(name)) { // then extend the bypass var props = name; - style$$1.applyBypass(this, props, updateTransitions); + style.applyBypass(this, props, updateTransitions); this.emitAndNotify('style'); // let the renderer know we've updated style } else if (string(name)) { if (value === undefined) { @@ -11744,21 +11816,21 @@ var ele = this[0]; if (ele) { - return style$$1.getStylePropertyValue(ele, name); + return style.getStylePropertyValue(ele, name); } else { // empty collection => can't get any value return; } } else { // then set the bypass with the property value - style$$1.applyBypass(this, name, value, updateTransitions); + style.applyBypass(this, name, value, updateTransitions); this.emitAndNotify('style'); // let the renderer know we've updated style } } else if (name === undefined) { var _ele = this[0]; if (_ele) { - return style$$1.getRawStyle(_ele); + return style.getRawStyle(_ele); } else { // empty collection => can't get any value return; @@ -11775,20 +11847,20 @@ } var updateTransitions = false; - var style$$1 = cy.style(); + var style = cy.style(); var eles = this; if (names === undefined) { for (var i = 0; i < eles.length; i++) { var ele = eles[i]; - style$$1.removeAllBypasses(ele, updateTransitions); + style.removeAllBypasses(ele, updateTransitions); } } else { names = names.split(/\s+/); for (var _i = 0; _i < eles.length; _i++) { var _ele2 = eles[_i]; - style$$1.removeBypasses(_ele2, names, updateTransitions); + style.removeBypasses(_ele2, names, updateTransitions); } } @@ -11958,6 +12030,10 @@ }; elesfn$q.isBundledBezier = cachePrototypeStyleFunction('isBundledBezier', function () { + if (!this.cy().styleEnabled()) { + return false; + } + return !this.removed() && this.pstyle('curve-style').value === 'bezier' && this.takesUpSpace(); }); elesfn$q.bypass = elesfn$q.css = elesfn$q.style; @@ -12070,7 +12146,7 @@ defineSwitchSet({ field: 'grabbable', overrideField: function overrideField(ele) { - return ele.cy().autoungrabify() ? false : undefined; + return ele.cy().autoungrabify() || ele.pannable() ? false : undefined; }, on: 'grabify', off: 'ungrabify' @@ -12107,6 +12183,11 @@ on: 'activate', off: 'unactivate' }); + defineSwitchSet({ + field: 'pannable', + on: 'panify', + off: 'unpanify' + }); elesfn$r.inactive = function () { var ele = this[0]; @@ -12459,10 +12540,10 @@ }); function defineParallelEdgesFunction(params) { - var defaults$$1 = { + var defaults = { codirected: false }; - params = extend({}, defaults$$1, params); + params = extend({}, defaults, params); return function parallelEdgesImpl(selector) { // micro-optimised for renderer var elements = []; @@ -12560,7 +12641,7 @@ elesfn$s.componentsOf = elesfn$s.components; var idFactory = { - generate: function generate(cy, element$$1, tryThisId) { + generate: function generate(cy, element, tryThisId) { var id = tryThisId != null ? tryThisId : uuid(); while (cy.hasElementWithId(id)) { @@ -12614,20 +12695,20 @@ this.length = 0; for (var _i = 0, _l = elements.length; _i < _l; _i++) { - var element$$1 = elements[_i]; + var element$1 = elements[_i][0]; // [0] in case elements is an array of collections, rather than array of elements - if (element$$1 == null) { + if (element$1 == null) { continue; } - var id = element$$1._private.data.id; + var id = element$1._private.data.id; if (options == null || options.unique && !map.has(id)) { map.set(id, { index: this.length, - ele: element$$1 + ele: element$1 }); - this[this.length] = element$$1; + this[this.length] = element$1; this.length++; } } @@ -12695,10 +12776,14 @@ }; elesfn$t.hasElementWithId = function (id) { + id = '' + id; // id must be string + return this._private.map.has(id); }; elesfn$t.getElementById = function (id) { + id = '' + id; // id must be string + var cy = this._private.cy; var entry = this._private.map.get(id); @@ -12721,6 +12806,8 @@ }; elesfn$t.indexOfId = function (id) { + id = '' + id; // id must be string + return this._private.map.get(id).index; }; @@ -12755,13 +12842,15 @@ var src = obj.data.source; var tgt = obj.data.target; - if (src != null && src !== _data2.source) { - spec.source = src; + if (src != null && src != _data2.source) { + spec.source = '' + src; // id must be string + move = true; } - if (tgt != null && tgt !== _data2.target) { - spec.target = tgt; + if (tgt != null && tgt != _data2.target) { + spec.target = '' + tgt; // id must be string + move = true; } @@ -12772,12 +12861,16 @@ // parent is immutable via data() var parent = obj.data.parent; - if ((parent != null || _data2.parent != null) && parent !== _data2.parent) { + if ((parent != null || _data2.parent != null) && parent != _data2.parent) { if (parent === undefined) { // can't set undefined imperatively, so use null parent = null; } + if (parent != null) { + parent = '' + parent; // id must be string + } + ele = ele.move({ parent: parent }); @@ -12807,6 +12900,7 @@ checkSwitch('selectable', 'selectify', 'unselectify'); checkSwitch('locked', 'lock', 'unlock'); checkSwitch('grabbable', 'grabify', 'ungrabify'); + checkSwitch('pannable', 'panify', 'unpanify'); if (obj.classes != null) { ele.classes(obj.classes); @@ -12825,6 +12919,7 @@ selectable: p.selectable, locked: p.locked, grabbable: p.grabbable, + pannable: p.pannable, classes: null }; json.classes = ''; @@ -12855,9 +12950,9 @@ for (var i = 0; i < this.length; i++) { var ele = this[i]; var json = ele.json(); - var clone$$1 = new Element(cy, json, false); // NB no restore + var clone = new Element(cy, json, false); // NB no restore - elesArr.push(clone$$1); + elesArr.push(clone); } return new Collection(cy, elesArr); @@ -12976,11 +13071,15 @@ var src = cy.getElementById(_data3.source); - var tgt = cy.getElementById(_data3.target); + var tgt = cy.getElementById(_data3.target); // only one edge in node if loop - src._private.edges.push(edge); + if (src.same(tgt)) { + src._private.edges.push(edge); + } else { + src._private.edges.push(edge); - tgt._private.edges.push(edge); + tgt._private.edges.push(edge); + } edge._private.source = src; edge._private.target = tgt; @@ -13272,9 +13371,14 @@ var notifyRenderer = false; var modifyPool = false; + var toString = function toString(id) { + return id == null ? id : '' + id; + }; // id must be string + + if (struct.source !== undefined || struct.target !== undefined) { - var srcId = struct.source; - var tgtId = struct.target; + var srcId = toString(struct.source); + var tgtId = toString(struct.target); var srcExists = srcId != null && cy.hasElementWithId(srcId); var tgtExists = tgtId != null && cy.hasElementWithId(tgtId); @@ -13306,7 +13410,7 @@ } } else if (struct.parent !== undefined) { // move node to new parent - var parentId = struct.parent; + var parentId = toString(struct.parent); var parentExists = parentId === null || cy.hasElementWithId(parentId); if (parentExists) { @@ -13395,13 +13499,13 @@ return elements; }, - remove: function remove(collection$$1) { - if (elementOrCollection(collection$$1)) ; else if (string(collection$$1)) { - var selector = collection$$1; - collection$$1 = this.$(selector); + remove: function remove(collection) { + if (elementOrCollection(collection)) ; else if (string(collection)) { + var selector = collection; + collection = this.$(selector); } - return collection$$1.remove(); + return collection.remove(); } }; @@ -13801,7 +13905,7 @@ var pEasing = ani_p.easing; var startTime = ani_p.startTime; var cy = isCore ? self : self.cy(); - var style$$1 = cy.style(); + var style = cy.style(); if (!ani_p.easingImpl) { if (pEasing == null) { @@ -13812,7 +13916,7 @@ var easingVals; if (string(pEasing)) { - var easingProp = style$$1.parse('transition-timing-function', pEasing); + var easingProp = style.parse('transition-timing-function', pEasing); easingVals = easingProp.value; } else { // then assume preparsed array @@ -13906,7 +14010,7 @@ if (animatingZoom) { if (valid(startZoom, endZoom)) { - _p.zoom = ease(startZoom, endZoom, percent, easing); + _p.zoom = bound(_p.minZoom, ease(startZoom, endZoom, percent, easing), _p.maxZoom); } self.emit('zoom'); @@ -13924,9 +14028,9 @@ var _name = prop.name; var end = prop; var start = ani_p.startStyle[_name]; - var propSpec = style$$1.properties[start.name]; + var propSpec = style.properties[start.name]; var easedVal = ease(start, end, percent, easing, propSpec); - style$$1.overrideBypass(self, _name, easedVal); + style.overrideBypass(self, _name, easedVal); } // for props @@ -14021,7 +14125,7 @@ } if (!ani_p.started) { - startAnimation(ele, ani, now, isCore); + startAnimation(ele, ani, now); } step(ele, ani, now, isCore); @@ -14193,6 +14297,10 @@ this.emitter().removeListener(events, argSelector$1(selector), callback); return this; }, + removeAllListeners: function removeAllListeners() { + this.emitter().removeAllListeners(); + return this; + }, one: function one(events, selector, callback) { this.emitter().one(events, argSelector$1(selector), callback); return this; @@ -14205,9 +14313,9 @@ this.emitter().emit(events, extraParams); return this; }, - emitAndNotify: function emitAndNotify(event$$1, eles) { - this.emit(event$$1); - this.notify(event$$1, eles); + emitAndNotify: function emitAndNotify(event, eles) { + this.emit(event); + this.notify(event, eles); return this; } }; @@ -14289,7 +14397,7 @@ var renderer = this.renderer(); // exit if destroy() called on core or renderer in between frames #1499 #1528 - if (this.isDestroyed() || !renderer) { + if (this.destroyed() || !renderer) { return; } @@ -14465,7 +14573,7 @@ // - empty collection on no args // - collection of elements in the graph on selector arg // - guarantee a returned collection when elements or collection specified - collection: function collection$$1(eles, opts) { + collection: function collection(eles, opts) { if (string(eles)) { return this.$(eles); } else if (elementOrCollection(eles)) { @@ -14676,7 +14784,7 @@ return cxtStyles[cxtKey]; } - var style$$1 = { + var style = { _private: { key: cxtKey } @@ -14692,12 +14800,12 @@ for (var j = 0; j < cxt.properties.length; j++) { var prop = cxt.properties[j]; - style$$1[prop.name] = prop; + style[prop.name] = prop; } } - cxtStyles[cxtKey] = style$$1; - return style$$1; + cxtStyles[cxtKey] = style; + return style; }; styfn.applyContextStyle = function (cxtMeta, cxtStyle, ele) { @@ -14736,6 +14844,7 @@ if (cxtProp.mapped === types.fn // context prop is function mapper + && eleProp != null // some props can be null even by default (e.g. a prop that overrides another one) && eleProp.mapping != null // ele prop is a concrete value from from a mapper && eleProp.mapping.value === cxtProp.value // the current prop on the ele is a flat prop value for the function mapper ) { @@ -14795,6 +14904,12 @@ var updateGrKey = function updateGrKey(val, grKey) { return _p.styleKeys[grKey] = hashInt(val, _p.styleKeys[grKey]); + }; + + var updateGrKeyWStr = function updateGrKeyWStr(strVal, grKey) { + for (var j = 0; j < strVal.length; j++) { + updateGrKey(strVal.charCodeAt(j), grKey); + } }; // - hashing works on 32 bit ints b/c we use bitwise ops // - small numbers get cut off (e.g. 0.123 is seen as 0 by the hashing function) // - raise up small numbers so more significant digits are seen by hashing @@ -14816,12 +14931,25 @@ var propInfo = this.properties[name]; var type = propInfo.type; - var _grKey = propInfo.groupKey; // numbers are cheaper to hash than strings + var _grKey = propInfo.groupKey; + var normalizedNumberVal = void 0; + + if (propInfo.hashOverride != null) { + normalizedNumberVal = propInfo.hashOverride(ele, parsedProp); + } else if (parsedProp.pfValue != null) { + normalizedNumberVal = parsedProp.pfValue; + } // might not be a number if it allows enums + + + var numberVal = propInfo.enums == null ? parsedProp.value : null; + var haveNormNum = normalizedNumberVal != null; + var haveUnitedNum = numberVal != null; + var haveNum = haveNormNum || haveUnitedNum; + var units = parsedProp.units; // numbers are cheaper to hash than strings // 1 hash op vs n hash ops (for length n string) - if (type.number) { - // use pfValue if available (e.g. normalised units) - var v = parsedProp.pfValue != null ? parsedProp.pfValue : parsedProp.value; + if (type.number && haveNum) { + var v = haveNormNum ? normalizedNumberVal : numberVal; if (type.multiple) { for (var _i2 = 0; _i2 < v.length; _i2++) { @@ -14830,12 +14958,12 @@ } else { updateGrKey(cleanNum(v), _grKey); } - } else { - var strVal = parsedProp.strValue; - for (var j = 0; j < strVal.length; j++) { - updateGrKey(strVal.charCodeAt(j), _grKey); + if (!haveNormNum && units != null) { + updateGrKeyWStr(units, _grKey); } + } else { + updateGrKeyWStr(parsedProp.strValue, _grKey); } } // overall style key // @@ -14912,12 +15040,12 @@ styfn.applyParsedProperty = function (ele, parsedProp) { var self = this; var prop = parsedProp; - var style$$1 = ele._private.style; + var style = ele._private.style; var flatProp; var types = self.types; var type = self.properties[prop.name].type; var propIsBypass = prop.bypass; - var origProp = style$$1[prop.name]; + var origProp = style[prop.name]; var origPropIsBypass = origProp && origProp.bypass; var _p = ele._private; var flatPropMapping = 'mapping'; @@ -14947,7 +15075,7 @@ if (prop.delete) { // delete the property and use the default value on falsey value - style$$1[prop.name] = undefined; + style[prop.name] = undefined; checkTriggers(); return true; } @@ -14976,7 +15104,7 @@ } else if (origProp.bypass) { // then replace the bypass property with the original // because the bypassed property was already applied (and therefore parsed), we can just replace it (no reapplying necessary) - style$$1[prop.name] = origProp.bypassed; + style[prop.name] = origProp.bypassed; checkTriggers(); return true; } else { @@ -15101,8 +15229,8 @@ case types.fn: { - var fn$$1 = prop.value; - var fnRetVal = prop.fnValue != null ? prop.fnValue : fn$$1(ele); // check for cached value before calling function + var fn = prop.value; + var fnRetVal = prop.fnValue != null ? prop.fnValue : fn(ele); // check for cached value before calling function prop.prevFnValue = fnRetVal; @@ -15144,7 +15272,7 @@ prop.bypassed = origProp; } - style$$1[prop.name] = prop; // and set + style[prop.name] = prop; // and set } else { // prop is not bypass if (origPropIsBypass) { @@ -15152,7 +15280,7 @@ origProp.bypassed = prop; } else { // then just replace the old prop with the new one - style$$1[prop.name] = prop; + style[prop.name] = prop; } } @@ -15170,18 +15298,18 @@ if (!keepBypasses) { ele._private.style = {}; } else { - var style$$1 = ele._private.style; - var propNames = Object.keys(style$$1); + var style = ele._private.style; + var propNames = Object.keys(style); for (var j = 0; j < propNames.length; j++) { var propName = propNames[j]; - var eleProp = style$$1[propName]; + var eleProp = style[propName]; if (eleProp != null) { if (eleProp.bypass) { eleProp.bypassed = null; } else { - style$$1[propName] = null; + style[propName] = null; } } } @@ -15205,7 +15333,7 @@ var delay = ele.pstyle('transition-delay').pfValue; if (props.length > 0 && duration > 0) { - var style$$1 = {}; // build up the style to animate towards + var style = {}; // build up the style to animate towards var anyPrev = false; @@ -15245,7 +15373,7 @@ if (diff) { - style$$1[prop] = toProp.strValue; // to val + style[prop] = toProp.strValue; // to val this.applyBypass(ele, prop, initVal); // from val @@ -15268,7 +15396,7 @@ } }).then(function () { return ele.animation({ - style: style$$1, + style: style, duration: duration, easing: ele.pstyle('transition-timing-function').value, queue: false @@ -15661,15 +15789,15 @@ styfn$3.getPropsList = function (propsObj) { var self = this; var rstyle = []; - var style$$1 = propsObj; + var style = propsObj; var props = self.properties; - if (style$$1) { - var names = Object.keys(style$$1); + if (style) { + var names = Object.keys(style); for (var i = 0; i < names.length; i++) { var name = names[i]; - var val = style$$1[name]; + var val = style[name]; var prop = props[name] || props[camel2dash(name)]; var styleProp = this.parse(prop.name, val); @@ -15901,19 +16029,19 @@ var styfn$6 = {}; (function () { - var number$$1 = number$1; - var rgba$$1 = rgbaNoBackRefs; - var hsla$$1 = hslaNoBackRefs; - var hex3$$1 = hex3; - var hex6$$1 = hex6; + var number = number$1; + var rgba = rgbaNoBackRefs; + var hsla = hslaNoBackRefs; + var hex3$1 = hex3; + var hex6$1 = hex6; var data = function data(prefix) { return '^' + prefix + '\\s*\\(\\s*([\\w\\.]+)\\s*\\)$'; }; var mapData = function mapData(prefix) { - var mapArg = number$$1 + '|\\w+|' + rgba$$1 + '|' + hsla$$1 + '|' + hex3$$1 + '|' + hex6$$1; - return '^' + prefix + '\\s*\\(([\\w\\.]+)\\s*\\,\\s*(' + number$$1 + ')\\s*\\,\\s*(' + number$$1 + ')\\s*,\\s*(' + mapArg + ')\\s*\\,\\s*(' + mapArg + ')\\)$'; + var mapArg = number + '|\\w+|' + rgba + '|' + hsla + '|' + hex3$1 + '|' + hex6$1; + return '^' + prefix + '\\s*\\(([\\w\\.]+)\\s*\\,\\s*(' + number + ')\\s*\\,\\s*(' + number + ')\\s*,\\s*(' + mapArg + ')\\s*\\,\\s*(' + mapArg + ')\\)$'; }; var urlRegexes = ['^url\\s*\\(\\s*[\'"]?(.+?)[\'"]?\\s*\\)$', '^(none)$', '^(.+)$']; // each visual style property has a type and needs to be validated according to it @@ -16041,7 +16169,8 @@ multiple: true }, bgClip: { - enums: ['none', 'node'] + enums: ['none', 'node'], + multiple: true }, color: { color: true @@ -16086,6 +16215,9 @@ textWrap: { enums: ['none', 'wrap', 'ellipsis'] }, + textOverflowWrap: { + enums: ['whitespace', 'anywhere'] + }, textBackgroundShape: { enums: ['rectangle', 'roundrectangle', 'round-rectangle'] }, @@ -16119,6 +16251,9 @@ halign: { enums: ['left', 'center', 'right'] }, + justification: { + enums: ['left', 'center', 'right', 'auto'] + }, text: { string: true }, @@ -16207,7 +16342,7 @@ } }, easing: { - regexes: ['^(spring)\\s*\\(\\s*(' + number$$1 + ')\\s*,\\s*(' + number$$1 + ')\\s*\\)$', '^(cubic-bezier)\\s*\\(\\s*(' + number$$1 + ')\\s*,\\s*(' + number$$1 + ')\\s*,\\s*(' + number$$1 + ')\\s*,\\s*(' + number$$1 + ')\\s*\\)$'], + regexes: ['^(spring)\\s*\\(\\s*(' + number + ')\\s*,\\s*(' + number + ')\\s*\\)$', '^(cubic-bezier)\\s*\\(\\s*(' + number + ')\\s*,\\s*(' + number + ')\\s*,\\s*(' + number + ')\\s*,\\s*(' + number + ')\\s*\\)$'], enums: ['linear', 'ease', 'ease-in', 'ease-out', 'ease-in-out', 'ease-in-sine', 'ease-out-sine', 'ease-in-out-sine', 'ease-in-quad', 'ease-out-quad', 'ease-in-out-quad', 'ease-in-cubic', 'ease-out-cubic', 'ease-in-out-cubic', 'ease-in-quart', 'ease-out-quart', 'ease-in-out-quart', 'ease-in-quint', 'ease-out-quint', 'ease-in-out-quint', 'ease-in-expo', 'ease-out-expo', 'ease-in-out-expo', 'ease-in-circ', 'ease-out-circ', 'ease-in-out-circ'] }, gradientDirection: { @@ -16320,6 +16455,10 @@ name: 'text-wrap', type: t.textWrap, triggersBounds: diff.any + }, { + name: 'text-overflow-wrap', + type: t.textOverflowWrap, + triggersBounds: diff.any }, { name: 'text-max-width', type: t.size, @@ -16328,6 +16467,10 @@ name: 'text-outline-width', type: t.size, triggersBounds: diff.any + }, { + name: 'line-height', + type: t.positiveNumber, + triggersBounds: diff.any }]; var commonLabel = [{ name: 'text-valign', @@ -16374,6 +16517,9 @@ name: 'text-background-shape', type: t.textBackgroundShape, triggersBounds: diff.any + }, { + name: 'text-justification', + type: t.justification }]; var behavior = [{ name: 'events', @@ -16440,14 +16586,25 @@ name: 'transition-timing-function', type: t.easing }]; + + var nodeSizeHashOverride = function nodeSizeHashOverride(ele, parsedProp) { + if (parsedProp.value === 'label') { + return -ele.poolIndex(); // no hash key hits is using label size (hitrate for perf probably low anyway) + } else { + return parsedProp.pfValue; + } + }; + var nodeBody = [{ name: 'height', type: t.nodeSize, - triggersBounds: diff.any + triggersBounds: diff.any, + hashOverride: nodeSizeHashOverride }, { name: 'width', type: t.nodeSize, - triggersBounds: diff.any + triggersBounds: diff.any, + hashOverride: nodeSizeHashOverride }, { name: 'shape', type: t.nodeShape, @@ -16694,7 +16851,7 @@ name: 'ghost-opacity', type: t.zeroOneNumber }]; - var core$$1 = [{ + var core = [{ name: 'selection-box-color', type: t.color }, { @@ -16751,7 +16908,8 @@ var arrowPrefixes = styfn$6.arrowPrefixes = ['source', 'mid-source', 'target', 'mid-target']; [{ name: 'arrow-shape', - type: t.arrowShape + type: t.arrowShape, + triggersBounds: diff.any }, { name: 'arrow-color', type: t.color @@ -16761,14 +16919,16 @@ }].forEach(function (prop) { arrowPrefixes.forEach(function (prefix) { var name = prefix + '-' + prop.name; - var type = prop.type; + var type = prop.type, + triggersBounds = prop.triggersBounds; edgeArrow.push({ name: name, - type: type + type: type, + triggersBounds: triggersBounds }); }); }, {}); - var props = styfn$6.properties = [].concat(behavior, transition, visibility, overlay, ghost, commonLabel, labelDimensions, mainLabel, sourceLabel, targetLabel, nodeBody, nodeBorder, backgroundImage, pie, compound, edgeLine, edgeArrow, core$$1); + var props = styfn$6.properties = [].concat(behavior, transition, visibility, overlay, ghost, commonLabel, labelDimensions, mainLabel, sourceLabel, targetLabel, nodeBody, nodeBorder, backgroundImage, pie, compound, edgeLine, edgeArrow, core); var propGroups = styfn$6.propertyGroups = { // common to all eles behavior: behavior, @@ -16791,7 +16951,7 @@ // edge props edgeLine: edgeLine, edgeArrow: edgeArrow, - core: core$$1 + core: core }; var propGroupNames = styfn$6.propertyGroupNames = {}; var propGroupKeys = styfn$6.propertyGroupKeys = Object.keys(propGroups); @@ -16881,6 +17041,8 @@ 'text-events': 'no', 'text-valign': 'top', 'text-halign': 'center', + 'text-justification': 'auto', + 'line-height': 1, 'color': '#000', 'text-outline-color': '#000', 'text-outline-width': 0, @@ -16889,6 +17051,7 @@ 'text-decoration': 'none', 'text-transform': 'none', 'text-wrap': 'none', + 'text-overflow-wrap': 'whitespace', 'text-max-width': 9999, 'text-background-color': '#000', 'text-background-opacity': 0, @@ -17508,9 +17671,9 @@ var regexes = type.regexes ? type.regexes : [type.regex]; for (var _i3 = 0; _i3 < regexes.length; _i3++) { - var regex$$1 = new RegExp(regexes[_i3]); // make a regex from the type string + var regex = new RegExp(regexes[_i3]); // make a regex from the type string - var m = regex$$1.exec(value); + var m = regex.exec(value); if (m) { // regex matches @@ -17660,13 +17823,13 @@ return this; // chaining }; - styfn$8.append = function (style$$1) { - if (stylesheet(style$$1)) { - style$$1.appendToStyle(this); - } else if (array(style$$1)) { - this.appendFromJson(style$$1); - } else if (string(style$$1)) { - this.appendFromString(style$$1); + styfn$8.append = function (style) { + if (stylesheet(style)) { + style.appendToStyle(this); + } else if (array(style)) { + this.appendFromJson(style); + } else if (string(style)) { + this.appendFromString(style); } // you probably wouldn't want to append a Style, since you'd duplicate the default parts @@ -17675,13 +17838,13 @@ Style.fromJson = function (cy, json) { - var style$$1 = new Style(cy); - style$$1.fromJson(json); - return style$$1; + var style = new Style(cy); + style.fromJson(json); + return style; }; - Style.fromString = function (cy, string$$1) { - return new Style(cy).fromString(string$$1); + Style.fromString = function (cy, string) { + return new Style(cy).fromString(string); }; [styfn, styfn$1, styfn$2, styfn$3, styfn$4, styfn$5, styfn$6, styfn$7].forEach(function (props) { @@ -17694,7 +17857,7 @@ Style.propertyGroupKeys = styfn$8.propertyGroupKeys; var corefn$7 = { - style: function style$$1(newStyle) { + style: function style(newStyle) { if (newStyle) { var s = this.setStyle(newStyle); s.update(); @@ -17702,15 +17865,15 @@ return this._private.style; }, - setStyle: function setStyle(style$$1) { + setStyle: function setStyle(style) { var _p = this._private; - if (stylesheet(style$$1)) { - _p.style = style$$1.generateStyle(this); - } else if (array(style$$1)) { - _p.style = Style.fromJson(this, style$$1); - } else if (string(style$$1)) { - _p.style = Style.fromString(this, style$$1); + if (stylesheet(style)) { + _p.style = style.generateStyle(this); + } else if (array(style)) { + _p.style = Style.fromJson(this, style); + } else if (string(style)) { + _p.style = Style.fromString(this, style); } else { _p.style = Style(this); } @@ -17721,27 +17884,27 @@ var defaultSelectionType = 'single'; var corefn$8 = { - autolock: function autolock(bool$$1) { - if (bool$$1 !== undefined) { - this._private.autolock = bool$$1 ? true : false; + autolock: function autolock(bool) { + if (bool !== undefined) { + this._private.autolock = bool ? true : false; } else { return this._private.autolock; } return this; // chaining }, - autoungrabify: function autoungrabify(bool$$1) { - if (bool$$1 !== undefined) { - this._private.autoungrabify = bool$$1 ? true : false; + autoungrabify: function autoungrabify(bool) { + if (bool !== undefined) { + this._private.autoungrabify = bool ? true : false; } else { return this._private.autoungrabify; } return this; // chaining }, - autounselectify: function autounselectify(bool$$1) { - if (bool$$1 !== undefined) { - this._private.autounselectify = bool$$1 ? true : false; + autounselectify: function autounselectify(bool) { + if (bool !== undefined) { + this._private.autounselectify = bool ? true : false; } else { return this._private.autounselectify; } @@ -17765,45 +17928,45 @@ return this; }, - panningEnabled: function panningEnabled(bool$$1) { - if (bool$$1 !== undefined) { - this._private.panningEnabled = bool$$1 ? true : false; + panningEnabled: function panningEnabled(bool) { + if (bool !== undefined) { + this._private.panningEnabled = bool ? true : false; } else { return this._private.panningEnabled; } return this; // chaining }, - userPanningEnabled: function userPanningEnabled(bool$$1) { - if (bool$$1 !== undefined) { - this._private.userPanningEnabled = bool$$1 ? true : false; + userPanningEnabled: function userPanningEnabled(bool) { + if (bool !== undefined) { + this._private.userPanningEnabled = bool ? true : false; } else { return this._private.userPanningEnabled; } return this; // chaining }, - zoomingEnabled: function zoomingEnabled(bool$$1) { - if (bool$$1 !== undefined) { - this._private.zoomingEnabled = bool$$1 ? true : false; + zoomingEnabled: function zoomingEnabled(bool) { + if (bool !== undefined) { + this._private.zoomingEnabled = bool ? true : false; } else { return this._private.zoomingEnabled; } return this; // chaining }, - userZoomingEnabled: function userZoomingEnabled(bool$$1) { - if (bool$$1 !== undefined) { - this._private.userZoomingEnabled = bool$$1 ? true : false; + userZoomingEnabled: function userZoomingEnabled(bool) { + if (bool !== undefined) { + this._private.userZoomingEnabled = bool ? true : false; } else { return this._private.userZoomingEnabled; } return this; // chaining }, - boxSelectionEnabled: function boxSelectionEnabled(bool$$1) { - if (bool$$1 !== undefined) { - this._private.boxSelectionEnabled = bool$$1 ? true : false; + boxSelectionEnabled: function boxSelectionEnabled(bool) { + if (bool !== undefined) { + this._private.boxSelectionEnabled = bool ? true : false; } else { return this._private.boxSelectionEnabled; } @@ -17995,22 +18158,22 @@ return; }, - zoomRange: function zoomRange(min$$1, max$$1) { + zoomRange: function zoomRange(min, max) { var _p = this._private; - if (max$$1 == null) { - var opts = min$$1; - min$$1 = opts.min; - max$$1 = opts.max; + if (max == null) { + var opts = min; + min = opts.min; + max = opts.max; } - if (number(min$$1) && number(max$$1) && min$$1 <= max$$1) { - _p.minZoom = min$$1; - _p.maxZoom = max$$1; - } else if (number(min$$1) && max$$1 === undefined && min$$1 <= _p.maxZoom) { - _p.minZoom = min$$1; - } else if (number(max$$1) && min$$1 === undefined && max$$1 >= _p.minZoom) { - _p.maxZoom = max$$1; + if (number(min) && number(max) && min <= max) { + _p.minZoom = min; + _p.maxZoom = max; + } else if (number(min) && max === undefined && min <= _p.maxZoom) { + _p.minZoom = min; + } else if (number(max) && min === undefined && max >= _p.minZoom) { + _p.maxZoom = max; } return this; @@ -18246,10 +18409,10 @@ var _p = this._private; var container = _p.container; return _p.sizeCache = _p.sizeCache || (container ? function () { - var style$$1 = window$1.getComputedStyle(container); + var style = window$1.getComputedStyle(container); var val = function val(name) { - return parseFloat(style$$1.getPropertyValue(name)); + return parseFloat(style.getPropertyValue(name)); }; return { @@ -18301,6 +18464,44 @@ corefn$8.autolockNodes = corefn$8.autolock; corefn$8.autoungrabifyNodes = corefn$8.autoungrabify; + var fn$6 = { + data: define$3.data({ + field: 'data', + bindingEvent: 'data', + allowBinding: true, + allowSetting: true, + settingEvent: 'data', + settingTriggersEvent: true, + triggerFnName: 'trigger', + allowGetting: true + }), + removeData: define$3.removeData({ + field: 'data', + event: 'data', + triggerFnName: 'trigger', + triggerEvent: true + }), + scratch: define$3.data({ + field: 'scratch', + bindingEvent: 'scratch', + allowBinding: true, + allowSetting: true, + settingEvent: 'scratch', + settingTriggersEvent: true, + triggerFnName: 'trigger', + allowGetting: true + }), + removeScratch: define$3.removeData({ + field: 'scratch', + event: 'scratch', + triggerFnName: 'trigger', + triggerEvent: true + }) + }; // aliases + + fn$6.attr = fn$6.data; + fn$6.removeAttr = fn$6.removeData; + var Core = function Core(opts) { var cy = this; opts = extend({}, opts); @@ -18360,6 +18561,8 @@ // list of listeners aniEles: new Collection(this), // elements being animated + data: {}, + // data for the core scratch: {}, // scratch object for core layout: null, @@ -18471,8 +18674,8 @@ for (var i = 0; i < readies.length; i++) { - var fn$$1 = readies[i]; - cy.on('ready', fn$$1); + var fn$1 = readies[i]; + cy.on('ready', fn$1); } if (reg) { @@ -18494,21 +18697,21 @@ isReady: function isReady() { return this._private.ready; }, - isDestroyed: function isDestroyed() { + destroyed: function destroyed() { return this._private.destroyed; }, - ready: function ready(fn$$1) { + ready: function ready(fn) { if (this.isReady()) { - this.emitter().emit('ready', [], fn$$1); // just calls fn as though triggered via ready event + this.emitter().emit('ready', [], fn); // just calls fn as though triggered via ready event } else { - this.on('ready', fn$$1); + this.on('ready', fn); } return this; }, destroy: function destroy() { var cy = this; - if (cy.isDestroyed()) return; + if (cy.destroyed()) return; cy.stopAnimationLoop(); cy.destroyRenderer(); this.emit('destroy'); @@ -18543,7 +18746,7 @@ container: function container() { return this._private.container || null; }, - mount: function mount(container, rendererOptions) { + mount: function mount(container) { if (container == null) { return; } @@ -18551,10 +18754,6 @@ var cy = this; var _p = cy._private; var options = _p.options; - var rOpts = rendererOptions ? rendererOptions : { - name: 'canvas' - }; - options.renderer = rOpts; if (!htmlElement(container) && htmlElement(container[0])) { container = container[0]; @@ -18564,7 +18763,11 @@ cy.destroyRenderer(); _p.container = container; _p.styleEnabled = true; - cy.initRenderer(rOpts); + cy.invalidateSize(); + cy.initRenderer(extend({}, options, options.renderer, { + // allow custom renderer name to be re-used, otherwise use canvas + name: options.renderer.name === 'null' ? 'canvas' : options.renderer.name + })); cy.startAnimationLoop(); cy.style(options.style); cy.emit('mount'); @@ -18605,7 +18808,8 @@ for (var i = 0; i < jsons.length; i++) { var json = jsons[i]; - var id = json.data.id; + var id = '' + json.data.id; // id must be string + var ele = cy.getElementById(id); idInJson[id] = true; @@ -18690,6 +18894,10 @@ } } + if (obj.data) { + cy.data(obj.data); + } + var fields = ['minZoom', 'maxZoom', 'zoomingEnabled', 'userZoomingEnabled', 'panningEnabled', 'userPanningEnabled', 'boxSelectionEnabled', 'autolock', 'autoungrabify', 'autounselectify']; for (var _i2 = 0; _i2 < fields.length; _i2++) { @@ -18728,6 +18936,7 @@ json.style = cy.style().json(); } + json.data = copy(cy.data()); var options = _p.options; json.zoomingEnabled = _p.zoomingEnabled; json.userZoomingEnabled = _p.userZoomingEnabled; @@ -18745,26 +18954,10 @@ json.motionBlur = options.motionBlur; return json; } - }, - scratch: define$3.data({ - field: 'scratch', - bindingEvent: 'scratch', - allowBinding: true, - allowSetting: true, - settingEvent: 'scratch', - settingTriggersEvent: true, - triggerFnName: 'trigger', - allowGetting: true - }), - removeScratch: define$3.removeData({ - field: 'scratch', - event: 'scratch', - triggerFnName: 'trigger', - triggerEvent: true - }) + } }); corefn$9.$id = corefn$9.getElementById; - [corefn, corefn$1, elesfn$u, corefn$2, corefn$3, corefn$4, corefn$5, corefn$6, corefn$7, corefn$8].forEach(function (props) { + [corefn, corefn$1, elesfn$u, corefn$2, corefn$3, corefn$4, corefn$5, corefn$6, corefn$7, corefn$8, fn$6].forEach(function (props) { extend(corefn$9, props); }); @@ -19064,7 +19257,7 @@ if (depth < eleDepth) { // only get influenced by elements above - percent += index / (nDepth - 1); + percent += index / nDepth; samples++; } } @@ -19120,8 +19313,8 @@ x: bb.x1 + bb.w / 2, y: bb.x1 + bb.h / 2 }; - var maxDepthSize = depths.reduce(function (max$$1, eles) { - return Math.max(max$$1, eles.length); + var maxDepthSize = depths.reduce(function (max, eles) { + return Math.max(max, eles.length); }, 0); var getPosition = function getPosition(ele) { @@ -19564,9 +19757,7 @@ // Cooling factor (how the temperature is reduced between consecutive iterations coolingFactor: 0.99, // Lower temperature threshold (below this point the layout will end) - minTemp: 1.0, - // Pass a reference to weaver to use threads for calculations - weaver: false + minTemp: 1.0 }; /** * @brief : constructor @@ -19586,67 +19777,6 @@ var options = this.options; var cy = options.cy; var layout = this; - var thread$$1 = this.thread; - var Thread = options.weaver ? options.weaver.Thread : null; - var falseThread = { - // use false thread as polyfill - listeners: [], - on: function on(e, cb) { - this.listeners.push({ - event: e, - callback: cb - }); - return this; - }, - trigger: function trigger(e) { - if (string(e)) { - e = { - type: e - }; - } - - var matchesEvent = function matchesEvent(l) { - return l.event === e.type; - }; - - var trigger = function trigger(l) { - l.callback(e); - }; - - this.listeners.filter(matchesEvent).forEach(trigger); - return this; - }, - pass: function pass(data) { - this.pass = data; - return this; - }, - run: function run(cb) { - var pass = this.pass; - return new Promise$1(function (resolve) { - resolve(cb(pass)); - }); - }, - stop: function stop() { - return this; - }, - stopped: function stopped() { - return true; - } - }; - - function broadcast(message) { - // for false thread - var e = { - type: 'message', - message: message - }; - falseThread.trigger(e); - } - - if (!thread$$1 || thread$$1.stopped()) { - thread$$1 = this.thread = Thread ? new Thread() : falseThread; - } - layout.stopped = false; if (options.animate === true || options.animate === false) { @@ -19672,753 +19802,115 @@ if (options.randomize) { - randomizePositions(layoutInfo, cy); + randomizePositions(layoutInfo); } - var startTime = Date.now(); - var refreshRequested = false; - - var refresh = function refresh(rOpts) { - rOpts = rOpts || {}; + var startTime = performanceNow(); - if (refreshRequested && !rOpts.next) { - return; - } + var refresh = function refresh() { + refreshPositions(layoutInfo, cy, options); // Fit the graph if necessary - if (!rOpts.force && Date.now() - startTime < options.animationThreshold) { - return; + if (true === options.fit) { + cy.fit(options.padding); } + }; - refreshRequested = true; - requestAnimationFrame(function () { - refreshPositions(layoutInfo, cy, options); // Fit the graph if necessary + var mainLoop = function mainLoop(i) { + if (layout.stopped || i >= options.numIter) { + // logDebug("Layout manually stopped. Stopping computation in step " + i); + return false; + } // Do one step in the phisical simulation - if (true === options.fit) { - cy.fit(options.padding); - } - refreshRequested = false; + step$1(layoutInfo, options); // Update temperature - if (rOpts.next) { - rOpts.next(); - } - }); - }; + layoutInfo.temperature = layoutInfo.temperature * options.coolingFactor; // logDebug("New temperature: " + layoutInfo.temperature); - thread$$1.on('message', function (e) { - var layoutNodes = e.message; - layoutInfo.layoutNodes = layoutNodes; - refresh(); - }); - thread$$1.pass({ - layoutInfo: layoutInfo, - options: { - animate: options.animate, - refresh: options.refresh, - componentSpacing: options.componentSpacing, - nodeOverlap: options.nodeOverlap, - nestingFactor: options.nestingFactor, - gravity: options.gravity, - numIter: options.numIter, - initialTemp: options.initialTemp, - coolingFactor: options.coolingFactor, - minTemp: options.minTemp - } - }).run(function (pass) { - var layoutInfo = pass.layoutInfo; - var options = pass.options; - /** - * @brief : Performs one iteration of the physical simulation - * @arg layoutInfo : LayoutInfo object already initialized - * @arg cy : Cytoscape object - * @arg options : Layout options - */ - - var step = function step(layoutInfo, options, _step) { - // var s = "\n\n###############################"; - // s += "\nSTEP: " + step; - // s += "\n###############################\n"; - // logDebug(s); - // Calculate node repulsions - calculateNodeForces(layoutInfo, options); // Calculate edge forces + if (layoutInfo.temperature < options.minTemp) { + // logDebug("Temperature drop below minimum threshold. Stopping computation in step " + i); + return false; + } - calculateEdgeForces(layoutInfo, options); // Calculate gravity forces + return true; + }; - calculateGravityForces(layoutInfo, options); // Propagate forces from parent to child + var done = function done() { + if (options.animate === true || options.animate === false) { + refresh(); // Layout has finished - propagateForces(layoutInfo, options); // Update positions based on calculated forces + layout.one('layoutstop', options.stop); + layout.emit({ + type: 'layoutstop', + layout: layout + }); + } else { + var nodes = options.eles.nodes(); + var getScaledPos = getScaleInBoundsFn(layoutInfo, options, nodes); + nodes.layoutPositions(layout, options, getScaledPos); + } + }; - updatePositions(layoutInfo, options); - }; - /** - * @brief : Computes the node repulsion forces - */ + var i = 0; + var loopRet = true; + if (options.animate === true) { + var frame = function frame() { + var f = 0; - var calculateNodeForces = function calculateNodeForces(layoutInfo, options) { - // Go through each of the graphs in graphSet - // Nodes only repel each other if they belong to the same graph - // var s = 'calculateNodeForces'; - // logDebug(s); - for (var i = 0; i < layoutInfo.graphSet.length; i++) { - var graph = layoutInfo.graphSet[i]; - var numNodes = graph.length; // s = "Set: " + graph.toString(); - // logDebug(s); - // Now get all the pairs of nodes - // Only get each pair once, (A, B) = (B, A) + while (loopRet && f < options.refresh) { + loopRet = mainLoop(i); + i++; + f++; + } - for (var j = 0; j < numNodes; j++) { - var node1 = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[j]]]; + if (!loopRet) { + // it's done + separateComponents(layoutInfo, options); + done(); + } else { + var now = performanceNow(); - for (var k = j + 1; k < numNodes; k++) { - var node2 = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[k]]]; - nodeRepulsion(node1, node2, layoutInfo, options); - } + if (now - startTime >= options.animationThreshold) { + refresh(); } - } - }; - var randomDistance = function randomDistance(max$$1) { - return -max$$1 + 2 * max$$1 * Math.random(); + requestAnimationFrame(frame); + } }; - /** - * @brief : Compute the node repulsion forces between a pair of nodes - */ + frame(); + } else { + while (loopRet) { + loopRet = mainLoop(i); + i++; + } - var nodeRepulsion = function nodeRepulsion(node1, node2, layoutInfo, options) { - // var s = "Node repulsion. Node1: " + node1.id + " Node2: " + node2.id; - var cmptId1 = node1.cmptId; - var cmptId2 = node2.cmptId; - - if (cmptId1 !== cmptId2 && !layoutInfo.isCompound) { - return; - } // Get direction of line connecting both node centers - + separateComponents(layoutInfo, options); + done(); + } - var directionX = node2.positionX - node1.positionX; - var directionY = node2.positionY - node1.positionY; - var maxRandDist = 1; // s += "\ndirectionX: " + directionX + ", directionY: " + directionY; - // If both centers are the same, apply a random force + return this; // chaining + }; + /** + * @brief : called on continuous layouts to stop them before they finish + */ - if (0 === directionX && 0 === directionY) { - directionX = randomDistance(maxRandDist); - directionY = randomDistance(maxRandDist); - } - var overlap = nodesOverlap(node1, node2, directionX, directionY); + CoseLayout.prototype.stop = function () { + this.stopped = true; - if (overlap > 0) { - // s += "\nNodes DO overlap."; - // s += "\nOverlap: " + overlap; - // If nodes overlap, repulsion force is proportional - // to the overlap - var force = options.nodeOverlap * overlap; // Compute the module and components of the force vector + if (this.thread) { + this.thread.stop(); + } - var distance = Math.sqrt(directionX * directionX + directionY * directionY); // s += "\nDistance: " + distance; + this.emit('layoutstop'); + return this; // chaining + }; - var forceX = force * directionX / distance; - var forceY = force * directionY / distance; - } else { - // s += "\nNodes do NOT overlap."; - // If there's no overlap, force is inversely proportional - // to squared distance - // Get clipping points for both nodes - var point1 = findClippingPoint(node1, directionX, directionY); - var point2 = findClippingPoint(node2, -1 * directionX, -1 * directionY); // Use clipping points to compute distance - - var distanceX = point2.x - point1.x; - var distanceY = point2.y - point1.y; - var distanceSqr = distanceX * distanceX + distanceY * distanceY; - var distance = Math.sqrt(distanceSqr); // s += "\nDistance: " + distance; - // Compute the module and components of the force vector - - var force = (node1.nodeRepulsion + node2.nodeRepulsion) / distanceSqr; - var forceX = force * distanceX / distance; - var forceY = force * distanceY / distance; - } // Apply force - - - if (!node1.isLocked) { - node1.offsetX -= forceX; - node1.offsetY -= forceY; - } - - if (!node2.isLocked) { - node2.offsetX += forceX; - node2.offsetY += forceY; - } // s += "\nForceX: " + forceX + " ForceY: " + forceY; - // logDebug(s); - - - return; - }; - /** - * @brief : Determines whether two nodes overlap or not - * @return : Amount of overlapping (0 => no overlap) - */ - - - var nodesOverlap = function nodesOverlap(node1, node2, dX, dY) { - if (dX > 0) { - var overlapX = node1.maxX - node2.minX; - } else { - var overlapX = node2.maxX - node1.minX; - } - - if (dY > 0) { - var overlapY = node1.maxY - node2.minY; - } else { - var overlapY = node2.maxY - node1.minY; - } - - if (overlapX >= 0 && overlapY >= 0) { - return Math.sqrt(overlapX * overlapX + overlapY * overlapY); - } else { - return 0; - } - }; - /** - * @brief : Finds the point in which an edge (direction dX, dY) intersects - * the rectangular bounding box of it's source/target node - */ - - - var findClippingPoint = function findClippingPoint(node, dX, dY) { - // Shorcuts - var X = node.positionX; - var Y = node.positionY; - var H = node.height || 1; - var W = node.width || 1; - var dirSlope = dY / dX; - var nodeSlope = H / W; // var s = 'Computing clipping point of node ' + node.id + - // " . Height: " + H + ", Width: " + W + - // "\nDirection " + dX + ", " + dY; - // - // Compute intersection - - var res = {}; // Case: Vertical direction (up) - - if (0 === dX && 0 < dY) { - res.x = X; // s += "\nUp direction"; - - res.y = Y + H / 2; - return res; - } // Case: Vertical direction (down) - - - if (0 === dX && 0 > dY) { - res.x = X; - res.y = Y + H / 2; // s += "\nDown direction"; - - return res; - } // Case: Intersects the right border - - - if (0 < dX && -1 * nodeSlope <= dirSlope && dirSlope <= nodeSlope) { - res.x = X + W / 2; - res.y = Y + W * dY / 2 / dX; // s += "\nRightborder"; - - return res; - } // Case: Intersects the left border - - - if (0 > dX && -1 * nodeSlope <= dirSlope && dirSlope <= nodeSlope) { - res.x = X - W / 2; - res.y = Y - W * dY / 2 / dX; // s += "\nLeftborder"; - - return res; - } // Case: Intersects the top border - - - if (0 < dY && (dirSlope <= -1 * nodeSlope || dirSlope >= nodeSlope)) { - res.x = X + H * dX / 2 / dY; - res.y = Y + H / 2; // s += "\nTop border"; - - return res; - } // Case: Intersects the bottom border - - - if (0 > dY && (dirSlope <= -1 * nodeSlope || dirSlope >= nodeSlope)) { - res.x = X - H * dX / 2 / dY; - res.y = Y - H / 2; // s += "\nBottom border"; - - return res; - } // s += "\nClipping point found at " + res.x + ", " + res.y; - // logDebug(s); - - - return res; - }; - /** - * @brief : Calculates all edge forces - */ - - - var calculateEdgeForces = function calculateEdgeForces(layoutInfo, options) { - // Iterate over all edges - for (var i = 0; i < layoutInfo.edgeSize; i++) { - // Get edge, source & target nodes - var edge = layoutInfo.layoutEdges[i]; - var sourceIx = layoutInfo.idToIndex[edge.sourceId]; - var source = layoutInfo.layoutNodes[sourceIx]; - var targetIx = layoutInfo.idToIndex[edge.targetId]; - var target = layoutInfo.layoutNodes[targetIx]; // Get direction of line connecting both node centers - - var directionX = target.positionX - source.positionX; - var directionY = target.positionY - source.positionY; // If both centers are the same, do nothing. - // A random force has already been applied as node repulsion - - if (0 === directionX && 0 === directionY) { - continue; - } // Get clipping points for both nodes - - - var point1 = findClippingPoint(source, directionX, directionY); - var point2 = findClippingPoint(target, -1 * directionX, -1 * directionY); - var lx = point2.x - point1.x; - var ly = point2.y - point1.y; - var l = Math.sqrt(lx * lx + ly * ly); - var force = Math.pow(edge.idealLength - l, 2) / edge.elasticity; - - if (0 !== l) { - var forceX = force * lx / l; - var forceY = force * ly / l; - } else { - var forceX = 0; - var forceY = 0; - } // Add this force to target and source nodes - - - if (!source.isLocked) { - source.offsetX += forceX; - source.offsetY += forceY; - } - - if (!target.isLocked) { - target.offsetX -= forceX; - target.offsetY -= forceY; - } // var s = 'Edge force between nodes ' + source.id + ' and ' + target.id; - // s += "\nDistance: " + l + " Force: (" + forceX + ", " + forceY + ")"; - // logDebug(s); - - } - }; - /** - * @brief : Computes gravity forces for all nodes - */ - - - var calculateGravityForces = function calculateGravityForces(layoutInfo, options) { - var distThreshold = 1; // var s = 'calculateGravityForces'; - // logDebug(s); - - for (var i = 0; i < layoutInfo.graphSet.length; i++) { - var graph = layoutInfo.graphSet[i]; - var numNodes = graph.length; // s = "Set: " + graph.toString(); - // logDebug(s); - // Compute graph center - - if (0 === i) { - var centerX = layoutInfo.clientHeight / 2; - var centerY = layoutInfo.clientWidth / 2; - } else { - // Get Parent node for this graph, and use its position as center - var temp = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[0]]]; - var parent = layoutInfo.layoutNodes[layoutInfo.idToIndex[temp.parentId]]; - var centerX = parent.positionX; - var centerY = parent.positionY; - } // s = "Center found at: " + centerX + ", " + centerY; - // logDebug(s); - // Apply force to all nodes in graph - - - for (var j = 0; j < numNodes; j++) { - var node = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[j]]]; // s = "Node: " + node.id; - - if (node.isLocked) { - continue; - } - - var dx = centerX - node.positionX; - var dy = centerY - node.positionY; - var d = Math.sqrt(dx * dx + dy * dy); - - if (d > distThreshold) { - var fx = options.gravity * dx / d; - var fy = options.gravity * dy / d; - node.offsetX += fx; - node.offsetY += fy; // s += ": Applied force: " + fx + ", " + fy; - } // s += ": skypped since it's too close to center"; - // logDebug(s); - - } - } - }; - /** - * @brief : This function propagates the existing offsets from - * parent nodes to its descendents. - * @arg layoutInfo : layoutInfo Object - * @arg cy : cytoscape Object - * @arg options : Layout options - */ - - - var propagateForces = function propagateForces(layoutInfo, options) { - // Inline implementation of a queue, used for traversing the graph in BFS order - var queue = []; - var start = 0; // Points to the start the queue - - var end = -1; // Points to the end of the queue - // logDebug('propagateForces'); - // Start by visiting the nodes in the root graph - - queue.push.apply(queue, layoutInfo.graphSet[0]); - end += layoutInfo.graphSet[0].length; // Traverse the graph, level by level, - - while (start <= end) { - // Get the node to visit and remove it from queue - var nodeId = queue[start++]; - var nodeIndex = layoutInfo.idToIndex[nodeId]; - var node = layoutInfo.layoutNodes[nodeIndex]; - var children = node.children; // We only need to process the node if it's compound - - if (0 < children.length && !node.isLocked) { - var offX = node.offsetX; - var offY = node.offsetY; // var s = "Propagating offset from parent node : " + node.id + - // ". OffsetX: " + offX + ". OffsetY: " + offY; - // s += "\n Children: " + children.toString(); - // logDebug(s); - - for (var i = 0; i < children.length; i++) { - var childNode = layoutInfo.layoutNodes[layoutInfo.idToIndex[children[i]]]; // Propagate offset - - childNode.offsetX += offX; - childNode.offsetY += offY; // Add children to queue to be visited - - queue[++end] = children[i]; - } // Reset parent offsets - - - node.offsetX = 0; - node.offsetY = 0; - } - } - }; - /** - * @brief : Updates the layout model positions, based on - * the accumulated forces - */ - - - var updatePositions = function updatePositions(layoutInfo, options) { - // var s = 'Updating positions'; - // logDebug(s); - // Reset boundaries for compound nodes - for (var i = 0; i < layoutInfo.nodeSize; i++) { - var n = layoutInfo.layoutNodes[i]; - - if (0 < n.children.length) { - // logDebug("Resetting boundaries of compound node: " + n.id); - n.maxX = undefined; - n.minX = undefined; - n.maxY = undefined; - n.minY = undefined; - } - } - - for (var i = 0; i < layoutInfo.nodeSize; i++) { - var n = layoutInfo.layoutNodes[i]; - - if (0 < n.children.length || n.isLocked) { - // No need to set compound or locked node position - // logDebug("Skipping position update of node: " + n.id); - continue; - } // s = "Node: " + n.id + " Previous position: (" + - // n.positionX + ", " + n.positionY + ")."; - // Limit displacement in order to improve stability - - - var tempForce = limitForce(n.offsetX, n.offsetY, layoutInfo.temperature); - n.positionX += tempForce.x; - n.positionY += tempForce.y; - n.offsetX = 0; - n.offsetY = 0; - n.minX = n.positionX - n.width; - n.maxX = n.positionX + n.width; - n.minY = n.positionY - n.height; - n.maxY = n.positionY + n.height; // s += " New Position: (" + n.positionX + ", " + n.positionY + ")."; - // logDebug(s); - // Update ancestry boudaries - - updateAncestryBoundaries(n, layoutInfo); - } // Update size, position of compund nodes - - - for (var i = 0; i < layoutInfo.nodeSize; i++) { - var n = layoutInfo.layoutNodes[i]; - - if (0 < n.children.length && !n.isLocked) { - n.positionX = (n.maxX + n.minX) / 2; - n.positionY = (n.maxY + n.minY) / 2; - n.width = n.maxX - n.minX; - n.height = n.maxY - n.minY; // s = "Updating position, size of compound node " + n.id; - // s += "\nPositionX: " + n.positionX + ", PositionY: " + n.positionY; - // s += "\nWidth: " + n.width + ", Height: " + n.height; - // logDebug(s); - } - } - }; - /** - * @brief : Limits a force (forceX, forceY) to be not - * greater (in modulo) than max. - 8 Preserves force direction. - */ - - - var limitForce = function limitForce(forceX, forceY, max$$1) { - // var s = "Limiting force: (" + forceX + ", " + forceY + "). Max: " + max; - var force = Math.sqrt(forceX * forceX + forceY * forceY); - - if (force > max$$1) { - var res = { - x: max$$1 * forceX / force, - y: max$$1 * forceY / force - }; - } else { - var res = { - x: forceX, - y: forceY - }; - } // s += ".\nResult: (" + res.x + ", " + res.y + ")"; - // logDebug(s); - - - return res; - }; - /** - * @brief : Function used for keeping track of compound node - * sizes, since they should bound all their subnodes. - */ - - - var updateAncestryBoundaries = function updateAncestryBoundaries(node, layoutInfo) { - // var s = "Propagating new position/size of node " + node.id; - var parentId = node.parentId; - - if (null == parentId) { - // If there's no parent, we are done - // s += ". No parent node."; - // logDebug(s); - return; - } // Get Parent Node - - - var p = layoutInfo.layoutNodes[layoutInfo.idToIndex[parentId]]; - var flag = false; // MaxX - - if (null == p.maxX || node.maxX + p.padRight > p.maxX) { - p.maxX = node.maxX + p.padRight; - flag = true; // s += "\nNew maxX for parent node " + p.id + ": " + p.maxX; - } // MinX - - - if (null == p.minX || node.minX - p.padLeft < p.minX) { - p.minX = node.minX - p.padLeft; - flag = true; // s += "\nNew minX for parent node " + p.id + ": " + p.minX; - } // MaxY - - - if (null == p.maxY || node.maxY + p.padBottom > p.maxY) { - p.maxY = node.maxY + p.padBottom; - flag = true; // s += "\nNew maxY for parent node " + p.id + ": " + p.maxY; - } // MinY - - - if (null == p.minY || node.minY - p.padTop < p.minY) { - p.minY = node.minY - p.padTop; - flag = true; // s += "\nNew minY for parent node " + p.id + ": " + p.minY; - } // If updated boundaries, propagate changes upward - - - if (flag) { - // logDebug(s); - return updateAncestryBoundaries(p, layoutInfo); - } // s += ". No changes in boundaries/position of parent node " + p.id; - // logDebug(s); - - - return; - }; - - var separateComponents = function separateComponents(layutInfo, options) { - var nodes = layoutInfo.layoutNodes; - var components = []; - - for (var i = 0; i < nodes.length; i++) { - var node = nodes[i]; - var cid = node.cmptId; - var component = components[cid] = components[cid] || []; - component.push(node); - } - - var totalA = 0; - - for (var i = 0; i < components.length; i++) { - var c = components[i]; - - if (!c) { - continue; - } - - c.x1 = Infinity; - c.x2 = -Infinity; - c.y1 = Infinity; - c.y2 = -Infinity; - - for (var j = 0; j < c.length; j++) { - var n = c[j]; - c.x1 = Math.min(c.x1, n.positionX - n.width / 2); - c.x2 = Math.max(c.x2, n.positionX + n.width / 2); - c.y1 = Math.min(c.y1, n.positionY - n.height / 2); - c.y2 = Math.max(c.y2, n.positionY + n.height / 2); - } - - c.w = c.x2 - c.x1; - c.h = c.y2 - c.y1; - totalA += c.w * c.h; - } - - components.sort(function (c1, c2) { - return c2.w * c2.h - c1.w * c1.h; - }); - var x = 0; - var y = 0; - var usedW = 0; - var rowH = 0; - var maxRowW = Math.sqrt(totalA) * layoutInfo.clientWidth / layoutInfo.clientHeight; - - for (var i = 0; i < components.length; i++) { - var c = components[i]; - - if (!c) { - continue; - } - - for (var j = 0; j < c.length; j++) { - var n = c[j]; - - if (!n.isLocked) { - n.positionX += x; - n.positionY += y; - } - } - - x += c.w + options.componentSpacing; - usedW += c.w + options.componentSpacing; - rowH = Math.max(rowH, c.h); - - if (usedW > maxRowW) { - y += rowH + options.componentSpacing; - x = 0; - usedW = 0; - rowH = 0; - } - } - }; - - var mainLoop = function mainLoop(i) { - - - step(layoutInfo, options, i); // Update temperature - - layoutInfo.temperature = layoutInfo.temperature * options.coolingFactor; // logDebug("New temperature: " + layoutInfo.temperature); - - if (layoutInfo.temperature < options.minTemp) { - // logDebug("Temperature drop below minimum threshold. Stopping computation in step " + i); - return false; - } - - return true; - }; - - var i = 0; - var loopRet; - - do { - var f = 0; - - while ((f < options.refresh || options.refresh === 0) && i < options.numIter) { - var loopRet = mainLoop(i); - - if (!loopRet) { - break; - } - - f++; - i++; - } - - if (options.animate === true) { - broadcast(layoutInfo.layoutNodes); // eslint-disable-line no-undef - } - } while (loopRet && i + 1 < options.numIter); - - separateComponents(layoutInfo, options); - return layoutInfo; - }).then(function (layoutInfoUpdated) { - layoutInfo.layoutNodes = layoutInfoUpdated.layoutNodes; // get the positions - - thread$$1.stop(); - done(); - }); - - var done = function done() { - if (options.animate === true || options.animate === false) { - refresh({ - force: true, - next: function next() { - // Layout has finished - layout.one('layoutstop', options.stop); - layout.emit({ - type: 'layoutstop', - layout: layout - }); - } - }); - } else { - options.eles.nodes().layoutPositions(layout, options, function (node) { - var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[node.data('id')]]; - return { - x: lnode.positionX, - y: lnode.positionY - }; - }); - } - }; - - return this; // chaining - }; - /** - * @brief : called on continuous layouts to stop them before they finish - */ - - - CoseLayout.prototype.stop = function () { - this.stopped = true; - - if (this.thread) { - this.thread.stop(); - } - - this.emit('layoutstop'); - return this; // chaining - }; - - CoseLayout.prototype.destroy = function () { - if (this.thread) { - this.thread.stop(); - } + CoseLayout.prototype.destroy = function () { + if (this.thread) { + this.thread.stop(); + } return this; // chaining }; @@ -20718,19 +20210,8 @@ } } }; - /** - * @brief : Updates the positions of nodes in the network - * @arg layoutInfo : LayoutInfo object - * @arg cy : Cytoscape object - * @arg options : Layout options - */ - - var refreshPositions = function refreshPositions(layoutInfo, cy, options) { - // var s = 'Refreshing positions'; - // logDebug(s); - var layout = options.layout; - var nodes = options.eles.nodes(); + var getScaleInBoundsFn = function getScaleInBoundsFn(layoutInfo, options, nodes) { var bb = layoutInfo.boundingBox; var coseBB = { x1: Infinity, @@ -20739,48 +20220,671 @@ y2: -Infinity }; - if (options.boundingBox) { - nodes.forEach(function (node) { - var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[node.data('id')]]; - coseBB.x1 = Math.min(coseBB.x1, lnode.positionX); - coseBB.x2 = Math.max(coseBB.x2, lnode.positionX); - coseBB.y1 = Math.min(coseBB.y1, lnode.positionY); - coseBB.y2 = Math.max(coseBB.y2, lnode.positionY); - }); - coseBB.w = coseBB.x2 - coseBB.x1; - coseBB.h = coseBB.y2 - coseBB.y1; + if (options.boundingBox) { + nodes.forEach(function (node) { + var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[node.data('id')]]; + coseBB.x1 = Math.min(coseBB.x1, lnode.positionX); + coseBB.x2 = Math.max(coseBB.x2, lnode.positionX); + coseBB.y1 = Math.min(coseBB.y1, lnode.positionY); + coseBB.y2 = Math.max(coseBB.y2, lnode.positionY); + }); + coseBB.w = coseBB.x2 - coseBB.x1; + coseBB.h = coseBB.y2 - coseBB.y1; + } + + return function (ele, i) { + var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[ele.data('id')]]; + + if (options.boundingBox) { + // then add extra bounding box constraint + var pctX = (lnode.positionX - coseBB.x1) / coseBB.w; + var pctY = (lnode.positionY - coseBB.y1) / coseBB.h; + return { + x: bb.x1 + pctX * bb.w, + y: bb.y1 + pctY * bb.h + }; + } else { + return { + x: lnode.positionX, + y: lnode.positionY + }; + } + }; + }; + /** + * @brief : Updates the positions of nodes in the network + * @arg layoutInfo : LayoutInfo object + * @arg cy : Cytoscape object + * @arg options : Layout options + */ + + + var refreshPositions = function refreshPositions(layoutInfo, cy, options) { + // var s = 'Refreshing positions'; + // logDebug(s); + var layout = options.layout; + var nodes = options.eles.nodes(); + var getScaledPos = getScaleInBoundsFn(layoutInfo, options, nodes); + nodes.positions(getScaledPos); // Trigger layoutReady only on first call + + if (true !== layoutInfo.ready) { + // s = 'Triggering layoutready'; + // logDebug(s); + layoutInfo.ready = true; + layout.one('layoutready', options.ready); + layout.emit({ + type: 'layoutready', + layout: this + }); + } + }; + /** + * @brief : Logs a debug message in JS console, if DEBUG is ON + */ + // var logDebug = function(text) { + // if (DEBUG) { + // console.debug(text); + // } + // }; + + /** + * @brief : Performs one iteration of the physical simulation + * @arg layoutInfo : LayoutInfo object already initialized + * @arg cy : Cytoscape object + * @arg options : Layout options + */ + + + var step$1 = function step(layoutInfo, options, _step) { + // var s = "\n\n###############################"; + // s += "\nSTEP: " + step; + // s += "\n###############################\n"; + // logDebug(s); + // Calculate node repulsions + calculateNodeForces(layoutInfo, options); // Calculate edge forces + + calculateEdgeForces(layoutInfo); // Calculate gravity forces + + calculateGravityForces(layoutInfo, options); // Propagate forces from parent to child + + propagateForces(layoutInfo); // Update positions based on calculated forces + + updatePositions(layoutInfo); + }; + /** + * @brief : Computes the node repulsion forces + */ + + + var calculateNodeForces = function calculateNodeForces(layoutInfo, options) { + // Go through each of the graphs in graphSet + // Nodes only repel each other if they belong to the same graph + // var s = 'calculateNodeForces'; + // logDebug(s); + for (var i = 0; i < layoutInfo.graphSet.length; i++) { + var graph = layoutInfo.graphSet[i]; + var numNodes = graph.length; // s = "Set: " + graph.toString(); + // logDebug(s); + // Now get all the pairs of nodes + // Only get each pair once, (A, B) = (B, A) + + for (var j = 0; j < numNodes; j++) { + var node1 = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[j]]]; + + for (var k = j + 1; k < numNodes; k++) { + var node2 = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[k]]]; + nodeRepulsion(node1, node2, layoutInfo, options); + } + } + } + }; + + var randomDistance = function randomDistance(max) { + return -max + 2 * max * Math.random(); + }; + /** + * @brief : Compute the node repulsion forces between a pair of nodes + */ + + + var nodeRepulsion = function nodeRepulsion(node1, node2, layoutInfo, options) { + // var s = "Node repulsion. Node1: " + node1.id + " Node2: " + node2.id; + var cmptId1 = node1.cmptId; + var cmptId2 = node2.cmptId; + + if (cmptId1 !== cmptId2 && !layoutInfo.isCompound) { + return; + } // Get direction of line connecting both node centers + + + var directionX = node2.positionX - node1.positionX; + var directionY = node2.positionY - node1.positionY; + var maxRandDist = 1; // s += "\ndirectionX: " + directionX + ", directionY: " + directionY; + // If both centers are the same, apply a random force + + if (0 === directionX && 0 === directionY) { + directionX = randomDistance(maxRandDist); + directionY = randomDistance(maxRandDist); + } + + var overlap = nodesOverlap(node1, node2, directionX, directionY); + + if (overlap > 0) { + // s += "\nNodes DO overlap."; + // s += "\nOverlap: " + overlap; + // If nodes overlap, repulsion force is proportional + // to the overlap + var force = options.nodeOverlap * overlap; // Compute the module and components of the force vector + + var distance = Math.sqrt(directionX * directionX + directionY * directionY); // s += "\nDistance: " + distance; + + var forceX = force * directionX / distance; + var forceY = force * directionY / distance; + } else { + // s += "\nNodes do NOT overlap."; + // If there's no overlap, force is inversely proportional + // to squared distance + // Get clipping points for both nodes + var point1 = findClippingPoint(node1, directionX, directionY); + var point2 = findClippingPoint(node2, -1 * directionX, -1 * directionY); // Use clipping points to compute distance + + var distanceX = point2.x - point1.x; + var distanceY = point2.y - point1.y; + var distanceSqr = distanceX * distanceX + distanceY * distanceY; + var distance = Math.sqrt(distanceSqr); // s += "\nDistance: " + distance; + // Compute the module and components of the force vector + + var force = (node1.nodeRepulsion + node2.nodeRepulsion) / distanceSqr; + var forceX = force * distanceX / distance; + var forceY = force * distanceY / distance; + } // Apply force + + + if (!node1.isLocked) { + node1.offsetX -= forceX; + node1.offsetY -= forceY; + } + + if (!node2.isLocked) { + node2.offsetX += forceX; + node2.offsetY += forceY; + } // s += "\nForceX: " + forceX + " ForceY: " + forceY; + // logDebug(s); + + + return; + }; + /** + * @brief : Determines whether two nodes overlap or not + * @return : Amount of overlapping (0 => no overlap) + */ + + + var nodesOverlap = function nodesOverlap(node1, node2, dX, dY) { + if (dX > 0) { + var overlapX = node1.maxX - node2.minX; + } else { + var overlapX = node2.maxX - node1.minX; + } + + if (dY > 0) { + var overlapY = node1.maxY - node2.minY; + } else { + var overlapY = node2.maxY - node1.minY; + } + + if (overlapX >= 0 && overlapY >= 0) { + return Math.sqrt(overlapX * overlapX + overlapY * overlapY); + } else { + return 0; + } + }; + /** + * @brief : Finds the point in which an edge (direction dX, dY) intersects + * the rectangular bounding box of it's source/target node + */ + + + var findClippingPoint = function findClippingPoint(node, dX, dY) { + // Shorcuts + var X = node.positionX; + var Y = node.positionY; + var H = node.height || 1; + var W = node.width || 1; + var dirSlope = dY / dX; + var nodeSlope = H / W; // var s = 'Computing clipping point of node ' + node.id + + // " . Height: " + H + ", Width: " + W + + // "\nDirection " + dX + ", " + dY; + // + // Compute intersection + + var res = {}; // Case: Vertical direction (up) + + if (0 === dX && 0 < dY) { + res.x = X; // s += "\nUp direction"; + + res.y = Y + H / 2; + return res; + } // Case: Vertical direction (down) + + + if (0 === dX && 0 > dY) { + res.x = X; + res.y = Y + H / 2; // s += "\nDown direction"; + + return res; + } // Case: Intersects the right border + + + if (0 < dX && -1 * nodeSlope <= dirSlope && dirSlope <= nodeSlope) { + res.x = X + W / 2; + res.y = Y + W * dY / 2 / dX; // s += "\nRightborder"; + + return res; + } // Case: Intersects the left border + + + if (0 > dX && -1 * nodeSlope <= dirSlope && dirSlope <= nodeSlope) { + res.x = X - W / 2; + res.y = Y - W * dY / 2 / dX; // s += "\nLeftborder"; + + return res; + } // Case: Intersects the top border + + + if (0 < dY && (dirSlope <= -1 * nodeSlope || dirSlope >= nodeSlope)) { + res.x = X + H * dX / 2 / dY; + res.y = Y + H / 2; // s += "\nTop border"; + + return res; + } // Case: Intersects the bottom border + + + if (0 > dY && (dirSlope <= -1 * nodeSlope || dirSlope >= nodeSlope)) { + res.x = X - H * dX / 2 / dY; + res.y = Y - H / 2; // s += "\nBottom border"; + + return res; + } // s += "\nClipping point found at " + res.x + ", " + res.y; + // logDebug(s); + + + return res; + }; + /** + * @brief : Calculates all edge forces + */ + + + var calculateEdgeForces = function calculateEdgeForces(layoutInfo, options) { + // Iterate over all edges + for (var i = 0; i < layoutInfo.edgeSize; i++) { + // Get edge, source & target nodes + var edge = layoutInfo.layoutEdges[i]; + var sourceIx = layoutInfo.idToIndex[edge.sourceId]; + var source = layoutInfo.layoutNodes[sourceIx]; + var targetIx = layoutInfo.idToIndex[edge.targetId]; + var target = layoutInfo.layoutNodes[targetIx]; // Get direction of line connecting both node centers + + var directionX = target.positionX - source.positionX; + var directionY = target.positionY - source.positionY; // If both centers are the same, do nothing. + // A random force has already been applied as node repulsion + + if (0 === directionX && 0 === directionY) { + continue; + } // Get clipping points for both nodes + + + var point1 = findClippingPoint(source, directionX, directionY); + var point2 = findClippingPoint(target, -1 * directionX, -1 * directionY); + var lx = point2.x - point1.x; + var ly = point2.y - point1.y; + var l = Math.sqrt(lx * lx + ly * ly); + var force = Math.pow(edge.idealLength - l, 2) / edge.elasticity; + + if (0 !== l) { + var forceX = force * lx / l; + var forceY = force * ly / l; + } else { + var forceX = 0; + var forceY = 0; + } // Add this force to target and source nodes + + + if (!source.isLocked) { + source.offsetX += forceX; + source.offsetY += forceY; + } + + if (!target.isLocked) { + target.offsetX -= forceX; + target.offsetY -= forceY; + } // var s = 'Edge force between nodes ' + source.id + ' and ' + target.id; + // s += "\nDistance: " + l + " Force: (" + forceX + ", " + forceY + ")"; + // logDebug(s); + + } + }; + /** + * @brief : Computes gravity forces for all nodes + */ + + + var calculateGravityForces = function calculateGravityForces(layoutInfo, options) { + var distThreshold = 1; // var s = 'calculateGravityForces'; + // logDebug(s); + + for (var i = 0; i < layoutInfo.graphSet.length; i++) { + var graph = layoutInfo.graphSet[i]; + var numNodes = graph.length; // s = "Set: " + graph.toString(); + // logDebug(s); + // Compute graph center + + if (0 === i) { + var centerX = layoutInfo.clientHeight / 2; + var centerY = layoutInfo.clientWidth / 2; + } else { + // Get Parent node for this graph, and use its position as center + var temp = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[0]]]; + var parent = layoutInfo.layoutNodes[layoutInfo.idToIndex[temp.parentId]]; + var centerX = parent.positionX; + var centerY = parent.positionY; + } // s = "Center found at: " + centerX + ", " + centerY; + // logDebug(s); + // Apply force to all nodes in graph + + + for (var j = 0; j < numNodes; j++) { + var node = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[j]]]; // s = "Node: " + node.id; + + if (node.isLocked) { + continue; + } + + var dx = centerX - node.positionX; + var dy = centerY - node.positionY; + var d = Math.sqrt(dx * dx + dy * dy); + + if (d > distThreshold) { + var fx = options.gravity * dx / d; + var fy = options.gravity * dy / d; + node.offsetX += fx; + node.offsetY += fy; // s += ": Applied force: " + fx + ", " + fy; + } // s += ": skypped since it's too close to center"; + // logDebug(s); + + } + } + }; + /** + * @brief : This function propagates the existing offsets from + * parent nodes to its descendents. + * @arg layoutInfo : layoutInfo Object + * @arg cy : cytoscape Object + * @arg options : Layout options + */ + + + var propagateForces = function propagateForces(layoutInfo, options) { + // Inline implementation of a queue, used for traversing the graph in BFS order + var queue = []; + var start = 0; // Points to the start the queue + + var end = -1; // Points to the end of the queue + // logDebug('propagateForces'); + // Start by visiting the nodes in the root graph + + queue.push.apply(queue, layoutInfo.graphSet[0]); + end += layoutInfo.graphSet[0].length; // Traverse the graph, level by level, + + while (start <= end) { + // Get the node to visit and remove it from queue + var nodeId = queue[start++]; + var nodeIndex = layoutInfo.idToIndex[nodeId]; + var node = layoutInfo.layoutNodes[nodeIndex]; + var children = node.children; // We only need to process the node if it's compound + + if (0 < children.length && !node.isLocked) { + var offX = node.offsetX; + var offY = node.offsetY; // var s = "Propagating offset from parent node : " + node.id + + // ". OffsetX: " + offX + ". OffsetY: " + offY; + // s += "\n Children: " + children.toString(); + // logDebug(s); + + for (var i = 0; i < children.length; i++) { + var childNode = layoutInfo.layoutNodes[layoutInfo.idToIndex[children[i]]]; // Propagate offset + + childNode.offsetX += offX; + childNode.offsetY += offY; // Add children to queue to be visited + + queue[++end] = children[i]; + } // Reset parent offsets + + + node.offsetX = 0; + node.offsetY = 0; + } + } + }; + /** + * @brief : Updates the layout model positions, based on + * the accumulated forces + */ + + + var updatePositions = function updatePositions(layoutInfo, options) { + // var s = 'Updating positions'; + // logDebug(s); + // Reset boundaries for compound nodes + for (var i = 0; i < layoutInfo.nodeSize; i++) { + var n = layoutInfo.layoutNodes[i]; + + if (0 < n.children.length) { + // logDebug("Resetting boundaries of compound node: " + n.id); + n.maxX = undefined; + n.minX = undefined; + n.maxY = undefined; + n.minY = undefined; + } + } + + for (var i = 0; i < layoutInfo.nodeSize; i++) { + var n = layoutInfo.layoutNodes[i]; + + if (0 < n.children.length || n.isLocked) { + // No need to set compound or locked node position + // logDebug("Skipping position update of node: " + n.id); + continue; + } // s = "Node: " + n.id + " Previous position: (" + + // n.positionX + ", " + n.positionY + ")."; + // Limit displacement in order to improve stability + + + var tempForce = limitForce(n.offsetX, n.offsetY, layoutInfo.temperature); + n.positionX += tempForce.x; + n.positionY += tempForce.y; + n.offsetX = 0; + n.offsetY = 0; + n.minX = n.positionX - n.width; + n.maxX = n.positionX + n.width; + n.minY = n.positionY - n.height; + n.maxY = n.positionY + n.height; // s += " New Position: (" + n.positionX + ", " + n.positionY + ")."; + // logDebug(s); + // Update ancestry boudaries + + updateAncestryBoundaries(n, layoutInfo); + } // Update size, position of compund nodes + + + for (var i = 0; i < layoutInfo.nodeSize; i++) { + var n = layoutInfo.layoutNodes[i]; + + if (0 < n.children.length && !n.isLocked) { + n.positionX = (n.maxX + n.minX) / 2; + n.positionY = (n.maxY + n.minY) / 2; + n.width = n.maxX - n.minX; + n.height = n.maxY - n.minY; // s = "Updating position, size of compound node " + n.id; + // s += "\nPositionX: " + n.positionX + ", PositionY: " + n.positionY; + // s += "\nWidth: " + n.width + ", Height: " + n.height; + // logDebug(s); + } + } + }; + /** + * @brief : Limits a force (forceX, forceY) to be not + * greater (in modulo) than max. + 8 Preserves force direction. + */ + + + var limitForce = function limitForce(forceX, forceY, max) { + // var s = "Limiting force: (" + forceX + ", " + forceY + "). Max: " + max; + var force = Math.sqrt(forceX * forceX + forceY * forceY); + + if (force > max) { + var res = { + x: max * forceX / force, + y: max * forceY / force + }; + } else { + var res = { + x: forceX, + y: forceY + }; + } // s += ".\nResult: (" + res.x + ", " + res.y + ")"; + // logDebug(s); + + + return res; + }; + /** + * @brief : Function used for keeping track of compound node + * sizes, since they should bound all their subnodes. + */ + + + var updateAncestryBoundaries = function updateAncestryBoundaries(node, layoutInfo) { + // var s = "Propagating new position/size of node " + node.id; + var parentId = node.parentId; + + if (null == parentId) { + // If there's no parent, we are done + // s += ". No parent node."; + // logDebug(s); + return; + } // Get Parent Node + + + var p = layoutInfo.layoutNodes[layoutInfo.idToIndex[parentId]]; + var flag = false; // MaxX + + if (null == p.maxX || node.maxX + p.padRight > p.maxX) { + p.maxX = node.maxX + p.padRight; + flag = true; // s += "\nNew maxX for parent node " + p.id + ": " + p.maxX; + } // MinX + + + if (null == p.minX || node.minX - p.padLeft < p.minX) { + p.minX = node.minX - p.padLeft; + flag = true; // s += "\nNew minX for parent node " + p.id + ": " + p.minX; + } // MaxY + + + if (null == p.maxY || node.maxY + p.padBottom > p.maxY) { + p.maxY = node.maxY + p.padBottom; + flag = true; // s += "\nNew maxY for parent node " + p.id + ": " + p.maxY; + } // MinY + + + if (null == p.minY || node.minY - p.padTop < p.minY) { + p.minY = node.minY - p.padTop; + flag = true; // s += "\nNew minY for parent node " + p.id + ": " + p.minY; + } // If updated boundaries, propagate changes upward + + + if (flag) { + // logDebug(s); + return updateAncestryBoundaries(p, layoutInfo); + } // s += ". No changes in boundaries/position of parent node " + p.id; + // logDebug(s); + + + return; + }; + + var separateComponents = function separateComponents(layoutInfo, options) { + var nodes = layoutInfo.layoutNodes; + var components = []; + + for (var i = 0; i < nodes.length; i++) { + var node = nodes[i]; + var cid = node.cmptId; + var component = components[cid] = components[cid] || []; + component.push(node); + } + + var totalA = 0; + + for (var i = 0; i < components.length; i++) { + var c = components[i]; + + if (!c) { + continue; + } + + c.x1 = Infinity; + c.x2 = -Infinity; + c.y1 = Infinity; + c.y2 = -Infinity; + + for (var j = 0; j < c.length; j++) { + var n = c[j]; + c.x1 = Math.min(c.x1, n.positionX - n.width / 2); + c.x2 = Math.max(c.x2, n.positionX + n.width / 2); + c.y1 = Math.min(c.y1, n.positionY - n.height / 2); + c.y2 = Math.max(c.y2, n.positionY + n.height / 2); + } + + c.w = c.x2 - c.x1; + c.h = c.y2 - c.y1; + totalA += c.w * c.h; } - nodes.positions(function (ele, i) { - var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[ele.data('id')]]; // s = "Node: " + lnode.id + ". Refreshed position: (" + - // lnode.positionX + ", " + lnode.positionY + ")."; - // logDebug(s); + components.sort(function (c1, c2) { + return c2.w * c2.h - c1.w * c1.h; + }); + var x = 0; + var y = 0; + var usedW = 0; + var rowH = 0; + var maxRowW = Math.sqrt(totalA) * layoutInfo.clientWidth / layoutInfo.clientHeight; - if (options.boundingBox) { - // then add extra bounding box constraint - var pctX = (lnode.positionX - coseBB.x1) / coseBB.w; - var pctY = (lnode.positionY - coseBB.y1) / coseBB.h; - return { - x: bb.x1 + pctX * bb.w, - y: bb.y1 + pctY * bb.h - }; - } else { - return { - x: lnode.positionX, - y: lnode.positionY - }; + for (var i = 0; i < components.length; i++) { + var c = components[i]; + + if (!c) { + continue; } - }); // Trigger layoutReady only on first call - if (true !== layoutInfo.ready) { - // s = 'Triggering layoutready'; - // logDebug(s); - layoutInfo.ready = true; - layout.one('layoutready', options.ready); - layout.emit({ - type: 'layoutready', - layout: this - }); + for (var j = 0; j < c.length; j++) { + var n = c[j]; + + if (!n.isLocked) { + n.positionX += x - c.x1; + n.positionY += y - c.y1; + } + } + + x += c.w + options.componentSpacing; + usedW += c.w + options.componentSpacing; + rowH = Math.max(rowH, c.h); + + if (usedW > maxRowW) { + y += rowH + options.componentSpacing; + x = 0; + usedW = 0; + rowH = 0; + } } }; @@ -20869,9 +20973,9 @@ if (val == null) { return Math.min(rows, cols); } else { - var min$$1 = Math.min(rows, cols); + var min = Math.min(rows, cols); - if (min$$1 == rows) { + if (min == rows) { rows = val; } else { cols = val; @@ -20883,9 +20987,9 @@ if (val == null) { return Math.max(rows, cols); } else { - var max$$1 = Math.max(rows, cols); + var max = Math.max(rows, cols); - if (max$$1 == rows) { + if (max == rows) { rows = val; } else { cols = val; @@ -21702,6 +21806,7 @@ prefixDash = ''; } + var bb = _p.labelBounds[prefix || 'main']; var text = ele.pstyle(prefixDash + 'label').value; var eventsEnabled = ele.pstyle('text-events').strValue === 'yes'; @@ -21710,17 +21815,13 @@ } var rstyle = _p.rstyle; - var bw = ele.pstyle('text-border-width').pfValue; - var pw = ele.pstyle('text-background-padding').pfValue; - var lw = preprop(rstyle, 'labelWidth', prefix) + bw + 2 * th + 2 * pw; - var lh = preprop(rstyle, 'labelHeight', prefix) + bw + 2 * th + 2 * pw; var lx = preprop(rstyle, 'labelX', prefix); var ly = preprop(rstyle, 'labelY', prefix); var theta = preprop(_p.rscratch, 'labelAngle', prefix); - var lx1 = lx - lw / 2; - var lx2 = lx + lw / 2; - var ly1 = ly - lh / 2; - var ly2 = ly + lh / 2; + var lx1 = bb.x1 - th; + var lx2 = bb.x2 + th; + var ly1 = bb.y1 - th; + var ly2 = bb.y2 + th; if (theta) { var cos = Math.cos(theta); @@ -21747,15 +21848,6 @@ } } else { // do a cheaper bb check - var bb = { - w: lw, - h: lh, - x1: lx1, - x2: lx2, - y1: ly1, - y2: ly2 - }; - if (inBoundingBox(bb, x, y)) { addEle(ele); return true; @@ -22532,7 +22624,28 @@ var r = this; var cy = r.cy; var hasCompounds = cy.hasCompoundNodes(); - var hashTable = new Map$1(); + var hashTable = { + map: new Map$1(), + get: function get(pairId) { + var map2 = this.map.get(pairId[0]); + + if (map2 != null) { + return map2.get(pairId[1]); + } else { + return null; + } + }, + set: function set(pairId, val) { + var map2 = this.map.get(pairId[0]); + + if (map2 == null) { + map2 = new Map$1(); + this.map.set(pairId[0], map2); + } + + map2.set(pairId[1], val); + } + }; var pairIds = []; var haystackEdges = []; // create a table of edge (src, tgt) => list of edges between them @@ -22553,13 +22666,11 @@ var edgeIsUnbundled = curveStyle === 'unbundled-bezier' || curveStyle === 'segments' || curveStyle === 'straight' || curveStyle === 'taxi'; var edgeIsBezier = curveStyle === 'unbundled-bezier' || curveStyle === 'bezier'; - - var srcIndex = _p.source.poolIndex(); - - var tgtIndex = _p.target.poolIndex(); - - var hash = (edgeIsUnbundled ? -1 : 1) * hashIntsArray([srcIndex, tgtIndex].sort()); - var pairId = hash; + var src = _p.source; + var tgt = _p.target; + var srcIndex = src.poolIndex(); + var tgtIndex = tgt.poolIndex(); + var pairId = [srcIndex, tgtIndex].sort(); var tableEntry = hashTable.get(pairId); if (tableEntry == null) { @@ -22865,18 +22976,21 @@ var srcArShape = edge.pstyle('source-arrow-shape').value; var tgtDist = edge.pstyle('target-distance-from-node').pfValue; var srcDist = edge.pstyle('source-distance-from-node').pfValue; + var curveStyle = edge.pstyle('curve-style').value; var rs = edge._private.rscratch; var et = rs.edgeType; + var taxi = curveStyle === 'taxi'; var self = et === 'self' || et === 'compound'; var bezier = et === 'bezier' || et === 'multibezier' || self; var multi = et !== 'bezier'; var lines = et === 'straight' || et === 'segments'; var segments = et === 'segments'; var hasEndpts = bezier || multi || lines; + var overrideEndpts = self || taxi; var srcManEndpt = edge.pstyle('source-endpoint'); - var srcManEndptVal = self ? 'outside-to-node' : srcManEndpt.value; + var srcManEndptVal = overrideEndpts ? 'outside-to-node' : srcManEndpt.value; var tgtManEndpt = edge.pstyle('target-endpoint'); - var tgtManEndptVal = self ? 'outside-to-node' : tgtManEndpt.value; + var tgtManEndptVal = overrideEndpts ? 'outside-to-node' : tgtManEndpt.value; rs.srcManEndpt = srcManEndpt; rs.tgtManEndpt = tgtManEndpt; var p1; // last known point of edge on target side @@ -23062,7 +23176,7 @@ var BRp$5 = {}; function pushBezierPts(r, edge, pts) { - var qbezierAt$$1 = function qbezierAt$$1(p1, p2, p3, t) { + var qbezierAt$1 = function qbezierAt$1(p1, p2, p3, t) { return qbezierAt(p1, p2, p3, t); }; @@ -23072,8 +23186,8 @@ for (var i = 0; i < r.bezierProjPcts.length; i++) { var p = r.bezierProjPcts[i]; bpts.push({ - x: qbezierAt$$1(pts[0], pts[2], pts[4], p), - y: qbezierAt$$1(pts[1], pts[3], pts[5], p) + x: qbezierAt$1(pts[0], pts[2], pts[4], p), + y: qbezierAt$1(pts[1], pts[3], pts[5], p) }); } } @@ -23282,21 +23396,21 @@ } // update each ctrlpt with segment info - for (var i = 0; i < ctrlpts.length; i++) { - var cp = ctrlpts[i]; - var prevCp = ctrlpts[i - 1]; + for (var _i = 0; _i < ctrlpts.length; _i++) { + var cp = ctrlpts[_i]; + var prevCp = ctrlpts[_i - 1]; if (prevCp) { cp.startDist = prevCp.startDist + prevCp.length; } - addSegment(cp, cp.p0, bpts[i * nProjs], 0, r.bezierProjPcts[0]); // first + addSegment(cp, cp.p0, bpts[_i * nProjs], 0, r.bezierProjPcts[0]); // first for (var j = 0; j < nProjs - 1; j++) { - addSegment(cp, bpts[i * nProjs + j], bpts[i * nProjs + j + 1], r.bezierProjPcts[j], r.bezierProjPcts[j + 1]); + addSegment(cp, bpts[_i * nProjs + j], bpts[_i * nProjs + j + 1], r.bezierProjPcts[j], r.bezierProjPcts[j + 1]); } - addSegment(cp, bpts[i * nProjs + nProjs - 1], cp.p2, r.bezierProjPcts[nProjs - 1], 1); // last + addSegment(cp, bpts[_i * nProjs + nProjs - 1], cp.p2, r.bezierProjPcts[nProjs - 1], 1); // last } return createControlPointInfo.cache = ctrlpts; @@ -23317,89 +23431,95 @@ case 'compound': case 'bezier': case 'multibezier': - var cps = createControlPointInfo(); - var selected; - var startDist = 0; - var totalDist = 0; // find the segment we're on - - for (var i = 0; i < cps.length; i++) { - var cp = cps[isSrc ? i : cps.length - 1 - i]; - - for (var j = 0; j < cp.segments.length; j++) { - var seg = cp.segments[isSrc ? j : cp.segments.length - 1 - j]; - var lastSeg = i === cps.length - 1 && j === cp.segments.length - 1; - startDist = totalDist; - totalDist += seg.length; - - if (totalDist >= offset || lastSeg) { - selected = { - cp: cp, - segment: seg - }; + { + var cps = createControlPointInfo(); + var selected; + var startDist = 0; + var totalDist = 0; // find the segment we're on + + for (var i = 0; i < cps.length; i++) { + var _cp = cps[isSrc ? i : cps.length - 1 - i]; + + for (var j = 0; j < _cp.segments.length; j++) { + var _seg = _cp.segments[isSrc ? j : _cp.segments.length - 1 - j]; + var lastSeg = i === cps.length - 1 && j === _cp.segments.length - 1; + startDist = totalDist; + totalDist += _seg.length; + + if (totalDist >= offset || lastSeg) { + selected = { + cp: _cp, + segment: _seg + }; + break; + } + } + + if (selected) { break; } } - if (selected) { - break; - } + var cp = selected.cp; + var seg = selected.segment; + var tSegment = (offset - startDist) / seg.length; + var segDt = seg.t1 - seg.t0; + var t = isSrc ? seg.t0 + segDt * tSegment : seg.t1 - segDt * tSegment; + t = bound(0, t, 1); + p = qbezierPtAt(cp.p0, cp.p1, cp.p2, t); + angle = bezierAngle(cp.p0, cp.p1, cp.p2, t); + break; } - var cp = selected.cp; - var seg = selected.segment; - var tSegment = (offset - startDist) / seg.length; - var segDt = seg.t1 - seg.t0; - var t = isSrc ? seg.t0 + segDt * tSegment : seg.t1 - segDt * tSegment; - t = bound(0, t, 1); - p = qbezierPtAt(cp.p0, cp.p1, cp.p2, t); - angle = bezierAngle(cp.p0, cp.p1, cp.p2, t, p); - break; - case 'straight': case 'segments': case 'haystack': - var d = 0, - di, - d0; - var p0, p1; - var l = rs.allpts.length; - - for (var i = 0; i + 3 < l; i += 2) { - if (isSrc) { - p0 = { - x: rs.allpts[i], - y: rs.allpts[i + 1] - }; - p1 = { - x: rs.allpts[i + 2], - y: rs.allpts[i + 3] - }; - } else { - p0 = { - x: rs.allpts[l - 2 - i], - y: rs.allpts[l - 1 - i] - }; - p1 = { - x: rs.allpts[l - 4 - i], - y: rs.allpts[l - 3 - i] - }; - } + { + var d = 0, + di, + d0; + var p0, p1; + var l = rs.allpts.length; + + for (var _i2 = 0; _i2 + 3 < l; _i2 += 2) { + if (isSrc) { + p0 = { + x: rs.allpts[_i2], + y: rs.allpts[_i2 + 1] + }; + p1 = { + x: rs.allpts[_i2 + 2], + y: rs.allpts[_i2 + 3] + }; + } else { + p0 = { + x: rs.allpts[l - 2 - _i2], + y: rs.allpts[l - 1 - _i2] + }; + p1 = { + x: rs.allpts[l - 4 - _i2], + y: rs.allpts[l - 3 - _i2] + }; + } - di = dist(p0, p1); - d0 = d; - d += di; + di = dist(p0, p1); + d0 = d; + d += di; - if (d >= offset) { - break; + if (d >= offset) { + break; + } } - } - var pD = offset - d0; - var t = pD / di; - t = bound(0, t, 1); - p = lineAt(p0, p1, t); - angle = lineAngle(p0, p1); - break; + var pD = offset - d0; + + var _t = pD / di; + + _t = bound(0, _t, 1); + p = lineAt(p0, p1, _t); + angle = lineAngle(p0, p1); + break; + } } setRs('labelX', prefix, p.x); @@ -23425,10 +23545,19 @@ var _p = ele._private; var text = this.getLabelText(ele, prefix); var labelDims = this.calculateLabelDimensions(ele, text); - setPrefixedProperty(_p.rstyle, 'labelWidth', prefix, labelDims.width); - setPrefixedProperty(_p.rscratch, 'labelWidth', prefix, labelDims.width); - setPrefixedProperty(_p.rstyle, 'labelHeight', prefix, labelDims.height); - setPrefixedProperty(_p.rscratch, 'labelHeight', prefix, labelDims.height); + var lineHeight = ele.pstyle('line-height').pfValue; + var textWrap = ele.pstyle('text-wrap').strValue; + var lines = getPrefixedProperty(_p.rscratch, 'labelWrapCachedLines', prefix) || []; + var numLines = textWrap !== 'wrap' ? 1 : Math.max(lines.length, 1); + var normPerLineHeight = labelDims.height / numLines; + var labelLineHeight = normPerLineHeight * lineHeight; + var width = labelDims.width; + var height = labelDims.height + (numLines - 1) * (lineHeight - 1) * normPerLineHeight; + setPrefixedProperty(_p.rstyle, 'labelWidth', prefix, width); + setPrefixedProperty(_p.rscratch, 'labelWidth', prefix, width); + setPrefixedProperty(_p.rstyle, 'labelHeight', prefix, height); + setPrefixedProperty(_p.rscratch, 'labelHeight', prefix, height); + setPrefixedProperty(_p.rscratch, 'labelLineHeight', prefix, labelLineHeight); }; BRp$6.getLabelText = function (ele, prefix) { @@ -23460,48 +23589,54 @@ var wrapStyle = ele.pstyle('text-wrap').value; if (wrapStyle === 'wrap') { - //console.log('wrap'); var labelKey = rscratch('labelKey'); // save recalc if the label is the same as before if (labelKey != null && rscratch('labelWrapKey') === labelKey) { - // console.log('wrap cache hit'); return rscratch('labelWrapCachedText'); - } // console.log('wrap cache miss'); - + } + var zwsp = "\u200B"; var lines = text.split('\n'); var maxW = ele.pstyle('text-max-width').pfValue; + var overflow = ele.pstyle('text-overflow-wrap').value; + var overflowAny = overflow === 'anywhere'; var wrappedLines = []; + var wordsRegex = /[\s\u200b]+/; + var wordSeparator = overflowAny ? '' : ' '; for (var l = 0; l < lines.length; l++) { var line = lines[l]; var lineDims = this.calculateLabelDimensions(ele, line); var lineW = lineDims.width; + if (overflowAny) { + var processedLine = line.split('').join(zwsp); + line = processedLine; + } + if (lineW > maxW) { // line is too long - var words = line.split(/\s+/); // NB: assume collapsed whitespace into single space - + var words = line.split(wordsRegex); var subline = ''; for (var w = 0; w < words.length; w++) { var word = words[w]; - var testLine = subline.length === 0 ? word : subline + ' ' + word; + var testLine = subline.length === 0 ? word : subline + wordSeparator + word; var testDims = this.calculateLabelDimensions(ele, testLine); var testW = testDims.width; if (testW <= maxW) { // word fits on current line - subline += word + ' '; + subline += word + wordSeparator; } else { // word starts new line wrappedLines.push(subline); - subline = word + ' '; + subline = word + wordSeparator; } } // if there's remaining text, put it in a wrapped line - if (!subline.match(/^\s+$/)) { + if (!subline.match(/^[\s\u200b]+$/)) { wrappedLines.push(subline); } } else { @@ -23513,9 +23648,9 @@ rscratch('labelWrapCachedLines', wrappedLines); text = rscratch('labelWrapCachedText', wrappedLines.join('\n')); - rscratch('labelWrapKey', labelKey); // console.log(text) + rscratch('labelWrapKey', labelKey); } else if (wrapStyle === 'ellipsis') { - var maxW = ele.pstyle('text-max-width').pfValue; + var _maxW = ele.pstyle('text-max-width').pfValue; var ellipsized = ''; var ellipsis = "\u2026"; var incLastCh = false; @@ -23523,7 +23658,7 @@ for (var i = 0; i < text.length; i++) { var widthWithNextCh = this.calculateLabelDimensions(ele, ellipsized + text[i] + ellipsis).width; - if (widthWithNextCh > maxW) { + if (widthWithNextCh > _maxW) { break; } @@ -23545,6 +23680,30 @@ return text; }; + BRp$6.getLabelJustification = function (ele) { + var justification = ele.pstyle('text-justification').strValue; + var textHalign = ele.pstyle('text-halign').strValue; + + if (justification === 'auto') { + if (ele.isNode()) { + switch (textHalign) { + case 'left': + return 'right'; + + case 'right': + return 'left'; + + default: + return 'center'; + } + } else { + return 'center'; + } + } else { + return justification; + } + }; + BRp$6.calculateLabelDimensions = function (ele, text) { var r = this; var cacheKey = hashString(text, ele._private.labelDimsKey); @@ -23681,6 +23840,7 @@ var _p = ele._private; var rstyle = _p.rstyle; rstyle.clean = false; + rstyle.cleanConnected = false; } } }; @@ -23699,9 +23859,11 @@ for (var i = 0; i < elesToUpdate.length; i++) { var ele = elesToUpdate[i]; + var rstyle = ele._private.rstyle; - if (ele.isNode() && !ele._private.rstyle.clean) { + if (ele.isNode() && !rstyle.cleanConnected) { enqueue(ele.connectedEdges()); + rstyle.cleanConnected = true; } } @@ -23894,9 +24056,9 @@ }; var BRp$c = {}; - /* global document, window */ + /* global document, window, ResizeObserver, MutationObserver */ - BRp$c.registerBinding = function (target, event$$1, handler, useCapture) { + BRp$c.registerBinding = function (target, event, handler, useCapture) { // eslint-disable-line no-unused-vars var args = Array.prototype.slice.apply(arguments, [1]); // copy @@ -23926,7 +24088,7 @@ r.supportsPassiveEvents = supportsPassive; } - var on = function on(event$$1, handler, useCapture) { + var on = function on(event, handler, useCapture) { var args = Array.prototype.slice.call(arguments); if (tgtIsDom && r.supportsPassiveEvents) { @@ -23991,8 +24153,8 @@ var allowPanningPassthrough = function allowPanningPassthrough(down, downs) { var allowPassthrough = true; - if (r.cy.hasCompoundNodes() && down && down.isEdge()) { - // a compound node below the edge => no passthrough panning + if (r.cy.hasCompoundNodes() && down && down.pannable()) { + // a grabbable compound node below the ele => no passthrough panning for (var i = 0; downs && i < downs.length; i++) { var down = downs[i]; @@ -24149,7 +24311,8 @@ } }; - var haveMutationsApi = typeof MutationObserver !== 'undefined'; // watch for when the cy container is removed from the dom + var haveMutationsApi = typeof MutationObserver !== 'undefined'; + var haveResizeObserverApi = typeof ResizeObserver !== 'undefined'; // watch for when the cy container is removed from the dom if (haveMutationsApi) { r.removeObserver = new MutationObserver(function (mutns) { @@ -24198,9 +24361,15 @@ r.registerBinding(window, 'resize', onResize); // eslint-disable-line no-undef - var forEachUp = function forEachUp(domEle, fn$$1) { + if (haveResizeObserverApi) { + r.resizeObserver = new ResizeObserver(onResize); // eslint-disable-line no-undef + + r.resizeObserver.observe(r.container); + } + + var forEachUp = function forEachUp(domEle, fn) { while (domEle != null) { - fn$$1(domEle); + fn(domEle); domEle = domEle.parentNode; } }; @@ -24409,7 +24578,7 @@ }; r.redrawHint('select', true); r.redraw(); - } else if (near.isEdge()) { + } else if (near.pannable()) { select[4] = 1; // for future pan } @@ -24575,7 +24744,7 @@ pos = r.projectIntoViewport(e.clientX, e.clientY); // Checks primary button down & out of time & mouse not moved much - } else if (select[4] == 1 && (down == null || down.isEdge())) { + } else if (select[4] == 1 && (down == null || down.pannable())) { if (isOverThresholdDrag) { if (!r.hoverData.dragging && cy.boxSelectionEnabled() && (multSelKeyDown || !cy.panningEnabled() || !cy.userPanningEnabled())) { goIntoBoxMode(); @@ -24592,12 +24761,12 @@ } } - if (down && down.isEdge() && down.active()) { + if (down && down.pannable() && down.active()) { down.unactivate(); } } } else { - if (down && down.isEdge() && down.active()) { + if (down && down.pannable() && down.active()) { down.unactivate(); } @@ -25039,6 +25208,7 @@ if (e.touches[1]) { + r.touchData.singleTouchMoved = true; freeDraggedElements(r.dragData.touchDragEles); var offsets = r.findContainerClientCoords(); offsetLeft = offsets[0]; @@ -25107,7 +25277,13 @@ } } - if (e.touches[2]) ; else if (e.touches[1]) ; else if (e.touches[0]) { + if (e.touches[2]) { + // ignore + // safari on ios pans the page otherwise (normally you should be able to preventdefault on touchmove...) + if (cy.boxSelectionEnabled()) { + e.preventDefault(); + } + } else if (e.touches[1]) ; else if (e.touches[0]) { var nears = r.findNearestElements(now[0], now[1], true, true); var near = nears[0]; @@ -25360,7 +25536,8 @@ } r.touchData.selecting = true; - r.redrawHint('select', true); + r.touchData.didSelect = true; + select[4] = 1; if (!select || select.length === 0 || select[0] === undefined) { select[0] = (now[0] + now[2] + now[4]) / 3; @@ -25372,10 +25549,10 @@ select[3] = (now[1] + now[3] + now[5]) / 3; } - select[4] = 1; - r.touchData.selecting = true; + r.redrawHint('select', true); r.redraw(); // pinch to zoom - } else if (capture && e.touches[1] && cy.zoomingEnabled() && cy.panningEnabled() && cy.userZoomingEnabled() && cy.userPanningEnabled()) { + } else if (capture && e.touches[1] && !r.touchData.didSelect // don't allow box selection to degrade to pinch-to-zoom + && cy.zoomingEnabled() && cy.panningEnabled() && cy.userZoomingEnabled() && cy.userPanningEnabled()) { // two fingers => pinch to zoom e.preventDefault(); r.data.bgActivePosistion = undefined; @@ -25474,156 +25651,156 @@ now[4] = pos[0]; now[5] = pos[1]; } - } else if (e.touches[0]) { - var start = r.touchData.start; - var last = r.touchData.last; - var near; + } else if (e.touches[0] && !r.touchData.didSelect // don't allow box selection to degrade to single finger events like panning + ) { + var start = r.touchData.start; + var last = r.touchData.last; + var near; - if (!r.hoverData.draggingEles && !r.swipePanning) { - near = r.findNearestElement(now[0], now[1], true, true); - } + if (!r.hoverData.draggingEles && !r.swipePanning) { + near = r.findNearestElement(now[0], now[1], true, true); + } - if (capture && start != null) { - e.preventDefault(); - } // dragging nodes + if (capture && start != null) { + e.preventDefault(); + } // dragging nodes - if (capture && start != null && r.nodeIsDraggable(start)) { - if (isOverThresholdDrag) { - // then dragging can happen - var draggedEles = r.dragData.touchDragEles; - var justStartedDrag = !r.dragData.didDrag; + if (capture && start != null && r.nodeIsDraggable(start)) { + if (isOverThresholdDrag) { + // then dragging can happen + var draggedEles = r.dragData.touchDragEles; + var justStartedDrag = !r.dragData.didDrag; - if (justStartedDrag) { - addNodesToDrag(draggedEles, { - inDragLayer: true - }); - } + if (justStartedDrag) { + addNodesToDrag(draggedEles, { + inDragLayer: true + }); + } - r.dragData.didDrag = true; - var totalShift = { - x: 0, - y: 0 - }; + r.dragData.didDrag = true; + var totalShift = { + x: 0, + y: 0 + }; - if (number(disp[0]) && number(disp[1])) { - totalShift.x += disp[0]; - totalShift.y += disp[1]; + if (number(disp[0]) && number(disp[1])) { + totalShift.x += disp[0]; + totalShift.y += disp[1]; - if (justStartedDrag) { - r.redrawHint('eles', true); - var dragDelta = r.touchData.dragDelta; + if (justStartedDrag) { + r.redrawHint('eles', true); + var dragDelta = r.touchData.dragDelta; - if (dragDelta && number(dragDelta[0]) && number(dragDelta[1])) { - totalShift.x += dragDelta[0]; - totalShift.y += dragDelta[1]; + if (dragDelta && number(dragDelta[0]) && number(dragDelta[1])) { + totalShift.x += dragDelta[0]; + totalShift.y += dragDelta[1]; + } } } - } - - r.hoverData.draggingEles = true; - draggedEles.silentShift(totalShift).emit('position drag'); - r.redrawHint('drag', true); - if (r.touchData.startPosition[0] == earlier[0] && r.touchData.startPosition[1] == earlier[1]) { - r.redrawHint('eles', true); - } + r.hoverData.draggingEles = true; + draggedEles.silentShift(totalShift).emit('position drag'); + r.redrawHint('drag', true); - r.redraw(); - } else { - // otherise keep track of drag delta for later - var dragDelta = r.touchData.dragDelta = r.touchData.dragDelta || []; + if (r.touchData.startPosition[0] == earlier[0] && r.touchData.startPosition[1] == earlier[1]) { + r.redrawHint('eles', true); + } - if (dragDelta.length === 0) { - dragDelta.push(disp[0]); - dragDelta.push(disp[1]); + r.redraw(); } else { - dragDelta[0] += disp[0]; - dragDelta[1] += disp[1]; + // otherise keep track of drag delta for later + var dragDelta = r.touchData.dragDelta = r.touchData.dragDelta || []; + + if (dragDelta.length === 0) { + dragDelta.push(disp[0]); + dragDelta.push(disp[1]); + } else { + dragDelta[0] += disp[0]; + dragDelta[1] += disp[1]; + } } - } - } // touchmove + } // touchmove - { - triggerEvents(start || near, ['touchmove', 'tapdrag', 'vmousemove'], e, { - x: now[0], - y: now[1] - }); + { + triggerEvents(start || near, ['touchmove', 'tapdrag', 'vmousemove'], e, { + x: now[0], + y: now[1] + }); - if ((!start || !start.grabbed()) && near != last) { - if (last) { - last.emit({ - originalEvent: e, - type: 'tapdragout', - position: { - x: now[0], - y: now[1] - } - }); - } + if ((!start || !start.grabbed()) && near != last) { + if (last) { + last.emit({ + originalEvent: e, + type: 'tapdragout', + position: { + x: now[0], + y: now[1] + } + }); + } - if (near) { - near.emit({ - originalEvent: e, - type: 'tapdragover', - position: { - x: now[0], - y: now[1] - } - }); + if (near) { + near.emit({ + originalEvent: e, + type: 'tapdragover', + position: { + x: now[0], + y: now[1] + } + }); + } } - } - r.touchData.last = near; - } // check to cancel taphold + r.touchData.last = near; + } // check to cancel taphold - if (capture) { - for (var i = 0; i < now.length; i++) { - if (now[i] && r.touchData.startPosition[i] && isOverThresholdDrag) { - r.touchData.singleTouchMoved = true; + if (capture) { + for (var i = 0; i < now.length; i++) { + if (now[i] && r.touchData.startPosition[i] && isOverThresholdDrag) { + r.touchData.singleTouchMoved = true; + } } - } - } // panning + } // panning - if (capture && (start == null || start.isEdge()) && cy.panningEnabled() && cy.userPanningEnabled()) { - var allowPassthrough = allowPanningPassthrough(start, r.touchData.starts); + if (capture && (start == null || start.pannable()) && cy.panningEnabled() && cy.userPanningEnabled()) { + var allowPassthrough = allowPanningPassthrough(start, r.touchData.starts); - if (allowPassthrough) { - e.preventDefault(); + if (allowPassthrough) { + e.preventDefault(); - if (r.swipePanning) { - cy.panBy({ - x: disp[0] * zoom, - y: disp[1] * zoom - }); - } else if (isOverThresholdDrag) { - r.swipePanning = true; - cy.panBy({ - x: dx * zoom, - y: dy * zoom - }); + if (!r.data.bgActivePosistion) { + r.data.bgActivePosistion = array2point(r.touchData.startPosition); + } - if (start) { - start.unactivate(); + if (r.swipePanning) { + cy.panBy({ + x: disp[0] * zoom, + y: disp[1] * zoom + }); + } else if (isOverThresholdDrag) { + r.swipePanning = true; + cy.panBy({ + x: dx * zoom, + y: dy * zoom + }); - if (!r.data.bgActivePosistion) { - r.data.bgActivePosistion = array2point(r.touchData.startPosition); + if (start) { + start.unactivate(); + r.redrawHint('select', true); + r.touchData.start = null; } - - r.redrawHint('select', true); - r.touchData.start = null; } - } - } // Re-project + } // Re-project - var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY); - now[0] = pos[0]; - now[1] = pos[1]; + var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY); + now[0] = pos[0]; + now[1] = pos[1]; + } } - } for (var j = 0; j < now.length; j++) { earlier[j] = now[j]; @@ -25854,15 +26031,21 @@ earlier[j] = now[j]; } - r.dragData.didDrag = false; // reset for next mousedown + r.dragData.didDrag = false; // reset for next touchstart if (e.touches.length === 0) { r.touchData.dragDelta = []; r.touchData.startPosition = null; r.touchData.startGPosition = null; + r.touchData.didSelect = false; } if (e.touches.length < 2) { + if (e.touches.length === 1) { + // the old start global pos'n may not be the same finger that remains + r.touchData.startGPosition = [e.touches[0].clientX, e.touches[0].clientY]; + } + r.pinching = false; r.redrawHint('eles', true); r.redraw(); @@ -26505,10 +26688,10 @@ } if (!stylesheetAlreadyExists) { - var stylesheet$$1 = document.createElement('style'); - stylesheet$$1.id = stylesheetId; - stylesheet$$1.innerHTML = '.' + className + ' { position: relative; }'; - head.insertBefore(stylesheet$$1, head.children[0]); // first so lowest priority + var stylesheet = document.createElement('style'); + stylesheet.id = stylesheetId; + stylesheet.innerHTML = '.' + className + ' { position: relative; }'; + head.insertBefore(stylesheet, head.children[0]); // first so lowest priority } var computedStyle = window$1.getComputedStyle(ctr); @@ -26646,6 +26829,10 @@ r.styleObserver.disconnect(); } + if (r.resizeObserver) { + r.resizeObserver.disconnect(); + } + if (r.labelCalcDiv) { try { document.body.removeChild(r.labelCalcDiv); // eslint-disable-line no-undef @@ -27660,7 +27847,7 @@ var layer = null; var maxElesPerLayer = eles.length / defNumLayers; - var allowLazyQueueing = !firstGet; + var allowLazyQueueing = !firstGet; for (var i = 0; i < eles.length; i++) { var ele = eles[i]; @@ -28167,7 +28354,7 @@ } }; - CRp$1.drawCachedElementPortion = function (context, ele, eleTxrCache, pxRatio, lvl, reason, getRotation) { + CRp$1.drawCachedElementPortion = function (context, ele, eleTxrCache, pxRatio, lvl, reason, getRotation, getOpacity) { var r = this; var bb = eleTxrCache.getBoundingBox(ele); @@ -28179,7 +28366,7 @@ var eleCache = eleTxrCache.getElement(ele, bb, pxRatio, lvl, reason); if (eleCache != null) { - var opacity = ele.effectiveOpacity(); + var opacity = getOpacity(r, ele); if (opacity === 0) { return; @@ -28254,6 +28441,14 @@ return r.getTextAngle(ele, 'target'); }; + var getOpacity = function getOpacity(r, ele) { + return ele.effectiveOpacity(); + }; + + var getTextOpacity = function getTextOpacity(e, ele) { + return ele.pstyle('text-opacity').pfValue * ele.effectiveOpacity(); + }; + CRp$1.drawCachedElement = function (context, ele, pxRatio, extent, lvl, requestHighQuality) { var r = this; var _r$data = r.data, @@ -28269,12 +28464,12 @@ } if (!extent || boundingBoxesIntersect(bb, extent)) { - r.drawCachedElementPortion(context, ele, eleTxrCache, pxRatio, lvl, reason, getZeroRotation); - r.drawCachedElementPortion(context, ele, lblTxrCache, pxRatio, lvl, reason, getLabelRotation); + r.drawCachedElementPortion(context, ele, eleTxrCache, pxRatio, lvl, reason, getZeroRotation, getOpacity); + r.drawCachedElementPortion(context, ele, lblTxrCache, pxRatio, lvl, reason, getLabelRotation, getTextOpacity); if (ele.isEdge()) { - r.drawCachedElementPortion(context, ele, slbTxrCache, pxRatio, lvl, reason, getSourceLabelRotation); - r.drawCachedElementPortion(context, ele, tlbTxrCache, pxRatio, lvl, reason, getTargetLabelRotation); + r.drawCachedElementPortion(context, ele, slbTxrCache, pxRatio, lvl, reason, getSourceLabelRotation, getTextOpacity); + r.drawCachedElementPortion(context, ele, tlbTxrCache, pxRatio, lvl, reason, getTargetLabelRotation, getTextOpacity); } r.drawElementOverlay(context, ele); @@ -28344,7 +28539,7 @@ var r = this; var rs = edge._private.rscratch; - if (!edge.visible()) { + if (shouldDrawOpacity && !edge.visible()) { return; } // if bezier ctrl pts can not be calculated, then die @@ -28695,7 +28890,7 @@ var nodeTW = nodeW + (getIndexedStyle(node, 'background-width-relative-to', 'value', index) === 'inner' ? 0 : paddingX2); var nodeTH = nodeH + (getIndexedStyle(node, 'background-height-relative-to', 'value', index) === 'inner' ? 0 : paddingX2); var rs = node._private.rscratch; - var clip = node.pstyle('background-clip').value; + var clip = getIndexedStyle(node, 'background-clip', 'value', index); var shouldClip = clip === 'node'; var imgOpacity = getIndexedStyle(node, 'background-image-opacity', 'value', index) * nodeOpacity; var imgW = img.width || img.cachedW; @@ -28847,7 +29042,7 @@ var r = this; if (force == null) { - if (!r.eleTextBiggerThanMin(ele)) { + if (useEleOpacity && !r.eleTextBiggerThanMin(ele)) { return; } } else if (force === false) { @@ -28861,29 +29056,16 @@ return; } - var textHalign = ele.pstyle('text-halign').strValue; - - switch (textHalign) { - case 'left': - context.textAlign = 'right'; - break; - - case 'right': - context.textAlign = 'left'; - break; - - default: - // e.g. center - context.textAlign = 'center'; - } - + var justification = r.getLabelJustification(ele); + context.textAlign = justification; context.textBaseline = 'bottom'; } else { - var label = ele.pstyle('label'); + var _label = ele.pstyle('label'); + var srcLabel = ele.pstyle('source-label'); var tgtLabel = ele.pstyle('target-label'); - if ((!label || !label.value) && (!srcLabel || !srcLabel.value) && (!tgtLabel || !tgtLabel.value)) { + if ((!_label || !_label.value) && (!srcLabel || !srcLabel.value) && (!tgtLabel || !tgtLabel.value)) { return; } @@ -28943,7 +29125,7 @@ var labelSize = ele.pstyle('font-size').pfValue + 'px'; var labelFamily = ele.pstyle('font-family').strValue; var labelWeight = ele.pstyle('font-weight').strValue; - var opacity = ele.pstyle('text-opacity').value * (useEleOpacity ? ele.effectiveOpacity() : 1); + var opacity = useEleOpacity ? ele.effectiveOpacity() * ele.pstyle('text-opacity').value : 1; var outlineOpacity = ele.pstyle('text-outline-opacity').value * opacity; var color = ele.pstyle('color').value; var outlineColor = ele.pstyle('text-outline-color').value; @@ -28955,8 +29137,8 @@ }; // TODO ensure re-used - function roundRect(ctx, x, y, width, height, radius) { - var radius = radius || 5; + function roundRect(ctx, x, y, width, height) { + var radius = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 5; ctx.beginPath(); ctx.moveTo(x + radius, y); ctx.lineTo(x + width - radius, y); @@ -28997,7 +29179,7 @@ var rscratch = _p.rscratch; var parentOpacity = useEleOpacity ? ele.effectiveOpacity() : 1; - if (parentOpacity === 0 || ele.pstyle('text-opacity').value === 0) { + if (useEleOpacity && (parentOpacity === 0 || ele.pstyle('text-opacity').value === 0)) { return; } // use 'main' as an alias for the main label (i.e. null prefix) @@ -29008,6 +29190,8 @@ var textX = getPrefixedProperty(rscratch, 'labelX', prefix); var textY = getPrefixedProperty(rscratch, 'labelY', prefix); + var orgTextX, orgTextY; // used for rotation + var text = this.getLabelText(ele, prefix); if (text != null && text !== '' && !isNaN(textX) && !isNaN(textY)) { @@ -29037,8 +29221,8 @@ } if (theta !== 0) { - var orgTextX = textX; - var orgTextY = textY; + orgTextX = textX; + orgTextY = textY; context.translate(orgTextX, orgTextY); context.rotate(theta); textX = 0; @@ -29154,7 +29338,35 @@ if (ele.pstyle('text-wrap').value === 'wrap') { var lines = getPrefixedProperty(rscratch, 'labelWrapCachedLines', prefix); - var lineHeight = textH / lines.length; + var lineHeight = getPrefixedProperty(rscratch, 'labelLineHeight', prefix); + var halfTextW = textW / 2; + var justification = this.getLabelJustification(ele); + + if (justification === 'auto') ; else if (halign === 'left') { + // auto justification : right + if (justification === 'left') { + textX += -textW; + } else if (justification === 'center') { + textX += -halfTextW; + } // else same as auto + + } else if (halign === 'center') { + // auto justfication : center + if (justification === 'left') { + textX += -halfTextW; + } else if (justification === 'right') { + textX += halfTextW; + } // else same as auto + + } else if (halign === 'right') { + // auto justification : left + if (justification === 'center') { + textX += halfTextW; + } else if (justification === 'right') { + textX += textW; + } // else same as auto + + } switch (valign) { case 'top': @@ -29207,7 +29419,7 @@ return; // can't draw node with undefined position } - if (!node.visible()) { + if (shouldDrawOpacity && !node.visible()) { return; } @@ -29598,7 +29810,7 @@ CRp$6.createGradientStyleFor = function (context, shapeStyleName, ele, fill, opacity) { var gradientStyle; var usePaths = this.usePaths(); - var colors$$1 = ele.pstyle(shapeStyleName + '-gradient-stop-colors').value, + var colors = ele.pstyle(shapeStyleName + '-gradient-stop-colors').value, positions = ele.pstyle(shapeStyleName + '-gradient-stop-positions').pfValue; if (fill === 'radial-gradient') { @@ -29678,11 +29890,11 @@ if (!gradientStyle) return null; // invalid gradient style - var hasPositions = positions.length === colors$$1.length; - var length = colors$$1.length; + var hasPositions = positions.length === colors.length; + var length = colors.length; for (var i = 0; i < length; i++) { - gradientStyle.addColorStop(hasPositions ? positions[i] : i / (length - 1), 'rgba(' + colors$$1[i][0] + ',' + colors$$1[i][1] + ',' + colors$$1[i][2] + ',' + opacity + ')'); + gradientStyle.addColorStop(hasPositions ? positions[i] : i / (length - 1), 'rgba(' + colors[i][0] + ',' + colors[i][1] + ',' + colors[i][2] + ',' + opacity + ')'); } return gradientStyle; @@ -30013,7 +30225,7 @@ } var extent = cy.extent(); - var vpManip = r.pinching || r.hoverData.dragging || r.swipePanning || r.data.wheelZooming || r.hoverData.draggingEles; + var vpManip = r.pinching || r.hoverData.dragging || r.swipePanning || r.data.wheelZooming || r.hoverData.draggingEles || r.cy.animated(); var hideEdges = r.hideEdgesOnViewport && vpManip; var needMbClear = []; needMbClear[r.NODE] = !needDraw[r.NODE] && motionBlur && !r.clearedForMotionBlur[r.NODE] || r.clearingMotionBlur; @@ -30533,26 +30745,38 @@ bufferCanvases: new Array(CRp$a.BUFFER_COUNT), bufferContexts: new Array(CRp$a.CANVAS_LAYERS) }; - var tapHlOff = '-webkit-tap-highlight-color: rgba(0,0,0,0);'; + var tapHlOffAttr = '-webkit-tap-highlight-color'; + var tapHlOffStyle = 'rgba(0,0,0,0)'; r.data.canvasContainer = document.createElement('div'); // eslint-disable-line no-undef var containerStyle = r.data.canvasContainer.style; - r.data.canvasContainer.setAttribute('style', tapHlOff); + r.data.canvasContainer.style[tapHlOffAttr] = tapHlOffStyle; containerStyle.position = 'relative'; containerStyle.zIndex = '0'; containerStyle.overflow = 'hidden'; var container = options.cy.container(); container.appendChild(r.data.canvasContainer); + container.style[tapHlOffAttr] = tapHlOffStyle; + var styleMap = { + '-webkit-user-select': 'none', + '-moz-user-select': '-moz-none', + 'user-select': 'none', + '-webkit-tap-highlight-color': 'rgba(0,0,0,0)', + 'outline-style': 'none' + }; - if ((container.getAttribute('style') || '').indexOf(tapHlOff) < 0) { - container.setAttribute('style', (container.getAttribute('style') || '') + tapHlOff); + if (ms()) { + styleMap['-ms-touch-action'] = 'none'; + styleMap['touch-action'] = 'none'; } for (var i = 0; i < CRp$a.CANVAS_LAYERS; i++) { var canvas = r.data.canvases[i] = document.createElement('canvas'); // eslint-disable-line no-undef r.data.contexts[i] = canvas.getContext('2d'); - canvas.setAttribute('style', '-webkit-user-select: none; -moz-user-select: -moz-none; user-select: none; -webkit-tap-highlight-color: rgba(0,0,0,0); outline-style: none;' + (ms() ? ' -ms-touch-action: none; touch-action: none; ' : '')); + Object.keys(styleMap).forEach(function (k) { + canvas.style[k] = styleMap[k]; + }); canvas.style.position = 'absolute'; canvas.setAttribute('data-id', 'layer' + i); canvas.style.zIndex = String(CRp$a.CANVAS_LAYERS - i); @@ -30788,20 +31012,20 @@ tlbTxrCache.onDequeue(refineInLayers); } - CRp$a.redrawHint = function (group, bool$$1) { + CRp$a.redrawHint = function (group, bool) { var r = this; switch (group) { case 'eles': - r.data.canvasNeedsRedraw[CRp$a.NODE] = bool$$1; + r.data.canvasNeedsRedraw[CRp$a.NODE] = bool; break; case 'drag': - r.data.canvasNeedsRedraw[CRp$a.DRAG] = bool$$1; + r.data.canvasNeedsRedraw[CRp$a.DRAG] = bool; break; case 'select': - r.data.canvasNeedsRedraw[CRp$a.SELECT_BOX] = bool$$1; + r.data.canvasNeedsRedraw[CRp$a.SELECT_BOX] = bool; break; } }; // whether to use Path2D caching for drawing @@ -30821,13 +31045,13 @@ return pathsImpld && this.pathsEnabled; }; - CRp$a.setImgSmoothing = function (context, bool$$1) { + CRp$a.setImgSmoothing = function (context, bool) { if (context.imageSmoothingEnabled != null) { - context.imageSmoothingEnabled = bool$$1; + context.imageSmoothingEnabled = bool; } else { - context.webkitImageSmoothingEnabled = bool$$1; - context.mozImageSmoothingEnabled = bool$$1; - context.msImageSmoothingEnabled = bool$$1; + context.webkitImageSmoothingEnabled = bool; + context.mozImageSmoothingEnabled = bool; + context.msImageSmoothingEnabled = bool; } }; @@ -30842,7 +31066,7 @@ CRp$a.makeOffscreenCanvas = function (width, height) { var canvas; - if ((typeof OffscreenCanvas === "undefined" ? "undefined" : _typeof(OffscreenCanvas)) !== ("undefined")) { + if ((typeof OffscreenCanvas === "undefined" ? "undefined" : _typeof(OffscreenCanvas)) !== ( "undefined" )) { canvas = new OffscreenCanvas(width, height); } else { canvas = document.createElement('canvas'); // eslint-disable-line no-undef @@ -31014,6 +31238,10 @@ this.emitter().removeListener(evt, cb); return this; }, + removeAllListeners: function removeAllListeners() { + this.emitter().removeAllListeners(); + return this; + }, emit: function emit(evt, params) { this.emitter().emit(evt, params); return this; @@ -31182,28 +31410,28 @@ sheetfn.style = sheetfn.css; // generate a real style object from the dummy stylesheet sheetfn.generateStyle = function (cy) { - var style$$1 = new Style(cy); - return this.appendToStyle(style$$1); + var style = new Style(cy); + return this.appendToStyle(style); }; // append a dummy stylesheet object on a real style object - sheetfn.appendToStyle = function (style$$1) { + sheetfn.appendToStyle = function (style) { for (var i = 0; i < this.length; i++) { var context = this[i]; var selector = context.selector; var props = context.properties; - style$$1.selector(selector); // apply selector + style.selector(selector); // apply selector for (var j = 0; j < props.length; j++) { var prop = props[j]; - style$$1.css(prop.name, prop.value); // apply property + style.css(prop.name, prop.value); // apply property } } - return style$$1; + return style; }; - var version = "3.5.0"; + var version = "3.9.0"; var cytoscape = function cytoscape(options) { // if no options specified, use default @@ -31230,8 +31458,8 @@ return this; }; - cytoscape.warnings = function (bool$$1) { - return warnings(bool$$1); + cytoscape.warnings = function (bool) { + return warnings(bool); }; // replaced by build system diff --git a/documentation/index.html b/documentation/index.html index 24dc91193c..a40dff1d5b 100644 --- a/documentation/index.html +++ b/documentation/index.html @@ -28,7 +28,7 @@
-

Cytoscape.js

+

Cytoscape.js

Graph theory (network) library for visualisation and analysis @@ -43,12 +43,13 @@

Cytoscape.js

Twitter updates News and tutorials Questions at StackOverflow -Ask a question at StackOverflow +Ask a question at StackOverflow GitHub license DOI +Cite npm Download -Extensions +Extensions npm installs master branch tests unstable branch tests @@ -56,6 +57,7 @@

Cytoscape.js

+

Demos

@@ -177,6 +179,19 @@

Demos + + + + + + + + +
+
+ cy.destroyed() +   +
+ + + +

Get whether the instance of Cytoscape.js has been destroyed or not.

+
+ + +
+
+
+ +

Data

+ + + + +
+
+ cy.data() +             +
+ + +
+ Aliases: + + + cy.attr(), + +
+ +

Read and write developer-defined data associated with the graph.

+
+ +
+
+
cy.data()
+ + +

Get the entire data object.

+
+
    +
+
+
+
cy.data( name )
+ + +

Get a particular data field.

+
+
    +
  • + name + +

    The name of the field to get.

    +
    + +
  • +
+
+
+
cy.data( namevalue )
+ + +

Set a particular data field.

+
+
    +
  • + name + +

    The name of the field to set.

    +
    + +
  • +
  • + value + +

    The value to set for the field.

    +
    + +
  • +
+
+
+
cy.data( obj )
+ + +

Update multiple data fields at once via an object.

+
+
    +
  • + obj + +

    The object containing name-value pairs to update data fields.

    +
    + +
  • +
+
+
+ +
+
+
+
+
+ cy.removeData() +         +
+ + +
+ Aliases: + + + cy.removeAttr(), + +
+ +

Remove developer-defined data associated with the elements.

+
+ +
+
+
cy.removeData()
+ + +

Removes all mutable data fields for the elements.

+
+
    +
+
+
+
cy.removeData( names )
+ + +

Removes the specified mutable data fields for the elements.

+
+
    +
  • + names + +

    A space-separated list of fields to delete.

    +
    + +
  • +
+
+
+ +
+
+
cy.scratch() -         +        
@@ -1829,7 +2119,7 @@

Details

cy.removeScratch() -     +    
@@ -1891,7 +2181,7 @@

Events

-

Listen to events that occur in the graph.

+

Listen to events that occur on the core.

@@ -2016,7 +2306,7 @@

Examples

-

Listen to events that occur in the graph, and run the handler only once.

+

Listen to events that occur on the core, and run the handler only once.

@@ -2092,7 +2382,7 @@

Examples

-

Remove event handlers.

+

Remove event handlers on the core.

@@ -2150,6 +2440,21 @@

Examples

+
+ + + + +

Remove all event handlers on the core.

+
+ + +
+
+
cy.emit() @@ -3751,6 +4056,51 @@

Examples

+

eles.data

+ + +

Details

+

Only JSON-serialisable data may be put in ele.data(). For temporary data or non-serialisable data, use ele.scratch().

+

The following fields are normally immutable:

+
    +
  • id : The id field is used to uniquely identify an element in the graph.
  • +
  • source & target : These fields define an edge’s relationship to nodes, and this relationship can not be changed after creation.
  • +
  • parent : The parent field defines the parent (compound) node.
  • +
+

In order to modify those fields, which alter graph topology, you must use ele.move().

+

Examples

+
var j = cy.$('#j');
+
+// set the weight field in data
+j.data('weight', 60);
+
+// set several fields at once
+j.data({
+  name: 'Jerry Jerry Dingleberry',
+  height: 176
+});
+
+var weight = j.data('weight');
+ + + + +

eles.removeData

+ + +

Details

+

Using ele.removeData() sets the specified fields to undefined. This allows you to use a meaningful null value in your element data.

+

The following data fields are normally immutable, and so they can not be removed:

+
    +
  • id : The id field is used to uniquely identify an element in the graph.
  • +
  • source & target : These fields define an edge’s relationship to nodes, and this relationship can not be changed after creation.
  • +
  • parent : The parent field defines the parent (compound) node.
  • +
+

To modify the topology of the graph without adding or removing elements, you must use ele.move(). Even so, only parent may be removed by ele.move(). An edge always requires a valid source and target.

+ + + +

Layout

@@ -4747,6 +5097,21 @@

Examples

+
+
+ eles.removeAllListeners() +   +
+ + + +

Remove all event handlers on the elements.

+
+ + +
+
+
eles.emit() @@ -5898,7 +6263,7 @@

Examples

-

Get the width of the element.

+

Get the width of the element. The raw width of the element is returned, independent of whether the element is visibile.

@@ -5951,7 +6316,7 @@

Examples

-

Get the height of the element.

+

Get the height of the element. The raw height of the element is returned, independent of whether the element is visibile.

@@ -6069,6 +6434,7 @@

Examples

Details

This function returns a plain object with the fields x1, x2, y1, y2, w, and h defined.

+

An element that does not take up space (e.g. display: none) has a bounding box of zero w and h. The x1, x2, y1, and y2 values will have no meaning for those zero-area elements. To get the position of a display: none node, use node.position() instead.

Note that the includeOverlays option necessarily includes the dimensions of the body of the element. So using includeOverlays: true with includeNodes: false, for example, does not make sense. The case where the includeOverlays option is only useful in getting the non-overlay dimensions of an element, e.g. { includeOverlays: false, includeNodes: true }.

@@ -6143,6 +6509,7 @@

Details

Details

This function returns a plain object with the fields x1, x2, y1, y2, w, and h defined.

+

An element that does not take up space (e.g. display: none) has a bounding box of zero w and h. The x1, x2, y1, and y2 values will have no meaning for those zero-area elements. To get the position of a display: none node, use node.position() instead.

Note that the includeOverlays option necessarily includes the dimensions of the body of the element. So using includeOverlays: true with includeNodes: false, for example, does not make sense. The case where the includeOverlays option is only useful in getting the non-overlay dimensions of an element, e.g. { includeOverlays: false, includeNodes: true }.

@@ -6279,6 +6646,61 @@

Examples

+
+
+ ele.pannable() +   +
+ + + +

Gets whether the element allows passthrough panning.

+
+ + +
+

Description

+

A pannable element allows passthrough panning: The user can pan the graph when dragging on the element. Thus, a pannable element is necessarily ungrabbable.

+

By default, an edge is pannable and a node is not pannable.

+ +
+
+
+
+ eles.panify() +   +
+ + + +

Enables passthrough panning on the elements.

+
+ + +
+

Examples

+
cy.$('#j').panify();
+ +
+
+
+
+ eles.unpanify() +   +
+ + + +

Disables passthrough panning on the elements.

+
+ + +
+

Examples

+
cy.$('#j').unpanify();
+ +
+

Edge points

@@ -6530,10 +6952,17 @@

Layout layout object. You may want to keep a reference to the layout for more advanced usecases, such as running multiple layouts simultaneously.

Note that you must call layout.run() in order for it to affect the graph.

Examples

+

Assign random positions to all nodes:

var layout = cy.elements().layout({
   name: 'random'
 });
 
+layout.run();
+

Apply a circle layout to only the shown elements:

+
var layout = cy.elements().not(':invisible, :transparent').layout({
+  name: 'circle'
+});
+
 layout.run();
@@ -6909,7 +7338,7 @@

Examples

eles.classes() et al -           +          
@@ -6929,7 +7358,7 @@

Examples

-
ele.classes()()
+
ele.classes()

Get the list of classes as an array for the element.

@@ -6938,7 +7367,7 @@

Examples

-
eles.classes()( classes )
+
eles.classes( classes )

Replace the list of classes for all elements in the collection.

@@ -6958,9 +7387,11 @@

Examples

Examples

Remove all classes:

-
cy.nodes().classes(); // no classes
+
cy.nodes().classes([]); // array
+cy.nodes().classes(''); // space-separated string

Replace classes:

-
cy.nodes().classes('foo');
+
cy.nodes().classes(['foo']); // array
+cy.nodes().classes('foo'); // space-separated string
@@ -10401,7 +10832,7 @@

Examples

  • weight: function(edge) [optional] -

    A function that returns the positive numeric weight for the edge.

    +

    A function that returns the positive numeric weight for the edge. The weight indicates the cost of going from one node to another node.

  • @@ -10479,7 +10910,7 @@

    Examples

  • weight: function(edge) [optional] -

    A function that returns the positive numeric weight for the edge.

    +

    A function that returns the positive numeric weight for the edge. The weight indicates the cost of going from one node to another node.

  • @@ -10551,7 +10982,7 @@

    Examples

  • weight: function(edge) [optional] -

    A function that returns the positive numeric weight for the edge.

    +

    A function that returns the numeric weight for the edge. The weight indicates the cost of going from one node to another node. The weight may be positive or negative, but no negative cycles are allowed.

  • @@ -10622,7 +11053,7 @@

    Examples

  • weight: function(edge) [optional] -

    A function that returns the positive numeric weight for the edge.

    +

    A function that returns the numeric weight for the edge. The weight indicates the cost of going from one node to another node. The weight may be positive or negative.

  • @@ -10786,7 +11217,7 @@

    Centrality weight: function(edge) [optional] -

    A function that returns the weight for the edge.

    +

    A function that returns the positive weight for the edge. The weight indicates the importance of the edge, with a high value representing high importance.

    @@ -10863,7 +11294,7 @@

    Details

  • weight: function(edge) [optional] -

    A function that returns the weight for the edge.

    +

    A function that returns the positive weight for the edge. The weight indicates the importance of the edge, with a high value representing high importance.

  • @@ -10949,7 +11380,7 @@

    Details

  • weight: function(edge) [optional] -

    A function that returns the weight for the edge.

    +

    A function that returns the positive weight for the edge. The weight indicates the importance of the edge, with a high value representing high importance.

  • @@ -11018,7 +11449,7 @@

    Examples

  • weight: function(edge) [optional] -

    A function that returns the weight for the edge.

    +

    A function that returns the positive weight for the edge. The weight indicates the importance of the edge, with a high value representing high importance.

  • @@ -11089,7 +11520,7 @@

    Details

  • weight: function(edge) [optional] -

    A function that returns the weight for the edge.

    +

    A function that returns the positive weight for the edge. The weight indicates the importance of the edge, with a high value representing high importance.

  • @@ -11381,30 +11812,10 @@

    Examples

    getQAt(i)

    A function that returns the ith value of the q vector.

    -
    - -
  • - nodeP - [optional] -

    An optionally-used reference to the node associated with the p attribute vector. It is useful for affecting the weights with information outside of the attributes, such as connectivity.

    -
    -
  • -
  • - nodeQ - [optional] -

    An optionally-used reference to the node associated with the q attribute vector. It is useful for affecting the weights with information outside of the attributes, such as connectivity.

  • -
  • - function( nodeP, nodeQ ) - -

    A custom function that returns the distance between nodeP and nodeQ. This allows for specifying the distance matrix directly, forgoing attributes.

    -
    -
  • - -
  • maxIterations @@ -11707,30 +12118,10 @@

    Examples

    getQAt(i)

    A function that returns the ith value of the q vector.

    -
    -
  • -
  • - nodeP - [optional] -

    An optionally-used reference to the node associated with the p attribute vector. It is useful for affecting the weights with information outside of the attributes, such as connectivity.

    -
    -
  • -
  • - nodeQ - [optional] -

    An optionally-used reference to the node associated with the q attribute vector. It is useful for affecting the weights with information outside of the attributes, such as connectivity.

  • -
  • - function( nodeP, nodeQ ) - -

    A custom function that returns the distance between nodeP and nodeQ. This allows for specifying the distance matrix directly, forgoing attributes.

    -
    -
  • - -
  • maxIterations @@ -12516,8 +12907,10 @@

    Notes & caveats

    It is important to note that strings need to be enclosed by quotation marks:

    //cy.filter('node[name = Jerry]'); // this doesn't work
     cy.filter('node[name = "Jerry"]'); // but this does
    -

    Note that metacharacters ( ^ $ \ / ( ) | ? + * [ ] { } , . ) need to be escaped:

    +

    Note that some characters need to be escaped for IDs, field names, and so on:

    cy.filter('#some\\$funky\\@id');
    +

    Some examples of these characters include ( ^ $ \ / ( ) | ? + * [ ] { } , . ). Try to avoid using non-alpha-numeric characters for field names and IDs to keep things simple. If you must use special characters for IDs, use a data selector rather than an ID selector:

    +
    cy.filter('[id = "some$funky@id"]');

    Group, class, & ID

    node, edge, or * (group selector) Matches elements based on group (node for nodes, edge for edges, * for all).

    @@ -12858,25 +13251,28 @@

    Background image var makeSvg = memoize( function(ele){ -// impl... - -return { svg: s, width: w, height: h }; -} ); -

  • - -

    // …

    -

    // init stylesheet -style: [ - { - selector: ‘node’, - style: {

    -
     'background-image': function(ele){ return makeSvg(ele).svg; },
    - 'width': function(ele){ return makeSvg(ele).width; },
    - 'height': function(ele){ return makeSvg(ele).height; }

    } - } -] -```

    +
    var makeSvg = memoize(function(ele){
    +  // impl...
    +
    +  return { svg: s, width: w, height: h };
    +});
    +//
    +// ...
    +//
    +// init stylesheet
    +var options = {
    +  style: [
    +    {
    +      selector: 'node',
    +      style: {
    +        'background-image': function(ele){ return makeSvg(ele).svg; },
    +        'width': function(ele){ return makeSvg(ele).width; },
    +        'height': function(ele){ return makeSvg(ele).height; }
    +      }
    +    }
    +  ]
    +};
    + @@ -12904,10 +13300,11 @@

    Background image Background image 4874.svg/1000px-Pigeon_silhouette_4874.svg.png' ], 'background-fit': 'cover cover', - `background-image-opacity`: 0.5 + 'background-image-opacity': 0.5 }

    Pie chart background

    These properties allow you to create pie chart backgrounds on nodes (demo). Note that 16 slices maximum are supported per node, so in the properties 1 <= i <= 16. Of course, you must specify a numerical value for each property in place of i. Each nonzero sized slice is placed in order of i, starting from the 12 o’clock position and working clockwise.

    You may find it useful to reserve a number to a particular colour for all nodes in your stylesheet. Then you can specify values for pie-i-background-size accordingly for each node via a mapper. This would allow you to create consistently coloured pie charts in each node of the graph based on element data.

    @@ -12993,6 +13390,7 @@

    Taxi edges taxicab geometry). The edge has a primary direction along either the x-axis or y-axis, which can be used to bundle edges in a hierarchy. That is, taxi edges are appropriate for trees and DAGs that are laid out in a hierarchical manner.

    A taxi edge has at most two visible turns: Starting from the source node, the edge goes in the primary direction for the specified distance. The edge then turns, going towards the target along the secondary axis. The first turn can be specified in order to bundle the edges of outgoing nodes. The second turn is implicit, based on the first turn, going the remaining distance along the main axis.

    When a taxi edge would be impossible to draw along the regular turning plan — i.e. one or more turns is too close the source or target — it is re-routed. The re-routing is carried out on a best-effort basis: Re-routing prioritises the specified direction for bundling over the specified turn distance. A downward edge, for example, will avoid going in the upward direction where possible. In practice, re-routing should not take place for graphs that are well laid out.

    +

    Only outside-to-node endpoints are supported for a taxi edge, i.e. source-endpoint: outside-to-node and target-endpoint: outside-to-node.

    +
    +
    +
    +
    +
    + layout.removeAllListeners() +   +
    + + + +

    Remove all event handlers on the layout.

    +
    + +
    @@ -14444,6 +14864,7 @@

    Extensions denotes a third-party extension, one that is maintained by outside developers.

    UI extensions

      +
    • anywhere-panning : Allow panning when dragging on nodes or edges.
    • automove : Automatically update node positions based on specified rules (e.g. synching node movements, constraining movements, etc.)
    • autopan-on-drag : Automatically pan the viewport when nodes are dragged outside of the viewport bounds.
    • canvas : An extension to create a canvas over or under a Cytoscape graph. Useful for customizing nodes/edges, drawing backgrounds, etc.
    • @@ -14472,11 +14893,14 @@

      UI extensions Layout extensions

        -
      • arbor : The Arbor physics simulation layout. It’s a basic physics layout.
      • cola : The Cola.js physics simulation layout. Cola makes beautiful layout results, it animates very smoothly, and it has great options for controlling the layout.
      • -
      • cose-bilkent : The CoSE layout by Bilkent with enhanced compound node placement. CoSE Bilkent gives near-perfect end results. However, it’s more expensive than the version of CoSE directly included with Cytoscape.js.
      • +
      • avsdf : The AVSDF layout. It organises nodes in a circle and tries to minimise edge crossings as much as possible.
      • +
      • cise : The CiSE layout creates circular clusters and uses a physics simulation to create distance between the clusters.
      • +
      • cose-bilkent : The CoSE layout by Bilkent with enhanced compound node placement. CoSE Bilkent gives near-perfect end results. However, it’s more expensive than both cose and fcose.
      • dagre : The Dagre layout for DAGs and trees.
      • +
      • elk : ELK layout algorithm adapter for Cytoscape.js.
      • euler : Euler is a fast, small file-size, high-quality force-directed (physics simulation) layout. It is excellent for non-compound graphs, and it has basic support for compound graphs.
      • +
      • fcose : The fCoSE layout is a faster version of the CoSE-Bilkent layout. It supports compound and non-compound graphs, giving top-tier end results and high performance for a force-directed layout.
      • klay : Klay is a layout that works well for most types of graphs. It gives good results for ordinary graphs, and it handles DAGs and compound graphs very nicely.
      • ngraph.forcelayout : A physics simulation layout that works particularly well on planar graphs. It is relatively fast.
      • polywas : A layout for GWAS (genome-wide association study) data illustrating inter-locus relationships.
      • @@ -14487,12 +14911,21 @@

        API extensions all-paths : Gets all longest, directed paths.
      • clipboard : Adds copy-paste utilities to Cytoscape.js.
      • +
      • dblclick : Adds a dblclick event to Cytoscape.js.
      • graphml : Adds GraphML import and export functionality to Cytoscape.js.
      • -
      • sbgn-stylesheet : A stylesheet preset for SBGN.
      • -
      • sbgnml-to-cytoscape : Converts XML-based SBGN files to Cytoscape.js JSON.
      • undo-redo : Adds undo-redo APIs to Cytoscape.js.
      • view-utilities : Adds search and highlight APIs to Cytoscape.js.
      +

      Utility packages

      +

      Registration

      To register an extension, make the following call: cytoscape( type, name, extension );

      The value of type can take on the following values:

      @@ -14729,6 +15162,17 @@

      Optimisations cy.mount()

    + +
    + + + + + Data +
    + + +
    @@ -14743,6 +15187,7 @@

    Optimisations cy.promiseOn()

    +
    @@ -14791,6 +15236,16 @@

    Optimisations cy.delayAnimation()

    +
    + + eles.data +
    + + +
    @@ -14856,6 +15311,7 @@

    Optimisations eles.one()

    +
    @@ -14911,6 +15367,9 @@

    Optimisations nodes.lock()

    + + +
    @@ -15407,6 +15866,7 @@

    Optimisations layout.promiseOn()

    +
    @@ -15457,6 +15917,11 @@

    Optimisations API extensions

    + +
    Registration diff --git a/documentation/js/cytoscape.min.js b/documentation/js/cytoscape.min.js index 056d225459..2239a01fdc 100644 --- a/documentation/js/cytoscape.min.js +++ b/documentation/js/cytoscape.min.js @@ -20,4 +20,4 @@ * SOFTWARE. */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).cytoscape=t()}(this,function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;nt?1:0},I=null!=Object.assign?Object.assign.bind(Object):function(e){for(var t=arguments,n=1;n255)return;t.push(Math.floor(a))}var o=r[1]||r[2]||r[3],s=r[1]&&r[2]&&r[3];if(o&&!s)return;var l=n[4];if(void 0!==l){if((l=parseFloat(l))<0||l>1)return;t.push(l)}}return t}(e)||function(e){var t,n,r,i,a,o,s,l;function u(e,t,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?e+6*(t-e)*n:n<.5?t:n<2/3?e+(t-e)*(2/3-n)*6:e}var c=new RegExp("^hsl[a]?\\(((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?)))\\s*,\\s*((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?))[%])\\s*,\\s*((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?))[%])(?:\\s*,\\s*((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?))))?\\)$").exec(e);if(c){if((n=parseInt(c[1]))<0?n=(360- -1*n%360)%360:n>360&&(n%=360),n/=360,(r=parseFloat(c[2]))<0||r>100)return;if(r/=100,(i=parseFloat(c[3]))<0||i>100)return;if(i/=100,void 0!==(a=c[4])&&((a=parseFloat(a))<0||a>1))return;if(0===r)o=s=l=Math.round(255*i);else{var h=i<.5?i*(1+r):i+r-i*r,d=2*i-h;o=Math.round(255*u(d,h,n+1/3)),s=Math.round(255*u(d,h,n)),l=Math.round(255*u(d,h,n-1/3))}t=[o,s,l,a]}return t}(e)},A={transparent:[0,0,0,0],aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],grey:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},L=function(e){for(var t=e.map,n=e.keys,r=n.length,i=0;i=t||n<0||h&&e-u>=a}function g(){var e=J();if(f(e))return v(e);s=setTimeout(g,function(e){var n=t-(e-l);return h?Q(n,a-(e-u)):n}(e))}function v(e){return s=void 0,d&&r?p(e):(r=i=void 0,o)}function y(){var e=J(),n=f(e);if(r=arguments,i=this,l=e,n){if(void 0===s)return function(e){return u=e,s=setTimeout(g,t),c?p(e):o}(l);if(h)return s=setTimeout(g,t),p(l)}return void 0===s&&(s=setTimeout(g,t)),o}return t=te(t)||0,ee(n)&&(c=!!n.leading,a=(h="maxWait"in n)?$(te(n.maxWait)||0,t):a,d="trailing"in n?!!n.trailing:d),y.cancel=function(){void 0!==s&&clearTimeout(s),u=0,r=l=i=s=void 0},y.flush=function(){return void 0===s?o:v(J())},y},re=a?a.performance:null,ie=re&&re.now?function(){return re.now()}:function(){return Date.now()},ae=function(){if(a){if(a.requestAnimationFrame)return function(e){a.requestAnimationFrame(e)};if(a.mozRequestAnimationFrame)return function(e){a.mozRequestAnimationFrame(e)};if(a.webkitRequestAnimationFrame)return function(e){a.webkitRequestAnimationFrame(e)};if(a.msRequestAnimationFrame)return function(e){a.msRequestAnimationFrame(e)}}return function(e){e&&setTimeout(function(){e(ie())},1e3/60)}}(),oe=function(e){return ae(e)},se=ie,le=function(e){for(var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5381;!(t=e.next()).done;)n=33*n^t.value;return n>>>0},ue=function(e){return(33*(arguments.length>1&&void 0!==arguments[1]?arguments[1]:5381)^e)>>>0},ce=function(e,t){var n={value:0,done:!1},r=0,i=e.length;return le({next:function(){return r=0&&(e[r]!==t||(e.splice(r,1),n));r--);},Be=function(e){e.splice(0,e.length)},Ne=function(e,t,n){return n&&(t=M(n,t)),e[t]},Ie=function(e,t,n,r){n&&(t=M(n,t)),e[t]=r},ze="undefined"!=typeof Map?Map:function(){function e(){t(this,e),this._obj={}}return r(e,[{key:"set",value:function(e,t){return this._obj[e]=t,this}},{key:"delete",value:function(e){return this._obj[e]=void 0,this}},{key:"clear",value:function(){this._obj={}}},{key:"has",value:function(e){return void 0!==this._obj[e]}},{key:"get",value:function(e){return this._obj[e]}}]),e}(),Ae=function(){function e(n){if(t(this,e),this._obj=Object.create(null),this.size=0,null!=n){var r;r=null!=n.instanceString&&n.instanceString()===this.instanceString()?n.toArray():n;for(var i=0;it?1:0},u=function(e,t,i,a,o){var s;if(null==i&&(i=0),null==o&&(o=n),i<0)throw new Error("lo must be non-negative");for(null==a&&(a=e.length);in;0<=n?t++:t--)u.push(t);return u}.apply(this).reverse()).length;ag;0<=g?++d:--d)v.push(a(e,r));return v},f=function(e,t,r,i){var a,o,s;for(null==i&&(i=n),a=e[r];r>t&&i(a,o=e[s=r-1>>1])<0;)e[r]=o,r=s;return e[r]=a},g=function(e,t,r){var i,a,o,s,l;for(null==r&&(r=n),a=e.length,l=t,o=e[t],i=2*t+1;i0;){var k=b.pop(),C=y(k),S=k.id();if(h[S]=C,C!==1/0)for(var D=k.neighborhood().intersect(f),P=0;P0)for(n.unshift(t);c[i];){var a=c[i];n.unshift(a.edge),n.unshift(a.node),i=(r=a.node).id()}return o.spawn(n)}}}},Xe={kruskal:function(e){e=e||function(e){return 1};for(var t=this.byGroup(),n=t.nodes,r=t.edges,i=n.length,a=new Array(i),o=n,s=function(e){for(var t=0;t0;){if(l=g.pop(),u=l.id(),v.delete(u),w++,u===h){for(var E=[],k=i,C=h,S=m[C];E.unshift(k),null!=S&&E.unshift(S),null!=(k=y[C]);)S=m[C=k.id()];return{found:!0,distance:d[u],path:this.spawn(E),steps:w}}f[u]=!0;for(var D=l._private.edges,P=0;PP&&(f[D]=P,m[D]=S,b[D]=w),!i){var T=S*u+C;!i&&f[T]>P&&(f[T]=P,m[T]=C,b[T]=w)}}}for(var M=0;M1&&void 0!==arguments[1]?arguments[1]:a,r=[],i=m(e);;){if(null==i)return t.spawn();var o=y(i),l=o.edge,u=o.pred;if(r.unshift(i[0]),i.same(n)&&r.length>0)break;null!=l&&r.unshift(l),i=u}return s.spawn(r)},hasNegativeWeightCycle:g,negativeWeightCycles:[]}}},Ue=Math.sqrt(2),$e=function(e,t,n){0===n.length&&Ee("Karger-Stein must be run on a connected (sub)graph");for(var r=n[e],i=r[1],a=r[2],o=t[i],s=t[a],l=n,u=l.length-1;u>=0;u--){var c=l[u],h=c[1],d=c[2];(t[h]===o&&t[d]===s||t[h]===s&&t[d]===o)&&l.splice(u,1)}for(var p=0;pr;){var i=Math.floor(Math.random()*t.length);t=$e(i,e,t),n--}return t},Je={kargerStein:function(){var e=this.byGroup(),t=e.nodes,n=e.edges;n.unmergeBy(function(e){return e.isLoop()});var r=t.length,i=n.length,a=Math.ceil(Math.pow(Math.log(r)/Math.LN2,2)),o=Math.floor(r/Ue);if(!(r<2)){for(var s=[],l=0;l0?1:e<0?-1:0},st=function(e,t){return Math.sqrt(lt(e,t))},lt=function(e,t){var n=t.x-e.x,r=t.y-e.y;return n*n+r*r},ut=function(e){for(var t=e.length,n=0,r=0;r=e.x1&&e.y2>=e.y1)return{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,w:e.x2-e.x1,h:e.y2-e.y1};if(null!=e.w&&null!=e.h&&e.w>=0&&e.h>=0)return{x1:e.x1,y1:e.y1,x2:e.x1+e.w,y2:e.y1+e.h,w:e.w,h:e.h}}},ft=function(e,t,n){e.x1=Math.min(e.x1,t),e.x2=Math.max(e.x2,t),e.w=e.x2-e.x1,e.y1=Math.min(e.y1,n),e.y2=Math.max(e.y2,n),e.h=e.y2-e.y1},gt=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return e.x1-=t,e.x2+=t,e.y1-=t,e.y2+=t,e.w=e.x2-e.x1,e.h=e.y2-e.y1,e},vt=function(e,t){e.x1=t.x1,e.y1=t.y1,e.x2=t.x2,e.y2=t.y2,e.w=e.x2-e.x1,e.h=e.y2-e.y1},yt=function(e,t){e.x1+=t.x,e.x2+=t.x,e.y1+=t.y,e.y2+=t.y},mt=function(e,t){return!(e.x1>t.x2)&&(!(t.x1>e.x2)&&(!(e.x2t.y2)&&!(t.y1>e.y2)))))))},bt=function(e,t,n){return e.x1<=t&&t<=e.x2&&e.y1<=n&&n<=e.y2},xt=function(e,t){return bt(e,t.x1,t.y1)&&bt(e,t.x2,t.y2)},wt=function(e,t,n,r,i,a,o){var s,l=Ft(i,a),u=i/2,c=a/2,h=r-c-o;if((s=It(e,t,n,r,n-u+l-o,h,n+u-l+o,h,!1)).length>0)return s;var d=n+u+o;if((s=It(e,t,n,r,d,r-c+l-o,d,r+c-l+o,!1)).length>0)return s;var p=r+c+o;if((s=It(e,t,n,r,n-u+l-o,p,n+u-l+o,p,!1)).length>0)return s;var f,g=n-u-o;if((s=It(e,t,n,r,g,r-c+l-o,g,r+c-l+o,!1)).length>0)return s;var v=n-u+l,y=r-c+l;if((f=Bt(e,t,n,r,v,y,l+o)).length>0&&f[0]<=v&&f[1]<=y)return[f[0],f[1]];var m=n+u-l,b=r-c+l;if((f=Bt(e,t,n,r,m,b,l+o)).length>0&&f[0]>=m&&f[1]<=b)return[f[0],f[1]];var x=n+u-l,w=r+c-l;if((f=Bt(e,t,n,r,x,w,l+o)).length>0&&f[0]>=x&&f[1]>=w)return[f[0],f[1]];var E=n-u+l,k=r+c-l;return(f=Bt(e,t,n,r,E,k,l+o)).length>0&&f[0]<=E&&f[1]>=k?[f[0],f[1]]:[]},Et=function(e,t,n,r,i,a,o){var s=o,l=Math.min(n,i),u=Math.max(n,i),c=Math.min(r,a),h=Math.max(r,a);return l-s<=e&&e<=u+s&&c-s<=t&&t<=h+s},kt=function(e,t,n,r,i,a,o,s,l){var u=Math.min(n,o,i)-l,c=Math.max(n,o,i)+l,h=Math.min(r,s,a)-l,d=Math.max(r,s,a)+l;return!(ec||td)},Ct=function(e,t,n,r,i,a,o,s){var l=[];!function(e,t,n,r,i){var a,o,s,l,u,c,h,d;s=-27*(r/=e)+(t/=e)*(9*(n/=e)-t*t*2),a=(o=(3*n-t*t)/9)*o*o+(s/=54)*s,i[1]=0,h=t/3,a>0?(u=(u=s+Math.sqrt(a))<0?-Math.pow(-u,1/3):Math.pow(u,1/3),c=(c=s-Math.sqrt(a))<0?-Math.pow(-c,1/3):Math.pow(c,1/3),i[0]=-h+u+c,h+=(u+c)/2,i[4]=i[2]=-h,h=Math.sqrt(3)*(-c+u)/2,i[3]=h,i[5]=-h):(i[5]=i[3]=0,0===a?(d=s<0?-Math.pow(-s,1/3):Math.pow(s,1/3),i[0]=2*d-h,i[4]=i[2]=-(d+h)):(l=(o=-o)*o*o,l=Math.acos(s/Math.sqrt(l)),d=2*Math.sqrt(o),i[0]=-h+d*Math.cos(l/3),i[2]=-h+d*Math.cos((l+2*Math.PI)/3),i[4]=-h+d*Math.cos((l+4*Math.PI)/3)))}(1*n*n-4*n*i+2*n*o+4*i*i-4*i*o+o*o+r*r-4*r*a+2*r*s+4*a*a-4*a*s+s*s,9*n*i-3*n*n-3*n*o-6*i*i+3*i*o+9*r*a-3*r*r-3*r*s-6*a*a+3*a*s,3*n*n-6*n*i+n*o-n*e+2*i*i+2*i*e-o*e+3*r*r-6*r*a+r*s-r*t+2*a*a+2*a*t-s*t,1*n*i-n*n+n*e-i*e+r*a-r*r+r*t-a*t,l);for(var u=[],c=0;c<6;c+=2)Math.abs(l[c+1])<1e-7&&l[c]>=0&&l[c]<=1&&u.push(l[c]);u.push(1),u.push(0);for(var h,d,p,f=-1,g=0;g=0?pl?(e-i)*(e-i)+(t-a)*(t-a):u-h},Dt=function(e,t,n){for(var r,i,a,o,s=0,l=0;l=e&&e>=a||r<=e&&e<=a))continue;(e-r)/(a-r)*(o-i)+i>t&&s++}return s%2!=0},Pt=function(e,t,n,r,i,a,o,s,l){var u,c=new Array(n.length);null!=s[0]?(u=Math.atan(s[1]/s[0]),s[0]<0?u+=Math.PI/2:u=-u-Math.PI/2):u=s;for(var h,d=Math.cos(-u),p=Math.sin(-u),f=0;f0){var g=Mt(c,-l);h=Tt(g)}else h=c;return Dt(e,t,h)},Tt=function(e){for(var t,n,r,i,a,o,s,l,u=new Array(e.length/2),c=0;c=0&&f<=1&&v.push(f),g>=0&&g<=1&&v.push(g),0===v.length)return[];var y=v[0]*s[0]+e,m=v[0]*s[1]+t;return v.length>1?v[0]==v[1]?[y,m]:[y,m,v[1]*s[0]+e,v[1]*s[1]+t]:[y,m]},Nt=function(e,t,n){return t<=e&&e<=n||n<=e&&e<=t?e:e<=t&&t<=n||n<=t&&t<=e?t:n},It=function(e,t,n,r,i,a,o,s,l){var u=e-i,c=n-e,h=o-i,d=t-a,p=r-t,f=s-a,g=h*d-f*u,v=c*d-p*u,y=f*c-h*p;if(0!==y){var m=g/y,b=v/y;return-.001<=m&&m<=1.001&&-.001<=b&&b<=1.001?[e+m*c,t+m*p]:l?[e+m*c,t+m*p]:[]}return 0===g||0===v?Nt(e,n,o)===o?[o,s]:Nt(e,n,i)===i?[i,a]:Nt(i,o,n)===n?[n,r]:[]:[]},zt=function(e,t,n,r,i,a,o,s){var l,u,c,h,d,p,f=[],g=new Array(n.length),v=!0;if(null==a&&(v=!1),v){for(var y=0;y0){var m=Mt(g,-s);u=Tt(m)}else u=g}else u=n;for(var b=0;bu&&(u=t)},h=function(e){return l[e]},d=0;d0?b.edgesTo(m)[0]:m.edgesTo(b)[0];var w=r(x);m=m.id(),d[m]>d[v]+w&&(d[m]=d[v]+w,p.nodes.indexOf(m)<0?p.push(m):p.updateItem(m),u[m]=0,l[m]=[]),d[m]==d[v]+w&&(u[m]=u[m]+u[v],l[m].push(v))}else for(var E=0;E0;)for(var D=n.pop(),P=0;P0&&o.push(n[s]);0!==o.length&&i.push(r.collection(o))}return i}(c,l,t,r);return b=function(e){for(var t=0;t5&&void 0!==arguments[5]?arguments[5]:on,o=r,s=0;s=2?dn(e,t,n,0,un,cn):dn(e,t,n,0,ln)},squaredEuclidean:function(e,t,n){return dn(e,t,n,0,un)},manhattan:function(e,t,n){return dn(e,t,n,0,ln)},max:function(e,t,n){return dn(e,t,n,-1/0,hn)}};function fn(e,t,n,r,i,a){var o;return o=p(e)?e:pn[e]||pn.euclidean,0===t&&p(e)?o(i,a):o(t,n,r,i,a)}pn["squared-euclidean"]=pn.squaredEuclidean,pn.squaredeuclidean=pn.squaredEuclidean;var gn=Me({k:2,m:2,sensitivityThreshold:1e-4,distance:"euclidean",maxIterations:10,attributes:[],testMode:!1,testCentroids:null}),vn=function(e){return gn(e)},yn=function(e,t,n,r,i){var a="kMedoids"===i?function(e){return r[e](n)}:function(e){return n[e]};return fn(e,r.length,a,function(e){return r[e](t)})},mn=function(e,t,n){for(var r=n.length,i=new Array(r),a=new Array(r),o=new Array(t),s=null,l=0;ln)return!1}return!0},En=function(e,t,n){for(var r=0;ri&&(i=t[l][u],a=u);o[a].push(e[l])}for(var c=0;c=i.threshold||"dendrogram"===i.mode&&1===e.length)return!1;var p,f=t[o],g=t[r[o]];p="dendrogram"===i.mode?{left:f,right:g,key:f.key}:{value:f.value.concat(g.value),key:f.key},e[f.index]=p,e.splice(g.index,1),t[f.key]=p;for(var v=0;vn[g.key][y.key]&&(a=n[g.key][y.key])):"max"===i.linkage?(a=n[f.key][y.key],n[f.key][y.key]1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],a=!(arguments.length>5&&void 0!==arguments[5])||arguments[5];r?e=e.slice(t,n):(n0&&e.splice(0,t));for(var o=0,s=e.length-1;s>=0;s--){var l=e[s];a?isFinite(l)||(e[s]=-1/0,o++):e.splice(s,1)}i&&e.sort(function(e,t){return e-t});var u=e.length,c=Math.floor(u/2);return u%2!=0?e[c+1+o]:(e[c-1+o]+e[c+o])/2}(e):"mean"===t?function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=0,i=0,a=t;a1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=1/0,i=t;i1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=-1/0,i=t;io&&(a=l,o=t[i*e+l])}a>0&&r.push(a)}for(var u=0;u=P?(T=P,P=_,M=B):_>T&&(T=_);for(var N=0;N0?1:0;C[k%u.minIterations*t+R]=F,O+=F}if(O>0&&(k>=u.minIterations-1||k==u.maxIterations-1)){for(var V=0,q=0;q0&&r.push(i);return r}(t,a,o),j=function(e,t,n){for(var r=Rn(e,t,n),i=0;il&&(s=u,l=c)}n[i]=a[s]}return r=Rn(e,t,n)}(t,r,X),W={},H=0;H0:void 0}},clearQueue:function(){return function(){var e=void 0!==this.length?this:[this];if(!(this._private.cy||this).styleEnabled())return this;for(var t=0;t0&&this.spawn(n).updateStyle().emit("class"),this},addClass:function(e){return this.toggleClass(e,!0)},hasClass:function(e){var t=this[0];return null!=t&&t._private.classes.has(e)},toggleClass:function(e,t){f(e)||(e=e.match(/\S+/g)||[]);for(var n=void 0===t,r=[],i=0,a=this.length;i0&&this.spawn(r).updateStyle().emit("class"),this},removeClass:function(e){return this.toggleClass(e,!1)},flashClass:function(e,t){var n=this;if(null==t)t=250;else if(0===t)return n;return n.addClass(e),setTimeout(function(){n.removeClass(e)},t),n}};Qn.className=Qn.classNames=Qn.classes;var Jn={metaChar:"[\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\]\\^\\`\\{\\|\\}\\~]",comparatorOp:"=|\\!=|>|>=|<|<=|\\$=|\\^=|\\*=",boolOp:"\\?|\\!|\\^",string:'"(?:\\\\"|[^"])*"|'+"'(?:\\\\'|[^'])*'",number:B,meta:"degree|indegree|outdegree",separator:"\\s*,\\s*",descendant:"\\s+",child:"\\s+>\\s+",subject:"\\$",group:"node|edge|\\*",directedEdge:"\\s+->\\s+",undirectedEdge:"\\s+<->\\s+"};Jn.variable="(?:[\\w-]|(?:\\\\"+Jn.metaChar+"))+",Jn.value=Jn.string+"|"+Jn.number,Jn.className=Jn.variable,Jn.id=Jn.variable,function(){var e,t,n;for(e=Jn.comparatorOp.split("|"),n=0;n=0||"="!==t&&(Jn.comparatorOp+="|\\!"+t)}();var er=0,tr=1,nr=2,rr=3,ir=4,ar=5,or=6,sr=7,lr=8,ur=9,cr=10,hr=11,dr=12,pr=13,fr=14,gr=15,vr=16,yr=17,mr=18,br=19,xr=20,wr=[{selector:":selected",matches:function(e){return e.selected()}},{selector:":unselected",matches:function(e){return!e.selected()}},{selector:":selectable",matches:function(e){return e.selectable()}},{selector:":unselectable",matches:function(e){return!e.selectable()}},{selector:":locked",matches:function(e){return e.locked()}},{selector:":unlocked",matches:function(e){return!e.locked()}},{selector:":visible",matches:function(e){return e.visible()}},{selector:":hidden",matches:function(e){return!e.visible()}},{selector:":transparent",matches:function(e){return e.transparent()}},{selector:":grabbed",matches:function(e){return e.grabbed()}},{selector:":free",matches:function(e){return!e.grabbed()}},{selector:":removed",matches:function(e){return e.removed()}},{selector:":inside",matches:function(e){return!e.removed()}},{selector:":grabbable",matches:function(e){return e.grabbable()}},{selector:":ungrabbable",matches:function(e){return!e.grabbable()}},{selector:":animated",matches:function(e){return e.animated()}},{selector:":unanimated",matches:function(e){return!e.animated()}},{selector:":parent",matches:function(e){return e.isParent()}},{selector:":childless",matches:function(e){return e.isChildless()}},{selector:":child",matches:function(e){return e.isChild()}},{selector:":orphan",matches:function(e){return e.isOrphan()}},{selector:":nonorphan",matches:function(e){return e.isChild()}},{selector:":compound",matches:function(e){return e.isNode()?e.isParent():e.source().isParent()||e.target().isParent()}},{selector:":loop",matches:function(e){return e.isLoop()}},{selector:":simple",matches:function(e){return e.isSimple()}},{selector:":active",matches:function(e){return e.active()}},{selector:":inactive",matches:function(e){return!e.active()}},{selector:":backgrounding",matches:function(e){return e.backgrounding()}},{selector:":nonbackgrounding",matches:function(e){return!e.backgrounding()}}].sort(function(e,t){return function(e,t){return-1*N(e,t)}(e.selector,t.selector)}),Er=function(){for(var e,t={},n=0;n0&&l.edgeCount>0)return Ce("The selector `"+e+"` is invalid because it uses both a compound selector and an edge selector"),!1;if(l.edgeCount>1)return Ce("The selector `"+e+"` is invalid because it uses multiple edge selectors"),!1;1===l.edgeCount&&Ce("The selector `"+e+"` is deprecated. Edge selectors do not take effect on changes to source and target nodes after an edge is added, for performance reasons. Use a class or data selector on edges instead, updating the class or data of an edge when your app detects a change in source or target nodes.")}return!0},toString:function(){if(null!=this.toStringCache)return this.toStringCache;for(var e=function(e){return null==e?"":e},t=function(t){return d(t)?'"'+t+'"':e(t)},n=function(e){return" "+e+" "},r=function(r,a){var o=r.type,s=r.value;switch(o){case er:var l=e(s);return l.substring(0,l.length-1);case rr:var u=r.field,c=r.operator;return"["+u+n(e(c))+t(s)+"]";case ar:var h=r.operator,d=r.field;return"["+e(h)+d+"]";case ir:return"["+r.field+"]";case or:var p=r.operator;return"[["+r.field+n(e(p))+t(s)+"]]";case sr:return s;case lr:return"#"+s;case ur:return"."+s;case yr:case gr:return i(r.parent,a)+n(">")+i(r.child,a);case mr:case vr:return i(r.ancestor,a)+" "+i(r.descendant,a);case br:var f=i(r.left,a),g=i(r.subject,a),v=i(r.right,a);return f+(f.length>0?" ":"")+g+v;case xr:return""}},i=function(e,t){return e.checks.reduce(function(n,i,a){return n+(t===e&&0===a?"$":"")+r(i,t)},"")},a="",o=0;o1&&o=0&&(t=t.replace("!",""),c=!0),t.indexOf("@")>=0&&(t=t.replace("@",""),u=!0),(o||l||u)&&(i=o||s?""+e:"",a=""+n),u&&(e=i=i.toLowerCase(),n=a=a.toLowerCase()),t){case"*=":r=i.indexOf(a)>=0;break;case"$=":r=i.indexOf(a,i.length-a.length)>=0;break;case"^=":r=0===i.indexOf(a);break;case"=":r=e===n;break;case">":h=!0,r=e>n;break;case">=":h=!0,r=e>=n;break;case"<":h=!0,r=e0;){var u=i.shift();t(u),a.add(u.id()),o&&r(i,a,u)}return e}function qr(e,t,n){if(n.isParent())for(var r=n._private.children,i=0;i1&&void 0!==arguments[1])||arguments[1],qr)},Fr.forEachUp=function(e){return Vr(this,e,!(arguments.length>1&&void 0!==arguments[1])||arguments[1],Yr)},Fr.forEachUpAndDown=function(e){return Vr(this,e,!(arguments.length>1&&void 0!==arguments[1])||arguments[1],Xr)},Fr.ancestors=Fr.parents,(Lr=Or={data:Un.data({field:"data",bindingEvent:"data",allowBinding:!0,allowSetting:!0,settingEvent:"data",settingTriggersEvent:!0,triggerFnName:"trigger",allowGetting:!0,immutableKeys:{id:!0,source:!0,target:!0,parent:!0},updateStyle:!0}),removeData:Un.removeData({field:"data",event:"data",triggerFnName:"trigger",triggerEvent:!0,immutableKeys:{id:!0,source:!0,target:!0,parent:!0},updateStyle:!0}),scratch:Un.data({field:"scratch",bindingEvent:"scratch",allowBinding:!0,allowSetting:!0,settingEvent:"scratch",settingTriggersEvent:!0,triggerFnName:"trigger",allowGetting:!0,updateStyle:!0}),removeScratch:Un.removeData({field:"scratch",event:"scratch",triggerFnName:"trigger",triggerEvent:!0,updateStyle:!0}),rscratch:Un.data({field:"rscratch",allowBinding:!1,allowSetting:!0,settingTriggersEvent:!1,allowGetting:!0}),removeRscratch:Un.removeData({field:"rscratch",triggerEvent:!1}),id:function(){var e=this[0];if(e)return e._private.data.id}}).attr=Lr.data,Lr.removeAttr=Lr.removeData;var jr,Wr,Hr=Or,Kr={};function Gr(e){return function(t){if(void 0===t&&(t=!0),0!==this.length&&this.isNode()&&!this.removed()){for(var n=0,r=this[0],i=r._private.edges,a=0;at}),minIndegree:Zr("indegree",function(e,t){return et}),minOutdegree:Zr("outdegree",function(e,t){return et})}),I(Kr,{totalDegree:function(e){for(var t=0,n=this.nodes(),r=0;r0,c=u;u&&(l=l[0]);var h=c?l.position():{x:0,y:0};return i={x:s.x-h.x,y:s.y-h.y},void 0===e?i:i[e]}for(var p=0;p0,m=y;y&&(v=v[0]);var b=m?v.position():{x:0,y:0};void 0!==t?f.position(e,t+b[e]):void 0!==i&&f.position({x:i.x+b.x,y:i.y+b.y})}}else if(!a)return;return this}}).modelPosition=jr.point=jr.position,jr.modelPositions=jr.points=jr.positions,jr.renderedPoint=jr.renderedPosition,jr.relativePoint=jr.relativePosition;var Qr,Jr,ei=Wr;Qr=Jr={},Jr.renderedBoundingBox=function(e){var t=this.boundingBox(e),n=this.cy(),r=n.zoom(),i=n.pan(),a=t.x1*r+i.x,o=t.x2*r+i.x,s=t.y1*r+i.y,l=t.y2*r+i.y;return{x1:a,x2:o,y1:s,y2:l,w:o-a,h:l-s}},Jr.dirtyCompoundBoundsCache=function(){var e=this.cy();return e.styleEnabled()&&e.hasCompoundNodes()?(this.forEachUp(function(e){if(e.isParent()){var t=e._private;t.compoundBoundsClean=!1,t.bbCache=null,e.emitAndNotify("bounds")}}),this):this},Jr.updateCompoundBounds=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.cy();if(!t.styleEnabled()||!t.hasCompoundNodes())return this;if(!e&&t.batching())return this;function n(e){if(e.isParent()){var t=e._private,n=e.children(),r="include"===e.pstyle("compound-sizing-wrt-labels").value,i={width:{val:e.pstyle("min-width").pfValue,left:e.pstyle("min-width-bias-left"),right:e.pstyle("min-width-bias-right")},height:{val:e.pstyle("min-height").pfValue,top:e.pstyle("min-height-bias-top"),bottom:e.pstyle("min-height-bias-bottom")}},a=n.boundingBox({includeLabels:r,includeOverlays:!1,useCache:!1}),o=t.position;0!==a.w&&0!==a.h||((a={w:e.pstyle("width").pfValue,h:e.pstyle("height").pfValue}).x1=o.x-a.w/2,a.x2=o.x+a.w/2,a.y1=o.y-a.h/2,a.y2=o.y+a.h/2);var s=i.width.left.value;"px"===i.width.left.units&&i.width.val>0&&(s=100*s/i.width.val);var l=i.width.right.value;"px"===i.width.right.units&&i.width.val>0&&(l=100*l/i.width.val);var u=i.height.top.value;"px"===i.height.top.units&&i.height.val>0&&(u=100*u/i.height.val);var c=i.height.bottom.value;"px"===i.height.bottom.units&&i.height.val>0&&(c=100*c/i.height.val);var h=y(i.width.val-a.w,s,l),d=h.biasDiff,p=h.biasComplementDiff,f=y(i.height.val-a.h,u,c),g=f.biasDiff,v=f.biasComplementDiff;t.autoPadding=function(e,t,n,r){if("%"!==n.units)return"px"===n.units?n.pfValue:0;switch(r){case"width":return e>0?n.pfValue*e:0;case"height":return t>0?n.pfValue*t:0;case"average":return e>0&&t>0?n.pfValue*(e+t)/2:0;case"min":return e>0&&t>0?e>t?n.pfValue*t:n.pfValue*e:0;case"max":return e>0&&t>0?e>t?n.pfValue*e:n.pfValue*t:0;default:return 0}}(a.w,a.h,e.pstyle("padding"),e.pstyle("padding-relative-to").value),t.autoWidth=Math.max(a.w,i.width.val),o.x=(-d+a.x1+a.x2+p)/2,t.autoHeight=Math.max(a.h,i.height.val),o.y=(-g+a.y1+a.y2+v)/2}function y(e,t,n){var r=0,i=0,a=t+n;return e>0&&a>0&&(r=t/a*e,i=n/a*e),{biasDiff:r,biasComplementDiff:i}}}for(var r=0;re.x2?r:e.x2,e.y1=ne.y2?i:e.y2,e.w=e.x2-e.x1,e.h=e.y2-e.y1)},ri=function(e,t){return ni(e,t.x1,t.y1,t.x2,t.y2)},ii=function(e,t,n){return Ne(e,t,n)},ai=function(e,t,n){if(!t.cy().headless()){var r,i,a=t._private,o=a.rstyle,s=o.arrowWidth/2;if("none"!==t.pstyle(n+"-arrow-shape").value){"source"===n?(r=o.srcX,i=o.srcY):"target"===n?(r=o.tgtX,i=o.tgtY):(r=o.midX,i=o.midY);var l=a.arrowBounds=a.arrowBounds||{},u=l[n]=l[n]||{};u.x1=r-s,u.y1=i-s,u.x2=r+s,u.y2=i+s,u.w=u.x2-u.x1,u.h=u.y2-u.y1,gt(u,1),ni(e,u.x1,u.y1,u.x2,u.y2)}}},oi=function(e,t,n){if(!t.cy().headless()){var r;r=n?n+"-":"";var i=t._private,a=i.rstyle;if(t.pstyle(r+"label").strValue){var o,s,l,u,c=t.pstyle("text-halign"),h=t.pstyle("text-valign"),d=ii(a,"labelWidth",n),p=ii(a,"labelHeight",n),f=ii(a,"labelX",n),g=ii(a,"labelY",n),v=t.pstyle(r+"text-margin-x").pfValue,y=t.pstyle(r+"text-margin-y").pfValue,m=t.isEdge(),b=t.pstyle(r+"text-rotation"),x=t.pstyle("text-outline-width").pfValue,w=t.pstyle("text-border-width").pfValue/2,E=t.pstyle("text-background-padding").pfValue,k=p+2*E,C=d+2*E,S=C/2,D=k/2;if(m)o=f-S,s=f+S,l=g-D,u=g+D;else{switch(c.value){case"left":o=f-C,s=f;break;case"center":o=f-S,s=f+S;break;case"right":o=f,s=f+C}switch(h.value){case"top":l=g-k,u=g;break;case"center":l=g-D,u=g+D;break;case"bottom":l=g,u=g+k}}o+=v-Math.max(x,w),s+=v+Math.max(x,w),l+=y-Math.max(x,w),u+=y+Math.max(x,w);var P=n||"main",T=i.labelBounds,M=T[P]=T[P]||{};M.x1=o,M.y1=l,M.x2=s,M.y2=u,M.w=s-o,M.h=u-l,gt(M,1);var _=m&&"autorotate"===b.strValue,B=null!=b.pfValue&&0!==b.pfValue;if(_||B){var N=_?ii(i.rstyle,"labelAngle",n):b.pfValue,I=Math.cos(N),z=Math.sin(N),A=(o+s)/2,L=(l+u)/2;if(!m){switch(c.value){case"left":A=s;break;case"right":A=o}switch(h.value){case"top":L=u;break;case"bottom":L=l}}var O=function(e,t){return{x:(e-=A)*I-(t-=L)*z+A,y:e*z+t*I+L}},R=O(o,l),F=O(o,u),V=O(s,l),q=O(s,u);o=Math.min(R.x,F.x,V.x,q.x),s=Math.max(R.x,F.x,V.x,q.x),l=Math.min(R.y,F.y,V.y,q.y),u=Math.max(R.y,F.y,V.y,q.y)}ni(e,o,l,s,u),ni(i.labelBounds.all,o,l,s,u)}return e}},si=function(e){var t=0,n=function(e){return(e?1:0)<(r=S[1].x)){var D=n;n=r,r=D}if(i>(a=S[1].y)){var P=i;i=a,a=P}ni(d,n-w,i-w,r+w,a+w)}else{for(var T=m.bezierPts||m.linePts||[],M=0;M(r=N.x)){var I=n;n=r,r=I}if((i=B.y)>(a=N.y)){var z=i;i=a,a=z}ni(d,n-=w,i-=w,r+=w,a+=w)}}if(c&&t.includeEdges&&v&&(ai(d,e,"mid-source"),ai(d,e,"mid-target"),ai(d,e,"source"),ai(d,e,"target")),c&&"yes"===e.pstyle("ghost").value){var A=e.pstyle("ghost-offset-x").pfValue,L=e.pstyle("ghost-offset-y").pfValue;ni(d,d.x1+A,d.y1+L,d.x2+A,d.y2+L)}var O=p.bodyBounds=p.bodyBounds||{};vt(O,d),gt(O,b),gt(O,1),c&&(n=d.x1,r=d.x2,i=d.y1,a=d.y2,ni(d,n-x,i-x,r+x,a+x));var R=p.overlayBounds=p.overlayBounds||{};vt(R,d),gt(R,b),gt(R,1);var F=p.labelBounds=p.labelBounds||{};null!=F.all?((l=F.all).x1=1/0,l.y1=1/0,l.x2=-1/0,l.y2=-1/0,l.w=0,l.h=0):F.all=pt(),c&&t.includeLabels&&(oi(d,e,null),v&&(oi(d,e,"source"),oi(d,e,"target")))}return d.x1=ti(d.x1),d.y1=ti(d.y1),d.x2=ti(d.x2),d.y2=ti(d.y2),d.w=ti(d.x2-d.x1),d.h=ti(d.y2-d.y1),d.w>0&&d.h>0&&y&&(gt(d,b),gt(d,1)),d}(e,ci),r.bbCache=n,r.bbCacheShift.x=r.bbCacheShift.y=0,r.bbCachePosKey=a):n=r.bbCache,!s&&(0!==r.bbCacheShift.x||0!==r.bbCacheShift.y)){var l=yt,u=r.bbCacheShift,c=function(e,t){null!=e&&l(e,t)};l(n,u);var h=r.bodyBounds,d=r.overlayBounds,p=r.labelBounds,f=r.arrowBounds;c(h,u),c(d,u),null!=f&&(c(f.source,u),c(f.target,u),c(f["mid-source"],u),c(f["mid-target"],u)),null!=p&&(c(p.main,u),c(p.all,u),c(p.source,u),c(p.target,u))}if(r.bbCacheShift.x=r.bbCacheShift.y=0,!i){var g=e.isNode();n=pt(),(t.includeNodes&&g||t.includeEdges&&!g)&&(t.includeOverlays?ri(n,r.overlayBounds):ri(n,r.bodyBounds)),t.includeLabels&&ri(n,r.labelBounds.all),n.w=n.x2-n.x1,n.h=n.y2-n.y1}return n},ci={includeNodes:!0,includeEdges:!0,includeLabels:!0,includeOverlays:!0,useCache:!0},hi=si(ci),di=Me(ci);Jr.boundingBox=function(e){if(1===this.length&&null!=this[0]._private.bbCache&&(void 0===e||void 0===e.useCache||!0===e.useCache))return e=void 0===e?ci:di(e),ui(this[0],e);var t=pt(),n=di(e=e||ci);if(this.cy().styleEnabled())for(var r=0;r=0;s--)o(s);return this},Ti.emit=Ti.trigger=function(e,t,n){var r=this.listeners,i=r.length;return this.emitting++,f(t)||(t=[t]),Bi(this,function(e,a){null!=n&&(r=[{event:a.event,type:a.type,namespace:a.namespace,callback:n}],i=r.length);for(var o=function(n){var i=r[n];if(i.type===a.type&&(!i.namespace||i.namespace===a.namespace||".*"===i.namespace)&&e.eventMatches(e.context,i,a)){var o=[a];null!=t&&function(e,t){for(var n=0;n1&&!r){var i=this.length-1,a=this[i],o=a._private.data.id;this[i]=void 0,this[e]=a,n.set(o,{ele:a,index:e})}return this.length--,this},unmergeOne:function(e){e=e[0];var t=this._private,n=e._private.data.id,r=t.map.get(n);if(!r)return this;var i=r.index;return this.unmergeAt(i),this},unmerge:function(e){var t=this._private.cy;if(!e)return this;if(e&&d(e)){var n=e;e=t.mutableElements().filter(n)}for(var r=0;r=0;t--){e(this[t])&&this.unmergeAt(t)}return this},map:function(e,t){for(var n=[],r=0;rr&&(r=o,n=a)}return{value:r,ele:n}},min:function(e,t){for(var n,r=1/0,i=0;i=0&&i1&&void 0!==arguments[1])||arguments[1],n=this[0],r=n.cy();if(r.styleEnabled()&&n){var i=n._private.style[e];return null!=i?i:t?r.style().getDefaultProperty(e):null}},numericStyle:function(e){var t=this[0];if(t.cy().styleEnabled()&&t){var n=t.pstyle(e);return void 0!==n.pfValue?n.pfValue:n.value}},numericStyleUnits:function(e){var t=this[0];if(t.cy().styleEnabled())return t?t.pstyle(e).units:void 0},renderedStyle:function(e){var t=this.cy();if(!t.styleEnabled())return this;var n=this[0];return n?t.style().getRenderedStyle(n,e):void 0},style:function(e,t){var n=this.cy();if(!n.styleEnabled())return this;var r=n.style();if(g(e)){var i=e;r.applyBypass(this,i,!1),this.emitAndNotify("style")}else if(d(e)){if(void 0===t){var a=this[0];return a?r.getStylePropertyValue(a,e):void 0}r.applyBypass(this,e,t,!1),this.emitAndNotify("style")}else if(void 0===e){var o=this[0];return o?r.getRawStyle(o):void 0}return this},removeStyle:function(e){var t=this.cy();if(!t.styleEnabled())return this;var n=t.style();if(void 0===e)for(var r=0;r0&&t.push(c[0]),t.push(s[0])}return this.spawn(t,{unique:!0}).filter(e)},"neighborhood"),closedNeighborhood:function(e){return this.neighborhood().add(this).filter(e)},openNeighborhood:function(e){return this.neighborhood(e)}}),ta.neighbourhood=ta.neighborhood,ta.closedNeighbourhood=ta.closedNeighborhood,ta.openNeighbourhood=ta.openNeighborhood,I(ta,{source:Rr(function(e){var t,n=this[0];return n&&(t=n._private.source||n.cy().collection()),t&&e?t.filter(e):t},"source"),target:Rr(function(e){var t,n=this[0];return n&&(t=n._private.target||n.cy().collection()),t&&e?t.filter(e):t},"target"),sources:aa({attr:"source"}),targets:aa({attr:"target"})}),I(ta,{edgesWith:Rr(oa(),"edgesWith"),edgesTo:Rr(oa({thisIsSrc:!0}),"edgesTo")}),I(ta,{connectedEdges:Rr(function(e){for(var t=[],n=0;n0);return a},component:function(){var e=this[0];return e.cy().mutableElements().components(e)[0]}}),ta.componentsOf=ta.components;var la=function(e,t,n){for(var r=null!=n?n:De();e.hasElementWithId(r);)r=De();return r},ua=function(e,t,n){if(void 0!==e&&w(e)){var r=new ze,i=!1;if(t){if(t.length>0&&g(t[0])&&!b(t[0])){i=!0;for(var a=[],o=new Le,s=0,l=t.length;s0&&void 0!==arguments[0])||arguments[0],r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],i=this.cy(),a=i._private,o=[],s=[],l=0,u=this.length;l0){for(var L=new ua(i,e),O=0;O0&&void 0!==arguments[0])||arguments[0],t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=[],r={},i=this._private.cy;function a(e){var i=r[e.id()];t&&e.removed()||i||(r[e.id()]=!0,e.isNode()?(n.push(e),function(e){for(var t=e._private.edges,n=0;n0&&(e?E.emitAndNotify("remove"):t&&E.emit("remove"));for(var k=0;k=a?function(t,r){for(var a=0;a0?i=l:r=l}while(Math.abs(a)>o&&++u1e-4&&Math.abs(s.v)>1e-4;);return a?function(e){return u[e*(u.length-1)|0]}:c}}(),fa=function(e,t,n,r){var i=da(e,t,n,r);return function(e,t,n){return e+(t-e)*i(n)}},ga={linear:function(e,t,n){return e+(t-e)*n},ease:fa(.25,.1,.25,1),"ease-in":fa(.42,0,1,1),"ease-out":fa(0,0,.58,1),"ease-in-out":fa(.42,0,.58,1),"ease-in-sine":fa(.47,0,.745,.715),"ease-out-sine":fa(.39,.575,.565,1),"ease-in-out-sine":fa(.445,.05,.55,.95),"ease-in-quad":fa(.55,.085,.68,.53),"ease-out-quad":fa(.25,.46,.45,.94),"ease-in-out-quad":fa(.455,.03,.515,.955),"ease-in-cubic":fa(.55,.055,.675,.19),"ease-out-cubic":fa(.215,.61,.355,1),"ease-in-out-cubic":fa(.645,.045,.355,1),"ease-in-quart":fa(.895,.03,.685,.22),"ease-out-quart":fa(.165,.84,.44,1),"ease-in-out-quart":fa(.77,0,.175,1),"ease-in-quint":fa(.755,.05,.855,.06),"ease-out-quint":fa(.23,1,.32,1),"ease-in-out-quint":fa(.86,0,.07,1),"ease-in-expo":fa(.95,.05,.795,.035),"ease-out-expo":fa(.19,1,.22,1),"ease-in-out-expo":fa(1,0,0,1),"ease-in-circ":fa(.6,.04,.98,.335),"ease-out-circ":fa(.075,.82,.165,1),"ease-in-out-circ":fa(.785,.135,.15,.86),spring:function(e,t,n){if(0===n)return ga.linear;var r=pa(e,t,n);return function(e,t,n){return e+(t-e)*r(n)}},"cubic-bezier":fa};function va(e,t,n,r,i){if(1===r)return n;var a=i(t,n,r);return null==e?a:((e.roundValue||e.color)&&(a=Math.round(a)),void 0!==e.min&&(a=Math.max(a,e.min)),void 0!==e.max&&(a=Math.min(a,e.max)),a)}function ya(e,t){return null!=e.pfValue||null!=e.value?null==e.pfValue||null!=t&&"%"===t.type.units?e.value:e.pfValue:e}function ma(e,t,n,r,i){var a=null!=i?i.type:null;n<0?n=0:n>1&&(n=1);var o=ya(e,i),s=ya(t,i);if(v(o)&&v(s))return va(a,o,s,n,r);if(f(o)&&f(s)){for(var l=[],u=0;u0?("spring"===h&&p.push(o.duration),o.easingImpl=ga[h].apply(null,p)):o.easingImpl=ga[h]}var f,g=o.easingImpl;if(f=0===o.duration?1:(n-l)/o.duration,o.applying&&(f=o.progress),f<0?f=0:f>1&&(f=1),null==o.delay){var v=o.startPosition,y=o.position;if(y&&i&&!e.locked()){var m={};xa(v.x,y.x)&&(m.x=ma(v.x,y.x,f,g)),xa(v.y,y.y)&&(m.y=ma(v.y,y.y,f,g)),e.position(m)}var b=o.startPan,x=o.pan,w=a.pan,E=null!=x&&r;E&&(xa(b.x,x.x)&&(w.x=ma(b.x,x.x,f,g)),xa(b.y,x.y)&&(w.y=ma(b.y,x.y,f,g)),e.emit("pan"));var k=o.startZoom,C=o.zoom,S=null!=C&&r;S&&(xa(k,C)&&(a.zoom=ma(k,C,f,g)),e.emit("zoom")),(E||S)&&e.emit("viewport");var D=o.style;if(D&&D.length>0&&i){for(var P=0;P=0;t--){(0,e[t])()}e.splice(0,e.length)},h=a.length-1;h>=0;h--){var d=a[h],p=d._private;p.stopped?(a.splice(h,1),p.hooked=!1,p.playing=!1,p.started=!1,c(p.frames)):(p.playing||p.applying)&&(p.playing&&p.applying&&(p.applying=!1),p.started||wa(0,d,e),ba(t,d,e,n),p.applying&&(p.applying=!1),c(p.frames),null!=p.step&&p.step(e),d.completed()&&(a.splice(h,1),p.hooked=!1,p.playing=!1,p.started=!1,c(p.completes)),s=!0)}return n||0!==a.length||0!==o.length||r.push(t),s}for(var a=!1,o=0;o0?t.notify("draw",n):t.notify("draw")),n.unmerge(r),t.emit("step")}var ka={animate:Un.animate(),animation:Un.animation(),animated:Un.animated(),clearQueue:Un.clearQueue(),delay:Un.delay(),delayAnimation:Un.delayAnimation(),stop:Un.stop(),addToAnimationPool:function(e){this.styleEnabled()&&this._private.aniEles.merge(e)},stopAnimationLoop:function(){this._private.animationsRunning=!1},startAnimationLoop:function(){var e=this;if(e._private.animationsRunning=!0,e.styleEnabled()){var t=e.renderer();t&&t.beforeRender?t.beforeRender(function(t,n){Ea(n,e)},t.beforeRenderPriorities.animations):function t(){e._private.animationsRunning&&oe(function(n){Ea(n,e),t()})}()}}},Ca={qualifierCompare:function(e,t){return null==e||null==t?null==e&&null==t:e.sameText(t)},eventMatches:function(e,t,n){var r=t.qualifier;return null==r||e!==n.target&&b(n.target)&&r.matches(n.target)},addEventFields:function(e,t){t.cy=e,t.target=e},callbackContext:function(e,t,n){return null!=t.qualifier?n.target:e}},Sa=function(e){return d(e)?new Ir(e):e},Da={createEmitter:function(){var e=this._private;return e.emitter||(e.emitter=new Pi(Ca,this)),this},emitter:function(){return this._private.emitter},on:function(e,t,n){return this.emitter().on(e,Sa(t),n),this},removeListener:function(e,t,n){return this.emitter().removeListener(e,Sa(t),n),this},one:function(e,t,n){return this.emitter().one(e,Sa(t),n),this},once:function(e,t,n){return this.emitter().one(e,Sa(t),n),this},emit:function(e,t){return this.emitter().emit(e,t),this},emitAndNotify:function(e,t){return this.emit(e),this.notify(e,t),this}};Un.eventAliasesOn(Da);var Pa={png:function(e){return e=e||{},this._private.renderer.png(e)},jpg:function(e){var t=this._private.renderer;return(e=e||{}).bg=e.bg||"#fff",t.jpg(e)}};Pa.jpeg=Pa.jpg;var Ta={layout:function(e){if(null!=e)if(null!=e.name){var t=e.name,n=this.extension("layout",t);if(null!=n){var r;r=d(e.eles)?this.$(e.eles):null!=e.eles?e.eles:this.$();var i=new n(I({},e,{cy:this,eles:r}));return i}Ee("No such layout `"+t+"` found. Did you forget to import it and `cytoscape.use()` it?")}else Ee("A `name` must be specified to make a layout");else Ee("Layout options must be specified to make a layout")}};Ta.createLayout=Ta.makeLayout=Ta.layout;var Ma={notify:function(e,t){var n=this._private;if(this.batching()){n.batchNotifications=n.batchNotifications||{};var r=n.batchNotifications[e]=n.batchNotifications[e]||this.collection();null!=t&&r.merge(t)}else if(n.notificationsEnabled){var i=this.renderer();!this.isDestroyed()&&i&&i.notify(e,t)}},notifications:function(e){var t=this._private;return void 0===e?t.notificationsEnabled:(t.notificationsEnabled=!!e,this)},noNotifications:function(e){this.notifications(!1),e(),this.notifications(!0)},batching:function(){return this._private.batchCount>0},startBatch:function(){var e=this._private;return null==e.batchCount&&(e.batchCount=0),0===e.batchCount&&(e.batchStyleEles=this.collection(),e.batchNotifications={}),e.batchCount++,this},endBatch:function(){var e=this._private;if(0===e.batchCount)return this;if(e.batchCount--,0===e.batchCount){e.batchStyleEles.updateStyle();var t=this.renderer();Object.keys(e.batchNotifications).forEach(function(n){var r=e.batchNotifications[n];r.empty()?t.notify(n):t.notify(n,r)})}return this},batch:function(e){return this.startBatch(),e(),this.endBatch(),this},batchData:function(e){var t=this;return this.batch(function(){for(var n=Object.keys(e),r=0;r0;)e.removeChild(e.childNodes[0]);this._private.renderer=null,this.mutableElements().forEach(function(e){var t=e._private;t.rscratch={},t.rstyle={},t.animation.current=[],t.animation.queue=[]})},onRender:function(e){return this.on("render",e)},offRender:function(e){return this.off("render",e)}};Ba.invalidateDimensions=Ba.resize;var Na={collection:function(e,t){return d(e)?this.$(e):m(e)?e.collection():f(e)?new ua(this,e,t):new ua(this)},nodes:function(e){var t=this.$(function(e){return e.isNode()});return e?t.filter(e):t},edges:function(e){var t=this.$(function(e){return e.isEdge()});return e?t.filter(e):t},$:function(e){var t=this._private.elements;return e?t.filter(e):t.spawnSelf()},mutableElements:function(){return this._private.elements}};Na.elements=Na.filter=Na.$;var Ia={};Ia.apply=function(e){var t=this._private,n=t.cy.collection();t.newStyle&&(t.contextStyles={},t.propDiffs={},this.cleanElements(e,!0));for(var r=0;r0;if(h||c&&d){var p=void 0;h&&d?p=l.properties:h?p=l.properties:d&&(p=l.mappedProperties);for(var f=0;f1&&(g=1),s.color){var w=i.valueMin[0],E=i.valueMax[0],k=i.valueMin[1],C=i.valueMax[1],S=i.valueMin[2],D=i.valueMax[2],P=null==i.valueMin[3]?1:i.valueMin[3],T=null==i.valueMax[3]?1:i.valueMax[3],M=[Math.round(w+(E-w)*g),Math.round(k+(C-k)*g),Math.round(S+(D-S)*g),Math.round(P+(T-P)*g)];n={bypass:i.bypass,name:i.name,value:M,strValue:"rgb("+M[0]+", "+M[1]+", "+M[2]+")"}}else{if(!s.number)return!1;var _=i.valueMin+(i.valueMax-i.valueMin)*g;n=this.parse(i.name,_,i.bypass,"mapping")}if(!n)return f(),!1;n.mapping=i,i=n;break;case o.data:for(var B=i.field.split("."),N=h.data,I=0;I0&&a>0){for(var s={},l=!1,u=0;u0?e.delayAnimation(o).play().promise().then(t):t()}).then(function(){return e.animation({style:s,duration:a,easing:e.pstyle("transition-timing-function").value,queue:!1}).play().promise()}).then(function(){n.removeBypasses(e,i),e.emitAndNotify("style"),r.transitioning=!1})}else r.transitioning&&(this.removeBypasses(e,i),e.emitAndNotify("style"),r.transitioning=!1)},Ia.checkTrigger=function(e,t,n,r,i,a){var o=this.properties[t],s=i(o);null!=s&&s(n,r)&&a(o)},Ia.checkZOrderTrigger=function(e,t,n,r){var i=this;this.checkTrigger(e,t,n,r,function(e){return e.triggersZOrder},function(){i._private.cy.notify("zorder",e)})},Ia.checkBoundsTrigger=function(e,t,n,r){this.checkTrigger(e,t,n,r,function(e){return e.triggersBounds},function(i){e.dirtyCompoundBoundsCache(),e.dirtyBoundingBoxCache(),"bezier"!==e.pstyle("curve-style").value&&("curve-style"!==t||"bezier"!==n&&"bezier"!==r)||!i.triggersBoundsOfParallelBeziers||e.parallelEdges().forEach(function(e){e.isBundledBezier()&&e.dirtyBoundingBoxCache()})})},Ia.checkTriggers=function(e,t,n,r){e.dirtyStyleCache(),this.checkZOrderTrigger(e,t,n,r),this.checkBoundsTrigger(e,t,n,r)};var za={applyBypass:function(e,t,n,r){var i=[];if("*"===t||"**"===t){if(void 0!==n)for(var a=0;at.length?i.substr(t.length):""}function o(){n=n.length>r.length?n.substr(r.length):""}for(i=i.replace(/[\/][*](\s|.)+?[*][\/]/g,"");;){if(i.match(/^\s*$/))break;var s=i.match(/^\s*((?:.|\s)+?)\s*\{((?:.|\s)+?)\}/);if(!s){Ce("Halting stylesheet parsing: String stylesheet contains more to parse but no selector and block found in: "+i);break}t=s[0];var l=s[1];if("core"!==l)if(new Ir(l).invalid){Ce("Skipping parsing of block: Invalid selector found in string stylesheet: "+l),a();continue}var u=s[2],c=!1;n=u;for(var h=[];;){if(n.match(/^\s*$/))break;var d=n.match(/^\s*(.+?)\s*:\s*(.+?)\s*;/);if(!d){Ce("Skipping parsing of block: Invalid formatting of style property and value definitions found in:"+u),c=!0;break}r=d[0];var p=d[1],f=d[2];if(this.properties[p])this.parse(p,f)?(h.push({name:p,val:f}),o()):(Ce("Skipping property: Invalid property definition in: "+r),o());else Ce("Skipping property: Invalid property name in: "+r),o()}if(c){a();break}this.selector(l);for(var g=0;g=7&&"d"===t[0]&&(l=new RegExp(o.data.regex).exec(t))){if(n)return!1;var h=o.data;return{name:e,value:l,strValue:""+t,mapped:h,field:l[1],bypass:n}}if(t.length>=10&&"m"===t[0]&&(u=new RegExp(o.mapData.regex).exec(t))){if(n)return!1;if(c.multiple)return!1;var g=o.mapData;if(!c.color&&!c.number)return!1;var y=this.parse(e,u[4]);if(!y||y.mapped)return!1;var m=this.parse(e,u[5]);if(!m||m.mapped)return!1;if(y.pfValue===m.pfValue||y.strValue===m.strValue)return Ce("`"+e+": "+t+"` is not a valid mapper because the output range is zero; converting to `"+e+": "+y.strValue+"`"),this.parse(e,y.strValue);if(c.color){var b=y.value,x=m.value;if(!(b[0]!==x[0]||b[1]!==x[1]||b[2]!==x[2]||b[3]!==x[3]&&(null!=b[3]&&1!==b[3]||null!=x[3]&&1!==x[3])))return!1}return{name:e,value:u,strValue:""+t,mapped:g,field:u[1],fieldMin:parseFloat(u[2]),fieldMax:parseFloat(u[3]),valueMin:y.value,valueMax:m.value,bypass:n}}}if(c.multiple&&"multiple"!==r){var w;if(w=s?t.split(/\s+/):f(t)?t:[t],c.evenMultiple&&w.length%2!=0)return null;for(var E=[],k=[],C=[],S="",D=!1,T=0;T0?" ":"")+M.strValue}return c.validate&&!c.validate(E,k)?null:c.singleEnum&&D?1===E.length&&d(E[0])?{name:e,value:E[0],strValue:E[0],bypass:n}:null:{name:e,value:E,pfValue:C,strValue:S,bypass:n,units:k}}var _,N,I=function(){for(var r=0;rc.max||c.strictMax&&t===c.max))return null;var F={name:e,value:t,strValue:""+t+(A||""),units:A,bypass:n};return c.unitless||"px"!==A&&"em"!==A?F.pfValue=t:F.pfValue="px"!==A&&A?this.getEmSizeInPixels()*t:t,"ms"!==A&&"s"!==A||(F.pfValue="ms"===A?t:1e3*t),"deg"!==A&&"rad"!==A||(F.pfValue="rad"===A?t:(_=t,Math.PI*_/180)),"%"===A&&(F.pfValue=t/100),F}if(c.propList){var V=[],q=""+t;if("none"===q);else{for(var Y=q.split(/\s*,\s*|\s+/),X=0;X0&&l>0&&!isNaN(n.w)&&!isNaN(n.h)&&n.w>0&&n.h>0)return{zoom:o=(o=(o=Math.min((s-2*t)/n.w,(l-2*t)/n.h))>this._private.maxZoom?this._private.maxZoom:o)=n.minZoom&&(n.maxZoom=t),this},minZoom:function(e){return void 0===e?this._private.minZoom:this.zoomRange({min:e})},maxZoom:function(e){return void 0===e?this._private.maxZoom:this.zoomRange({max:e})},getZoomedViewport:function(e){var t,n,r=this._private,i=r.pan,a=r.zoom,o=!1;if(r.zoomingEnabled||(o=!0),v(e)?n=e:g(e)&&(n=e.level,null!=e.position?t=tt(e.position,a,i):null!=e.renderedPosition&&(t=e.renderedPosition),null==t||r.panningEnabled||(o=!0)),n=(n=n>r.maxZoom?r.maxZoom:n)t.maxZoom||!t.zoomingEnabled?a=!0:(t.zoom=s,i.push("zoom"))}if(r&&(!a||!e.cancelOnFailedZoom)&&t.panningEnabled){var l=e.pan;v(l.x)&&(t.pan.x=l.x,o=!1),v(l.y)&&(t.pan.y=l.y,o=!1),o||i.push("pan")}return i.length>0&&(i.push("viewport"),this.emit(i.join(" ")),this.notify("viewport")),this},center:function(e){var t=this.getCenterPan(e);return t&&(this._private.pan=t,this.emit("pan viewport"),this.notify("viewport")),this},getCenterPan:function(e,t){if(this._private.panningEnabled){if(d(e)){var n=e;e=this.mutableElements().filter(n)}else m(e)||(e=this.mutableElements());if(0!==e.length){var r=e.boundingBox(),i=this.width(),a=this.height();return{x:(i-(t=void 0===t?this._private.zoom:t)*(r.x1+r.x2))/2,y:(a-t*(r.y1+r.y2))/2}}}},reset:function(){return this._private.panningEnabled&&this._private.zoomingEnabled?(this.viewport({pan:{x:0,y:0},zoom:1}),this):this},invalidateSize:function(){this._private.sizeCache=null},size:function(){var e,t,n=this._private,r=n.container;return n.sizeCache=n.sizeCache||(r?(e=a.getComputedStyle(r),t=function(t){return parseFloat(e.getPropertyValue(t))},{width:r.clientWidth-t("padding-left")-t("padding-right"),height:r.clientHeight-t("padding-top")-t("padding-bottom")}):{width:1,height:1})},width:function(){return this.size().width},height:function(){return this.size().height},extent:function(){var e=this._private.pan,t=this._private.zoom,n=this.renderedExtent(),r={x1:(n.x1-e.x)/t,x2:(n.x2-e.x)/t,y1:(n.y1-e.y)/t,y2:(n.y2-e.y)/t};return r.w=r.x2-r.x1,r.h=r.y2-r.y1,r},renderedExtent:function(){var e=this.width(),t=this.height();return{x1:0,y1:0,x2:e,y2:t,w:e,h:t}}};ja.centre=ja.center,ja.autolockNodes=ja.autolock,ja.autoungrabifyNodes=ja.autoungrabify;var Wa=function(e){var t=this,n=(e=I({},e)).container;n&&!y(n)&&y(n[0])&&(n=n[0]);var r=n?n._cyreg:null;(r=r||{})&&r.cy&&(r.cy.destroy(),r={});var i=r.readies=r.readies||[];n&&(n._cyreg=r),r.cy=t;var o=void 0!==a&&void 0!==n&&!e.headless,s=e;s.layout=I({name:o?"grid":"null"},s.layout),s.renderer=I({name:o?"canvas":"null"},s.renderer);var l=function(e,t,n){return void 0!==t?t:void 0!==n?n:e},u=this._private={container:n,ready:!1,options:s,elements:new ua(this),listeners:[],aniEles:new ua(this),scratch:{},layout:null,renderer:null,destroyed:!1,notificationsEnabled:!0,minZoom:1e-50,maxZoom:1e50,zoomingEnabled:l(!0,s.zoomingEnabled),userZoomingEnabled:l(!0,s.userZoomingEnabled),panningEnabled:l(!0,s.panningEnabled),userPanningEnabled:l(!0,s.userPanningEnabled),boxSelectionEnabled:l(!0,s.boxSelectionEnabled),autolock:l(!1,s.autolock,s.autolockNodes),autoungrabify:l(!1,s.autoungrabify,s.autoungrabifyNodes),autounselectify:l(!1,s.autounselectify),styleEnabled:void 0===s.styleEnabled?o:s.styleEnabled,zoom:v(s.zoom)?s.zoom:1,pan:{x:g(s.pan)&&v(s.pan.x)?s.pan.x:0,y:g(s.pan)&&v(s.pan.y)?s.pan.y:0},animation:{current:[],queue:[]},hasCompoundNodes:!1};this.createEmitter(),this.selectionType(s.selectionType),this.zoomRange({min:s.minZoom,max:s.maxZoom});u.styleEnabled&&t.setStyle([]);var c=I({},s,s.renderer);t.initRenderer(c);!function(e,t){if(e.some(C))return Kn.all(e).then(t);t(e)}([s.style,s.elements],function(e){var n=e[0],a=e[1];u.styleEnabled&&t.style().append(n),function(e,n,r){t.notifications(!1);var i=t.mutableElements();i.length>0&&i.remove(),null!=e&&(g(e)||f(e))&&t.add(e),t.one("layoutready",function(e){t.notifications(!0),t.emit(e),t.one("load",n),t.emitAndNotify("load")}).one("layoutstop",function(){t.one("done",r),t.emit("done")});var a=I({},t._private.options.layout);a.eles=t.elements(),t.layout(a).run()}(a,function(){t.startAnimationLoop(),u.ready=!0,p(s.ready)&&t.on("ready",s.ready);for(var e=0;e0,u=pt(n.boundingBox?n.boundingBox:{x1:0,y1:0,w:r.width(),h:r.height()});if(m(n.roots))e=n.roots;else if(f(n.roots)){for(var c=[],h=0;h0;){var I=M.shift(),z=T(I,_);if(z)I.outgoers().filter(function(e){return e.isNode()&&i.has(e)}).forEach(B);else if(null===z){Ce("Detected double maximal shift for node `"+I.id()+"`. Bailing maximal adjustment due to cycle. Use `options.maximal: true` only on DAGs.");break}}}P();var A=0;if(n.avoidOverlap)for(var L=0;L0&&x[0].length<=3?l/2:0),h=2*Math.PI/x[r].length*i;return 0===r&&1===x[0].length&&(c=1),{x:G+c*Math.cos(h),y:Z+c*Math.sin(h)}}return{x:G+(i+1-(a+1)/2)*o,y:(r+1)*s}}),this};var $a={fit:!0,padding:30,boundingBox:void 0,avoidOverlap:!0,nodeDimensionsIncludeLabels:!1,spacingFactor:void 0,radius:void 0,startAngle:1.5*Math.PI,sweep:void 0,clockwise:!0,sort:void 0,animate:!1,animationDuration:500,animationEasing:void 0,animateFilter:function(e,t){return!0},ready:void 0,stop:void 0,transform:function(e,t){return t}};function Qa(e){this.options=I({},$a,e)}Qa.prototype.run=function(){var e=this.options,t=e,n=e.cy,r=t.eles,i=void 0!==t.counterclockwise?!t.counterclockwise:t.clockwise,a=r.nodes().not(":parent");t.sort&&(a=a.sort(t.sort));for(var o,s=pt(t.boundingBox?t.boundingBox:{x1:0,y1:0,w:n.width(),h:n.height()}),l=s.x1+s.w/2,u=s.y1+s.h/2,c=(void 0===t.sweep?2*Math.PI-2*Math.PI/a.length:t.sweep)/Math.max(1,a.length-1),h=0,d=0;d1&&t.avoidOverlap){h*=1.75;var y=Math.cos(c)-Math.cos(0),m=Math.sin(c)-Math.sin(0),b=Math.sqrt(h*h/(y*y+m*m));o=Math.max(b,o)}return a.layoutPositions(this,t,function(e,n){var r=t.startAngle+n*c*(i?1:-1),a=o*Math.cos(r),s=o*Math.sin(r);return{x:l+a,y:u+s}}),this};var Ja,eo={fit:!0,padding:30,startAngle:1.5*Math.PI,sweep:void 0,clockwise:!0,equidistant:!1,minNodeSpacing:10,boundingBox:void 0,avoidOverlap:!0,nodeDimensionsIncludeLabels:!1,height:void 0,width:void 0,spacingFactor:void 0,concentric:function(e){return e.degree()},levelWidth:function(e){return e.maxDegree()/4},animate:!1,animationDuration:500,animationEasing:void 0,animateFilter:function(e,t){return!0},ready:void 0,stop:void 0,transform:function(e,t){return t}};function to(e){this.options=I({},eo,e)}to.prototype.run=function(){for(var e=this.options,t=e,n=void 0!==t.counterclockwise?!t.counterclockwise:t.clockwise,r=e.cy,i=t.eles.nodes().not(":parent"),a=pt(t.boundingBox?t.boundingBox:{x1:0,y1:0,w:r.width(),h:r.height()}),o=a.x1+a.w/2,s=a.y1+a.h/2,l=[],u=0,c=0;c0)Math.abs(y[0].value-b.value)>=g&&(y=[],v.push(y));y.push(b)}var x=u+t.minNodeSpacing;if(!t.avoidOverlap){var w=v.length>0&&v[0].length>1,E=(Math.min(a.w,a.h)/2-x)/(v.length+w?1:0);x=Math.min(x,E)}for(var k=0,C=0;C1&&t.avoidOverlap){var T=Math.cos(P)-Math.cos(0),M=Math.sin(P)-Math.sin(0),_=Math.sqrt(x*x/(T*T+M*M));k=Math.max(_,k)}S.r=k,k+=x}if(t.equidistant){for(var B=0,N=0,I=0;I0)var l=(d=r.nodeOverlap*o)*i/(m=Math.sqrt(i*i+a*a)),h=d*a/m;else{var d,p=c(e,i,a),f=c(t,-1*i,-1*a),g=f.x-p.x,v=f.y-p.y,y=g*g+v*v,m=Math.sqrt(y);l=(d=(e.nodeRepulsion+t.nodeRepulsion)/y)*g/m,h=d*v/m}e.isLocked||(e.offsetX-=l,e.offsetY-=h),t.isLocked||(t.offsetX+=l,t.offsetY+=h)}},u=function(e,t,n,r){if(n>0)var i=e.maxX-t.minX;else i=t.maxX-e.minX;if(r>0)var a=e.maxY-t.minY;else a=t.maxY-e.minY;return i>=0&&a>=0?Math.sqrt(i*i+a*a):0},c=function(e,t,n){var r=e.positionX,i=e.positionY,a=e.height||1,o=e.width||1,s=n/t,l=a/o,u={};return 0===t&&0n?(u.x=r,u.y=i+a/2,u):0t&&-1*l<=s&&s<=l?(u.x=r-o/2,u.y=i-o*n/2/t,u):0=l)?(u.x=r+a*t/2/n,u.y=i+a/2,u):0>n&&(s<=-1*l||s>=l)?(u.x=r-a*t/2/n,u.y=i-a/2,u):u},h=function(e,t){for(var n=0;n1){var f=t.gravity*h/p,g=t.gravity*d/p;c.offsetX+=f,c.offsetY+=g}}}}},p=function(e,t){var n=[],r=0,i=-1;for(n.push.apply(n,e.graphSet[0]),i+=e.graphSet[0].length;r<=i;){var a=n[r++],o=e.idToIndex[a],s=e.layoutNodes[o],l=s.children;if(0n)var i={x:n*e/r,y:n*t/r};else i={x:e,y:t};return i},v=function e(t,n){var r=t.parentId;if(null!=r){var i=n.layoutNodes[n.idToIndex[r]],a=!1;return(null==i.maxX||t.maxX+i.padRight>i.maxX)&&(i.maxX=t.maxX+i.padRight,a=!0),(null==i.minX||t.minX-i.padLefti.maxY)&&(i.maxY=t.maxY+i.padBottom,a=!0),(null==i.minY||t.minY-i.padTopg&&(d+=f+t.componentSpacing,h=0,p=0,f=0)}}}(0,i),r}).then(function(e){o.layoutNodes=e.layoutNodes,r.stop(),c()});var c=function(){!0===e.animate||!1===e.animate?u({force:!0,next:function(){n.one("layoutstop",e.stop),n.emit({type:"layoutstop",layout:n})}}):e.eles.nodes().layoutPositions(n,e,function(e){var t=o.layoutNodes[o.idToIndex[e.data("id")]];return{x:t.positionX,y:t.positionY}})};return this},ro.prototype.stop=function(){return this.stopped=!0,this.thread&&this.thread.stop(),this.emit("layoutstop"),this},ro.prototype.destroy=function(){return this.thread&&this.thread.stop(),this};var io=function(e,t,n){for(var r=n.eles.edges(),i=n.eles.nodes(),a={isCompound:e.hasCompoundNodes(),layoutNodes:[],idToIndex:{},nodeSize:i.size(),graphSet:[],indexToGraph:[],layoutEdges:[],edgeSize:r.size(),temperature:n.initialTemp,clientWidth:e.width(),clientHeight:e.width(),boundingBox:pt(n.boundingBox?n.boundingBox:{x1:0,y1:0,w:e.width(),h:e.height()})},o=n.eles.components(),s={},l=0;l0){a.graphSet.push(w);for(l=0;lr.count?0:r.graph},oo=function e(t,n,r,i){var a=i.graphSet[r];if(-1a){var p=u(),f=c();(p-1)*f>=a?u(p-1):(f-1)*p>=a&&c(f-1)}else for(;l*s=a?c(v+1):u(g+1)}var y=i.w/l,m=i.h/s;if(t.condense&&(y=0,m=0),t.avoidOverlap)for(var b=0;b=l&&(_=0,M++)},N={},I=0;I(r=St(e,t,x[w],x[w+1],x[w+2],x[w+3])))return v(n,r),!0}else if("bezier"===a.edgeType||"multibezier"===a.edgeType||"self"===a.edgeType||"compound"===a.edgeType)for(x=a.allpts,w=0;w+5(r=Ct(e,t,x[w],x[w+1],x[w+2],x[w+3],x[w+4],x[w+5])))return v(n,r),!0;m=m||i.source,b=b||i.target;var E=o.getArrowWidth(l,c),k=[{name:"source",x:a.arrowStartX,y:a.arrowStartY,angle:a.srcArrowAngle},{name:"target",x:a.arrowEndX,y:a.arrowEndY,angle:a.tgtArrowAngle},{name:"mid-source",x:a.midX,y:a.midY,angle:a.midsrcArrowAngle},{name:"mid-target",x:a.midX,y:a.midY,angle:a.midtgtArrowAngle}];for(w=0;w0&&(y(m),y(b))}function b(e,t,n){return Ne(e,t,n)}function x(n,r){var i,a=n._private,o=f;i=r?r+"-":"";var s=n.pstyle(i+"label").value;if("yes"===n.pstyle("text-events").strValue&&s){var l=a.rstyle,u=n.pstyle("text-border-width").pfValue,c=n.pstyle("text-background-padding").pfValue,h=b(l,"labelWidth",r)+u+2*o+2*c,d=b(l,"labelHeight",r)+u+2*o+2*c,p=b(l,"labelX",r),g=b(l,"labelY",r),y=b(a.rscratch,"labelAngle",r),m=p-h/2,x=p+h/2,w=g-d/2,E=g+d/2;if(y){var k=Math.cos(y),C=Math.sin(y),S=function(e,t){return{x:(e-=p)*k-(t-=g)*C+p,y:e*C+t*k+g}},D=S(m,w),P=S(m,E),T=S(x,w),M=S(x,E),_=[D.x,D.y,T.x,T.y,M.x,M.y,P.x,P.y];if(Dt(e,t,_))return v(n),!0}else{if(bt({w:h,h:d,x1:m,x2:x,y1:w,y2:E},e,t))return v(n),!0}}}n&&(l=l.interactive);for(var w=l.length-1;w>=0;w--){var E=l[w];E.isNode()?y(E)||x(E):m(E)||x(E)||x(E,"source")||x(E,"target")}return u},getAllInBox:function(e,t,n,r){for(var i,a,o=this.getCachedZSortedEles().interactive,s=[],l=Math.min(e,n),u=Math.max(e,n),c=Math.min(t,r),h=Math.max(t,r),d=pt({x1:e=l,y1:t=c,x2:n=u,y2:r=h}),p=0;p0?Math.max(e-t,0):Math.min(e+t,0)},x=b(y,g),w=b(m,v),E=!1;"auto"===u?u=Math.abs(x)>Math.abs(w)?"horizontal":"vertical":"upward"===u||"downward"===u?(u="vertical",E=!0):"leftward"!==u&&"rightward"!==u||(u="horizontal",E=!0);var k="vertical"===u,C=k?w:x,S=k?m:y,D=ot(S),P=!1;E&&f||!("downward"===c&&S<0||"upward"===c&&S>0||"leftward"===c&&S>0||"rightward"===c&&S<0)||(C=(D*=-1)*Math.abs(C),P=!0);var T=f?d*C:d*D,M=function(e){return Math.abs(e)=Math.abs(C)},_=M(T),B=M(C-T);if((_||B)&&!P)if(k){var N=Math.abs(S)<=a/2,I=Math.abs(y)<=o/2;if(N){var z=(r.x1+r.x2)/2,A=r.y1,L=r.y2;n.segpts=[z,A,z,L]}else if(I){var O=(r.y1+r.y2)/2,R=r.x1,F=r.x2;n.segpts=[R,O,F,O]}else n.segpts=[r.x1,r.y2]}else{var V=Math.abs(S)<=i/2,q=Math.abs(m)<=s/2;if(V){var Y=(r.y1+r.y2)/2,X=r.x1,j=r.x2;n.segpts=[X,Y,j,Y]}else if(q){var W=(r.x1+r.x2)/2,H=r.y1,K=r.y2;n.segpts=[W,H,W,K]}else n.segpts=[r.x2,r.y1]}else if(k){var G=r.y1+T+(l?a/2*D:0),Z=r.x1,U=r.x2;n.segpts=[Z,G,U,G]}else{var $=r.x1+T+(l?i/2*D:0),Q=r.y1,J=r.y2;n.segpts=[$,Q,$,J]}},Co.tryToCorrectInvalidPoints=function(e,t){var n=e._private.rscratch;if("bezier"===n.edgeType){var r=t.srcPos,i=t.tgtPos,a=t.srcW,o=t.srcH,s=t.tgtW,l=t.tgtH,u=t.srcShape,c=t.tgtShape,h=!v(n.startX)||!v(n.startY),d=!v(n.arrowStartX)||!v(n.arrowStartY),p=!v(n.endX)||!v(n.endY),f=!v(n.arrowEndX)||!v(n.arrowEndY),g=3*(this.getArrowWidth(e.pstyle("width").pfValue,e.pstyle("arrow-scale").value)*this.arrowShapeWidth),y=st({x:n.ctrlpts[0],y:n.ctrlpts[1]},{x:n.startX,y:n.startY}),m=yd.poolIndex()){var p=h;h=d,d=p}var f=s.srcPos=h.position(),g=s.tgtPos=d.position(),y=s.srcW=h.outerWidth(),m=s.srcH=h.outerHeight(),b=s.tgtW=d.outerWidth(),x=s.tgtH=d.outerHeight(),w=s.srcShape=n.nodeShapes[t.getNodeShape(h)],E=s.tgtShape=n.nodeShapes[t.getNodeShape(d)];s.dirCounts={north:0,west:0,south:0,east:0,northwest:0,southwest:0,northeast:0,southeast:0};for(var k=0;k=c||b){h={cp:v,segment:m};break}}if(h)break}v=h.cp;var x=(c-p)/(m=h.segment).length,w=m.t1-m.t0,E=u?m.t0+w*x:m.t1-w*x;E=dt(0,E,1),t=ht(v.p0,v.p1,v.p2,E),l=function(e,t,n,r){var i=dt(0,r-.001,1),a=dt(0,r+.001,1),o=ht(e,t,n,i),s=ht(e,t,n,a);return Bo(o,s)}(v.p0,v.p1,v.p2,E);break;case"straight":case"segments":case"haystack":var k,C,S,D,P=0,T=r.allpts.length;for(g=0;g+3=c));g+=2);E=dt(0,E=(c-C)/k,1),t=function(e,t,n,r){var i=t.x-e.x,a=t.y-e.y,o=st(e,t),s=i/o,l=a/o;return n=null==n?0:n,r=null!=r?r:n*o,{x:e.x+s*r,y:e.y+l*r}}(S,D,E),l=Bo(S,D)}o("labelX",s,t.x),o("labelY",s,t.y),o("labelAutoAngle",s,l)}};l("source"),l("target"),this.applyLabelDimensions(e)}},Mo.applyLabelDimensions=function(e){this.applyPrefixedLabelDimensions(e),e.isEdge()&&(this.applyPrefixedLabelDimensions(e,"source"),this.applyPrefixedLabelDimensions(e,"target"))},Mo.applyPrefixedLabelDimensions=function(e,t){var n=e._private,r=this.getLabelText(e,t),i=this.calculateLabelDimensions(e,r);Ie(n.rstyle,"labelWidth",t,i.width),Ie(n.rscratch,"labelWidth",t,i.width),Ie(n.rstyle,"labelHeight",t,i.height),Ie(n.rscratch,"labelHeight",t,i.height)},Mo.getLabelText=function(e,t){var n=e._private,r=t?t+"-":"",i=e.pstyle(r+"label").strValue,a=e.pstyle("text-transform").value,o=function(e,r){return r?(Ie(n.rscratch,e,t,r),r):Ne(n.rscratch,e,t)};if(!i)return"";"none"==a||("uppercase"==a?i=i.toUpperCase():"lowercase"==a&&(i=i.toLowerCase()));var s=e.pstyle("text-wrap").value;if("wrap"===s){var l=o("labelKey");if(null!=l&&o("labelWrapKey")===l)return o("labelWrapCachedText");for(var u=i.split("\n"),c=e.pstyle("text-max-width").pfValue,h=[],d=0;dc){for(var f=p.split(/\s+/),g="",v=0;vc)break;b+=i[w],w===i.length-1&&(x=!0)}return x||(b+="…"),b}return i},Mo.calculateLabelDimensions=function(e,t){var n=he(t,e._private.labelDimsKey),r=this.labelDimCache||(this.labelDimCache=[]),i=r[n];if(null!=i)return i;var a=e.pstyle("font-style").strValue,o=1*e.pstyle("font-size").pfValue+"px",s=e.pstyle("font-family").strValue,l=e.pstyle("font-weight").strValue,u=this.labelCalcDiv;u||(u=this.labelCalcDiv=document.createElement("div"),document.body.appendChild(u));var c=u.style;return c.fontFamily=s,c.fontStyle=a,c.fontSize=o,c.fontWeight=l,c.position="absolute",c.left="-9999px",c.top="-9999px",c.zIndex="-1",c.visibility="hidden",c.pointerEvents="none",c.padding="0",c.lineHeight="1","wrap"===e.pstyle("text-wrap").value?c.whiteSpace="pre":c.whiteSpace="normal",u.textContent=t,r[n]={width:Math.ceil(u.clientWidth/1),height:Math.ceil(u.clientHeight/1)}},Mo.calculateLabelAngle=function(e,t){var n=e._private.rscratch,r=e.isEdge(),i=t?t+"-":"",a=e.pstyle(i+"text-rotation"),o=a.strValue;return"none"===o?0:r&&"autorotate"===o?n.labelAutoAngle:"autorotate"===o?0:a.pfValue},Mo.calculateLabelAngles=function(e){var t=this,n=e.isEdge(),r=e._private.rscratch;r.labelAngle=t.calculateLabelAngle(e),n&&(r.sourceLabelAngle=t.calculateLabelAngle(e,"source"),r.targetLabelAngle=t.calculateLabelAngle(e,"target"))};var No={},Io=!1;No.getNodeShape=function(e){var t=e.pstyle("shape").value;if("cutrectangle"===t&&(e.width()<28||e.height()<28))return Io||(Ce("The `cutrectangle` node shape can not be used at small sizes so `rectangle` is used instead"),Io=!0),"rectangle";if(e.isParent())return"rectangle"===t||"roundrectangle"===t||"cutrectangle"===t||"barrel"===t?t:"rectangle";if("polygon"===t){var n=e.pstyle("shape-polygon-points").value;return this.nodeShapes.makePolygon(n).name}return t};var zo={registerCalculationListeners:function(){var e=this.cy,t=e.collection(),n=this,r=function(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(t.merge(e),n)for(var r=0;r=e.desktopTapThreshold2}var P=r(t);m&&(e.hoverData.tapholdCancelled=!0);a=!0,n(g,["mousemove","vmousemove","tapdrag"],t,{x:h[0],y:h[1]});var T=function(){e.data.bgActivePosistion=void 0,e.hoverData.selecting||o.emit({originalEvent:t,type:"boxstart",position:{x:h[0],y:h[1]}}),f[4]=1,e.hoverData.selecting=!0,e.redrawHint("select",!0),e.redraw()};if(3===e.hoverData.which){if(m){var M={originalEvent:t,type:"cxtdrag",position:{x:h[0],y:h[1]}};x?x.emit(M):o.emit(M),e.hoverData.cxtDragged=!0,e.hoverData.cxtOver&&g===e.hoverData.cxtOver||(e.hoverData.cxtOver&&e.hoverData.cxtOver.emit({originalEvent:t,type:"cxtdragout",position:{x:h[0],y:h[1]}}),e.hoverData.cxtOver=g,g&&g.emit({originalEvent:t,type:"cxtdragover",position:{x:h[0],y:h[1]}}))}}else if(e.hoverData.dragging){if(a=!0,o.panningEnabled()&&o.userPanningEnabled()){var _;if(e.hoverData.justStartedPan){var B=e.hoverData.mdownPos;_={x:(h[0]-B[0])*s,y:(h[1]-B[1])*s},e.hoverData.justStartedPan=!1}else _={x:w[0]*s,y:w[1]*s};o.panBy(_),e.hoverData.dragged=!0}h=e.projectIntoViewport(t.clientX,t.clientY)}else if(1!=f[4]||null!=x&&!x.isEdge()){if(x&&x.isEdge()&&x.active()&&x.unactivate(),x&&x.grabbed()||g==b||(b&&n(b,["mouseout","tapdragout"],t,{x:h[0],y:h[1]}),g&&n(g,["mouseover","tapdragover"],t,{x:h[0],y:h[1]}),e.hoverData.last=g),x)if(m){if(o.boxSelectionEnabled()&&P)x&&x.grabbed()&&(c(E),x.emit("freeon"),E.emit("free"),e.dragData.didDrag&&(x.emit("dragfreeon"),E.emit("dragfree"))),T();else if(x&&x.grabbed()&&e.nodeIsDraggable(x)){var N=!e.dragData.didDrag;N&&e.redrawHint("eles",!0),e.dragData.didDrag=!0;var I=o.collection();e.hoverData.draggingEles||l(E,{inDragLayer:!0});var z={x:0,y:0};if(v(w[0])&&v(w[1])&&(z.x+=w[0],z.y+=w[1],N)){var A=e.hoverData.dragDelta;A&&v(A[0])&&v(A[1])&&(z.x+=A[0],z.y+=A[1])}for(var L=0;L0&&e.redrawHint("eles",!0),e.dragData.possibleDragElements=u=a.collection()),l!=h||e.dragData.didDrag||e.hoverData.selecting||null!=l&&l._private.selectable&&(e.hoverData.dragging||("additive"===a.selectionType()||d?l.selected()?l.unselect(["tapunselect"]):l.select(["tapselect"]):d||(a.$(t).unmerge(l).unselect(["tapunselect"]),l.select(["tapselect"]))),e.redrawHint("eles",!0)),e.hoverData.selecting){var g=a.collection(e.getAllInBox(s[0],s[1],s[2],s[3]));e.redrawHint("select",!0),g.length>0&&e.redrawHint("eles",!0),a.emit({type:"boxend",originalEvent:i,position:{x:o[0],y:o[1]}});var v=function(e){return e.selectable()&&!e.selected()};"additive"===a.selectionType()?g.emit("box").stdFilter(v).select().emit("boxselect"):(d||a.$(t).unmerge(g).unselect(),g.emit("box").stdFilter(v).select().emit("boxselect")),e.redraw()}if(e.hoverData.dragging&&(e.hoverData.dragging=!1,e.redrawHint("select",!0),e.redrawHint("eles",!0),e.redraw()),!s[4]){e.redrawHint("drag",!0),e.redrawHint("eles",!0);var y=h&&h.grabbed();c(u),y&&(h.emit("freeon"),u.emit("free"),e.dragData.didDrag&&(h.emit("dragfreeon"),u.emit("dragfree")))}}s[4]=0,e.hoverData.down=null,e.hoverData.cxtStarted=!1,e.hoverData.draggingEles=!1,e.hoverData.selecting=!1,e.hoverData.isOverThresholdDrag=!1,e.dragData.didDrag=!1,e.hoverData.dragged=!1,e.hoverData.dragDelta=[],e.hoverData.mdownPos=null,e.hoverData.mdownGPos=null}},!1);var m,b,x,w,E,k,C,S,D,P,T,M,_;e.registerBinding(e.container,"wheel",function(t){if(!e.scrollingPage){var n,r=e.cy,i=e.projectIntoViewport(t.clientX,t.clientY),a=[i[0]*r.zoom()+r.pan().x,i[1]*r.zoom()+r.pan().y];e.hoverData.draggingEles||e.hoverData.dragging||e.hoverData.cxtStarted||0!==e.selection[4]?t.preventDefault():r.panningEnabled()&&r.userPanningEnabled()&&r.zoomingEnabled()&&r.userZoomingEnabled()&&(t.preventDefault(),e.data.wheelZooming=!0,clearTimeout(e.data.wheelTimeout),e.data.wheelTimeout=setTimeout(function(){e.data.wheelZooming=!1,e.redrawHint("eles",!0),e.redraw()},150),n=null!=t.deltaY?t.deltaY/-250:null!=t.wheelDeltaY?t.wheelDeltaY/1e3:t.wheelDelta/1e3,n*=e.wheelSensitivity,1===t.deltaMode&&(n*=33),r.zoom({level:r.zoom()*Math.pow(10,n),renderedPosition:{x:a[0],y:a[1]}}))}},!0),e.registerBinding(window,"scroll",function(t){e.scrollingPage=!0,clearTimeout(e.scrollingPageTimeout),e.scrollingPageTimeout=setTimeout(function(){e.scrollingPage=!1},250)},!0),e.registerBinding(e.container,"mouseout",function(t){var n=e.projectIntoViewport(t.clientX,t.clientY);e.cy.emit({originalEvent:t,type:"mouseout",position:{x:n[0],y:n[1]}})},!1),e.registerBinding(e.container,"mouseover",function(t){var n=e.projectIntoViewport(t.clientX,t.clientY);e.cy.emit({originalEvent:t,type:"mouseover",position:{x:n[0],y:n[1]}})},!1);var B,N,I,z,A=function(e,t,n,r){return Math.sqrt((n-e)*(n-e)+(r-t)*(r-t))},L=function(e,t,n,r){return(n-e)*(n-e)+(r-t)*(r-t)};if(e.registerBinding(e.container,"touchstart",B=function(t){if(y(t)){d(),e.touchData.capture=!0,e.data.bgActivePosistion=void 0;var r=e.cy,i=e.touchData.now,a=e.touchData.earlier;if(t.touches[0]){var s=e.projectIntoViewport(t.touches[0].clientX,t.touches[0].clientY);i[0]=s[0],i[1]=s[1]}if(t.touches[1]){s=e.projectIntoViewport(t.touches[1].clientX,t.touches[1].clientY);i[2]=s[0],i[3]=s[1]}if(t.touches[2]){s=e.projectIntoViewport(t.touches[2].clientX,t.touches[2].clientY);i[4]=s[0],i[5]=s[1]}if(t.touches[1]){c(e.dragData.touchDragEles);var h=e.findContainerClientCoords();D=h[0],P=h[1],T=h[2],M=h[3],m=t.touches[0].clientX-D,b=t.touches[0].clientY-P,x=t.touches[1].clientX-D,w=t.touches[1].clientY-P,_=0<=m&&m<=T&&0<=x&&x<=T&&0<=b&&b<=M&&0<=w&&w<=M;var p=r.pan(),f=r.zoom();E=A(m,b,x,w),k=L(m,b,x,w),S=[((C=[(m+x)/2,(b+w)/2])[0]-p.x)/f,(C[1]-p.y)/f];if(k<4e4&&!t.touches[2]){var g=e.findNearestElement(i[0],i[1],!0,!0),v=e.findNearestElement(i[2],i[3],!0,!0);return g&&g.isNode()?(g.activate().emit({originalEvent:t,type:"cxttapstart",position:{x:i[0],y:i[1]}}),e.touchData.start=g):v&&v.isNode()?(v.activate().emit({originalEvent:t,type:"cxttapstart",position:{x:i[0],y:i[1]}}),e.touchData.start=v):r.emit({originalEvent:t,type:"cxttapstart",position:{x:i[0],y:i[1]}}),e.touchData.start&&(e.touchData.start._private.grabbed=!1),e.touchData.cxt=!0,e.touchData.cxtDragged=!1,e.data.bgActivePosistion=void 0,void e.redraw()}}if(t.touches[2]);else if(t.touches[1]);else if(t.touches[0]){var B=e.findNearestElements(i[0],i[1],!0,!0),N=B[0];if(null!=N&&(N.activate(),e.touchData.start=N,e.touchData.starts=B,e.nodeIsGrabbable(N))){var I=e.dragData.touchDragEles=r.collection(),z=null;e.redrawHint("eles",!0),e.redrawHint("drag",!0),N.selected()?(z=r.$(function(t){return t.selected()&&e.nodeIsGrabbable(t)}),l(z,{addToList:I})):u(N,{addToList:I}),o(N);var O=function(e){return{originalEvent:t,type:e,position:{x:i[0],y:i[1]}}};N.emit(O("grabon")),z?z.forEach(function(e){e.emit(O("grab"))}):N.emit(O("grab"))}n(N,["touchstart","tapstart","vmousedown"],t,{x:i[0],y:i[1]}),null==N&&(e.data.bgActivePosistion={x:s[0],y:s[1]},e.redrawHint("select",!0),e.redraw()),e.touchData.singleTouchMoved=!1,e.touchData.singleTouchStartTime=+new Date,clearTimeout(e.touchData.tapholdTimeout),e.touchData.tapholdTimeout=setTimeout(function(){!1!==e.touchData.singleTouchMoved||e.pinching||e.touchData.selecting||n(e.touchData.start,["taphold"],t,{x:i[0],y:i[1]})},e.tapholdDuration)}if(t.touches.length>=1){for(var R=e.touchData.startPosition=[],F=0;F=e.touchTapThreshold2}if(r&&e.touchData.cxt){t.preventDefault();var N=t.touches[0].clientX-D,I=t.touches[0].clientY-P,z=t.touches[1].clientX-D,O=t.touches[1].clientY-P,R=L(N,I,z,O);if(R/k>=2.25||R>=22500){e.touchData.cxt=!1,e.data.bgActivePosistion=void 0,e.redrawHint("select",!0);var F={originalEvent:t,type:"cxttapend",position:{x:s[0],y:s[1]}};e.touchData.start?(e.touchData.start.unactivate().emit(F),e.touchData.start=null):o.emit(F)}}if(r&&e.touchData.cxt){F={originalEvent:t,type:"cxtdrag",position:{x:s[0],y:s[1]}};e.data.bgActivePosistion=void 0,e.redrawHint("select",!0),e.touchData.start?e.touchData.start.emit(F):o.emit(F),e.touchData.start&&(e.touchData.start._private.grabbed=!1),e.touchData.cxtDragged=!0;var V=e.findNearestElement(s[0],s[1],!0,!0);e.touchData.cxtOver&&V===e.touchData.cxtOver||(e.touchData.cxtOver&&e.touchData.cxtOver.emit({originalEvent:t,type:"cxtdragout",position:{x:s[0],y:s[1]}}),e.touchData.cxtOver=V,V&&V.emit({originalEvent:t,type:"cxtdragover",position:{x:s[0],y:s[1]}}))}else if(r&&t.touches[2]&&o.boxSelectionEnabled())t.preventDefault(),e.data.bgActivePosistion=void 0,this.lastThreeTouch=+new Date,e.touchData.selecting||o.emit({originalEvent:t,type:"boxstart",position:{x:s[0],y:s[1]}}),e.touchData.selecting=!0,e.redrawHint("select",!0),a&&0!==a.length&&void 0!==a[0]?(a[2]=(s[0]+s[2]+s[4])/3,a[3]=(s[1]+s[3]+s[5])/3):(a[0]=(s[0]+s[2]+s[4])/3,a[1]=(s[1]+s[3]+s[5])/3,a[2]=(s[0]+s[2]+s[4])/3+1,a[3]=(s[1]+s[3]+s[5])/3+1),a[4]=1,e.touchData.selecting=!0,e.redraw();else if(r&&t.touches[1]&&o.zoomingEnabled()&&o.panningEnabled()&&o.userZoomingEnabled()&&o.userPanningEnabled()){if(t.preventDefault(),e.data.bgActivePosistion=void 0,e.redrawHint("select",!0),ee=e.dragData.touchDragEles){e.redrawHint("drag",!0);for(var q=0;q0&&!e.hoverData.draggingEles&&!e.swipePanning&&null!=e.data.bgActivePosistion&&(e.data.bgActivePosistion=void 0,e.redrawHint("select",!0),e.redraw())}},!1),e.registerBinding(window,"touchcancel",I=function(t){var n=e.touchData.start;e.touchData.capture=!1,n&&n.unactivate()}),e.registerBinding(window,"touchend",z=function(r){var i=e.touchData.start;if(e.touchData.capture){0===r.touches.length&&(e.touchData.capture=!1),r.preventDefault();var a=e.selection;e.swipePanning=!1,e.hoverData.draggingEles=!1;var o,s=e.cy,l=s.zoom(),u=e.touchData.now,h=e.touchData.earlier;if(r.touches[0]){var d=e.projectIntoViewport(r.touches[0].clientX,r.touches[0].clientY);u[0]=d[0],u[1]=d[1]}if(r.touches[1]){d=e.projectIntoViewport(r.touches[1].clientX,r.touches[1].clientY);u[2]=d[0],u[3]=d[1]}if(r.touches[2]){d=e.projectIntoViewport(r.touches[2].clientX,r.touches[2].clientY);u[4]=d[0],u[5]=d[1]}if(i&&i.unactivate(),e.touchData.cxt){if(o={originalEvent:r,type:"cxttapend",position:{x:u[0],y:u[1]}},i?i.emit(o):s.emit(o),!e.touchData.cxtDragged){var p={originalEvent:r,type:"cxttap",position:{x:u[0],y:u[1]}};i?i.emit(p):s.emit(p)}return e.touchData.start&&(e.touchData.start._private.grabbed=!1),e.touchData.cxt=!1,e.touchData.start=null,void e.redraw()}if(!r.touches[2]&&s.boxSelectionEnabled()&&e.touchData.selecting){e.touchData.selecting=!1;var f=s.collection(e.getAllInBox(a[0],a[1],a[2],a[3]));a[0]=void 0,a[1]=void 0,a[2]=void 0,a[3]=void 0,a[4]=0,e.redrawHint("select",!0),s.emit({type:"boxend",originalEvent:r,position:{x:u[0],y:u[1]}});f.emit("box").stdFilter(function(e){return e.selectable()&&!e.selected()}).select().emit("boxselect"),f.nonempty()&&e.redrawHint("eles",!0),e.redraw()}if(null!=i&&i.unactivate(),r.touches[2])e.data.bgActivePosistion=void 0,e.redrawHint("select",!0);else if(r.touches[1]);else if(r.touches[0]);else if(!r.touches[0]){e.data.bgActivePosistion=void 0,e.redrawHint("select",!0);var g=e.dragData.touchDragEles;if(null!=i){var v=i._private.grabbed;c(g),e.redrawHint("drag",!0),e.redrawHint("eles",!0),v&&(i.emit("freeon"),g.emit("free"),e.dragData.didDrag&&(i.emit("dragfreeon"),g.emit("dragfree"))),n(i,["touchend","tapend","vmouseup","tapdragout"],r,{x:u[0],y:u[1]}),i.unactivate(),e.touchData.start=null}else{var y=e.findNearestElement(u[0],u[1],!0,!0);n(y,["touchend","tapend","vmouseup","tapdragout"],r,{x:u[0],y:u[1]})}var m=e.touchData.startPosition[0]-u[0],b=m*m,x=e.touchData.startPosition[1]-u[1],w=(b+x*x)*l*l;e.touchData.singleTouchMoved||(i||s.$(":selected").unselect(["tapunselect"]),n(i,["tap","vclick"],r,{x:u[0],y:u[1]})),null!=i&&!e.dragData.didDrag&&i._private.selectable&&w0)return g[0]}return null},d=Object.keys(c),p=0;p0?l:wt(i,a,e,t,n,r,o)},checkPoint:function(e,t,n,r,i,a,o){var s=Ft(r,i),l=2*s;if(Pt(e,t,this.points,a,o,r,i-l,[0,-1],n))return!0;if(Pt(e,t,this.points,a,o,r-l,i,[0,-1],n))return!0;var u=r/2+2*n,c=i/2+2*n;return!!Dt(e,t,[a-u,o-c,a-u,o,a+u,o,a+u,o-c])||(!!_t(e,t,l,l,a+r/2-s,o+i/2-s,n)||!!_t(e,t,l,l,a-r/2+s,o+i/2-s,n))}}},Fo.registerNodeShapes=function(){var e=this.nodeShapes={},t=this;this.generateEllipse(),this.generatePolygon("triangle",Lt(3,0)),this.generatePolygon("rectangle",Lt(4,0)),e.square=e.rectangle,this.generateRoundRectangle(),this.generateCutRectangle(),this.generateBarrel(),this.generateBottomRoundrectangle(),this.generatePolygon("diamond",[0,1,1,0,0,-1,-1,0]),this.generatePolygon("pentagon",Lt(5,0)),this.generatePolygon("hexagon",Lt(6,0)),this.generatePolygon("heptagon",Lt(7,0)),this.generatePolygon("octagon",Lt(8,0));var n=new Array(20),r=Rt(5,0),i=Rt(5,Math.PI/5),a=.5*(3-Math.sqrt(5));a*=1.57;for(var o=0;o=e.deqFastCost*g)break}else if(i){if(p>=e.deqCost*l||p>=e.deqAvgCost*s)break}else if(f>=e.deqNoDrawCost*(1e3/60))break;var v=e.deq(t,h,c);if(!(v.length>0))break;for(var y=0;y0&&(e.onDeqd(t,u),!i&&e.shouldRedraw(t,u,h,c)&&r())},i(t))}}},Wo=function(){function e(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:be;t(this,e),this.idsByKey=new ze,this.keyForId=new ze,this.cachesByLvl=new ze,this.lvls=[],this.getKey=n,this.doesEleInvalidateKey=r}return r(e,[{key:"getIdsFor",value:function(e){null==e&&Ee("Can not get id list for null key");var t=this.idsByKey,n=this.idsByKey.get(e);return n||(n=new Le,t.set(e,n)),n}},{key:"addIdForKey",value:function(e,t){null!=e&&this.getIdsFor(e).add(t)}},{key:"deleteIdForKey",value:function(e,t){null!=e&&this.getIdsFor(e).delete(t)}},{key:"getNumberOfIdsForKey",value:function(e){return null==e?0:this.getIdsFor(e).size}},{key:"updateKeyMappingFor",value:function(e){var t=e.id(),n=this.keyForId.get(t),r=this.getKey(e);this.deleteIdForKey(n,t),this.addIdForKey(r,t),this.keyForId.set(t,r)}},{key:"deleteKeyMappingFor",value:function(e){var t=e.id(),n=this.keyForId.get(t);this.deleteIdForKey(n,t),this.keyForId.delete(t)}},{key:"keyHasChangedFor",value:function(e){var t=e.id();return this.keyForId.get(t)!==this.getKey(e)}},{key:"isInvalid",value:function(e){return this.keyHasChangedFor(e)||this.doesEleInvalidateKey(e)}},{key:"getCachesAt",value:function(e){var t=this.cachesByLvl,n=this.lvls,r=t.get(e);return r||(r=new ze,t.set(e,r),n.push(e)),r}},{key:"getCache",value:function(e,t){return this.getCachesAt(t).get(e)}},{key:"get",value:function(e,t){var n=this.getKey(e),r=this.getCache(n,t);return null!=r&&this.updateKeyMappingFor(e),r}},{key:"getForCachedKey",value:function(e,t){var n=this.keyForId.get(e.id());return this.getCache(n,t)}},{key:"hasCache",value:function(e,t){return this.getCachesAt(t).has(e)}},{key:"has",value:function(e,t){var n=this.getKey(e);return this.hasCache(n,t)}},{key:"setCache",value:function(e,t,n){n.key=e,this.getCachesAt(t).set(e,n)}},{key:"set",value:function(e,t,n){var r=this.getKey(e);this.setCache(r,t,n),this.updateKeyMappingFor(e)}},{key:"deleteCache",value:function(e,t){this.getCachesAt(t).delete(e)}},{key:"delete",value:function(e,t){var n=this.getKey(e);this.deleteCache(n,t)}},{key:"invalidateKey",value:function(e){var t=this;this.lvls.forEach(function(n){return t.deleteCache(e,n)})}},{key:"invalidate",value:function(e){var t=e.id(),n=this.keyForId.get(t);this.deleteKeyMappingFor(e);var r=this.doesEleInvalidateKey(e);return r&&this.invalidateKey(n),r||0===this.getNumberOfIdsForKey(n)}}]),e}(),Ho={dequeue:"dequeue",downscale:"downscale",highQuality:"highQuality"},Ko=Me({getKey:null,doesEleInvalidateKey:be,drawElement:null,getBoundingBox:null,getRotationPoint:null,getRotationOffset:null,isVisible:me,allowEdgeTxrCaching:!0,allowParentTxrCaching:!0}),Go=function(e,t){this.renderer=e,this.onDequeues=[];var n=Ko(t);I(this,n),this.lookup=new Wo(n.getKey,n.doesEleInvalidateKey),this.setupDequeueing()},Zo=Go.prototype;Zo.reasons=Ho,Zo.getTextureQueue=function(e){return this.eleImgCaches=this.eleImgCaches||{},this.eleImgCaches[e]=this.eleImgCaches[e]||[]},Zo.getRetiredTextureQueue=function(e){var t=this.eleImgCaches.retired=this.eleImgCaches.retired||{};return t[e]=t[e]||[]},Zo.getElementQueue=function(){return this.eleCacheQueue=this.eleCacheQueue||new Ve(function(e,t){return t.reqs-e.reqs})},Zo.getElementKeyToQueue=function(){return this.eleKeyToCacheQueue=this.eleKeyToCacheQueue||{}},Zo.getElement=function(e,t,n,r,i){var a=this,o=this.renderer,s=o.cy.zoom(),l=this.lookup;if(0===t.w||0===t.h||isNaN(t.w)||isNaN(t.h)||!e.visible())return null;if(!a.allowEdgeTxrCaching&&e.isEdge()||!a.allowParentTxrCaching&&e.isParent())return null;if(null==r&&(r=Math.ceil(at(s*n))),r<-4)r=-4;else if(s>=7.99||r>3)return null;var u=Math.pow(2,r),c=t.h*u,h=t.w*u,d=o.eleTextBiggerThanMin(e,u);if(!this.isVisible(e,d))return null;var p,f=l.get(e,r);if(f&&f.invalidated&&(f.invalidated=!1,f.texture.invalidatedWidth-=f.width),f)return f;if(p=c<=25?25:c<=50?50:50*Math.ceil(c/50),c>1024||h>1024)return null;var g=a.getTextureQueue(p),v=g[g.length-2],y=function(){return a.recycleTexture(p,h)||a.addTexture(p,h)};v||(v=g[g.length-1]),v||(v=y()),v.width-v.usedWidthr;P--)S=a.getElement(e,t,n,P,Ho.downscale);D()}else{var T;if(!x&&!w&&!E)for(var M=r-1;M>=-4;M--){var _=l.get(e,M);if(_){T=_;break}}if(b(T))return a.queueElement(e,r),T;v.context.translate(v.usedWidth,0),v.context.scale(u,u),this.drawElement(v.context,e,t,d,!1),v.context.scale(1/u,1/u),v.context.translate(-v.usedWidth,0)}return f={x:v.usedWidth,texture:v,level:r,scale:u,width:h,height:c,scaledLabelShown:d},v.usedWidth+=Math.ceil(h+8),v.eleCaches.push(f),l.set(e,r,f),a.checkTextureFullness(v),f},Zo.invalidateElements=function(e){for(var t=0;t=.2*e.width&&this.retireTexture(e)},Zo.checkTextureFullness=function(e){var t=this.getTextureQueue(e.height);e.usedWidth/e.width>.8&&e.fullnessChecks>=10?_e(t,e):e.fullnessChecks++},Zo.retireTexture=function(e){var t=e.height,n=this.getTextureQueue(t),r=this.lookup;_e(n,e),e.retired=!0;for(var i=e.eleCaches,a=0;a=t)return a.retired=!1,a.usedWidth=0,a.invalidatedWidth=0,a.fullnessChecks=0,Be(a.eleCaches),a.context.setTransform(1,0,0,1,0,0),a.context.clearRect(0,0,a.width,a.height),_e(r,a),n.push(a),a}},Zo.queueElement=function(e,t){var n=this.getElementQueue(),r=this.getElementKeyToQueue(),i=this.getKey(e),a=r[i];if(a)a.level=Math.max(a.level,t),a.eles.merge(e),a.reqs++,n.updateItem(a);else{var o={eles:e.spawn().merge(e),level:t,reqs:1,key:i};n.push(o),r[i]=o}},Zo.dequeue=function(e){for(var t=this.getElementQueue(),n=this.getElementKeyToQueue(),r=[],i=this.lookup,a=0;a<1&&t.size()>0;a++){var o=t.pop(),s=o.key,l=o.eles[0],u=i.hasCache(l,o.level);if(n[s]=null,!u){r.push(o);var c=this.getBoundingBox(l);this.getElement(l,c,e,o.level,Ho.dequeue)}}return r},Zo.removeFromQueue=function(e){var t=this.getElementQueue(),n=this.getElementKeyToQueue(),r=this.getKey(e),i=n[r];null!=i&&(1===i.eles.length?(i.reqs=ye,t.updateItem(i),t.pop(),n[r]=null):i.eles.unmerge(e))},Zo.onDequeue=function(e){this.onDequeues.push(e)},Zo.offDequeue=function(e){_e(this.onDequeues,e)},Zo.setupDequeueing=jo({deqRedrawThreshold:100,deqCost:.15,deqAvgCost:.1,deqNoDrawCost:.9,deqFastCost:.9,deq:function(e,t,n){return e.dequeue(t,n)},onDeqd:function(e,t){for(var n=0;n=3.99||n>2)return null;r.validateLayersElesOrdering(n,e);var o,s,l=r.layersByLevel,u=Math.pow(2,n),c=l[n]=l[n]||[];if(r.levelIsComplete(n,e))return c;!function(){var t=function(t){if(r.validateLayersElesOrdering(t,e),r.levelIsComplete(t,e))return s=l[t],!0},i=function(e){if(!s)for(var r=n+e;-4<=r&&r<=2&&!t(r);r+=e);};i(1),i(-1);for(var a=c.length-1;a>=0;a--){var o=c[a];o.invalid&&_e(c,o)}}();var h=function(t){var i=(t=t||{}).after;if(function(){if(!o){o=pt();for(var t=0;t16e6)return null;var a=r.makeLayer(o,n);if(null!=i){var s=c.indexOf(i)+1;c.splice(s,0,a)}else(void 0===t.insert||t.insert)&&c.unshift(a);return a};if(r.skipping&&!a)return null;for(var d=null,p=e.length/1,f=!a,g=0;g=p||!xt(d.bb,v.boundingBox()))&&!(d=h({insert:!0,after:d})))return null;s||f?r.queueLayer(d,v):r.drawEleInLayer(d,v,n,t),d.eles.push(v),m[n]=d}}return s||(f?null:c)},$o.getEleLevelForLayerLevel=function(e,t){return e},$o.drawEleInLayer=function(e,t,n,r){var i=this.renderer,a=e.context,o=t.boundingBox();0!==o.w&&0!==o.h&&t.visible()&&(n=this.getEleLevelForLayerLevel(n,r),i.setImgSmoothing(a,!1),i.drawCachedElement(a,t,null,null,n,!0),i.setImgSmoothing(a,!0))},$o.levelIsComplete=function(e,t){var n=this.layersByLevel[e];if(!n||0===n.length)return!1;for(var r=0,i=0;i0)return!1;if(a.invalid)return!1;r+=a.eles.length}return r===t.length},$o.validateLayersElesOrdering=function(e,t){var n=this.layersByLevel[e];if(n)for(var r=0;r0){e=!0;break}}return e},$o.invalidateElements=function(e){var t=this;0!==e.length&&(t.lastInvalidationTime=se(),0!==e.length&&t.haveLayers()&&t.updateElementsInLayers(e,function(e,n,r){t.invalidateLayer(e)}))},$o.invalidateLayer=function(e){if(this.lastInvalidationTime=se(),!e.invalid){var t=e.level,n=e.eles,r=this.layersByLevel[t];_e(r,e),e.elesQueue=[],e.invalid=!0,e.replacement&&(e.replacement.invalid=!0);for(var i=0;i3&&void 0!==arguments[3])||arguments[3],i=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],a=!(arguments.length>5&&void 0!==arguments[5])||arguments[5],o=this,s=t._private.rscratch;if(t.visible()&&!s.badLine&&null!=s.allpts&&!isNaN(s.allpts[0])){var l;n&&(l=n,e.translate(-l.x1,-l.y1));var u=a?t.pstyle("opacity").value:1,c=t.pstyle("line-style").value,h=t.pstyle("width").pfValue,d=t.pstyle("line-cap").value,p=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u;e.lineWidth=h,e.lineCap=d,o.eleStrokeStyle(e,t,n),o.drawEdgePath(t,e,s.allpts,c),e.lineCap="butt"},f=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u;o.drawArrowheads(e,t,n)};if(e.lineJoin="round","yes"===t.pstyle("ghost").value){var g=t.pstyle("ghost-offset-x").pfValue,v=t.pstyle("ghost-offset-y").pfValue,y=t.pstyle("ghost-opacity").value,m=u*y;e.translate(g,v),p(m),f(m),e.translate(-g,-v)}p(),f(),i&&o.drawEdgeOverlay(e,t),o.drawElementText(e,t,null,r),n&&e.translate(l.x1,l.y1)}},drawEdgeOverlay:function(e,t){if(t.visible()){var n=t.pstyle("overlay-opacity").value;if(0!==n){var r=this,i=r.usePaths(),a=t._private.rscratch,o=2*t.pstyle("overlay-padding").pfValue,s=t.pstyle("overlay-color").value;e.lineWidth=o,"self"!==a.edgeType||i?e.lineCap="round":e.lineCap="butt",r.colorStrokeStyle(e,s[0],s[1],s[2],n),r.drawEdgePath(t,e,a.allpts,"solid")}}},drawEdgePath:function(e,t,n,r){var i,a=e._private.rscratch,o=t,s=!1,l=this.usePaths(),u=e.pstyle("line-dash-pattern").pfValue,c=e.pstyle("line-dash-offset").pfValue;if(l){var h=n.join("$");a.pathCacheKey&&a.pathCacheKey===h?(i=t=a.pathCache,s=!0):(i=t=new Path2D,a.pathCacheKey=h,a.pathCache=i)}if(o.setLineDash)switch(r){case"dotted":o.setLineDash([1,1]);break;case"dashed":o.setLineDash(u),o.lineDashOffset=c;break;case"solid":o.setLineDash([])}if(!s&&!a.badLine)switch(t.beginPath&&t.beginPath(),t.moveTo(n[0],n[1]),a.edgeType){case"bezier":case"self":case"compound":case"multibezier":for(var d=2;d+35&&void 0!==arguments[5])||arguments[5],o=this;if(null==r){if(!o.eleTextBiggerThanMin(t))return}else if(!1===r)return;if(t.isNode()){if(!(s=t.pstyle("label"))||!s.value)return;switch(t.pstyle("text-halign").strValue){case"left":e.textAlign="right";break;case"right":e.textAlign="left";break;default:e.textAlign="center"}e.textBaseline="bottom"}else{var s=t.pstyle("label"),l=t.pstyle("source-label"),u=t.pstyle("target-label");if(!(s&&s.value||l&&l.value||u&&u.value))return;e.textAlign="center",e.textBaseline="bottom"}var c,h=!n;n&&(c=n,e.translate(-c.x1,-c.y1)),null==i?(o.drawText(e,t,null,h,a),t.isEdge()&&(o.drawText(e,t,"source",h,a),o.drawText(e,t,"target",h,a))):o.drawText(e,t,i,h,a),n&&e.translate(c.x1,c.y1)},ps.getFontCache=function(e){var t;this.fontCaches=this.fontCaches||[];for(var n=0;n2&&void 0!==arguments[2])||arguments[2],r=t.pstyle("font-style").strValue,i=t.pstyle("font-size").pfValue+"px",a=t.pstyle("font-family").strValue,o=t.pstyle("font-weight").strValue,s=t.pstyle("text-opacity").value*(n?t.effectiveOpacity():1),l=t.pstyle("text-outline-opacity").value*s,u=t.pstyle("color").value,c=t.pstyle("text-outline-color").value;e.font=r+" "+o+" "+i+" "+a,e.lineJoin="round",this.colorFillStyle(e,u[0],u[1],u[2],s),this.colorStrokeStyle(e,c[0],c[1],c[2],l)},ps.getTextAngle=function(e,t){var n=e._private.rscratch,r=t?t+"-":"",i=e.pstyle(r+"text-rotation"),a=Ne(n,"labelAngle",t);return"autorotate"===i.strValue?e.isEdge()?a:0:"none"===i.strValue?0:i.pfValue},ps.drawText=function(e,t,n){var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],a=t._private.rscratch,o=i?t.effectiveOpacity():1;if(0!==o&&0!==t.pstyle("text-opacity").value){"main"===n&&(n=null);var s,l,u,c,h,d,p=Ne(a,"labelX",n),f=Ne(a,"labelY",n),g=this.getLabelText(t,n);if(null!=g&&""!==g&&!isNaN(p)&&!isNaN(f)){this.setupTextStyle(e,t,i);var v,y=n?n+"-":"",m=Ne(a,"labelWidth",n),b=Ne(a,"labelHeight",n),x=t.pstyle(y+"text-margin-x").pfValue,w=t.pstyle(y+"text-margin-y").pfValue,E=t.isEdge(),k=t.pstyle("text-halign").value,C=t.pstyle("text-valign").value;if(E&&(k="center",C="center"),p+=x,f+=w,0!==(v=r?this.getTextAngle(t,n):0)){var S=p,D=f;e.translate(S,D),e.rotate(v),p=0,f=0}switch(C){case"top":break;case"center":f+=b/2;break;case"bottom":f+=b}var P=t.pstyle("text-background-opacity").value,T=t.pstyle("text-border-opacity").value,M=t.pstyle("text-border-width").pfValue,_=t.pstyle("text-background-padding").pfValue;if(P>0||M>0&&T>0){var B=p-_;switch(k){case"left":B-=m;break;case"center":B-=m/2}var N=f-b-_,I=m+2*_,z=b+2*_;if(P>0){var A=e.fillStyle,L=t.pstyle("text-background-color").value;e.fillStyle="rgba("+L[0]+","+L[1]+","+L[2]+","+P*o+")","roundrectangle"==t.pstyle("text-background-shape").strValue?(l=B,u=N,c=I,h=z,d=(d=2)||5,(s=e).beginPath(),s.moveTo(l+d,u),s.lineTo(l+c-d,u),s.quadraticCurveTo(l+c,u,l+c,u+d),s.lineTo(l+c,u+h-d),s.quadraticCurveTo(l+c,u+h,l+c-d,u+h),s.lineTo(l+d,u+h),s.quadraticCurveTo(l,u+h,l,u+h-d),s.lineTo(l,u+d),s.quadraticCurveTo(l,u,l+d,u),s.closePath(),s.fill()):e.fillRect(B,N,I,z),e.fillStyle=A}if(M>0&&T>0){var O=e.strokeStyle,R=e.lineWidth,F=t.pstyle("text-border-color").value,V=t.pstyle("text-border-style").value;if(e.strokeStyle="rgba("+F[0]+","+F[1]+","+F[2]+","+T*o+")",e.lineWidth=M,e.setLineDash)switch(V){case"dotted":e.setLineDash([1,1]);break;case"dashed":e.setLineDash([4,2]);break;case"double":e.lineWidth=M/4,e.setLineDash([]);break;case"solid":e.setLineDash([])}if(e.strokeRect(B,N,I,z),"double"===V){var q=M/2;e.strokeRect(B+q,N+q,I-2*q,z-2*q)}e.setLineDash&&e.setLineDash([]),e.lineWidth=R,e.strokeStyle=O}}var Y=2*t.pstyle("text-outline-width").pfValue;if(Y>0&&(e.lineWidth=Y),"wrap"===t.pstyle("text-wrap").value){var X=Ne(a,"labelWrapCachedLines",n),j=b/X.length;switch(C){case"top":f-=(X.length-1)*j;break;case"center":case"bottom":f-=(X.length-1)*j}for(var W=0;W0&&e.strokeText(X[W],p,f),e.fillText(X[W],p,f),f+=j}else Y>0&&e.strokeText(g,p,f),e.fillText(g,p,f);0!==v&&(e.rotate(-v),e.translate(-S,-D))}}};var fs={drawNode:function(e,t,n){var r,i,a=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],s=!(arguments.length>5&&void 0!==arguments[5])||arguments[5],l=this,u=t._private,c=u.rscratch,h=t.position();if(v(h.x)&&v(h.y)&&t.visible()){var d,p,f=s?t.effectiveOpacity():1,g=l.usePaths(),y=!1,m=t.padding();r=t.width()+2*m,i=t.height()+2*m,n&&(p=n,e.translate(-p.x1,-p.y1));for(var b=t.pstyle("background-image").value,x=new Array(b.length),w=new Array(b.length),E=0,k=0;k0&&void 0!==arguments[0]?arguments[0]:T;l.eleFillStyle(e,t,n)},I=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:B;l.colorStrokeStyle(e,M[0],M[1],M[2],t)},z=t.pstyle("shape").strValue,A=t.pstyle("shape-polygon-points").pfValue;if(g){e.translate(h.x,h.y);var L=l.nodePathCache=l.nodePathCache||[],O=de("polygon"===z?z+","+A.join(","):z,""+i,""+r),R=L[O];null!=R?(d=R,y=!0,c.pathCache=d):(d=new Path2D,L[O]=c.pathCache=d)}var F=function(){if(!y){var n=h;g&&(n={x:0,y:0}),l.nodeShapes[l.getNodeShape(t)].draw(d||e,n.x,n.y,r,i)}g?e.fill(d):e.fill()},V=function(){for(var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:f,r=u.backgrounding,i=0,a=0;a0&&void 0!==arguments[0]&&arguments[0],a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:f;l.hasPie(t)&&(l.drawPie(e,t,a),n&&(g||l.nodeShapes[l.getNodeShape(t)].draw(e,h.x,h.y,r,i)))},Y=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:f,n=(D>0?D:-D)*t,r=D>0?0:255;0!==D&&(l.colorFillStyle(e,r,r,r,n),g?e.fill(d):e.fill())},X=function(){if(P>0){if(e.lineWidth=P,e.lineCap="butt",e.setLineDash)switch(_){case"dotted":e.setLineDash([1,1]);break;case"dashed":e.setLineDash([4,2]);break;case"solid":case"double":e.setLineDash([])}if(g?e.stroke(d):e.stroke(),"double"===_){e.lineWidth=P/3;var t=e.globalCompositeOperation;e.globalCompositeOperation="destination-out",g?e.stroke(d):e.stroke(),e.globalCompositeOperation=t}e.setLineDash&&e.setLineDash([])}};if("yes"===t.pstyle("ghost").value){var j=t.pstyle("ghost-offset-x").pfValue,W=t.pstyle("ghost-offset-y").pfValue,H=t.pstyle("ghost-opacity").value,K=H*f;e.translate(j,W),N(H*T),F(),V(K),q(0!==D||0!==P),Y(K),I(H*B),X(),e.translate(-j,-W)}N(),F(),V(),q(0!==D||0!==P),Y(),I(),X(),g&&e.translate(-h.x,-h.y),l.drawElementText(e,t,null,a),o&&l.drawNodeOverlay(e,t,h,r,i),n&&e.translate(p.x1,p.y1)}},drawNodeOverlay:function(e,t,n,r,i){if(t.visible()){var a=t.pstyle("overlay-padding").pfValue,o=t.pstyle("overlay-opacity").value,s=t.pstyle("overlay-color").value;if(o>0){if(n=n||t.position(),null==r||null==i){var l=t.padding();r=t.width()+2*l,i=t.height()+2*l}this.colorFillStyle(e,s[0],s[1],s[2],o),this.nodeShapes.roundrectangle.draw(e,n.x,n.y,r+2*a,i+2*a),e.fill()}}},hasPie:function(e){return(e=e[0])._private.hasPie},drawPie:function(e,t,n,r){t=t[0],r=r||t.position();var i=t.cy().style(),a=t.pstyle("pie-size"),o=r.x,s=r.y,l=t.width(),u=t.height(),c=Math.min(l,u)/2,h=0;this.usePaths()&&(o=0,s=0),"%"===a.units?c*=a.pfValue:void 0!==a.pfValue&&(c=a.pfValue/2);for(var d=1;d<=i.pieBackgroundN;d++){var p=t.pstyle("pie-"+d+"-background-size").value,f=t.pstyle("pie-"+d+"-background-color").value,g=t.pstyle("pie-"+d+"-background-opacity").value*n,v=p/100;v+h>1&&(v=1-h);var y=1.5*Math.PI+2*Math.PI*h,m=y+2*Math.PI*v;0===p||h>=1||h+v>1||(e.beginPath(),e.moveTo(o,s),e.arc(o,s,c,y,m),e.closePath(),this.colorFillStyle(e,f[0],f[1],f[2],g),e.fill(),h+=v)}}},gs={};gs.getPixelRatio=function(){var e=this.data.contexts[0];if(null!=this.forcedPixelRatio)return this.forcedPixelRatio;var t=e.backingStorePixelRatio||e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1;return(window.devicePixelRatio||1)/t},gs.paintCache=function(e){for(var t,n=this.paintCaches=this.paintCaches||[],r=!0,i=0;io.minMbLowQualFrames&&(o.motionBlurPxRatio=o.mbPxRBlurry)),o.clearingMotionBlur&&(o.motionBlurPxRatio=1),o.textureDrawLastFrame&&!h&&(c[o.NODE]=!0,c[o.SELECT_BOX]=!0);var m=l.style(),b=l.zoom(),x=void 0!==i?i:b,w=l.pan(),E={x:w.x,y:w.y},k={zoom:b,pan:{x:w.x,y:w.y}},C=o.prevViewport;void 0===C||k.zoom!==C.zoom||k.pan.x!==C.pan.x||k.pan.y!==C.pan.y||g&&!f||(o.motionBlurPxRatio=1),a&&(E=a),x*=s,E.x*=s,E.y*=s;var S=o.getCachedZSortedEles();function D(e,t,n,r,i){var a=e.globalCompositeOperation;e.globalCompositeOperation="destination-out",o.colorFillStyle(e,255,255,255,o.motionBlurTransparency),e.fillRect(t,n,r,i),e.globalCompositeOperation=a}function P(e,r){var s,l,c,h;o.clearingMotionBlur||e!==u.bufferContexts[o.MOTIONBLUR_BUFFER_NODE]&&e!==u.bufferContexts[o.MOTIONBLUR_BUFFER_DRAG]?(s=E,l=x,c=o.canvasWidth,h=o.canvasHeight):(s={x:w.x*p,y:w.y*p},l=b*p,c=o.canvasWidth*p,h=o.canvasHeight*p),e.setTransform(1,0,0,1,0,0),"motionBlur"===r?D(e,0,0,c,h):t||void 0!==r&&!r||e.clearRect(0,0,c,h),n||(e.translate(s.x,s.y),e.scale(l,l)),a&&e.translate(a.x,a.y),i&&e.scale(i,i)}if(h||(o.textureDrawLastFrame=!1),h){if(o.textureDrawLastFrame=!0,!o.textureCache){o.textureCache={},o.textureCache.bb=l.mutableElements().boundingBox(),o.textureCache.texture=o.data.bufferCanvases[o.TEXTURE_BUFFER];var T=o.data.bufferContexts[o.TEXTURE_BUFFER];T.setTransform(1,0,0,1,0,0),T.clearRect(0,0,o.canvasWidth*o.textureMult,o.canvasHeight*o.textureMult),o.render({forcedContext:T,drawOnlyNodeLayer:!0,forcedPxRatio:s*o.textureMult}),(k=o.textureCache.viewport={zoom:l.zoom(),pan:l.pan(),width:o.canvasWidth,height:o.canvasHeight}).mpan={x:(0-k.pan.x)/k.zoom,y:(0-k.pan.y)/k.zoom}}c[o.DRAG]=!1,c[o.NODE]=!1;var M=u.contexts[o.NODE],_=o.textureCache.texture;k=o.textureCache.viewport;M.setTransform(1,0,0,1,0,0),d?D(M,0,0,k.width,k.height):M.clearRect(0,0,k.width,k.height);var B=m.core("outside-texture-bg-color").value,N=m.core("outside-texture-bg-opacity").value;o.colorFillStyle(M,B[0],B[1],B[2],N),M.fillRect(0,0,k.width,k.height);b=l.zoom();P(M,!1),M.clearRect(k.mpan.x,k.mpan.y,k.width/k.zoom/s,k.height/k.zoom/s),M.drawImage(_,k.mpan.x,k.mpan.y,k.width/k.zoom/s,k.height/k.zoom/s)}else o.textureOnViewport&&!t&&(o.textureCache=null);var I=l.extent(),z=o.pinching||o.hoverData.dragging||o.swipePanning||o.data.wheelZooming||o.hoverData.draggingEles,A=o.hideEdgesOnViewport&&z,L=[];if(L[o.NODE]=!c[o.NODE]&&d&&!o.clearedForMotionBlur[o.NODE]||o.clearingMotionBlur,L[o.NODE]&&(o.clearedForMotionBlur[o.NODE]=!0),L[o.DRAG]=!c[o.DRAG]&&d&&!o.clearedForMotionBlur[o.DRAG]||o.clearingMotionBlur,L[o.DRAG]&&(o.clearedForMotionBlur[o.DRAG]=!0),c[o.NODE]||n||r||L[o.NODE]){var O=d&&!L[o.NODE]&&1!==p;P(M=t||(O?o.data.bufferContexts[o.MOTIONBLUR_BUFFER_NODE]:u.contexts[o.NODE]),d&&!O?"motionBlur":void 0),A?o.drawCachedNodes(M,S.nondrag,s,I):o.drawLayeredElements(M,S.nondrag,s,I),o.debug&&o.drawDebugPoints(M,S.nondrag),n||d||(c[o.NODE]=!1)}if(!r&&(c[o.DRAG]||n||L[o.DRAG])){O=d&&!L[o.DRAG]&&1!==p;P(M=t||(O?o.data.bufferContexts[o.MOTIONBLUR_BUFFER_DRAG]:u.contexts[o.DRAG]),d&&!O?"motionBlur":void 0),A?o.drawCachedNodes(M,S.drag,s,I):o.drawCachedElements(M,S.drag,s,I),o.debug&&o.drawDebugPoints(M,S.drag),n||d||(c[o.DRAG]=!1)}if(o.showFps||!r&&c[o.SELECT_BOX]&&!n){if(P(M=t||u.contexts[o.SELECT_BOX]),1==o.selection[4]&&(o.hoverData.selecting||o.touchData.selecting)){b=o.cy.zoom();var R=m.core("selection-box-border-width").value/b;M.lineWidth=R,M.fillStyle="rgba("+m.core("selection-box-color").value[0]+","+m.core("selection-box-color").value[1]+","+m.core("selection-box-color").value[2]+","+m.core("selection-box-opacity").value+")",M.fillRect(o.selection[0],o.selection[1],o.selection[2]-o.selection[0],o.selection[3]-o.selection[1]),R>0&&(M.strokeStyle="rgba("+m.core("selection-box-border-color").value[0]+","+m.core("selection-box-border-color").value[1]+","+m.core("selection-box-border-color").value[2]+","+m.core("selection-box-opacity").value+")",M.strokeRect(o.selection[0],o.selection[1],o.selection[2]-o.selection[0],o.selection[3]-o.selection[1]))}if(u.bgActivePosistion&&!o.hoverData.selecting){b=o.cy.zoom();var F=u.bgActivePosistion;M.fillStyle="rgba("+m.core("active-bg-color").value[0]+","+m.core("active-bg-color").value[1]+","+m.core("active-bg-color").value[2]+","+m.core("active-bg-opacity").value+")",M.beginPath(),M.arc(F.x,F.y,m.core("active-bg-size").pfValue/b,0,2*Math.PI),M.fill()}var V=o.lastRedrawTime;if(o.showFps&&V){V=Math.round(V);var q=Math.round(1e3/V);M.setTransform(1,0,0,1,0,0),M.fillStyle="rgba(255, 0, 0, 0.75)",M.strokeStyle="rgba(255, 0, 0, 0.75)",M.lineWidth=1,M.fillText("1 frame = "+V+" ms = "+q+" fps",0,20);M.strokeRect(0,30,250,20),M.fillRect(0,30,250*Math.min(q/60,1),20)}n||(c[o.SELECT_BOX]=!1)}if(d&&1!==p){var Y=u.contexts[o.NODE],X=o.data.bufferCanvases[o.MOTIONBLUR_BUFFER_NODE],j=u.contexts[o.DRAG],W=o.data.bufferCanvases[o.MOTIONBLUR_BUFFER_DRAG],H=function(e,t,n){e.setTransform(1,0,0,1,0,0),n||!y?e.clearRect(0,0,o.canvasWidth,o.canvasHeight):D(e,0,0,o.canvasWidth,o.canvasHeight);var r=p;e.drawImage(t,0,0,o.canvasWidth*r,o.canvasHeight*r,0,0,o.canvasWidth,o.canvasHeight)};(c[o.NODE]||L[o.NODE])&&(H(Y,X,L[o.NODE]),c[o.NODE]=!1),(c[o.DRAG]||L[o.DRAG])&&(H(j,W,L[o.DRAG]),c[o.DRAG]=!1)}o.prevViewport=k,o.clearingMotionBlur&&(o.clearingMotionBlur=!1,o.motionBlurCleared=!0,o.motionBlur=!0),d&&(o.motionBlurTimeout=setTimeout(function(){o.motionBlurTimeout=null,o.clearedForMotionBlur[o.NODE]=!1,o.clearedForMotionBlur[o.DRAG]=!1,o.motionBlur=!1,o.clearingMotionBlur=!h,o.mbFrames=0,c[o.NODE]=!0,c[o.DRAG]=!0,o.redraw()},100)),t||l.emit("render")};for(var vs={drawPolygonPath:function(e,t,n,r,i,a){var o=r/2,s=i/2;e.beginPath&&e.beginPath(),e.moveTo(t+o*a[0],n+s*a[1]);for(var l=1;l0&&a>0){d.clearRect(0,0,i,a),d.globalCompositeOperation="source-over";var p=this.getCachedZSortedEles();if(e.full)d.translate(-n.x1*l,-n.y1*l),d.scale(l,l),this.drawElements(d,p),d.scale(1/l,1/l),d.translate(n.x1*l,n.y1*l);else{var f=t.pan(),g={x:f.x*l,y:f.y*l};l*=t.zoom(),d.translate(g.x,g.y),d.scale(l,l),this.drawElements(d,p),d.scale(1/l,1/l),d.translate(-g.x,-g.y)}e.bg&&(d.globalCompositeOperation="destination-over",d.fillStyle=e.bg,d.rect(0,0,i,a),d.fill())}return h},ks.png=function(e){return Ss(e,this.bufferCanvasImage(e),"image/png")},ks.jpg=function(e){return Ss(e,this.bufferCanvasImage(e),"image/jpeg")};var Ds={nodeShapeImpl:function(e,t,n,r,i,a,o){switch(e){case"ellipse":return this.drawEllipsePath(t,n,r,i,a);case"polygon":return this.drawPolygonPath(t,n,r,i,a,o);case"roundrectangle":case"round-rectangle":return this.drawRoundRectanglePath(t,n,r,i,a);case"cutrectangle":case"cut-rectangle":return this.drawCutRectanglePath(t,n,r,i,a);case"bottomroundrectangle":case"bottom-round-rectangle":return this.drawBottomRoundRectanglePath(t,n,r,i,a);case"barrel":return this.drawBarrelPath(t,n,r,i,a)}}},Ps=Ms,Ts=Ms.prototype;function Ms(e){var t=this;t.data={canvases:new Array(Ts.CANVAS_LAYERS),contexts:new Array(Ts.CANVAS_LAYERS),canvasNeedsRedraw:new Array(Ts.CANVAS_LAYERS),bufferCanvases:new Array(Ts.BUFFER_COUNT),bufferContexts:new Array(Ts.CANVAS_LAYERS)};var n="-webkit-tap-highlight-color: rgba(0,0,0,0);";t.data.canvasContainer=document.createElement("div");var r=t.data.canvasContainer.style;t.data.canvasContainer.setAttribute("style",n),r.position="relative",r.zIndex="0",r.overflow="hidden";var i=e.cy.container();i.appendChild(t.data.canvasContainer),(i.getAttribute("style")||"").indexOf(n)<0&&i.setAttribute("style",(i.getAttribute("style")||"")+n);for(var a=0;at?1:0},z=null!=Object.assign?Object.assign.bind(Object):function(e){for(var t=arguments,n=1;n255)return;t.push(Math.floor(a))}var o=r[1]||r[2]||r[3],s=r[1]&&r[2]&&r[3];if(o&&!s)return;var l=n[4];if(void 0!==l){if((l=parseFloat(l))<0||l>1)return;t.push(l)}}return t}(e)||function(e){var t,n,r,i,a,o,s,l;function u(e,t,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?e+6*(t-e)*n:n<.5?t:n<2/3?e+(t-e)*(2/3-n)*6:e}var c=new RegExp("^hsl[a]?\\(((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?)))\\s*,\\s*((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?))[%])\\s*,\\s*((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?))[%])(?:\\s*,\\s*((?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?))))?\\)$").exec(e);if(c){if((n=parseInt(c[1]))<0?n=(360- -1*n%360)%360:n>360&&(n%=360),n/=360,(r=parseFloat(c[2]))<0||r>100)return;if(r/=100,(i=parseFloat(c[3]))<0||i>100)return;if(i/=100,void 0!==(a=c[4])&&((a=parseFloat(a))<0||a>1))return;if(0===r)o=s=l=Math.round(255*i);else{var h=i<.5?i*(1+r):i+r-i*r,d=2*i-h;o=Math.round(255*u(d,h,n+1/3)),s=Math.round(255*u(d,h,n)),l=Math.round(255*u(d,h,n-1/3))}t=[o,s,l,a]}return t}(e)},L={transparent:[0,0,0,0],aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],grey:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},A=function(e){for(var t=e.map,n=e.keys,r=n.length,i=0;i=t||n<0||h&&e-u>=a}function g(){var e=J();if(f(e))return v(e);s=setTimeout(g,function(e){var n=t-(e-l);return h?Q(n,a-(e-u)):n}(e))}function v(e){return s=void 0,d&&r?p(e):(r=i=void 0,o)}function y(){var e=J(),n=f(e);if(r=arguments,i=this,l=e,n){if(void 0===s)return function(e){return u=e,s=setTimeout(g,t),c?p(e):o}(l);if(h)return s=setTimeout(g,t),p(l)}return void 0===s&&(s=setTimeout(g,t)),o}return t=te(t)||0,ee(n)&&(c=!!n.leading,a=(h="maxWait"in n)?$(te(n.maxWait)||0,t):a,d="trailing"in n?!!n.trailing:d),y.cancel=function(){void 0!==s&&clearTimeout(s),u=0,r=l=i=s=void 0},y.flush=function(){return void 0===s?o:v(J())},y},re=a?a.performance:null,ie=re&&re.now?function(){return re.now()}:function(){return Date.now()},ae=function(){if(a){if(a.requestAnimationFrame)return function(e){a.requestAnimationFrame(e)};if(a.mozRequestAnimationFrame)return function(e){a.mozRequestAnimationFrame(e)};if(a.webkitRequestAnimationFrame)return function(e){a.webkitRequestAnimationFrame(e)};if(a.msRequestAnimationFrame)return function(e){a.msRequestAnimationFrame(e)}}return function(e){e&&setTimeout(function(){e(ie())},1e3/60)}}(),oe=function(e){return ae(e)},se=ie,le=function(e){for(var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5381;!(t=e.next()).done;)n=33*n^t.value;return n>>>0},ue=function(e){return(33*(arguments.length>1&&void 0!==arguments[1]?arguments[1]:5381)^e)>>>0},ce=function(e,t){var n={value:0,done:!1},r=0,i=e.length;return le({next:function(){return r=0&&(e[r]!==t||(e.splice(r,1),n));r--);},_e=function(e){e.splice(0,e.length)},Ne=function(e,t,n){return n&&(t=B(n,t)),e[t]},ze=function(e,t,n,r){n&&(t=B(n,t)),e[t]=r},Ie="undefined"!=typeof Map?Map:function(){function e(){t(this,e),this._obj={}}return r(e,[{key:"set",value:function(e,t){return this._obj[e]=t,this}},{key:"delete",value:function(e){return this._obj[e]=void 0,this}},{key:"clear",value:function(){this._obj={}}},{key:"has",value:function(e){return void 0!==this._obj[e]}},{key:"get",value:function(e){return this._obj[e]}}]),e}(),Le=function(){function e(n){if(t(this,e),this._obj=Object.create(null),this.size=0,null!=n){var r;r=null!=n.instanceString&&n.instanceString()===this.instanceString()?n.toArray():n;for(var i=0;it?1:0},u=function(e,t,i,a,o){var s;if(null==i&&(i=0),null==o&&(o=n),i<0)throw new Error("lo must be non-negative");for(null==a&&(a=e.length);in;0<=n?t++:t--)u.push(t);return u}.apply(this).reverse()).length;ag;0<=g?++d:--d)v.push(a(e,r));return v},f=function(e,t,r,i){var a,o,s;for(null==i&&(i=n),a=e[r];r>t&&i(a,o=e[s=r-1>>1])<0;)e[r]=o,r=s;return e[r]=a},g=function(e,t,r){var i,a,o,s,l;for(null==r&&(r=n),a=e.length,l=t,o=e[t],i=2*t+1;i0;){var k=b.pop(),C=y(k),S=k.id();if(h[S]=C,C!==1/0)for(var D=k.neighborhood().intersect(f),P=0;P0)for(n.unshift(t);c[i];){var a=c[i];n.unshift(a.edge),n.unshift(a.node),i=(r=a.node).id()}return o.spawn(n)}}}},je={kruskal:function(e){e=e||function(e){return 1};for(var t=this.byGroup(),n=t.nodes,r=t.edges,i=n.length,a=new Array(i),o=n,s=function(e){for(var t=0;t0;){if(l=g.pop(),u=l.id(),v.delete(u),w++,u===h){for(var E=[],k=i,C=h,S=m[C];E.unshift(k),null!=S&&E.unshift(S),null!=(k=y[C]);)S=m[C=k.id()];return{found:!0,distance:d[u],path:this.spawn(E),steps:w}}f[u]=!0;for(var D=l._private.edges,P=0;PP&&(f[D]=P,m[D]=S,b[D]=w),!i){var T=S*u+C;!i&&f[T]>P&&(f[T]=P,m[T]=C,b[T]=w)}}}for(var B=0;B1&&void 0!==arguments[1]?arguments[1]:a,r=[],i=m(e);;){if(null==i)return t.spawn();var o=y(i),l=o.edge,u=o.pred;if(r.unshift(i[0]),i.same(n)&&r.length>0)break;null!=l&&r.unshift(l),i=u}return s.spawn(r)},hasNegativeWeightCycle:g,negativeWeightCycles:[]}}},Ue=Math.sqrt(2),$e=function(e,t,n){0===n.length&&Ee("Karger-Stein must be run on a connected (sub)graph");for(var r=n[e],i=r[1],a=r[2],o=t[i],s=t[a],l=n,u=l.length-1;u>=0;u--){var c=l[u],h=c[1],d=c[2];(t[h]===o&&t[d]===s||t[h]===s&&t[d]===o)&&l.splice(u,1)}for(var p=0;pr;){var i=Math.floor(Math.random()*t.length);t=$e(i,e,t),n--}return t},Je={kargerStein:function(){var e=this.byGroup(),t=e.nodes,n=e.edges;n.unmergeBy(function(e){return e.isLoop()});var r=t.length,i=n.length,a=Math.ceil(Math.pow(Math.log(r)/Math.LN2,2)),o=Math.floor(r/Ue);if(!(r<2)){for(var s=[],l=0;l0?1:e<0?-1:0},st=function(e,t){return Math.sqrt(lt(e,t))},lt=function(e,t){var n=t.x-e.x,r=t.y-e.y;return n*n+r*r},ut=function(e){for(var t=e.length,n=0,r=0;r=e.x1&&e.y2>=e.y1)return{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,w:e.x2-e.x1,h:e.y2-e.y1};if(null!=e.w&&null!=e.h&&e.w>=0&&e.h>=0)return{x1:e.x1,y1:e.y1,x2:e.x1+e.w,y2:e.y1+e.h,w:e.w,h:e.h}}},ft=function(e,t,n){e.x1=Math.min(e.x1,t),e.x2=Math.max(e.x2,t),e.w=e.x2-e.x1,e.y1=Math.min(e.y1,n),e.y2=Math.max(e.y2,n),e.h=e.y2-e.y1},gt=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return e.x1-=t,e.x2+=t,e.y1-=t,e.y2+=t,e.w=e.x2-e.x1,e.h=e.y2-e.y1,e},vt=function(e,t){e.x1=t.x1,e.y1=t.y1,e.x2=t.x2,e.y2=t.y2,e.w=e.x2-e.x1,e.h=e.y2-e.y1},yt=function(e,t){e.x1+=t.x,e.x2+=t.x,e.y1+=t.y,e.y2+=t.y},mt=function(e,t){return!(e.x1>t.x2)&&(!(t.x1>e.x2)&&(!(e.x2t.y2)&&!(t.y1>e.y2)))))))},bt=function(e,t,n){return e.x1<=t&&t<=e.x2&&e.y1<=n&&n<=e.y2},xt=function(e,t){return bt(e,t.x1,t.y1)&&bt(e,t.x2,t.y2)},wt=function(e,t,n,r,i,a,o){var s,l=Vt(i,a),u=i/2,c=a/2,h=r-c-o;if((s=zt(e,t,n,r,n-u+l-o,h,n+u-l+o,h,!1)).length>0)return s;var d=n+u+o;if((s=zt(e,t,n,r,d,r-c+l-o,d,r+c-l+o,!1)).length>0)return s;var p=r+c+o;if((s=zt(e,t,n,r,n-u+l-o,p,n+u-l+o,p,!1)).length>0)return s;var f,g=n-u-o;if((s=zt(e,t,n,r,g,r-c+l-o,g,r+c-l+o,!1)).length>0)return s;var v=n-u+l,y=r-c+l;if((f=_t(e,t,n,r,v,y,l+o)).length>0&&f[0]<=v&&f[1]<=y)return[f[0],f[1]];var m=n+u-l,b=r-c+l;if((f=_t(e,t,n,r,m,b,l+o)).length>0&&f[0]>=m&&f[1]<=b)return[f[0],f[1]];var x=n+u-l,w=r+c-l;if((f=_t(e,t,n,r,x,w,l+o)).length>0&&f[0]>=x&&f[1]>=w)return[f[0],f[1]];var E=n-u+l,k=r+c-l;return(f=_t(e,t,n,r,E,k,l+o)).length>0&&f[0]<=E&&f[1]>=k?[f[0],f[1]]:[]},Et=function(e,t,n,r,i,a,o){var s=o,l=Math.min(n,i),u=Math.max(n,i),c=Math.min(r,a),h=Math.max(r,a);return l-s<=e&&e<=u+s&&c-s<=t&&t<=h+s},kt=function(e,t,n,r,i,a,o,s,l){var u=Math.min(n,o,i)-l,c=Math.max(n,o,i)+l,h=Math.min(r,s,a)-l,d=Math.max(r,s,a)+l;return!(ec||td)},Ct=function(e,t,n,r,i,a,o,s){var l=[];!function(e,t,n,r,i){var a,o,s,l,u,c,h,d;s=-27*(r/=e)+(t/=e)*(9*(n/=e)-t*t*2),a=(o=(3*n-t*t)/9)*o*o+(s/=54)*s,i[1]=0,h=t/3,a>0?(u=(u=s+Math.sqrt(a))<0?-Math.pow(-u,1/3):Math.pow(u,1/3),c=(c=s-Math.sqrt(a))<0?-Math.pow(-c,1/3):Math.pow(c,1/3),i[0]=-h+u+c,h+=(u+c)/2,i[4]=i[2]=-h,h=Math.sqrt(3)*(-c+u)/2,i[3]=h,i[5]=-h):(i[5]=i[3]=0,0===a?(d=s<0?-Math.pow(-s,1/3):Math.pow(s,1/3),i[0]=2*d-h,i[4]=i[2]=-(d+h)):(l=(o=-o)*o*o,l=Math.acos(s/Math.sqrt(l)),d=2*Math.sqrt(o),i[0]=-h+d*Math.cos(l/3),i[2]=-h+d*Math.cos((l+2*Math.PI)/3),i[4]=-h+d*Math.cos((l+4*Math.PI)/3)))}(1*n*n-4*n*i+2*n*o+4*i*i-4*i*o+o*o+r*r-4*r*a+2*r*s+4*a*a-4*a*s+s*s,9*n*i-3*n*n-3*n*o-6*i*i+3*i*o+9*r*a-3*r*r-3*r*s-6*a*a+3*a*s,3*n*n-6*n*i+n*o-n*e+2*i*i+2*i*e-o*e+3*r*r-6*r*a+r*s-r*t+2*a*a+2*a*t-s*t,1*n*i-n*n+n*e-i*e+r*a-r*r+r*t-a*t,l);for(var u=[],c=0;c<6;c+=2)Math.abs(l[c+1])<1e-7&&l[c]>=0&&l[c]<=1&&u.push(l[c]);u.push(1),u.push(0);for(var h,d,p,f=-1,g=0;g=0?pl?(e-i)*(e-i)+(t-a)*(t-a):u-h},Dt=function(e,t,n){for(var r,i,a,o,s=0,l=0;l=e&&e>=a||r<=e&&e<=a))continue;(e-r)/(a-r)*(o-i)+i>t&&s++}return s%2!=0},Pt=function(e,t,n,r,i,a,o,s,l){var u,c=new Array(n.length);null!=s[0]?(u=Math.atan(s[1]/s[0]),s[0]<0?u+=Math.PI/2:u=-u-Math.PI/2):u=s;for(var h,d=Math.cos(-u),p=Math.sin(-u),f=0;f0){var g=Bt(c,-l);h=Tt(g)}else h=c;return Dt(e,t,h)},Tt=function(e){for(var t,n,r,i,a,o,s,l,u=new Array(e.length/2),c=0;c=0&&f<=1&&v.push(f),g>=0&&g<=1&&v.push(g),0===v.length)return[];var y=v[0]*s[0]+e,m=v[0]*s[1]+t;return v.length>1?v[0]==v[1]?[y,m]:[y,m,v[1]*s[0]+e,v[1]*s[1]+t]:[y,m]},Nt=function(e,t,n){return t<=e&&e<=n||n<=e&&e<=t?e:e<=t&&t<=n||n<=t&&t<=e?t:n},zt=function(e,t,n,r,i,a,o,s,l){var u=e-i,c=n-e,h=o-i,d=t-a,p=r-t,f=s-a,g=h*d-f*u,v=c*d-p*u,y=f*c-h*p;if(0!==y){var m=g/y,b=v/y;return-.001<=m&&m<=1.001&&-.001<=b&&b<=1.001?[e+m*c,t+m*p]:l?[e+m*c,t+m*p]:[]}return 0===g||0===v?Nt(e,n,o)===o?[o,s]:Nt(e,n,i)===i?[i,a]:Nt(i,o,n)===n?[n,r]:[]:[]},It=function(e,t,n,r,i,a,o,s){var l,u,c,h,d,p,f=[],g=new Array(n.length),v=!0;if(null==a&&(v=!1),v){for(var y=0;y0){var m=Bt(g,-s);u=Tt(m)}else u=g}else u=n;for(var b=0;bu&&(u=t)},h=function(e){return l[e]},d=0;d0?b.edgesTo(m)[0]:m.edgesTo(b)[0];var w=r(x);m=m.id(),d[m]>d[v]+w&&(d[m]=d[v]+w,p.nodes.indexOf(m)<0?p.push(m):p.updateItem(m),u[m]=0,l[m]=[]),d[m]==d[v]+w&&(u[m]=u[m]+u[v],l[m].push(v))}else for(var E=0;E0;)for(var D=n.pop(),P=0;P0&&o.push(n[s]);0!==o.length&&i.push(r.collection(o))}return i}(c,l,t,r);return b=function(e){for(var t=0;t5&&void 0!==arguments[5]?arguments[5]:on,o=r,s=0;s=2?dn(e,t,n,0,un,cn):dn(e,t,n,0,ln)},squaredEuclidean:function(e,t,n){return dn(e,t,n,0,un)},manhattan:function(e,t,n){return dn(e,t,n,0,ln)},max:function(e,t,n){return dn(e,t,n,-1/0,hn)}};function fn(e,t,n,r,i,a){var o;return o=p(e)?e:pn[e]||pn.euclidean,0===t&&p(e)?o(i,a):o(t,n,r,i,a)}pn["squared-euclidean"]=pn.squaredEuclidean,pn.squaredeuclidean=pn.squaredEuclidean;var gn=Be({k:2,m:2,sensitivityThreshold:1e-4,distance:"euclidean",maxIterations:10,attributes:[],testMode:!1,testCentroids:null}),vn=function(e){return gn(e)},yn=function(e,t,n,r,i){var a="kMedoids"!==i?function(e){return n[e]}:function(e){return r[e](n)},o=n,s=t;return fn(e,r.length,a,function(e){return r[e](t)},o,s)},mn=function(e,t,n){for(var r=n.length,i=new Array(r),a=new Array(r),o=new Array(t),s=null,l=0;ln)return!1}return!0},En=function(e,t,n){for(var r=0;ri&&(i=t[l][u],a=u);o[a].push(e[l])}for(var c=0;c=i.threshold||"dendrogram"===i.mode&&1===e.length)return!1;var p,f=t[o],g=t[r[o]];p="dendrogram"===i.mode?{left:f,right:g,key:f.key}:{value:f.value.concat(g.value),key:f.key},e[f.index]=p,e.splice(g.index,1),t[f.key]=p;for(var v=0;vn[g.key][y.key]&&(a=n[g.key][y.key])):"max"===i.linkage?(a=n[f.key][y.key],n[f.key][y.key]1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],a=!(arguments.length>5&&void 0!==arguments[5])||arguments[5];r?e=e.slice(t,n):(n0&&e.splice(0,t));for(var o=0,s=e.length-1;s>=0;s--){var l=e[s];a?isFinite(l)||(e[s]=-1/0,o++):e.splice(s,1)}i&&e.sort(function(e,t){return e-t});var u=e.length,c=Math.floor(u/2);return u%2!=0?e[c+1+o]:(e[c-1+o]+e[c+o])/2}(e):"mean"===t?function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=0,i=0,a=t;a1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=1/0,i=t;i1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=-1/0,i=t;io&&(a=l,o=t[i*e+l])}a>0&&r.push(a)}for(var u=0;u=P?(T=P,P=M,B=_):M>T&&(T=M);for(var N=0;N0?1:0;C[k%u.minIterations*t+R]=V,O+=V}if(O>0&&(k>=u.minIterations-1||k==u.maxIterations-1)){for(var F=0,q=0;q0&&r.push(i);return r}(t,a,o),X=function(e,t,n){for(var r=Rn(e,t,n),i=0;il&&(s=u,l=c)}n[i]=a[s]}return r=Rn(e,t,n)}(t,r,j),W={},H=0;H0:void 0}},clearQueue:function(){return function(){var e=void 0!==this.length?this:[this];if(!(this._private.cy||this).styleEnabled())return this;for(var t=0;t0&&this.spawn(n).updateStyle().emit("class"),this},addClass:function(e){return this.toggleClass(e,!0)},hasClass:function(e){var t=this[0];return null!=t&&t._private.classes.has(e)},toggleClass:function(e,t){f(e)||(e=e.match(/\S+/g)||[]);for(var n=void 0===t,r=[],i=0,a=this.length;i0&&this.spawn(r).updateStyle().emit("class"),this},removeClass:function(e){return this.toggleClass(e,!1)},flashClass:function(e,t){var n=this;if(null==t)t=250;else if(0===t)return n;return n.addClass(e),setTimeout(function(){n.removeClass(e)},t),n}};Qn.className=Qn.classNames=Qn.classes;var Jn={metaChar:"[\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\]\\^\\`\\{\\|\\}\\~]",comparatorOp:"=|\\!=|>|>=|<|<=|\\$=|\\^=|\\*=",boolOp:"\\?|\\!|\\^",string:'"(?:\\\\"|[^"])*"|'+"'(?:\\\\'|[^'])*'",number:_,meta:"degree|indegree|outdegree",separator:"\\s*,\\s*",descendant:"\\s+",child:"\\s+>\\s+",subject:"\\$",group:"node|edge|\\*",directedEdge:"\\s+->\\s+",undirectedEdge:"\\s+<->\\s+"};Jn.variable="(?:[\\w-]|(?:\\\\"+Jn.metaChar+"))+",Jn.value=Jn.string+"|"+Jn.number,Jn.className=Jn.variable,Jn.id=Jn.variable,function(){var e,t,n;for(e=Jn.comparatorOp.split("|"),n=0;n=0||"="!==t&&(Jn.comparatorOp+="|\\!"+t)}();var er=0,tr=1,nr=2,rr=3,ir=4,ar=5,or=6,sr=7,lr=8,ur=9,cr=10,hr=11,dr=12,pr=13,fr=14,gr=15,vr=16,yr=17,mr=18,br=19,xr=20,wr=[{selector:":selected",matches:function(e){return e.selected()}},{selector:":unselected",matches:function(e){return!e.selected()}},{selector:":selectable",matches:function(e){return e.selectable()}},{selector:":unselectable",matches:function(e){return!e.selectable()}},{selector:":locked",matches:function(e){return e.locked()}},{selector:":unlocked",matches:function(e){return!e.locked()}},{selector:":visible",matches:function(e){return e.visible()}},{selector:":hidden",matches:function(e){return!e.visible()}},{selector:":transparent",matches:function(e){return e.transparent()}},{selector:":grabbed",matches:function(e){return e.grabbed()}},{selector:":free",matches:function(e){return!e.grabbed()}},{selector:":removed",matches:function(e){return e.removed()}},{selector:":inside",matches:function(e){return!e.removed()}},{selector:":grabbable",matches:function(e){return e.grabbable()}},{selector:":ungrabbable",matches:function(e){return!e.grabbable()}},{selector:":animated",matches:function(e){return e.animated()}},{selector:":unanimated",matches:function(e){return!e.animated()}},{selector:":parent",matches:function(e){return e.isParent()}},{selector:":childless",matches:function(e){return e.isChildless()}},{selector:":child",matches:function(e){return e.isChild()}},{selector:":orphan",matches:function(e){return e.isOrphan()}},{selector:":nonorphan",matches:function(e){return e.isChild()}},{selector:":compound",matches:function(e){return e.isNode()?e.isParent():e.source().isParent()||e.target().isParent()}},{selector:":loop",matches:function(e){return e.isLoop()}},{selector:":simple",matches:function(e){return e.isSimple()}},{selector:":active",matches:function(e){return e.active()}},{selector:":inactive",matches:function(e){return!e.active()}},{selector:":backgrounding",matches:function(e){return e.backgrounding()}},{selector:":nonbackgrounding",matches:function(e){return!e.backgrounding()}}].sort(function(e,t){return function(e,t){return-1*N(e,t)}(e.selector,t.selector)}),Er=function(){for(var e,t={},n=0;n0&&l.edgeCount>0)return Ce("The selector `"+e+"` is invalid because it uses both a compound selector and an edge selector"),!1;if(l.edgeCount>1)return Ce("The selector `"+e+"` is invalid because it uses multiple edge selectors"),!1;1===l.edgeCount&&Ce("The selector `"+e+"` is deprecated. Edge selectors do not take effect on changes to source and target nodes after an edge is added, for performance reasons. Use a class or data selector on edges instead, updating the class or data of an edge when your app detects a change in source or target nodes.")}return!0},toString:function(){if(null!=this.toStringCache)return this.toStringCache;for(var e=function(e){return null==e?"":e},t=function(t){return d(t)?'"'+t+'"':e(t)},n=function(e){return" "+e+" "},r=function(r,a){var o=r.type,s=r.value;switch(o){case er:var l=e(s);return l.substring(0,l.length-1);case rr:var u=r.field,c=r.operator;return"["+u+n(e(c))+t(s)+"]";case ar:var h=r.operator,d=r.field;return"["+e(h)+d+"]";case ir:return"["+r.field+"]";case or:var p=r.operator;return"[["+r.field+n(e(p))+t(s)+"]]";case sr:return s;case lr:return"#"+s;case ur:return"."+s;case yr:case gr:return i(r.parent,a)+n(">")+i(r.child,a);case mr:case vr:return i(r.ancestor,a)+" "+i(r.descendant,a);case br:var f=i(r.left,a),g=i(r.subject,a),v=i(r.right,a);return f+(f.length>0?" ":"")+g+v;case xr:return""}},i=function(e,t){return e.checks.reduce(function(n,i,a){return n+(t===e&&0===a?"$":"")+r(i,t)},"")},a="",o=0;o1&&o=0&&(t=t.replace("!",""),c=!0),t.indexOf("@")>=0&&(t=t.replace("@",""),u=!0),(o||l||u)&&(i=o||s?""+e:"",a=""+n),u&&(e=i=i.toLowerCase(),n=a=a.toLowerCase()),t){case"*=":r=i.indexOf(a)>=0;break;case"$=":r=i.indexOf(a,i.length-a.length)>=0;break;case"^=":r=0===i.indexOf(a);break;case"=":r=e===n;break;case">":h=!0,r=e>n;break;case">=":h=!0,r=e>=n;break;case"<":h=!0,r=e0;){var u=i.shift();t(u),a.add(u.id()),o&&r(i,a,u)}return e}function qr(e,t,n){if(n.isParent())for(var r=n._private.children,i=0;i1&&void 0!==arguments[1])||arguments[1],qr)},Vr.forEachUp=function(e){return Fr(this,e,!(arguments.length>1&&void 0!==arguments[1])||arguments[1],Yr)},Vr.forEachUpAndDown=function(e){return Fr(this,e,!(arguments.length>1&&void 0!==arguments[1])||arguments[1],jr)},Vr.ancestors=Vr.parents,(Ar=Or={data:Un.data({field:"data",bindingEvent:"data",allowBinding:!0,allowSetting:!0,settingEvent:"data",settingTriggersEvent:!0,triggerFnName:"trigger",allowGetting:!0,immutableKeys:{id:!0,source:!0,target:!0,parent:!0},updateStyle:!0}),removeData:Un.removeData({field:"data",event:"data",triggerFnName:"trigger",triggerEvent:!0,immutableKeys:{id:!0,source:!0,target:!0,parent:!0},updateStyle:!0}),scratch:Un.data({field:"scratch",bindingEvent:"scratch",allowBinding:!0,allowSetting:!0,settingEvent:"scratch",settingTriggersEvent:!0,triggerFnName:"trigger",allowGetting:!0,updateStyle:!0}),removeScratch:Un.removeData({field:"scratch",event:"scratch",triggerFnName:"trigger",triggerEvent:!0,updateStyle:!0}),rscratch:Un.data({field:"rscratch",allowBinding:!1,allowSetting:!0,settingTriggersEvent:!1,allowGetting:!0}),removeRscratch:Un.removeData({field:"rscratch",triggerEvent:!1}),id:function(){var e=this[0];if(e)return e._private.data.id}}).attr=Ar.data,Ar.removeAttr=Ar.removeData;var Xr,Wr,Hr=Or,Kr={};function Gr(e){return function(t){if(void 0===t&&(t=!0),0!==this.length&&this.isNode()&&!this.removed()){for(var n=0,r=this[0],i=r._private.edges,a=0;at}),minIndegree:Zr("indegree",function(e,t){return et}),minOutdegree:Zr("outdegree",function(e,t){return et})}),z(Kr,{totalDegree:function(e){for(var t=0,n=this.nodes(),r=0;r0,c=u;u&&(l=l[0]);var h=c?l.position():{x:0,y:0};return i={x:s.x-h.x,y:s.y-h.y},void 0===e?i:i[e]}for(var p=0;p0,m=y;y&&(v=v[0]);var b=m?v.position():{x:0,y:0};void 0!==t?f.position(e,t+b[e]):void 0!==i&&f.position({x:i.x+b.x,y:i.y+b.y})}}else if(!a)return;return this}}).modelPosition=Xr.point=Xr.position,Xr.modelPositions=Xr.points=Xr.positions,Xr.renderedPoint=Xr.renderedPosition,Xr.relativePoint=Xr.relativePosition;var Qr,Jr,ei=Wr;Qr=Jr={},Jr.renderedBoundingBox=function(e){var t=this.boundingBox(e),n=this.cy(),r=n.zoom(),i=n.pan(),a=t.x1*r+i.x,o=t.x2*r+i.x,s=t.y1*r+i.y,l=t.y2*r+i.y;return{x1:a,x2:o,y1:s,y2:l,w:o-a,h:l-s}},Jr.dirtyCompoundBoundsCache=function(){var e=this.cy();return e.styleEnabled()&&e.hasCompoundNodes()?(this.forEachUp(function(e){if(e.isParent()){var t=e._private;t.compoundBoundsClean=!1,t.bbCache=null,e.emitAndNotify("bounds")}}),this):this},Jr.updateCompoundBounds=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.cy();if(!t.styleEnabled()||!t.hasCompoundNodes())return this;if(!e&&t.batching())return this;function n(e){if(e.isParent()){var t=e._private,n=e.children(),r="include"===e.pstyle("compound-sizing-wrt-labels").value,i={width:{val:e.pstyle("min-width").pfValue,left:e.pstyle("min-width-bias-left"),right:e.pstyle("min-width-bias-right")},height:{val:e.pstyle("min-height").pfValue,top:e.pstyle("min-height-bias-top"),bottom:e.pstyle("min-height-bias-bottom")}},a=n.boundingBox({includeLabels:r,includeOverlays:!1,useCache:!1}),o=t.position;0!==a.w&&0!==a.h||((a={w:e.pstyle("width").pfValue,h:e.pstyle("height").pfValue}).x1=o.x-a.w/2,a.x2=o.x+a.w/2,a.y1=o.y-a.h/2,a.y2=o.y+a.h/2);var s=i.width.left.value;"px"===i.width.left.units&&i.width.val>0&&(s=100*s/i.width.val);var l=i.width.right.value;"px"===i.width.right.units&&i.width.val>0&&(l=100*l/i.width.val);var u=i.height.top.value;"px"===i.height.top.units&&i.height.val>0&&(u=100*u/i.height.val);var c=i.height.bottom.value;"px"===i.height.bottom.units&&i.height.val>0&&(c=100*c/i.height.val);var h=y(i.width.val-a.w,s,l),d=h.biasDiff,p=h.biasComplementDiff,f=y(i.height.val-a.h,u,c),g=f.biasDiff,v=f.biasComplementDiff;t.autoPadding=function(e,t,n,r){if("%"!==n.units)return"px"===n.units?n.pfValue:0;switch(r){case"width":return e>0?n.pfValue*e:0;case"height":return t>0?n.pfValue*t:0;case"average":return e>0&&t>0?n.pfValue*(e+t)/2:0;case"min":return e>0&&t>0?e>t?n.pfValue*t:n.pfValue*e:0;case"max":return e>0&&t>0?e>t?n.pfValue*e:n.pfValue*t:0;default:return 0}}(a.w,a.h,e.pstyle("padding"),e.pstyle("padding-relative-to").value),t.autoWidth=Math.max(a.w,i.width.val),o.x=(-d+a.x1+a.x2+p)/2,t.autoHeight=Math.max(a.h,i.height.val),o.y=(-g+a.y1+a.y2+v)/2}function y(e,t,n){var r=0,i=0,a=t+n;return e>0&&a>0&&(r=t/a*e,i=n/a*e),{biasDiff:r,biasComplementDiff:i}}}for(var r=0;re.x2?r:e.x2,e.y1=ne.y2?i:e.y2,e.w=e.x2-e.x1,e.h=e.y2-e.y1)},ri=function(e,t){return null==t?e:ni(e,t.x1,t.y1,t.x2,t.y2)},ii=function(e,t,n){return Ne(e,t,n)},ai=function(e,t,n){if(!t.cy().headless()){var r,i,a=t._private,o=a.rstyle,s=o.arrowWidth/2;if("none"!==t.pstyle(n+"-arrow-shape").value){"source"===n?(r=o.srcX,i=o.srcY):"target"===n?(r=o.tgtX,i=o.tgtY):(r=o.midX,i=o.midY);var l=a.arrowBounds=a.arrowBounds||{},u=l[n]=l[n]||{};u.x1=r-s,u.y1=i-s,u.x2=r+s,u.y2=i+s,u.w=u.x2-u.x1,u.h=u.y2-u.y1,gt(u,1),ni(e,u.x1,u.y1,u.x2,u.y2)}}},oi=function(e,t,n){if(!t.cy().headless()){var r;r=n?n+"-":"";var i=t._private,a=i.rstyle;if(t.pstyle(r+"label").strValue){var o,s,l,u,c=t.pstyle("text-halign"),h=t.pstyle("text-valign"),d=ii(a,"labelWidth",n),p=ii(a,"labelHeight",n),f=ii(a,"labelX",n),g=ii(a,"labelY",n),v=t.pstyle(r+"text-margin-x").pfValue,y=t.pstyle(r+"text-margin-y").pfValue,m=t.isEdge(),b=t.pstyle(r+"text-rotation"),x=t.pstyle("text-outline-width").pfValue,w=t.pstyle("text-border-width").pfValue/2,E=t.pstyle("text-background-padding").pfValue,k=p,C=d,S=C/2,D=k/2;if(m)o=f-S,s=f+S,l=g-D,u=g+D;else{switch(c.value){case"left":o=f-C,s=f;break;case"center":o=f-S,s=f+S;break;case"right":o=f,s=f+C}switch(h.value){case"top":l=g-k,u=g;break;case"center":l=g-D,u=g+D;break;case"bottom":l=g,u=g+k}}o+=v-Math.max(x,w)-E,s+=v+Math.max(x,w)+E,l+=y-Math.max(x,w)-E,u+=y+Math.max(x,w)+E;var P=n||"main",T=i.labelBounds,B=T[P]=T[P]||{};B.x1=o,B.y1=l,B.x2=s,B.y2=u,B.w=s-o,B.h=u-l,gt(B,1);var M=m&&"autorotate"===b.strValue,_=null!=b.pfValue&&0!==b.pfValue;if(M||_){var N=M?ii(i.rstyle,"labelAngle",n):b.pfValue,z=Math.cos(N),I=Math.sin(N),L=(o+s)/2,A=(l+u)/2;if(!m){switch(c.value){case"left":L=s;break;case"right":L=o}switch(h.value){case"top":A=u;break;case"bottom":A=l}}var O=function(e,t){return{x:(e-=L)*z-(t-=A)*I+L,y:e*I+t*z+A}},R=O(o,l),V=O(o,u),F=O(s,l),q=O(s,u);o=Math.min(R.x,V.x,F.x,q.x),s=Math.max(R.x,V.x,F.x,q.x),l=Math.min(R.y,V.y,F.y,q.y),u=Math.max(R.y,V.y,F.y,q.y)}ni(e,o,l,s,u),ni(i.labelBounds.all,o,l,s,u)}return e}},si=function(e){var t=0,n=function(e){return(e?1:0)<(r=S[1].x)){var D=n;n=r,r=D}if(i>(a=S[1].y)){var P=i;i=a,a=P}ni(d,n-w,i-w,r+w,a+w)}else{for(var T=v.bezierPts||v.linePts||[],B=0;B(r=N.x)){var z=n;n=r,r=z}if((i=_.y)>(a=N.y)){var I=i;i=a,a=I}ni(d,n-=w,i-=w,r+=w,a+=w)}}if(c&&t.includeEdges&&g&&(ai(d,e,"mid-source"),ai(d,e,"mid-target"),ai(d,e,"source"),ai(d,e,"target")),c&&"yes"===e.pstyle("ghost").value){var L=e.pstyle("ghost-offset-x").pfValue,A=e.pstyle("ghost-offset-y").pfValue;ni(d,d.x1+L,d.y1+A,d.x2+L,d.y2+A)}var O=p.bodyBounds=p.bodyBounds||{};vt(O,d),gt(O,y),gt(O,1),c&&(n=d.x1,r=d.x2,i=d.y1,a=d.y2,ni(d,n-x,i-x,r+x,a+x));var R=p.overlayBounds=p.overlayBounds||{};vt(R,d),gt(R,y),gt(R,1);var V=p.labelBounds=p.labelBounds||{};null!=V.all?((l=V.all).x1=1/0,l.y1=1/0,l.x2=-1/0,l.y2=-1/0,l.w=0,l.h=0):V.all=pt(),c&&t.includeLabels&&(oi(d,e,null),g&&(oi(d,e,"source"),oi(d,e,"target")))}return d.x1=ti(d.x1),d.y1=ti(d.y1),d.x2=ti(d.x2),d.y2=ti(d.y2),d.w=ti(d.x2-d.x1),d.h=ti(d.y2-d.y1),d.w>0&&d.h>0&&b&&(gt(d,y),gt(d,1)),d}(e,ci),r.bbCache=n,r.bbCacheShift.x=r.bbCacheShift.y=0,r.bbCachePosKey=a):n=r.bbCache,!s&&(0!==r.bbCacheShift.x||0!==r.bbCacheShift.y)){var l=yt,u=r.bbCacheShift,c=function(e,t){null!=e&&l(e,t)};l(n,u);var h=r.bodyBounds,d=r.overlayBounds,p=r.labelBounds,f=r.arrowBounds;c(h,u),c(d,u),null!=f&&(c(f.source,u),c(f.target,u),c(f["mid-source"],u),c(f["mid-target"],u)),null!=p&&(c(p.main,u),c(p.all,u),c(p.source,u),c(p.target,u))}if(r.bbCacheShift.x=r.bbCacheShift.y=0,!i){var g=e.isNode();n=pt(),(t.includeNodes&&g||t.includeEdges&&!g)&&(t.includeOverlays?ri(n,r.overlayBounds):ri(n,r.bodyBounds)),t.includeLabels&&ri(n,r.labelBounds.all),n.w=n.x2-n.x1,n.h=n.y2-n.y1}return n},ci={includeNodes:!0,includeEdges:!0,includeLabels:!0,includeOverlays:!0,useCache:!0},hi=si(ci),di=Be(ci);Jr.boundingBox=function(e){var t;if(1!==this.length||null==this[0]._private.bbCache||void 0!==e&&void 0!==e.useCache&&!0!==e.useCache){t=pt();var n=di(e=e||ci);if(this.cy().styleEnabled())for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:Pi,t=arguments.length>1?arguments[1]:void 0,n=0;n=0;s--)o(s);return this},Bi.removeAllListeners=function(){return this.removeListener("*")},Bi.emit=Bi.trigger=function(e,t,n){var r=this.listeners,i=r.length;return this.emitting++,f(t)||(t=[t]),Ni(this,function(e,a){null!=n&&(r=[{event:a.event,type:a.type,namespace:a.namespace,callback:n}],i=r.length);for(var o=function(n){var i=r[n];if(i.type===a.type&&(!i.namespace||i.namespace===a.namespace||".*"===i.namespace)&&e.eventMatches(e.context,i,a)){var o=[a];null!=t&&function(e,t){for(var n=0;n1&&!r){var i=this.length-1,a=this[i],o=a._private.data.id;this[i]=void 0,this[e]=a,n.set(o,{ele:a,index:e})}return this.length--,this},unmergeOne:function(e){e=e[0];var t=this._private,n=e._private.data.id,r=t.map.get(n);if(!r)return this;var i=r.index;return this.unmergeAt(i),this},unmerge:function(e){var t=this._private.cy;if(!e)return this;if(e&&d(e)){var n=e;e=t.mutableElements().filter(n)}for(var r=0;r=0;t--){e(this[t])&&this.unmergeAt(t)}return this},map:function(e,t){for(var n=[],r=0;rr&&(r=o,n=a)}return{value:r,ele:n}},min:function(e,t){for(var n,r=1/0,i=0;i=0&&i1&&void 0!==arguments[1])||arguments[1],n=this[0],r=n.cy();if(r.styleEnabled()&&n){var i=n._private.style[e];return null!=i?i:t?r.style().getDefaultProperty(e):null}},numericStyle:function(e){var t=this[0];if(t.cy().styleEnabled()&&t){var n=t.pstyle(e);return void 0!==n.pfValue?n.pfValue:n.value}},numericStyleUnits:function(e){var t=this[0];if(t.cy().styleEnabled())return t?t.pstyle(e).units:void 0},renderedStyle:function(e){var t=this.cy();if(!t.styleEnabled())return this;var n=this[0];return n?t.style().getRenderedStyle(n,e):void 0},style:function(e,t){var n=this.cy();if(!n.styleEnabled())return this;var r=n.style();if(g(e)){var i=e;r.applyBypass(this,i,!1),this.emitAndNotify("style")}else if(d(e)){if(void 0===t){var a=this[0];return a?r.getStylePropertyValue(a,e):void 0}r.applyBypass(this,e,t,!1),this.emitAndNotify("style")}else if(void 0===e){var o=this[0];return o?r.getRawStyle(o):void 0}return this},removeStyle:function(e){var t=this.cy();if(!t.styleEnabled())return this;var n=t.style();if(void 0===e)for(var r=0;r0&&t.push(c[0]),t.push(s[0])}return this.spawn(t,{unique:!0}).filter(e)},"neighborhood"),closedNeighborhood:function(e){return this.neighborhood().add(this).filter(e)},openNeighborhood:function(e){return this.neighborhood(e)}}),na.neighbourhood=na.neighborhood,na.closedNeighbourhood=na.closedNeighborhood,na.openNeighbourhood=na.openNeighborhood,z(na,{source:Rr(function(e){var t,n=this[0];return n&&(t=n._private.source||n.cy().collection()),t&&e?t.filter(e):t},"source"),target:Rr(function(e){var t,n=this[0];return n&&(t=n._private.target||n.cy().collection()),t&&e?t.filter(e):t},"target"),sources:oa({attr:"source"}),targets:oa({attr:"target"})}),z(na,{edgesWith:Rr(sa(),"edgesWith"),edgesTo:Rr(sa({thisIsSrc:!0}),"edgesTo")}),z(na,{connectedEdges:Rr(function(e){for(var t=[],n=0;n0);return a},component:function(){var e=this[0];return e.cy().mutableElements().components(e)[0]}}),na.componentsOf=na.components;var ua=function(e,t,n){for(var r=null!=n?n:De();e.hasElementWithId(r);)r=De();return r},ca=function(e,t,n){if(void 0!==e&&w(e)){var r=new Ie,i=!1;if(t){if(t.length>0&&g(t[0])&&!b(t[0])){i=!0;for(var a=[],o=new Ae,s=0,l=t.length;s0&&void 0!==arguments[0])||arguments[0],r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],i=this.cy(),a=i._private,o=[],s=[],l=0,u=this.length;l0){for(var A=new ca(i,e),O=0;O0&&void 0!==arguments[0])||arguments[0],t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=[],r={},i=this._private.cy;function a(e){var i=r[e.id()];t&&e.removed()||i||(r[e.id()]=!0,e.isNode()?(n.push(e),function(e){for(var t=e._private.edges,n=0;n0&&(e?E.emitAndNotify("remove"):t&&E.emit("remove"));for(var k=0;k=a?function(t,r){for(var a=0;a0?i=l:r=l}while(Math.abs(a)>o&&++u1e-4&&Math.abs(s.v)>1e-4;);return a?function(e){return u[e*(u.length-1)|0]}:c}}(),ga=function(e,t,n,r){var i=pa(e,t,n,r);return function(e,t,n){return e+(t-e)*i(n)}},va={linear:function(e,t,n){return e+(t-e)*n},ease:ga(.25,.1,.25,1),"ease-in":ga(.42,0,1,1),"ease-out":ga(0,0,.58,1),"ease-in-out":ga(.42,0,.58,1),"ease-in-sine":ga(.47,0,.745,.715),"ease-out-sine":ga(.39,.575,.565,1),"ease-in-out-sine":ga(.445,.05,.55,.95),"ease-in-quad":ga(.55,.085,.68,.53),"ease-out-quad":ga(.25,.46,.45,.94),"ease-in-out-quad":ga(.455,.03,.515,.955),"ease-in-cubic":ga(.55,.055,.675,.19),"ease-out-cubic":ga(.215,.61,.355,1),"ease-in-out-cubic":ga(.645,.045,.355,1),"ease-in-quart":ga(.895,.03,.685,.22),"ease-out-quart":ga(.165,.84,.44,1),"ease-in-out-quart":ga(.77,0,.175,1),"ease-in-quint":ga(.755,.05,.855,.06),"ease-out-quint":ga(.23,1,.32,1),"ease-in-out-quint":ga(.86,0,.07,1),"ease-in-expo":ga(.95,.05,.795,.035),"ease-out-expo":ga(.19,1,.22,1),"ease-in-out-expo":ga(1,0,0,1),"ease-in-circ":ga(.6,.04,.98,.335),"ease-out-circ":ga(.075,.82,.165,1),"ease-in-out-circ":ga(.785,.135,.15,.86),spring:function(e,t,n){if(0===n)return va.linear;var r=fa(e,t,n);return function(e,t,n){return e+(t-e)*r(n)}},"cubic-bezier":ga};function ya(e,t,n,r,i){if(1===r)return n;var a=i(t,n,r);return null==e?a:((e.roundValue||e.color)&&(a=Math.round(a)),void 0!==e.min&&(a=Math.max(a,e.min)),void 0!==e.max&&(a=Math.min(a,e.max)),a)}function ma(e,t){return null!=e.pfValue||null!=e.value?null==e.pfValue||null!=t&&"%"===t.type.units?e.value:e.pfValue:e}function ba(e,t,n,r,i){var a=null!=i?i.type:null;n<0?n=0:n>1&&(n=1);var o=ma(e,i),s=ma(t,i);if(v(o)&&v(s))return ya(a,o,s,n,r);if(f(o)&&f(s)){for(var l=[],u=0;u0?("spring"===h&&p.push(o.duration),o.easingImpl=va[h].apply(null,p)):o.easingImpl=va[h]}var f,g=o.easingImpl;if(f=0===o.duration?1:(n-l)/o.duration,o.applying&&(f=o.progress),f<0?f=0:f>1&&(f=1),null==o.delay){var v=o.startPosition,y=o.position;if(y&&i&&!e.locked()){var m={};wa(v.x,y.x)&&(m.x=ba(v.x,y.x,f,g)),wa(v.y,y.y)&&(m.y=ba(v.y,y.y,f,g)),e.position(m)}var b=o.startPan,x=o.pan,w=a.pan,E=null!=x&&r;E&&(wa(b.x,x.x)&&(w.x=ba(b.x,x.x,f,g)),wa(b.y,x.y)&&(w.y=ba(b.y,x.y,f,g)),e.emit("pan"));var k=o.startZoom,C=o.zoom,S=null!=C&&r;S&&(wa(k,C)&&(a.zoom=dt(a.minZoom,ba(k,C,f,g),a.maxZoom)),e.emit("zoom")),(E||S)&&e.emit("viewport");var D=o.style;if(D&&D.length>0&&i){for(var P=0;P=0;t--){(0,e[t])()}e.splice(0,e.length)},h=a.length-1;h>=0;h--){var d=a[h],p=d._private;p.stopped?(a.splice(h,1),p.hooked=!1,p.playing=!1,p.started=!1,c(p.frames)):(p.playing||p.applying)&&(p.playing&&p.applying&&(p.applying=!1),p.started||Ea(0,d,e),xa(t,d,e,n),p.applying&&(p.applying=!1),c(p.frames),null!=p.step&&p.step(e),d.completed()&&(a.splice(h,1),p.hooked=!1,p.playing=!1,p.started=!1,c(p.completes)),s=!0)}return n||0!==a.length||0!==o.length||r.push(t),s}for(var a=!1,o=0;o0?t.notify("draw",n):t.notify("draw")),n.unmerge(r),t.emit("step")}var Ca={animate:Un.animate(),animation:Un.animation(),animated:Un.animated(),clearQueue:Un.clearQueue(),delay:Un.delay(),delayAnimation:Un.delayAnimation(),stop:Un.stop(),addToAnimationPool:function(e){this.styleEnabled()&&this._private.aniEles.merge(e)},stopAnimationLoop:function(){this._private.animationsRunning=!1},startAnimationLoop:function(){var e=this;if(e._private.animationsRunning=!0,e.styleEnabled()){var t=e.renderer();t&&t.beforeRender?t.beforeRender(function(t,n){ka(n,e)},t.beforeRenderPriorities.animations):function t(){e._private.animationsRunning&&oe(function(n){ka(n,e),t()})}()}}},Sa={qualifierCompare:function(e,t){return null==e||null==t?null==e&&null==t:e.sameText(t)},eventMatches:function(e,t,n){var r=t.qualifier;return null==r||e!==n.target&&b(n.target)&&r.matches(n.target)},addEventFields:function(e,t){t.cy=e,t.target=e},callbackContext:function(e,t,n){return null!=t.qualifier?n.target:e}},Da=function(e){return d(e)?new zr(e):e},Pa={createEmitter:function(){var e=this._private;return e.emitter||(e.emitter=new Ti(Sa,this)),this},emitter:function(){return this._private.emitter},on:function(e,t,n){return this.emitter().on(e,Da(t),n),this},removeListener:function(e,t,n){return this.emitter().removeListener(e,Da(t),n),this},removeAllListeners:function(){return this.emitter().removeAllListeners(),this},one:function(e,t,n){return this.emitter().one(e,Da(t),n),this},once:function(e,t,n){return this.emitter().one(e,Da(t),n),this},emit:function(e,t){return this.emitter().emit(e,t),this},emitAndNotify:function(e,t){return this.emit(e),this.notify(e,t),this}};Un.eventAliasesOn(Pa);var Ta={png:function(e){return e=e||{},this._private.renderer.png(e)},jpg:function(e){var t=this._private.renderer;return(e=e||{}).bg=e.bg||"#fff",t.jpg(e)}};Ta.jpeg=Ta.jpg;var Ba={layout:function(e){if(null!=e)if(null!=e.name){var t=e.name,n=this.extension("layout",t);if(null!=n){var r;r=d(e.eles)?this.$(e.eles):null!=e.eles?e.eles:this.$();var i=new n(z({},e,{cy:this,eles:r}));return i}Ee("No such layout `"+t+"` found. Did you forget to import it and `cytoscape.use()` it?")}else Ee("A `name` must be specified to make a layout");else Ee("Layout options must be specified to make a layout")}};Ba.createLayout=Ba.makeLayout=Ba.layout;var Ma={notify:function(e,t){var n=this._private;if(this.batching()){n.batchNotifications=n.batchNotifications||{};var r=n.batchNotifications[e]=n.batchNotifications[e]||this.collection();null!=t&&r.merge(t)}else if(n.notificationsEnabled){var i=this.renderer();!this.destroyed()&&i&&i.notify(e,t)}},notifications:function(e){var t=this._private;return void 0===e?t.notificationsEnabled:(t.notificationsEnabled=!!e,this)},noNotifications:function(e){this.notifications(!1),e(),this.notifications(!0)},batching:function(){return this._private.batchCount>0},startBatch:function(){var e=this._private;return null==e.batchCount&&(e.batchCount=0),0===e.batchCount&&(e.batchStyleEles=this.collection(),e.batchNotifications={}),e.batchCount++,this},endBatch:function(){var e=this._private;if(0===e.batchCount)return this;if(e.batchCount--,0===e.batchCount){e.batchStyleEles.updateStyle();var t=this.renderer();Object.keys(e.batchNotifications).forEach(function(n){var r=e.batchNotifications[n];r.empty()?t.notify(n):t.notify(n,r)})}return this},batch:function(e){return this.startBatch(),e(),this.endBatch(),this},batchData:function(e){var t=this;return this.batch(function(){for(var n=Object.keys(e),r=0;r0;)e.removeChild(e.childNodes[0]);this._private.renderer=null,this.mutableElements().forEach(function(e){var t=e._private;t.rscratch={},t.rstyle={},t.animation.current=[],t.animation.queue=[]})},onRender:function(e){return this.on("render",e)},offRender:function(e){return this.off("render",e)}};Na.invalidateDimensions=Na.resize;var za={collection:function(e,t){return d(e)?this.$(e):m(e)?e.collection():f(e)?new ca(this,e,t):new ca(this)},nodes:function(e){var t=this.$(function(e){return e.isNode()});return e?t.filter(e):t},edges:function(e){var t=this.$(function(e){return e.isEdge()});return e?t.filter(e):t},$:function(e){var t=this._private.elements;return e?t.filter(e):t.spawnSelf()},mutableElements:function(){return this._private.elements}};za.elements=za.filter=za.$;var Ia={};Ia.apply=function(e){var t=this._private,n=t.cy.collection();t.newStyle&&(t.contextStyles={},t.propDiffs={},this.cleanElements(e,!0));for(var r=0;r0;if(h||c&&d){var p=void 0;h&&d?p=l.properties:h?p=l.properties:d&&(p=l.mappedProperties);for(var f=0;f1&&(g=1),s.color){var w=i.valueMin[0],E=i.valueMax[0],k=i.valueMin[1],C=i.valueMax[1],S=i.valueMin[2],D=i.valueMax[2],P=null==i.valueMin[3]?1:i.valueMin[3],T=null==i.valueMax[3]?1:i.valueMax[3],B=[Math.round(w+(E-w)*g),Math.round(k+(C-k)*g),Math.round(S+(D-S)*g),Math.round(P+(T-P)*g)];n={bypass:i.bypass,name:i.name,value:B,strValue:"rgb("+B[0]+", "+B[1]+", "+B[2]+")"}}else{if(!s.number)return!1;var M=i.valueMin+(i.valueMax-i.valueMin)*g;n=this.parse(i.name,M,i.bypass,"mapping")}if(!n)return f(),!1;n.mapping=i,i=n;break;case o.data:for(var _=i.field.split("."),N=h.data,z=0;z<_.length&&N;z++){N=N[_[z]]}if(null!=N&&(n=this.parse(i.name,N,i.bypass,"mapping")),!n)return f(),!1;n.mapping=i,i=n;break;case o.fn:var I=i.value,L=null!=i.fnValue?i.fnValue:I(e);if(i.prevFnValue=L,null==L)return Ce("Custom function mappers may not return null (i.e. `"+i.name+"` for ele `"+e.id()+"` is null)"),!1;if(!(n=this.parse(i.name,L,i.bypass,"mapping")))return Ce("Custom function mappers may not return invalid values for the property type (i.e. `"+i.name+"` for ele `"+e.id()+"` is invalid)"),!1;n.mapping=Se(i),i=n;break;case void 0:break;default:return!1}return l?(i.bypassed=c?u.bypassed:u,a[i.name]=i):c?u.bypassed=i:a[i.name]=i,p(),!0},Ia.cleanElements=function(e,t){for(var n=0;n0&&a>0){for(var s={},l=!1,u=0;u0?e.delayAnimation(o).play().promise().then(t):t()}).then(function(){return e.animation({style:s,duration:a,easing:e.pstyle("transition-timing-function").value,queue:!1}).play().promise()}).then(function(){n.removeBypasses(e,i),e.emitAndNotify("style"),r.transitioning=!1})}else r.transitioning&&(this.removeBypasses(e,i),e.emitAndNotify("style"),r.transitioning=!1)},Ia.checkTrigger=function(e,t,n,r,i,a){var o=this.properties[t],s=i(o);null!=s&&s(n,r)&&a(o)},Ia.checkZOrderTrigger=function(e,t,n,r){var i=this;this.checkTrigger(e,t,n,r,function(e){return e.triggersZOrder},function(){i._private.cy.notify("zorder",e)})},Ia.checkBoundsTrigger=function(e,t,n,r){this.checkTrigger(e,t,n,r,function(e){return e.triggersBounds},function(i){e.dirtyCompoundBoundsCache(),e.dirtyBoundingBoxCache(),"bezier"!==e.pstyle("curve-style").value&&("curve-style"!==t||"bezier"!==n&&"bezier"!==r)||!i.triggersBoundsOfParallelBeziers||e.parallelEdges().forEach(function(e){e.isBundledBezier()&&e.dirtyBoundingBoxCache()})})},Ia.checkTriggers=function(e,t,n,r){e.dirtyStyleCache(),this.checkZOrderTrigger(e,t,n,r),this.checkBoundsTrigger(e,t,n,r)};var La={applyBypass:function(e,t,n,r){var i=[];if("*"===t||"**"===t){if(void 0!==n)for(var a=0;at.length?i.substr(t.length):""}function o(){n=n.length>r.length?n.substr(r.length):""}for(i=i.replace(/[\/][*](\s|.)+?[*][\/]/g,"");;){if(i.match(/^\s*$/))break;var s=i.match(/^\s*((?:.|\s)+?)\s*\{((?:.|\s)+?)\}/);if(!s){Ce("Halting stylesheet parsing: String stylesheet contains more to parse but no selector and block found in: "+i);break}t=s[0];var l=s[1];if("core"!==l)if(new zr(l).invalid){Ce("Skipping parsing of block: Invalid selector found in string stylesheet: "+l),a();continue}var u=s[2],c=!1;n=u;for(var h=[];;){if(n.match(/^\s*$/))break;var d=n.match(/^\s*(.+?)\s*:\s*(.+?)\s*;/);if(!d){Ce("Skipping parsing of block: Invalid formatting of style property and value definitions found in:"+u),c=!0;break}r=d[0];var p=d[1],f=d[2];if(this.properties[p])this.parse(p,f)?(h.push({name:p,val:f}),o()):(Ce("Skipping property: Invalid property definition in: "+r),o());else Ce("Skipping property: Invalid property name in: "+r),o()}if(c){a();break}this.selector(l);for(var g=0;g=7&&"d"===t[0]&&(l=new RegExp(o.data.regex).exec(t))){if(n)return!1;var h=o.data;return{name:e,value:l,strValue:""+t,mapped:h,field:l[1],bypass:n}}if(t.length>=10&&"m"===t[0]&&(u=new RegExp(o.mapData.regex).exec(t))){if(n)return!1;if(c.multiple)return!1;var g=o.mapData;if(!c.color&&!c.number)return!1;var y=this.parse(e,u[4]);if(!y||y.mapped)return!1;var m=this.parse(e,u[5]);if(!m||m.mapped)return!1;if(y.pfValue===m.pfValue||y.strValue===m.strValue)return Ce("`"+e+": "+t+"` is not a valid mapper because the output range is zero; converting to `"+e+": "+y.strValue+"`"),this.parse(e,y.strValue);if(c.color){var b=y.value,x=m.value;if(!(b[0]!==x[0]||b[1]!==x[1]||b[2]!==x[2]||b[3]!==x[3]&&(null!=b[3]&&1!==b[3]||null!=x[3]&&1!==x[3])))return!1}return{name:e,value:u,strValue:""+t,mapped:g,field:u[1],fieldMin:parseFloat(u[2]),fieldMax:parseFloat(u[3]),valueMin:y.value,valueMax:m.value,bypass:n}}}if(c.multiple&&"multiple"!==r){var w;if(w=s?t.split(/\s+/):f(t)?t:[t],c.evenMultiple&&w.length%2!=0)return null;for(var E=[],k=[],C=[],S="",D=!1,T=0;T0?" ":"")+B.strValue}return c.validate&&!c.validate(E,k)?null:c.singleEnum&&D?1===E.length&&d(E[0])?{name:e,value:E[0],strValue:E[0],bypass:n}:null:{name:e,value:E,pfValue:C,strValue:S,bypass:n,units:k}}var M,N,z=function(){for(var r=0;rc.max||c.strictMax&&t===c.max))return null;var V={name:e,value:t,strValue:""+t+(L||""),units:L,bypass:n};return c.unitless||"px"!==L&&"em"!==L?V.pfValue=t:V.pfValue="px"!==L&&L?this.getEmSizeInPixels()*t:t,"ms"!==L&&"s"!==L||(V.pfValue="ms"===L?t:1e3*t),"deg"!==L&&"rad"!==L||(V.pfValue="rad"===L?t:(M=t,Math.PI*M/180)),"%"===L&&(V.pfValue=t/100),V}if(c.propList){var F=[],q=""+t;if("none"===q);else{for(var Y=q.split(/\s*,\s*|\s+/),j=0;j0&&l>0&&!isNaN(n.w)&&!isNaN(n.h)&&n.w>0&&n.h>0)return{zoom:o=(o=(o=Math.min((s-2*t)/n.w,(l-2*t)/n.h))>this._private.maxZoom?this._private.maxZoom:o)=n.minZoom&&(n.maxZoom=t),this},minZoom:function(e){return void 0===e?this._private.minZoom:this.zoomRange({min:e})},maxZoom:function(e){return void 0===e?this._private.maxZoom:this.zoomRange({max:e})},getZoomedViewport:function(e){var t,n,r=this._private,i=r.pan,a=r.zoom,o=!1;if(r.zoomingEnabled||(o=!0),v(e)?n=e:g(e)&&(n=e.level,null!=e.position?t=tt(e.position,a,i):null!=e.renderedPosition&&(t=e.renderedPosition),null==t||r.panningEnabled||(o=!0)),n=(n=n>r.maxZoom?r.maxZoom:n)t.maxZoom||!t.zoomingEnabled?a=!0:(t.zoom=s,i.push("zoom"))}if(r&&(!a||!e.cancelOnFailedZoom)&&t.panningEnabled){var l=e.pan;v(l.x)&&(t.pan.x=l.x,o=!1),v(l.y)&&(t.pan.y=l.y,o=!1),o||i.push("pan")}return i.length>0&&(i.push("viewport"),this.emit(i.join(" ")),this.notify("viewport")),this},center:function(e){var t=this.getCenterPan(e);return t&&(this._private.pan=t,this.emit("pan viewport"),this.notify("viewport")),this},getCenterPan:function(e,t){if(this._private.panningEnabled){if(d(e)){var n=e;e=this.mutableElements().filter(n)}else m(e)||(e=this.mutableElements());if(0!==e.length){var r=e.boundingBox(),i=this.width(),a=this.height();return{x:(i-(t=void 0===t?this._private.zoom:t)*(r.x1+r.x2))/2,y:(a-t*(r.y1+r.y2))/2}}}},reset:function(){return this._private.panningEnabled&&this._private.zoomingEnabled?(this.viewport({pan:{x:0,y:0},zoom:1}),this):this},invalidateSize:function(){this._private.sizeCache=null},size:function(){var e,t,n=this._private,r=n.container;return n.sizeCache=n.sizeCache||(r?(e=a.getComputedStyle(r),t=function(t){return parseFloat(e.getPropertyValue(t))},{width:r.clientWidth-t("padding-left")-t("padding-right"),height:r.clientHeight-t("padding-top")-t("padding-bottom")}):{width:1,height:1})},width:function(){return this.size().width},height:function(){return this.size().height},extent:function(){var e=this._private.pan,t=this._private.zoom,n=this.renderedExtent(),r={x1:(n.x1-e.x)/t,x2:(n.x2-e.x)/t,y1:(n.y1-e.y)/t,y2:(n.y2-e.y)/t};return r.w=r.x2-r.x1,r.h=r.y2-r.y1,r},renderedExtent:function(){var e=this.width(),t=this.height();return{x1:0,y1:0,x2:e,y2:t,w:e,h:t}}};Wa.centre=Wa.center,Wa.autolockNodes=Wa.autolock,Wa.autoungrabifyNodes=Wa.autoungrabify;var Ha={data:Un.data({field:"data",bindingEvent:"data",allowBinding:!0,allowSetting:!0,settingEvent:"data",settingTriggersEvent:!0,triggerFnName:"trigger",allowGetting:!0}),removeData:Un.removeData({field:"data",event:"data",triggerFnName:"trigger",triggerEvent:!0}),scratch:Un.data({field:"scratch",bindingEvent:"scratch",allowBinding:!0,allowSetting:!0,settingEvent:"scratch",settingTriggersEvent:!0,triggerFnName:"trigger",allowGetting:!0}),removeScratch:Un.removeData({field:"scratch",event:"scratch",triggerFnName:"trigger",triggerEvent:!0})};Ha.attr=Ha.data,Ha.removeAttr=Ha.removeData;var Ka=function(e){var t=this,n=(e=z({},e)).container;n&&!y(n)&&y(n[0])&&(n=n[0]);var r=n?n._cyreg:null;(r=r||{})&&r.cy&&(r.cy.destroy(),r={});var i=r.readies=r.readies||[];n&&(n._cyreg=r),r.cy=t;var o=void 0!==a&&void 0!==n&&!e.headless,s=e;s.layout=z({name:o?"grid":"null"},s.layout),s.renderer=z({name:o?"canvas":"null"},s.renderer);var l=function(e,t,n){return void 0!==t?t:void 0!==n?n:e},u=this._private={container:n,ready:!1,options:s,elements:new ca(this),listeners:[],aniEles:new ca(this),data:{},scratch:{},layout:null,renderer:null,destroyed:!1,notificationsEnabled:!0,minZoom:1e-50,maxZoom:1e50,zoomingEnabled:l(!0,s.zoomingEnabled),userZoomingEnabled:l(!0,s.userZoomingEnabled),panningEnabled:l(!0,s.panningEnabled),userPanningEnabled:l(!0,s.userPanningEnabled),boxSelectionEnabled:l(!0,s.boxSelectionEnabled),autolock:l(!1,s.autolock,s.autolockNodes),autoungrabify:l(!1,s.autoungrabify,s.autoungrabifyNodes),autounselectify:l(!1,s.autounselectify),styleEnabled:void 0===s.styleEnabled?o:s.styleEnabled,zoom:v(s.zoom)?s.zoom:1,pan:{x:g(s.pan)&&v(s.pan.x)?s.pan.x:0,y:g(s.pan)&&v(s.pan.y)?s.pan.y:0},animation:{current:[],queue:[]},hasCompoundNodes:!1};this.createEmitter(),this.selectionType(s.selectionType),this.zoomRange({min:s.minZoom,max:s.maxZoom});u.styleEnabled&&t.setStyle([]);var c=z({},s,s.renderer);t.initRenderer(c);!function(e,t){if(e.some(C))return Kn.all(e).then(t);t(e)}([s.style,s.elements],function(e){var n=e[0],a=e[1];u.styleEnabled&&t.style().append(n),function(e,n,r){t.notifications(!1);var i=t.mutableElements();i.length>0&&i.remove(),null!=e&&(g(e)||f(e))&&t.add(e),t.one("layoutready",function(e){t.notifications(!0),t.emit(e),t.one("load",n),t.emitAndNotify("load")}).one("layoutstop",function(){t.one("done",r),t.emit("done")});var a=z({},t._private.options.layout);a.eles=t.elements(),t.layout(a).run()}(a,function(){t.startAnimationLoop(),u.ready=!0,p(s.ready)&&t.on("ready",s.ready);for(var e=0;e0,u=pt(n.boundingBox?n.boundingBox:{x1:0,y1:0,w:r.width(),h:r.height()});if(m(n.roots))e=n.roots;else if(f(n.roots)){for(var c=[],h=0;h0;){var z=B.shift(),I=T(z,M);if(I)z.outgoers().filter(function(e){return e.isNode()&&i.has(e)}).forEach(_);else if(null===I){Ce("Detected double maximal shift for node `"+z.id()+"`. Bailing maximal adjustment due to cycle. Use `options.maximal: true` only on DAGs.");break}}}P();var L=0;if(n.avoidOverlap)for(var A=0;A0&&x[0].length<=3?l/2:0),h=2*Math.PI/x[r].length*i;return 0===r&&1===x[0].length&&(c=1),{x:G+c*Math.cos(h),y:Z+c*Math.sin(h)}}return{x:G+(i+1-(a+1)/2)*o,y:(r+1)*s}}),this};var Ja={fit:!0,padding:30,boundingBox:void 0,avoidOverlap:!0,nodeDimensionsIncludeLabels:!1,spacingFactor:void 0,radius:void 0,startAngle:1.5*Math.PI,sweep:void 0,clockwise:!0,sort:void 0,animate:!1,animationDuration:500,animationEasing:void 0,animateFilter:function(e,t){return!0},ready:void 0,stop:void 0,transform:function(e,t){return t}};function eo(e){this.options=z({},Ja,e)}eo.prototype.run=function(){var e=this.options,t=e,n=e.cy,r=t.eles,i=void 0!==t.counterclockwise?!t.counterclockwise:t.clockwise,a=r.nodes().not(":parent");t.sort&&(a=a.sort(t.sort));for(var o,s=pt(t.boundingBox?t.boundingBox:{x1:0,y1:0,w:n.width(),h:n.height()}),l=s.x1+s.w/2,u=s.y1+s.h/2,c=(void 0===t.sweep?2*Math.PI-2*Math.PI/a.length:t.sweep)/Math.max(1,a.length-1),h=0,d=0;d1&&t.avoidOverlap){h*=1.75;var y=Math.cos(c)-Math.cos(0),m=Math.sin(c)-Math.sin(0),b=Math.sqrt(h*h/(y*y+m*m));o=Math.max(b,o)}return a.layoutPositions(this,t,function(e,n){var r=t.startAngle+n*c*(i?1:-1),a=o*Math.cos(r),s=o*Math.sin(r);return{x:l+a,y:u+s}}),this};var to,no={fit:!0,padding:30,startAngle:1.5*Math.PI,sweep:void 0,clockwise:!0,equidistant:!1,minNodeSpacing:10,boundingBox:void 0,avoidOverlap:!0,nodeDimensionsIncludeLabels:!1,height:void 0,width:void 0,spacingFactor:void 0,concentric:function(e){return e.degree()},levelWidth:function(e){return e.maxDegree()/4},animate:!1,animationDuration:500,animationEasing:void 0,animateFilter:function(e,t){return!0},ready:void 0,stop:void 0,transform:function(e,t){return t}};function ro(e){this.options=z({},no,e)}ro.prototype.run=function(){for(var e=this.options,t=e,n=void 0!==t.counterclockwise?!t.counterclockwise:t.clockwise,r=e.cy,i=t.eles.nodes().not(":parent"),a=pt(t.boundingBox?t.boundingBox:{x1:0,y1:0,w:r.width(),h:r.height()}),o=a.x1+a.w/2,s=a.y1+a.h/2,l=[],u=0,c=0;c0)Math.abs(y[0].value-b.value)>=g&&(y=[],v.push(y));y.push(b)}var x=u+t.minNodeSpacing;if(!t.avoidOverlap){var w=v.length>0&&v[0].length>1,E=(Math.min(a.w,a.h)/2-x)/(v.length+w?1:0);x=Math.min(x,E)}for(var k=0,C=0;C1&&t.avoidOverlap){var T=Math.cos(P)-Math.cos(0),B=Math.sin(P)-Math.sin(0),M=Math.sqrt(x*x/(T*T+B*B));k=Math.max(M,k)}S.r=k,k+=x}if(t.equidistant){for(var _=0,N=0,z=0;z=e.numIter)&&(po(r,e),r.temperature=r.temperature*e.coolingFactor,!(r.temperature=e.animationThreshold&&a(),oe(t)):(So(r,e),s())}()}else{for(;u;)u=o(l),l++;So(r,e),s()}return this},ao.prototype.stop=function(){return this.stopped=!0,this.thread&&this.thread.stop(),this.emit("layoutstop"),this},ao.prototype.destroy=function(){return this.thread&&this.thread.stop(),this};var oo=function(e,t,n){for(var r=n.eles.edges(),i=n.eles.nodes(),a={isCompound:e.hasCompoundNodes(),layoutNodes:[],idToIndex:{},nodeSize:i.size(),graphSet:[],indexToGraph:[],layoutEdges:[],edgeSize:r.size(),temperature:n.initialTemp,clientWidth:e.width(),clientHeight:e.width(),boundingBox:pt(n.boundingBox?n.boundingBox:{x1:0,y1:0,w:e.width(),h:e.height()})},o=n.eles.components(),s={},l=0;l0){a.graphSet.push(w);for(l=0;lr.count?0:r.graph},lo=function e(t,n,r,i){var a=i.graphSet[r];if(-10)var s=(u=r.nodeOverlap*o)*i/(g=Math.sqrt(i*i+a*a)),l=u*a/g;else{var u,c=mo(e,i,a),h=mo(t,-1*i,-1*a),d=h.x-c.x,p=h.y-c.y,f=d*d+p*p,g=Math.sqrt(f);s=(u=(e.nodeRepulsion+t.nodeRepulsion)/f)*d/g,l=u*p/g}e.isLocked||(e.offsetX-=s,e.offsetY-=l),t.isLocked||(t.offsetX+=s,t.offsetY+=l)}},yo=function(e,t,n,r){if(n>0)var i=e.maxX-t.minX;else i=t.maxX-e.minX;if(r>0)var a=e.maxY-t.minY;else a=t.maxY-e.minY;return i>=0&&a>=0?Math.sqrt(i*i+a*a):0},mo=function(e,t,n){var r=e.positionX,i=e.positionY,a=e.height||1,o=e.width||1,s=n/t,l=a/o,u={};return 0===t&&0n?(u.x=r,u.y=i+a/2,u):0t&&-1*l<=s&&s<=l?(u.x=r-o/2,u.y=i-o*n/2/t,u):0=l)?(u.x=r+a*t/2/n,u.y=i+a/2,u):0>n&&(s<=-1*l||s>=l)?(u.x=r-a*t/2/n,u.y=i-a/2,u):u},bo=function(e,t){for(var n=0;n1){var f=t.gravity*h/p,g=t.gravity*d/p;c.offsetX+=f,c.offsetY+=g}}}}},wo=function(e,t){var n=[],r=0,i=-1;for(n.push.apply(n,e.graphSet[0]),i+=e.graphSet[0].length;r<=i;){var a=n[r++],o=e.idToIndex[a],s=e.layoutNodes[o],l=s.children;if(0n)var i={x:n*e/r,y:n*t/r};else i={x:e,y:t};return i},Co=function e(t,n){var r=t.parentId;if(null!=r){var i=n.layoutNodes[n.idToIndex[r]],a=!1;return(null==i.maxX||t.maxX+i.padRight>i.maxX)&&(i.maxX=t.maxX+i.padRight,a=!0),(null==i.minX||t.minX-i.padLefti.maxY)&&(i.maxY=t.maxY+i.padBottom,a=!0),(null==i.minY||t.minY-i.padTopf&&(h+=p+t.componentSpacing,c=0,d=0,p=0)}}},Do={fit:!0,padding:30,boundingBox:void 0,avoidOverlap:!0,avoidOverlapPadding:10,nodeDimensionsIncludeLabels:!1,spacingFactor:void 0,condense:!1,rows:void 0,cols:void 0,position:function(e){},sort:void 0,animate:!1,animationDuration:500,animationEasing:void 0,animateFilter:function(e,t){return!0},ready:void 0,stop:void 0,transform:function(e,t){return t}};function Po(e){this.options=z({},Do,e)}Po.prototype.run=function(){var e=this.options,t=e,n=e.cy,r=t.eles.nodes().not(":parent");t.sort&&(r=r.sort(t.sort));var i=pt(t.boundingBox?t.boundingBox:{x1:0,y1:0,w:n.width(),h:n.height()});if(0===i.h||0===i.w)r.layoutPositions(this,t,function(e){return{x:i.x1,y:i.y1}});else{var a=r.size(),o=Math.sqrt(a*i.h/i.w),s=Math.round(o),l=Math.round(i.w/i.h*o),u=function(e){if(null==e)return Math.min(s,l);Math.min(s,l)==s?s=e:l=e},c=function(e){if(null==e)return Math.max(s,l);Math.max(s,l)==s?s=e:l=e},h=t.rows,d=null!=t.cols?t.cols:t.columns;if(null!=h&&null!=d)s=h,l=d;else if(null!=h&&null==d)s=h,l=Math.ceil(a/s);else if(null==h&&null!=d)l=d,s=Math.ceil(a/l);else if(l*s>a){var p=u(),f=c();(p-1)*f>=a?u(p-1):(f-1)*p>=a&&c(f-1)}else for(;l*s=a?c(v+1):u(g+1)}var y=i.w/l,m=i.h/s;if(t.condense&&(y=0,m=0),t.avoidOverlap)for(var b=0;b=l&&(M=0,B++)},N={},z=0;z(r=St(e,t,x[w],x[w+1],x[w+2],x[w+3])))return v(n,r),!0}else if("bezier"===a.edgeType||"multibezier"===a.edgeType||"self"===a.edgeType||"compound"===a.edgeType)for(x=a.allpts,w=0;w+5(r=Ct(e,t,x[w],x[w+1],x[w+2],x[w+3],x[w+4],x[w+5])))return v(n,r),!0;m=m||i.source,b=b||i.target;var E=o.getArrowWidth(l,c),k=[{name:"source",x:a.arrowStartX,y:a.arrowStartY,angle:a.srcArrowAngle},{name:"target",x:a.arrowEndX,y:a.arrowEndY,angle:a.tgtArrowAngle},{name:"mid-source",x:a.midX,y:a.midY,angle:a.midsrcArrowAngle},{name:"mid-target",x:a.midX,y:a.midY,angle:a.midtgtArrowAngle}];for(w=0;w0&&(y(m),y(b))}function b(e,t,n){return Ne(e,t,n)}function x(n,r){var i,a=n._private,o=f;i=r?r+"-":"";var s=a.labelBounds[r||"main"],l=n.pstyle(i+"label").value;if("yes"===n.pstyle("text-events").strValue&&l){var u=a.rstyle,c=b(u,"labelX",r),h=b(u,"labelY",r),d=b(a.rscratch,"labelAngle",r),p=s.x1-o,g=s.x2+o,y=s.y1-o,m=s.y2+o;if(d){var x=Math.cos(d),w=Math.sin(d),E=function(e,t){return{x:(e-=c)*x-(t-=h)*w+c,y:e*w+t*x+h}},k=E(p,y),C=E(p,m),S=E(g,y),D=E(g,m),P=[k.x,k.y,S.x,S.y,D.x,D.y,C.x,C.y];if(Dt(e,t,P))return v(n),!0}else if(bt(s,e,t))return v(n),!0}}n&&(l=l.interactive);for(var w=l.length-1;w>=0;w--){var E=l[w];E.isNode()?y(E)||x(E):m(E)||x(E)||x(E,"source")||x(E,"target")}return u},getAllInBox:function(e,t,n,r){for(var i,a,o=this.getCachedZSortedEles().interactive,s=[],l=Math.min(e,n),u=Math.max(e,n),c=Math.min(t,r),h=Math.max(t,r),d=pt({x1:e=l,y1:t=c,x2:n=u,y2:r=h}),p=0;p0?Math.max(e-t,0):Math.min(e+t,0)},x=b(y,g),w=b(m,v),E=!1;"auto"===u?u=Math.abs(x)>Math.abs(w)?"horizontal":"vertical":"upward"===u||"downward"===u?(u="vertical",E=!0):"leftward"!==u&&"rightward"!==u||(u="horizontal",E=!0);var k="vertical"===u,C=k?w:x,S=k?m:y,D=ot(S),P=!1;E&&f||!("downward"===c&&S<0||"upward"===c&&S>0||"leftward"===c&&S>0||"rightward"===c&&S<0)||(C=(D*=-1)*Math.abs(C),P=!0);var T=f?d*C:d*D,B=function(e){return Math.abs(e)=Math.abs(C)},M=B(T),_=B(C-T);if((M||_)&&!P)if(k){var N=Math.abs(S)<=a/2,z=Math.abs(y)<=o/2;if(N){var I=(r.x1+r.x2)/2,L=r.y1,A=r.y2;n.segpts=[I,L,I,A]}else if(z){var O=(r.y1+r.y2)/2,R=r.x1,V=r.x2;n.segpts=[R,O,V,O]}else n.segpts=[r.x1,r.y2]}else{var F=Math.abs(S)<=i/2,q=Math.abs(m)<=s/2;if(F){var Y=(r.y1+r.y2)/2,j=r.x1,X=r.x2;n.segpts=[j,Y,X,Y]}else if(q){var W=(r.x1+r.x2)/2,H=r.y1,K=r.y2;n.segpts=[W,H,W,K]}else n.segpts=[r.x2,r.y1]}else if(k){var G=r.y1+T+(l?a/2*D:0),Z=r.x1,U=r.x2;n.segpts=[Z,G,U,G]}else{var $=r.x1+T+(l?i/2*D:0),Q=r.y1,J=r.y2;n.segpts=[$,Q,$,J]}},Fo.tryToCorrectInvalidPoints=function(e,t){var n=e._private.rscratch;if("bezier"===n.edgeType){var r=t.srcPos,i=t.tgtPos,a=t.srcW,o=t.srcH,s=t.tgtW,l=t.tgtH,u=t.srcShape,c=t.tgtShape,h=!v(n.startX)||!v(n.startY),d=!v(n.arrowStartX)||!v(n.arrowStartY),p=!v(n.endX)||!v(n.endY),f=!v(n.arrowEndX)||!v(n.arrowEndY),g=3*(this.getArrowWidth(e.pstyle("width").pfValue,e.pstyle("arrow-scale").value)*this.arrowShapeWidth),y=st({x:n.ctrlpts[0],y:n.ctrlpts[1]},{x:n.startX,y:n.startY}),m=yd.poolIndex()){var p=h;h=d,d=p}var f=s.srcPos=h.position(),g=s.tgtPos=d.position(),y=s.srcW=h.outerWidth(),m=s.srcH=h.outerHeight(),b=s.tgtW=d.outerWidth(),x=s.tgtH=d.outerHeight(),w=s.srcShape=n.nodeShapes[t.getNodeShape(h)],E=s.tgtShape=n.nodeShapes[t.getNodeShape(d)];s.dirCounts={north:0,west:0,south:0,east:0,northwest:0,southwest:0,northeast:0,southeast:0};for(var k=0;k=c||b){h={cp:v,segment:m};break}}if(h)break}var x=h.cp,w=h.segment,E=(c-p)/w.length,k=w.t1-w.t0,C=u?w.t0+k*E:w.t1-k*E;C=dt(0,C,1),t=ht(x.p0,x.p1,x.p2,C),l=function(e,t,n,r){var i=dt(0,r-.001,1),a=dt(0,r+.001,1),o=ht(e,t,n,i),s=ht(e,t,n,a);return Ko(o,s)}(x.p0,x.p1,x.p2,C);break;case"straight":case"segments":case"haystack":for(var S,D,P,T,B=0,M=r.allpts.length,_=0;_+3=c));_+=2);var N=(c-D)/S;N=dt(0,N,1),t=function(e,t,n,r){var i=t.x-e.x,a=t.y-e.y,o=st(e,t),s=i/o,l=a/o;return n=null==n?0:n,r=null!=r?r:n*o,{x:e.x+s*r,y:e.y+l*r}}(P,T,N),l=Ko(P,T)}o("labelX",s,t.x),o("labelY",s,t.y),o("labelAutoAngle",s,l)}};l("source"),l("target"),this.applyLabelDimensions(e)}},Wo.applyLabelDimensions=function(e){this.applyPrefixedLabelDimensions(e),e.isEdge()&&(this.applyPrefixedLabelDimensions(e,"source"),this.applyPrefixedLabelDimensions(e,"target"))},Wo.applyPrefixedLabelDimensions=function(e,t){var n=e._private,r=this.getLabelText(e,t),i=this.calculateLabelDimensions(e,r),a=e.pstyle("line-height").pfValue,o=e.pstyle("text-wrap").strValue,s=Ne(n.rscratch,"labelWrapCachedLines",t)||[],l="wrap"!==o?1:Math.max(s.length,1),u=i.height/l,c=u*a,h=i.width,d=i.height+(l-1)*(a-1)*u;ze(n.rstyle,"labelWidth",t,h),ze(n.rscratch,"labelWidth",t,h),ze(n.rstyle,"labelHeight",t,d),ze(n.rscratch,"labelHeight",t,d),ze(n.rscratch,"labelLineHeight",t,c)},Wo.getLabelText=function(e,t){var n=e._private,r=t?t+"-":"",i=e.pstyle(r+"label").strValue,a=e.pstyle("text-transform").value,o=function(e,r){return r?(ze(n.rscratch,e,t,r),r):Ne(n.rscratch,e,t)};if(!i)return"";"none"==a||("uppercase"==a?i=i.toUpperCase():"lowercase"==a&&(i=i.toLowerCase()));var s=e.pstyle("text-wrap").value;if("wrap"===s){var l=o("labelKey");if(null!=l&&o("labelWrapKey")===l)return o("labelWrapCachedText");for(var u=i.split("\n"),c=e.pstyle("text-max-width").pfValue,h="anywhere"===e.pstyle("text-overflow-wrap").value,d=[],p=/[\s\u200b]+/,f=h?"":" ",g=0;gc){for(var b=v.split(p),x="",w=0;wC)break;S+=i[P],P===i.length-1&&(D=!0)}return D||(S+="…"),S}return i},Wo.getLabelJustification=function(e){var t=e.pstyle("text-justification").strValue,n=e.pstyle("text-halign").strValue;if("auto"!==t)return t;if(!e.isNode())return"center";switch(n){case"left":return"right";case"right":return"left";default:return"center"}},Wo.calculateLabelDimensions=function(e,t){var n=he(t,e._private.labelDimsKey),r=this.labelDimCache||(this.labelDimCache=[]),i=r[n];if(null!=i)return i;var a=e.pstyle("font-style").strValue,o=1*e.pstyle("font-size").pfValue+"px",s=e.pstyle("font-family").strValue,l=e.pstyle("font-weight").strValue,u=this.labelCalcDiv;u||(u=this.labelCalcDiv=document.createElement("div"),document.body.appendChild(u));var c=u.style;return c.fontFamily=s,c.fontStyle=a,c.fontSize=o,c.fontWeight=l,c.position="absolute",c.left="-9999px",c.top="-9999px",c.zIndex="-1",c.visibility="hidden",c.pointerEvents="none",c.padding="0",c.lineHeight="1","wrap"===e.pstyle("text-wrap").value?c.whiteSpace="pre":c.whiteSpace="normal",u.textContent=t,r[n]={width:Math.ceil(u.clientWidth/1),height:Math.ceil(u.clientHeight/1)}},Wo.calculateLabelAngle=function(e,t){var n=e._private.rscratch,r=e.isEdge(),i=t?t+"-":"",a=e.pstyle(i+"text-rotation"),o=a.strValue;return"none"===o?0:r&&"autorotate"===o?n.labelAutoAngle:"autorotate"===o?0:a.pfValue},Wo.calculateLabelAngles=function(e){var t=this,n=e.isEdge(),r=e._private.rscratch;r.labelAngle=t.calculateLabelAngle(e),n&&(r.sourceLabelAngle=t.calculateLabelAngle(e,"source"),r.targetLabelAngle=t.calculateLabelAngle(e,"target"))};var Go={},Zo=!1;Go.getNodeShape=function(e){var t=e.pstyle("shape").value;if("cutrectangle"===t&&(e.width()<28||e.height()<28))return Zo||(Ce("The `cutrectangle` node shape can not be used at small sizes so `rectangle` is used instead"),Zo=!0),"rectangle";if(e.isParent())return"rectangle"===t||"roundrectangle"===t||"cutrectangle"===t||"barrel"===t?t:"rectangle";if("polygon"===t){var n=e.pstyle("shape-polygon-points").value;return this.nodeShapes.makePolygon(n).name}return t};var Uo={registerCalculationListeners:function(){var e=this.cy,t=e.collection(),n=this,r=function(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(t.merge(e),n)for(var r=0;r=e.desktopTapThreshold2}var P=r(t);y&&(e.hoverData.tapholdCancelled=!0);a=!0,n(g,["mousemove","vmousemove","tapdrag"],t,{x:h[0],y:h[1]});var T=function(){e.data.bgActivePosistion=void 0,e.hoverData.selecting||o.emit({originalEvent:t,type:"boxstart",position:{x:h[0],y:h[1]}}),f[4]=1,e.hoverData.selecting=!0,e.redrawHint("select",!0),e.redraw()};if(3===e.hoverData.which){if(y){var B={originalEvent:t,type:"cxtdrag",position:{x:h[0],y:h[1]}};x?x.emit(B):o.emit(B),e.hoverData.cxtDragged=!0,e.hoverData.cxtOver&&g===e.hoverData.cxtOver||(e.hoverData.cxtOver&&e.hoverData.cxtOver.emit({originalEvent:t,type:"cxtdragout",position:{x:h[0],y:h[1]}}),e.hoverData.cxtOver=g,g&&g.emit({originalEvent:t,type:"cxtdragover",position:{x:h[0],y:h[1]}}))}}else if(e.hoverData.dragging){if(a=!0,o.panningEnabled()&&o.userPanningEnabled()){var M;if(e.hoverData.justStartedPan){var _=e.hoverData.mdownPos;M={x:(h[0]-_[0])*s,y:(h[1]-_[1])*s},e.hoverData.justStartedPan=!1}else M={x:w[0]*s,y:w[1]*s};o.panBy(M),e.hoverData.dragged=!0}h=e.projectIntoViewport(t.clientX,t.clientY)}else if(1!=f[4]||null!=x&&!x.pannable()){if(x&&x.pannable()&&x.active()&&x.unactivate(),x&&x.grabbed()||g==b||(b&&n(b,["mouseout","tapdragout"],t,{x:h[0],y:h[1]}),g&&n(g,["mouseover","tapdragover"],t,{x:h[0],y:h[1]}),e.hoverData.last=g),x)if(y){if(o.boxSelectionEnabled()&&P)x&&x.grabbed()&&(c(E),x.emit("freeon"),E.emit("free"),e.dragData.didDrag&&(x.emit("dragfreeon"),E.emit("dragfree"))),T();else if(x&&x.grabbed()&&e.nodeIsDraggable(x)){var N=!e.dragData.didDrag;N&&e.redrawHint("eles",!0),e.dragData.didDrag=!0;var z=o.collection();e.hoverData.draggingEles||l(E,{inDragLayer:!0});var I={x:0,y:0};if(v(w[0])&&v(w[1])&&(I.x+=w[0],I.y+=w[1],N)){var L=e.hoverData.dragDelta;L&&v(L[0])&&v(L[1])&&(I.x+=L[0],I.y+=L[1])}for(var A=0;A0&&e.redrawHint("eles",!0),e.dragData.possibleDragElements=u=a.collection()),l!=h||e.dragData.didDrag||e.hoverData.selecting||null!=l&&l._private.selectable&&(e.hoverData.dragging||("additive"===a.selectionType()||d?l.selected()?l.unselect(["tapunselect"]):l.select(["tapselect"]):d||(a.$(t).unmerge(l).unselect(["tapunselect"]),l.select(["tapselect"]))),e.redrawHint("eles",!0)),e.hoverData.selecting){var g=a.collection(e.getAllInBox(s[0],s[1],s[2],s[3]));e.redrawHint("select",!0),g.length>0&&e.redrawHint("eles",!0),a.emit({type:"boxend",originalEvent:i,position:{x:o[0],y:o[1]}});var v=function(e){return e.selectable()&&!e.selected()};"additive"===a.selectionType()?g.emit("box").stdFilter(v).select().emit("boxselect"):(d||a.$(t).unmerge(g).unselect(),g.emit("box").stdFilter(v).select().emit("boxselect")),e.redraw()}if(e.hoverData.dragging&&(e.hoverData.dragging=!1,e.redrawHint("select",!0),e.redrawHint("eles",!0),e.redraw()),!s[4]){e.redrawHint("drag",!0),e.redrawHint("eles",!0);var y=h&&h.grabbed();c(u),y&&(h.emit("freeon"),u.emit("free"),e.dragData.didDrag&&(h.emit("dragfreeon"),u.emit("dragfree")))}}s[4]=0,e.hoverData.down=null,e.hoverData.cxtStarted=!1,e.hoverData.draggingEles=!1,e.hoverData.selecting=!1,e.hoverData.isOverThresholdDrag=!1,e.dragData.didDrag=!1,e.hoverData.dragged=!1,e.hoverData.dragDelta=[],e.hoverData.mdownPos=null,e.hoverData.mdownGPos=null}},!1);var b,x,w,E,k,C,S,D,P,T,B,M,_;e.registerBinding(e.container,"wheel",function(t){if(!e.scrollingPage){var n,r=e.cy,i=e.projectIntoViewport(t.clientX,t.clientY),a=[i[0]*r.zoom()+r.pan().x,i[1]*r.zoom()+r.pan().y];e.hoverData.draggingEles||e.hoverData.dragging||e.hoverData.cxtStarted||0!==e.selection[4]?t.preventDefault():r.panningEnabled()&&r.userPanningEnabled()&&r.zoomingEnabled()&&r.userZoomingEnabled()&&(t.preventDefault(),e.data.wheelZooming=!0,clearTimeout(e.data.wheelTimeout),e.data.wheelTimeout=setTimeout(function(){e.data.wheelZooming=!1,e.redrawHint("eles",!0),e.redraw()},150),n=null!=t.deltaY?t.deltaY/-250:null!=t.wheelDeltaY?t.wheelDeltaY/1e3:t.wheelDelta/1e3,n*=e.wheelSensitivity,1===t.deltaMode&&(n*=33),r.zoom({level:r.zoom()*Math.pow(10,n),renderedPosition:{x:a[0],y:a[1]}}))}},!0),e.registerBinding(window,"scroll",function(t){e.scrollingPage=!0,clearTimeout(e.scrollingPageTimeout),e.scrollingPageTimeout=setTimeout(function(){e.scrollingPage=!1},250)},!0),e.registerBinding(e.container,"mouseout",function(t){var n=e.projectIntoViewport(t.clientX,t.clientY);e.cy.emit({originalEvent:t,type:"mouseout",position:{x:n[0],y:n[1]}})},!1),e.registerBinding(e.container,"mouseover",function(t){var n=e.projectIntoViewport(t.clientX,t.clientY);e.cy.emit({originalEvent:t,type:"mouseover",position:{x:n[0],y:n[1]}})},!1);var N,z,I,L,A=function(e,t,n,r){return Math.sqrt((n-e)*(n-e)+(r-t)*(r-t))},O=function(e,t,n,r){return(n-e)*(n-e)+(r-t)*(r-t)};if(e.registerBinding(e.container,"touchstart",N=function(t){if(m(t)){d(),e.touchData.capture=!0,e.data.bgActivePosistion=void 0;var r=e.cy,i=e.touchData.now,a=e.touchData.earlier;if(t.touches[0]){var s=e.projectIntoViewport(t.touches[0].clientX,t.touches[0].clientY);i[0]=s[0],i[1]=s[1]}if(t.touches[1]){s=e.projectIntoViewport(t.touches[1].clientX,t.touches[1].clientY);i[2]=s[0],i[3]=s[1]}if(t.touches[2]){s=e.projectIntoViewport(t.touches[2].clientX,t.touches[2].clientY);i[4]=s[0],i[5]=s[1]}if(t.touches[1]){e.touchData.singleTouchMoved=!0,c(e.dragData.touchDragEles);var h=e.findContainerClientCoords();P=h[0],T=h[1],B=h[2],M=h[3],b=t.touches[0].clientX-P,x=t.touches[0].clientY-T,w=t.touches[1].clientX-P,E=t.touches[1].clientY-T,_=0<=b&&b<=B&&0<=w&&w<=B&&0<=x&&x<=M&&0<=E&&E<=M;var p=r.pan(),f=r.zoom();k=A(b,x,w,E),C=O(b,x,w,E),D=[((S=[(b+w)/2,(x+E)/2])[0]-p.x)/f,(S[1]-p.y)/f];if(C<4e4&&!t.touches[2]){var g=e.findNearestElement(i[0],i[1],!0,!0),v=e.findNearestElement(i[2],i[3],!0,!0);return g&&g.isNode()?(g.activate().emit({originalEvent:t,type:"cxttapstart",position:{x:i[0],y:i[1]}}),e.touchData.start=g):v&&v.isNode()?(v.activate().emit({originalEvent:t,type:"cxttapstart",position:{x:i[0],y:i[1]}}),e.touchData.start=v):r.emit({originalEvent:t,type:"cxttapstart",position:{x:i[0],y:i[1]}}),e.touchData.start&&(e.touchData.start._private.grabbed=!1),e.touchData.cxt=!0,e.touchData.cxtDragged=!1,e.data.bgActivePosistion=void 0,void e.redraw()}}if(t.touches[2])r.boxSelectionEnabled()&&t.preventDefault();else if(t.touches[1]);else if(t.touches[0]){var y=e.findNearestElements(i[0],i[1],!0,!0),N=y[0];if(null!=N&&(N.activate(),e.touchData.start=N,e.touchData.starts=y,e.nodeIsGrabbable(N))){var z=e.dragData.touchDragEles=r.collection(),I=null;e.redrawHint("eles",!0),e.redrawHint("drag",!0),N.selected()?(I=r.$(function(t){return t.selected()&&e.nodeIsGrabbable(t)}),l(I,{addToList:z})):u(N,{addToList:z}),o(N);var L=function(e){return{originalEvent:t,type:e,position:{x:i[0],y:i[1]}}};N.emit(L("grabon")),I?I.forEach(function(e){e.emit(L("grab"))}):N.emit(L("grab"))}n(N,["touchstart","tapstart","vmousedown"],t,{x:i[0],y:i[1]}),null==N&&(e.data.bgActivePosistion={x:s[0],y:s[1]},e.redrawHint("select",!0),e.redraw()),e.touchData.singleTouchMoved=!1,e.touchData.singleTouchStartTime=+new Date,clearTimeout(e.touchData.tapholdTimeout),e.touchData.tapholdTimeout=setTimeout(function(){!1!==e.touchData.singleTouchMoved||e.pinching||e.touchData.selecting||n(e.touchData.start,["taphold"],t,{x:i[0],y:i[1]})},e.tapholdDuration)}if(t.touches.length>=1){for(var R=e.touchData.startPosition=[],V=0;V=e.touchTapThreshold2}if(r&&e.touchData.cxt){t.preventDefault();var N=t.touches[0].clientX-P,z=t.touches[0].clientY-T,I=t.touches[1].clientX-P,L=t.touches[1].clientY-T,R=O(N,z,I,L);if(R/C>=2.25||R>=22500){e.touchData.cxt=!1,e.data.bgActivePosistion=void 0,e.redrawHint("select",!0);var V={originalEvent:t,type:"cxttapend",position:{x:s[0],y:s[1]}};e.touchData.start?(e.touchData.start.unactivate().emit(V),e.touchData.start=null):o.emit(V)}}if(r&&e.touchData.cxt){V={originalEvent:t,type:"cxtdrag",position:{x:s[0],y:s[1]}};e.data.bgActivePosistion=void 0,e.redrawHint("select",!0),e.touchData.start?e.touchData.start.emit(V):o.emit(V),e.touchData.start&&(e.touchData.start._private.grabbed=!1),e.touchData.cxtDragged=!0;var F=e.findNearestElement(s[0],s[1],!0,!0);e.touchData.cxtOver&&F===e.touchData.cxtOver||(e.touchData.cxtOver&&e.touchData.cxtOver.emit({originalEvent:t,type:"cxtdragout",position:{x:s[0],y:s[1]}}),e.touchData.cxtOver=F,F&&F.emit({originalEvent:t,type:"cxtdragover",position:{x:s[0],y:s[1]}}))}else if(r&&t.touches[2]&&o.boxSelectionEnabled())t.preventDefault(),e.data.bgActivePosistion=void 0,this.lastThreeTouch=+new Date,e.touchData.selecting||o.emit({originalEvent:t,type:"boxstart",position:{x:s[0],y:s[1]}}),e.touchData.selecting=!0,e.touchData.didSelect=!0,a[4]=1,a&&0!==a.length&&void 0!==a[0]?(a[2]=(s[0]+s[2]+s[4])/3,a[3]=(s[1]+s[3]+s[5])/3):(a[0]=(s[0]+s[2]+s[4])/3,a[1]=(s[1]+s[3]+s[5])/3,a[2]=(s[0]+s[2]+s[4])/3+1,a[3]=(s[1]+s[3]+s[5])/3+1),e.redrawHint("select",!0),e.redraw();else if(r&&t.touches[1]&&!e.touchData.didSelect&&o.zoomingEnabled()&&o.panningEnabled()&&o.userZoomingEnabled()&&o.userPanningEnabled()){if(t.preventDefault(),e.data.bgActivePosistion=void 0,e.redrawHint("select",!0),ee=e.dragData.touchDragEles){e.redrawHint("drag",!0);for(var q=0;q0&&!e.hoverData.draggingEles&&!e.swipePanning&&null!=e.data.bgActivePosistion&&(e.data.bgActivePosistion=void 0,e.redrawHint("select",!0),e.redraw())}},!1),e.registerBinding(window,"touchcancel",I=function(t){var n=e.touchData.start;e.touchData.capture=!1,n&&n.unactivate()}),e.registerBinding(window,"touchend",L=function(r){var i=e.touchData.start;if(e.touchData.capture){0===r.touches.length&&(e.touchData.capture=!1),r.preventDefault();var a=e.selection;e.swipePanning=!1,e.hoverData.draggingEles=!1;var o,s=e.cy,l=s.zoom(),u=e.touchData.now,h=e.touchData.earlier;if(r.touches[0]){var d=e.projectIntoViewport(r.touches[0].clientX,r.touches[0].clientY);u[0]=d[0],u[1]=d[1]}if(r.touches[1]){d=e.projectIntoViewport(r.touches[1].clientX,r.touches[1].clientY);u[2]=d[0],u[3]=d[1]}if(r.touches[2]){d=e.projectIntoViewport(r.touches[2].clientX,r.touches[2].clientY);u[4]=d[0],u[5]=d[1]}if(i&&i.unactivate(),e.touchData.cxt){if(o={originalEvent:r,type:"cxttapend",position:{x:u[0],y:u[1]}},i?i.emit(o):s.emit(o),!e.touchData.cxtDragged){var p={originalEvent:r,type:"cxttap",position:{x:u[0],y:u[1]}};i?i.emit(p):s.emit(p)}return e.touchData.start&&(e.touchData.start._private.grabbed=!1),e.touchData.cxt=!1,e.touchData.start=null,void e.redraw()}if(!r.touches[2]&&s.boxSelectionEnabled()&&e.touchData.selecting){e.touchData.selecting=!1;var f=s.collection(e.getAllInBox(a[0],a[1],a[2],a[3]));a[0]=void 0,a[1]=void 0,a[2]=void 0,a[3]=void 0,a[4]=0,e.redrawHint("select",!0),s.emit({type:"boxend",originalEvent:r,position:{x:u[0],y:u[1]}});f.emit("box").stdFilter(function(e){return e.selectable()&&!e.selected()}).select().emit("boxselect"),f.nonempty()&&e.redrawHint("eles",!0),e.redraw()}if(null!=i&&i.unactivate(),r.touches[2])e.data.bgActivePosistion=void 0,e.redrawHint("select",!0);else if(r.touches[1]);else if(r.touches[0]);else if(!r.touches[0]){e.data.bgActivePosistion=void 0,e.redrawHint("select",!0);var g=e.dragData.touchDragEles;if(null!=i){var v=i._private.grabbed;c(g),e.redrawHint("drag",!0),e.redrawHint("eles",!0),v&&(i.emit("freeon"),g.emit("free"),e.dragData.didDrag&&(i.emit("dragfreeon"),g.emit("dragfree"))),n(i,["touchend","tapend","vmouseup","tapdragout"],r,{x:u[0],y:u[1]}),i.unactivate(),e.touchData.start=null}else{var y=e.findNearestElement(u[0],u[1],!0,!0);n(y,["touchend","tapend","vmouseup","tapdragout"],r,{x:u[0],y:u[1]})}var m=e.touchData.startPosition[0]-u[0],b=m*m,x=e.touchData.startPosition[1]-u[1],w=(b+x*x)*l*l;e.touchData.singleTouchMoved||(i||s.$(":selected").unselect(["tapunselect"]),n(i,["tap","vclick"],r,{x:u[0],y:u[1]})),null!=i&&!e.dragData.didDrag&&i._private.selectable&&w0)return g[0]}return null},d=Object.keys(c),p=0;p0?l:wt(i,a,e,t,n,r,o)},checkPoint:function(e,t,n,r,i,a,o){var s=Vt(r,i),l=2*s;if(Pt(e,t,this.points,a,o,r,i-l,[0,-1],n))return!0;if(Pt(e,t,this.points,a,o,r-l,i,[0,-1],n))return!0;var u=r/2+2*n,c=i/2+2*n;return!!Dt(e,t,[a-u,o-c,a-u,o,a+u,o,a+u,o-c])||(!!Mt(e,t,l,l,a+r/2-s,o+i/2-s,n)||!!Mt(e,t,l,l,a-r/2+s,o+i/2-s,n))}}},ts.registerNodeShapes=function(){var e=this.nodeShapes={},t=this;this.generateEllipse(),this.generatePolygon("triangle",At(3,0)),this.generatePolygon("rectangle",At(4,0)),e.square=e.rectangle,this.generateRoundRectangle(),this.generateCutRectangle(),this.generateBarrel(),this.generateBottomRoundrectangle(),this.generatePolygon("diamond",[0,1,1,0,0,-1,-1,0]),this.generatePolygon("pentagon",At(5,0)),this.generatePolygon("hexagon",At(6,0)),this.generatePolygon("heptagon",At(7,0)),this.generatePolygon("octagon",At(8,0));var n=new Array(20),r=Rt(5,0),i=Rt(5,Math.PI/5),a=.5*(3-Math.sqrt(5));a*=1.57;for(var o=0;o=e.deqFastCost*g)break}else if(i){if(p>=e.deqCost*l||p>=e.deqAvgCost*s)break}else if(f>=e.deqNoDrawCost*(1e3/60))break;var v=e.deq(t,h,c);if(!(v.length>0))break;for(var y=0;y0&&(e.onDeqd(t,u),!i&&e.shouldRedraw(t,u,h,c)&&r())},i(t))}}},ss=function(){function e(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:be;t(this,e),this.idsByKey=new Ie,this.keyForId=new Ie,this.cachesByLvl=new Ie,this.lvls=[],this.getKey=n,this.doesEleInvalidateKey=r}return r(e,[{key:"getIdsFor",value:function(e){null==e&&Ee("Can not get id list for null key");var t=this.idsByKey,n=this.idsByKey.get(e);return n||(n=new Ae,t.set(e,n)),n}},{key:"addIdForKey",value:function(e,t){null!=e&&this.getIdsFor(e).add(t)}},{key:"deleteIdForKey",value:function(e,t){null!=e&&this.getIdsFor(e).delete(t)}},{key:"getNumberOfIdsForKey",value:function(e){return null==e?0:this.getIdsFor(e).size}},{key:"updateKeyMappingFor",value:function(e){var t=e.id(),n=this.keyForId.get(t),r=this.getKey(e);this.deleteIdForKey(n,t),this.addIdForKey(r,t),this.keyForId.set(t,r)}},{key:"deleteKeyMappingFor",value:function(e){var t=e.id(),n=this.keyForId.get(t);this.deleteIdForKey(n,t),this.keyForId.delete(t)}},{key:"keyHasChangedFor",value:function(e){var t=e.id();return this.keyForId.get(t)!==this.getKey(e)}},{key:"isInvalid",value:function(e){return this.keyHasChangedFor(e)||this.doesEleInvalidateKey(e)}},{key:"getCachesAt",value:function(e){var t=this.cachesByLvl,n=this.lvls,r=t.get(e);return r||(r=new Ie,t.set(e,r),n.push(e)),r}},{key:"getCache",value:function(e,t){return this.getCachesAt(t).get(e)}},{key:"get",value:function(e,t){var n=this.getKey(e),r=this.getCache(n,t);return null!=r&&this.updateKeyMappingFor(e),r}},{key:"getForCachedKey",value:function(e,t){var n=this.keyForId.get(e.id());return this.getCache(n,t)}},{key:"hasCache",value:function(e,t){return this.getCachesAt(t).has(e)}},{key:"has",value:function(e,t){var n=this.getKey(e);return this.hasCache(n,t)}},{key:"setCache",value:function(e,t,n){n.key=e,this.getCachesAt(t).set(e,n)}},{key:"set",value:function(e,t,n){var r=this.getKey(e);this.setCache(r,t,n),this.updateKeyMappingFor(e)}},{key:"deleteCache",value:function(e,t){this.getCachesAt(t).delete(e)}},{key:"delete",value:function(e,t){var n=this.getKey(e);this.deleteCache(n,t)}},{key:"invalidateKey",value:function(e){var t=this;this.lvls.forEach(function(n){return t.deleteCache(e,n)})}},{key:"invalidate",value:function(e){var t=e.id(),n=this.keyForId.get(t);this.deleteKeyMappingFor(e);var r=this.doesEleInvalidateKey(e);return r&&this.invalidateKey(n),r||0===this.getNumberOfIdsForKey(n)}}]),e}(),ls={dequeue:"dequeue",downscale:"downscale",highQuality:"highQuality"},us=Be({getKey:null,doesEleInvalidateKey:be,drawElement:null,getBoundingBox:null,getRotationPoint:null,getRotationOffset:null,isVisible:me,allowEdgeTxrCaching:!0,allowParentTxrCaching:!0}),cs=function(e,t){this.renderer=e,this.onDequeues=[];var n=us(t);z(this,n),this.lookup=new ss(n.getKey,n.doesEleInvalidateKey),this.setupDequeueing()},hs=cs.prototype;hs.reasons=ls,hs.getTextureQueue=function(e){return this.eleImgCaches=this.eleImgCaches||{},this.eleImgCaches[e]=this.eleImgCaches[e]||[]},hs.getRetiredTextureQueue=function(e){var t=this.eleImgCaches.retired=this.eleImgCaches.retired||{};return t[e]=t[e]||[]},hs.getElementQueue=function(){return this.eleCacheQueue=this.eleCacheQueue||new Fe(function(e,t){return t.reqs-e.reqs})},hs.getElementKeyToQueue=function(){return this.eleKeyToCacheQueue=this.eleKeyToCacheQueue||{}},hs.getElement=function(e,t,n,r,i){var a=this,o=this.renderer,s=o.cy.zoom(),l=this.lookup;if(0===t.w||0===t.h||isNaN(t.w)||isNaN(t.h)||!e.visible())return null;if(!a.allowEdgeTxrCaching&&e.isEdge()||!a.allowParentTxrCaching&&e.isParent())return null;if(null==r&&(r=Math.ceil(at(s*n))),r<-4)r=-4;else if(s>=7.99||r>3)return null;var u=Math.pow(2,r),c=t.h*u,h=t.w*u,d=o.eleTextBiggerThanMin(e,u);if(!this.isVisible(e,d))return null;var p,f=l.get(e,r);if(f&&f.invalidated&&(f.invalidated=!1,f.texture.invalidatedWidth-=f.width),f)return f;if(p=c<=25?25:c<=50?50:50*Math.ceil(c/50),c>1024||h>1024)return null;var g=a.getTextureQueue(p),v=g[g.length-2],y=function(){return a.recycleTexture(p,h)||a.addTexture(p,h)};v||(v=g[g.length-1]),v||(v=y()),v.width-v.usedWidthr;P--)S=a.getElement(e,t,n,P,ls.downscale);D()}else{var T;if(!x&&!w&&!E)for(var B=r-1;B>=-4;B--){var M=l.get(e,B);if(M){T=M;break}}if(b(T))return a.queueElement(e,r),T;v.context.translate(v.usedWidth,0),v.context.scale(u,u),this.drawElement(v.context,e,t,d,!1),v.context.scale(1/u,1/u),v.context.translate(-v.usedWidth,0)}return f={x:v.usedWidth,texture:v,level:r,scale:u,width:h,height:c,scaledLabelShown:d},v.usedWidth+=Math.ceil(h+8),v.eleCaches.push(f),l.set(e,r,f),a.checkTextureFullness(v),f},hs.invalidateElements=function(e){for(var t=0;t=.2*e.width&&this.retireTexture(e)},hs.checkTextureFullness=function(e){var t=this.getTextureQueue(e.height);e.usedWidth/e.width>.8&&e.fullnessChecks>=10?Me(t,e):e.fullnessChecks++},hs.retireTexture=function(e){var t=e.height,n=this.getTextureQueue(t),r=this.lookup;Me(n,e),e.retired=!0;for(var i=e.eleCaches,a=0;a=t)return a.retired=!1,a.usedWidth=0,a.invalidatedWidth=0,a.fullnessChecks=0,_e(a.eleCaches),a.context.setTransform(1,0,0,1,0,0),a.context.clearRect(0,0,a.width,a.height),Me(r,a),n.push(a),a}},hs.queueElement=function(e,t){var n=this.getElementQueue(),r=this.getElementKeyToQueue(),i=this.getKey(e),a=r[i];if(a)a.level=Math.max(a.level,t),a.eles.merge(e),a.reqs++,n.updateItem(a);else{var o={eles:e.spawn().merge(e),level:t,reqs:1,key:i};n.push(o),r[i]=o}},hs.dequeue=function(e){for(var t=this.getElementQueue(),n=this.getElementKeyToQueue(),r=[],i=this.lookup,a=0;a<1&&t.size()>0;a++){var o=t.pop(),s=o.key,l=o.eles[0],u=i.hasCache(l,o.level);if(n[s]=null,!u){r.push(o);var c=this.getBoundingBox(l);this.getElement(l,c,e,o.level,ls.dequeue)}}return r},hs.removeFromQueue=function(e){var t=this.getElementQueue(),n=this.getElementKeyToQueue(),r=this.getKey(e),i=n[r];null!=i&&(1===i.eles.length?(i.reqs=ye,t.updateItem(i),t.pop(),n[r]=null):i.eles.unmerge(e))},hs.onDequeue=function(e){this.onDequeues.push(e)},hs.offDequeue=function(e){Me(this.onDequeues,e)},hs.setupDequeueing=os({deqRedrawThreshold:100,deqCost:.15,deqAvgCost:.1,deqNoDrawCost:.9,deqFastCost:.9,deq:function(e,t,n){return e.dequeue(t,n)},onDeqd:function(e,t){for(var n=0;n=3.99||n>2)return null;r.validateLayersElesOrdering(n,e);var o,s,l=r.layersByLevel,u=Math.pow(2,n),c=l[n]=l[n]||[];if(r.levelIsComplete(n,e))return c;!function(){var t=function(t){if(r.validateLayersElesOrdering(t,e),r.levelIsComplete(t,e))return s=l[t],!0},i=function(e){if(!s)for(var r=n+e;-4<=r&&r<=2&&!t(r);r+=e);};i(1),i(-1);for(var a=c.length-1;a>=0;a--){var o=c[a];o.invalid&&Me(c,o)}}();var h=function(t){var i=(t=t||{}).after;if(function(){if(!o){o=pt();for(var t=0;t16e6)return null;var a=r.makeLayer(o,n);if(null!=i){var s=c.indexOf(i)+1;c.splice(s,0,a)}else(void 0===t.insert||t.insert)&&c.unshift(a);return a};if(r.skipping&&!a)return null;for(var d=null,p=e.length/1,f=!a,g=0;g=p||!xt(d.bb,v.boundingBox()))&&!(d=h({insert:!0,after:d})))return null;s||f?r.queueLayer(d,v):r.drawEleInLayer(d,v,n,t),d.eles.push(v),m[n]=d}}return s||(f?null:c)},ps.getEleLevelForLayerLevel=function(e,t){return e},ps.drawEleInLayer=function(e,t,n,r){var i=this.renderer,a=e.context,o=t.boundingBox();0!==o.w&&0!==o.h&&t.visible()&&(n=this.getEleLevelForLayerLevel(n,r),i.setImgSmoothing(a,!1),i.drawCachedElement(a,t,null,null,n,!0),i.setImgSmoothing(a,!0))},ps.levelIsComplete=function(e,t){var n=this.layersByLevel[e];if(!n||0===n.length)return!1;for(var r=0,i=0;i0)return!1;if(a.invalid)return!1;r+=a.eles.length}return r===t.length},ps.validateLayersElesOrdering=function(e,t){var n=this.layersByLevel[e];if(n)for(var r=0;r0){e=!0;break}}return e},ps.invalidateElements=function(e){var t=this;0!==e.length&&(t.lastInvalidationTime=se(),0!==e.length&&t.haveLayers()&&t.updateElementsInLayers(e,function(e,n,r){t.invalidateLayer(e)}))},ps.invalidateLayer=function(e){if(this.lastInvalidationTime=se(),!e.invalid){var t=e.level,n=e.eles,r=this.layersByLevel[t];Me(r,e),e.elesQueue=[],e.invalid=!0,e.replacement&&(e.replacement.invalid=!0);for(var i=0;i3&&void 0!==arguments[3])||arguments[3],i=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],a=!(arguments.length>5&&void 0!==arguments[5])||arguments[5],o=this,s=t._private.rscratch;if((!a||t.visible())&&!s.badLine&&null!=s.allpts&&!isNaN(s.allpts[0])){var l;n&&(l=n,e.translate(-l.x1,-l.y1));var u=a?t.pstyle("opacity").value:1,c=t.pstyle("line-style").value,h=t.pstyle("width").pfValue,d=t.pstyle("line-cap").value,p=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u;e.lineWidth=h,e.lineCap=d,o.eleStrokeStyle(e,t,n),o.drawEdgePath(t,e,s.allpts,c),e.lineCap="butt"},f=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u;o.drawArrowheads(e,t,n)};if(e.lineJoin="round","yes"===t.pstyle("ghost").value){var g=t.pstyle("ghost-offset-x").pfValue,v=t.pstyle("ghost-offset-y").pfValue,y=t.pstyle("ghost-opacity").value,m=u*y;e.translate(g,v),p(m),f(m),e.translate(-g,-v)}p(),f(),i&&o.drawEdgeOverlay(e,t),o.drawElementText(e,t,null,r),n&&e.translate(l.x1,l.y1)}},drawEdgeOverlay:function(e,t){if(t.visible()){var n=t.pstyle("overlay-opacity").value;if(0!==n){var r=this,i=r.usePaths(),a=t._private.rscratch,o=2*t.pstyle("overlay-padding").pfValue,s=t.pstyle("overlay-color").value;e.lineWidth=o,"self"!==a.edgeType||i?e.lineCap="round":e.lineCap="butt",r.colorStrokeStyle(e,s[0],s[1],s[2],n),r.drawEdgePath(t,e,a.allpts,"solid")}}},drawEdgePath:function(e,t,n,r){var i,a=e._private.rscratch,o=t,s=!1,l=this.usePaths(),u=e.pstyle("line-dash-pattern").pfValue,c=e.pstyle("line-dash-offset").pfValue;if(l){var h=n.join("$");a.pathCacheKey&&a.pathCacheKey===h?(i=t=a.pathCache,s=!0):(i=t=new Path2D,a.pathCacheKey=h,a.pathCache=i)}if(o.setLineDash)switch(r){case"dotted":o.setLineDash([1,1]);break;case"dashed":o.setLineDash(u),o.lineDashOffset=c;break;case"solid":o.setLineDash([])}if(!s&&!a.badLine)switch(t.beginPath&&t.beginPath(),t.moveTo(n[0],n[1]),a.edgeType){case"bezier":case"self":case"compound":case"multibezier":for(var d=2;d+35&&void 0!==arguments[5])||arguments[5],o=this;if(null==r){if(a&&!o.eleTextBiggerThanMin(t))return}else if(!1===r)return;if(t.isNode()){var s=t.pstyle("label");if(!s||!s.value)return;var l=o.getLabelJustification(t);e.textAlign=l,e.textBaseline="bottom"}else{var u=t.pstyle("label"),c=t.pstyle("source-label"),h=t.pstyle("target-label");if(!(u&&u.value||c&&c.value||h&&h.value))return;e.textAlign="center",e.textBaseline="bottom"}var d,p=!n;n&&(d=n,e.translate(-d.x1,-d.y1)),null==i?(o.drawText(e,t,null,p,a),t.isEdge()&&(o.drawText(e,t,"source",p,a),o.drawText(e,t,"target",p,a))):o.drawText(e,t,i,p,a),n&&e.translate(d.x1,d.y1)},_s.getFontCache=function(e){var t;this.fontCaches=this.fontCaches||[];for(var n=0;n2&&void 0!==arguments[2])||arguments[2],r=t.pstyle("font-style").strValue,i=t.pstyle("font-size").pfValue+"px",a=t.pstyle("font-family").strValue,o=t.pstyle("font-weight").strValue,s=n?t.effectiveOpacity()*t.pstyle("text-opacity").value:1,l=t.pstyle("text-outline-opacity").value*s,u=t.pstyle("color").value,c=t.pstyle("text-outline-color").value;e.font=r+" "+o+" "+i+" "+a,e.lineJoin="round",this.colorFillStyle(e,u[0],u[1],u[2],s),this.colorStrokeStyle(e,c[0],c[1],c[2],l)},_s.getTextAngle=function(e,t){var n=e._private.rscratch,r=t?t+"-":"",i=e.pstyle(r+"text-rotation"),a=Ne(n,"labelAngle",t);return"autorotate"===i.strValue?e.isEdge()?a:0:"none"===i.strValue?0:i.pfValue},_s.drawText=function(e,t,n){var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],a=t._private.rscratch,o=i?t.effectiveOpacity():1;if(!i||0!==o&&0!==t.pstyle("text-opacity").value){"main"===n&&(n=null);var s,l,u=Ne(a,"labelX",n),c=Ne(a,"labelY",n),h=this.getLabelText(t,n);if(null!=h&&""!==h&&!isNaN(u)&&!isNaN(c)){this.setupTextStyle(e,t,i);var d,p=n?n+"-":"",f=Ne(a,"labelWidth",n),g=Ne(a,"labelHeight",n),v=t.pstyle(p+"text-margin-x").pfValue,y=t.pstyle(p+"text-margin-y").pfValue,m=t.isEdge(),b=t.pstyle("text-halign").value,x=t.pstyle("text-valign").value;switch(m&&(b="center",x="center"),u+=v,c+=y,0!==(d=r?this.getTextAngle(t,n):0)&&(s=u,l=c,e.translate(s,l),e.rotate(d),u=0,c=0),x){case"top":break;case"center":c+=g/2;break;case"bottom":c+=g}var w=t.pstyle("text-background-opacity").value,E=t.pstyle("text-border-opacity").value,k=t.pstyle("text-border-width").pfValue,C=t.pstyle("text-background-padding").pfValue;if(w>0||k>0&&E>0){var S=u-C;switch(b){case"left":S-=f;break;case"center":S-=f/2}var D=c-g-C,P=f+2*C,T=g+2*C;if(w>0){var B=e.fillStyle,M=t.pstyle("text-background-color").value;e.fillStyle="rgba("+M[0]+","+M[1]+","+M[2]+","+w*o+")","roundrectangle"==t.pstyle("text-background-shape").strValue?function(e,t,n,r,i){var a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:5;e.beginPath(),e.moveTo(t+a,n),e.lineTo(t+r-a,n),e.quadraticCurveTo(t+r,n,t+r,n+a),e.lineTo(t+r,n+i-a),e.quadraticCurveTo(t+r,n+i,t+r-a,n+i),e.lineTo(t+a,n+i),e.quadraticCurveTo(t,n+i,t,n+i-a),e.lineTo(t,n+a),e.quadraticCurveTo(t,n,t+a,n),e.closePath(),e.fill()}(e,S,D,P,T,2):e.fillRect(S,D,P,T),e.fillStyle=B}if(k>0&&E>0){var _=e.strokeStyle,N=e.lineWidth,z=t.pstyle("text-border-color").value,I=t.pstyle("text-border-style").value;if(e.strokeStyle="rgba("+z[0]+","+z[1]+","+z[2]+","+E*o+")",e.lineWidth=k,e.setLineDash)switch(I){case"dotted":e.setLineDash([1,1]);break;case"dashed":e.setLineDash([4,2]);break;case"double":e.lineWidth=k/4,e.setLineDash([]);break;case"solid":e.setLineDash([])}if(e.strokeRect(S,D,P,T),"double"===I){var L=k/2;e.strokeRect(S+L,D+L,P-2*L,T-2*L)}e.setLineDash&&e.setLineDash([]),e.lineWidth=N,e.strokeStyle=_}}var A=2*t.pstyle("text-outline-width").pfValue;if(A>0&&(e.lineWidth=A),"wrap"===t.pstyle("text-wrap").value){var O=Ne(a,"labelWrapCachedLines",n),R=Ne(a,"labelLineHeight",n),V=f/2,F=this.getLabelJustification(t);switch("auto"===F||("left"===b?"left"===F?u+=-f:"center"===F&&(u+=-V):"center"===b?"left"===F?u+=-V:"right"===F&&(u+=V):"right"===b&&("center"===F?u+=V:"right"===F&&(u+=f))),x){case"top":c-=(O.length-1)*R;break;case"center":case"bottom":c-=(O.length-1)*R}for(var q=0;q0&&e.strokeText(O[q],u,c),e.fillText(O[q],u,c),c+=R}else A>0&&e.strokeText(h,u,c),e.fillText(h,u,c);0!==d&&(e.rotate(-d),e.translate(-s,-l))}}};var Ns={drawNode:function(e,t,n){var r,i,a=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],s=!(arguments.length>5&&void 0!==arguments[5])||arguments[5],l=this,u=t._private,c=u.rscratch,h=t.position();if(v(h.x)&&v(h.y)&&(!s||t.visible())){var d,p,f=s?t.effectiveOpacity():1,g=l.usePaths(),y=!1,m=t.padding();r=t.width()+2*m,i=t.height()+2*m,n&&(p=n,e.translate(-p.x1,-p.y1));for(var b=t.pstyle("background-image").value,x=new Array(b.length),w=new Array(b.length),E=0,k=0;k0&&void 0!==arguments[0]?arguments[0]:T;l.eleFillStyle(e,t,n)},z=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:_;l.colorStrokeStyle(e,B[0],B[1],B[2],t)},I=t.pstyle("shape").strValue,L=t.pstyle("shape-polygon-points").pfValue;if(g){e.translate(h.x,h.y);var A=l.nodePathCache=l.nodePathCache||[],O=de("polygon"===I?I+","+L.join(","):I,""+i,""+r),R=A[O];null!=R?(d=R,y=!0,c.pathCache=d):(d=new Path2D,A[O]=c.pathCache=d)}var V=function(){if(!y){var n=h;g&&(n={x:0,y:0}),l.nodeShapes[l.getNodeShape(t)].draw(d||e,n.x,n.y,r,i)}g?e.fill(d):e.fill()},F=function(){for(var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:f,r=u.backgrounding,i=0,a=0;a0&&void 0!==arguments[0]&&arguments[0],a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:f;l.hasPie(t)&&(l.drawPie(e,t,a),n&&(g||l.nodeShapes[l.getNodeShape(t)].draw(e,h.x,h.y,r,i)))},Y=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:f,n=(D>0?D:-D)*t,r=D>0?0:255;0!==D&&(l.colorFillStyle(e,r,r,r,n),g?e.fill(d):e.fill())},j=function(){if(P>0){if(e.lineWidth=P,e.lineCap="butt",e.setLineDash)switch(M){case"dotted":e.setLineDash([1,1]);break;case"dashed":e.setLineDash([4,2]);break;case"solid":case"double":e.setLineDash([])}if(g?e.stroke(d):e.stroke(),"double"===M){e.lineWidth=P/3;var t=e.globalCompositeOperation;e.globalCompositeOperation="destination-out",g?e.stroke(d):e.stroke(),e.globalCompositeOperation=t}e.setLineDash&&e.setLineDash([])}};if("yes"===t.pstyle("ghost").value){var X=t.pstyle("ghost-offset-x").pfValue,W=t.pstyle("ghost-offset-y").pfValue,H=t.pstyle("ghost-opacity").value,K=H*f;e.translate(X,W),N(H*T),V(),F(K),q(0!==D||0!==P),Y(K),z(H*_),j(),e.translate(-X,-W)}N(),V(),F(),q(0!==D||0!==P),Y(),z(),j(),g&&e.translate(-h.x,-h.y),l.drawElementText(e,t,null,a),o&&l.drawNodeOverlay(e,t,h,r,i),n&&e.translate(p.x1,p.y1)}},drawNodeOverlay:function(e,t,n,r,i){if(t.visible()){var a=t.pstyle("overlay-padding").pfValue,o=t.pstyle("overlay-opacity").value,s=t.pstyle("overlay-color").value;if(o>0){if(n=n||t.position(),null==r||null==i){var l=t.padding();r=t.width()+2*l,i=t.height()+2*l}this.colorFillStyle(e,s[0],s[1],s[2],o),this.nodeShapes.roundrectangle.draw(e,n.x,n.y,r+2*a,i+2*a),e.fill()}}},hasPie:function(e){return(e=e[0])._private.hasPie},drawPie:function(e,t,n,r){t=t[0],r=r||t.position();var i=t.cy().style(),a=t.pstyle("pie-size"),o=r.x,s=r.y,l=t.width(),u=t.height(),c=Math.min(l,u)/2,h=0;this.usePaths()&&(o=0,s=0),"%"===a.units?c*=a.pfValue:void 0!==a.pfValue&&(c=a.pfValue/2);for(var d=1;d<=i.pieBackgroundN;d++){var p=t.pstyle("pie-"+d+"-background-size").value,f=t.pstyle("pie-"+d+"-background-color").value,g=t.pstyle("pie-"+d+"-background-opacity").value*n,v=p/100;v+h>1&&(v=1-h);var y=1.5*Math.PI+2*Math.PI*h,m=y+2*Math.PI*v;0===p||h>=1||h+v>1||(e.beginPath(),e.moveTo(o,s),e.arc(o,s,c,y,m),e.closePath(),this.colorFillStyle(e,f[0],f[1],f[2],g),e.fill(),h+=v)}}},zs={};zs.getPixelRatio=function(){var e=this.data.contexts[0];if(null!=this.forcedPixelRatio)return this.forcedPixelRatio;var t=e.backingStorePixelRatio||e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1;return(window.devicePixelRatio||1)/t},zs.paintCache=function(e){for(var t,n=this.paintCaches=this.paintCaches||[],r=!0,i=0;io.minMbLowQualFrames&&(o.motionBlurPxRatio=o.mbPxRBlurry)),o.clearingMotionBlur&&(o.motionBlurPxRatio=1),o.textureDrawLastFrame&&!h&&(c[o.NODE]=!0,c[o.SELECT_BOX]=!0);var m=l.style(),b=l.zoom(),x=void 0!==i?i:b,w=l.pan(),E={x:w.x,y:w.y},k={zoom:b,pan:{x:w.x,y:w.y}},C=o.prevViewport;void 0===C||k.zoom!==C.zoom||k.pan.x!==C.pan.x||k.pan.y!==C.pan.y||g&&!f||(o.motionBlurPxRatio=1),a&&(E=a),x*=s,E.x*=s,E.y*=s;var S=o.getCachedZSortedEles();function D(e,t,n,r,i){var a=e.globalCompositeOperation;e.globalCompositeOperation="destination-out",o.colorFillStyle(e,255,255,255,o.motionBlurTransparency),e.fillRect(t,n,r,i),e.globalCompositeOperation=a}function P(e,r){var s,l,c,h;o.clearingMotionBlur||e!==u.bufferContexts[o.MOTIONBLUR_BUFFER_NODE]&&e!==u.bufferContexts[o.MOTIONBLUR_BUFFER_DRAG]?(s=E,l=x,c=o.canvasWidth,h=o.canvasHeight):(s={x:w.x*p,y:w.y*p},l=b*p,c=o.canvasWidth*p,h=o.canvasHeight*p),e.setTransform(1,0,0,1,0,0),"motionBlur"===r?D(e,0,0,c,h):t||void 0!==r&&!r||e.clearRect(0,0,c,h),n||(e.translate(s.x,s.y),e.scale(l,l)),a&&e.translate(a.x,a.y),i&&e.scale(i,i)}if(h||(o.textureDrawLastFrame=!1),h){if(o.textureDrawLastFrame=!0,!o.textureCache){o.textureCache={},o.textureCache.bb=l.mutableElements().boundingBox(),o.textureCache.texture=o.data.bufferCanvases[o.TEXTURE_BUFFER];var T=o.data.bufferContexts[o.TEXTURE_BUFFER];T.setTransform(1,0,0,1,0,0),T.clearRect(0,0,o.canvasWidth*o.textureMult,o.canvasHeight*o.textureMult),o.render({forcedContext:T,drawOnlyNodeLayer:!0,forcedPxRatio:s*o.textureMult}),(k=o.textureCache.viewport={zoom:l.zoom(),pan:l.pan(),width:o.canvasWidth,height:o.canvasHeight}).mpan={x:(0-k.pan.x)/k.zoom,y:(0-k.pan.y)/k.zoom}}c[o.DRAG]=!1,c[o.NODE]=!1;var B=u.contexts[o.NODE],M=o.textureCache.texture;k=o.textureCache.viewport;B.setTransform(1,0,0,1,0,0),d?D(B,0,0,k.width,k.height):B.clearRect(0,0,k.width,k.height);var _=m.core("outside-texture-bg-color").value,N=m.core("outside-texture-bg-opacity").value;o.colorFillStyle(B,_[0],_[1],_[2],N),B.fillRect(0,0,k.width,k.height);b=l.zoom();P(B,!1),B.clearRect(k.mpan.x,k.mpan.y,k.width/k.zoom/s,k.height/k.zoom/s),B.drawImage(M,k.mpan.x,k.mpan.y,k.width/k.zoom/s,k.height/k.zoom/s)}else o.textureOnViewport&&!t&&(o.textureCache=null);var z=l.extent(),I=o.pinching||o.hoverData.dragging||o.swipePanning||o.data.wheelZooming||o.hoverData.draggingEles||o.cy.animated(),L=o.hideEdgesOnViewport&&I,A=[];if(A[o.NODE]=!c[o.NODE]&&d&&!o.clearedForMotionBlur[o.NODE]||o.clearingMotionBlur,A[o.NODE]&&(o.clearedForMotionBlur[o.NODE]=!0),A[o.DRAG]=!c[o.DRAG]&&d&&!o.clearedForMotionBlur[o.DRAG]||o.clearingMotionBlur,A[o.DRAG]&&(o.clearedForMotionBlur[o.DRAG]=!0),c[o.NODE]||n||r||A[o.NODE]){var O=d&&!A[o.NODE]&&1!==p;P(B=t||(O?o.data.bufferContexts[o.MOTIONBLUR_BUFFER_NODE]:u.contexts[o.NODE]),d&&!O?"motionBlur":void 0),L?o.drawCachedNodes(B,S.nondrag,s,z):o.drawLayeredElements(B,S.nondrag,s,z),o.debug&&o.drawDebugPoints(B,S.nondrag),n||d||(c[o.NODE]=!1)}if(!r&&(c[o.DRAG]||n||A[o.DRAG])){O=d&&!A[o.DRAG]&&1!==p;P(B=t||(O?o.data.bufferContexts[o.MOTIONBLUR_BUFFER_DRAG]:u.contexts[o.DRAG]),d&&!O?"motionBlur":void 0),L?o.drawCachedNodes(B,S.drag,s,z):o.drawCachedElements(B,S.drag,s,z),o.debug&&o.drawDebugPoints(B,S.drag),n||d||(c[o.DRAG]=!1)}if(o.showFps||!r&&c[o.SELECT_BOX]&&!n){if(P(B=t||u.contexts[o.SELECT_BOX]),1==o.selection[4]&&(o.hoverData.selecting||o.touchData.selecting)){b=o.cy.zoom();var R=m.core("selection-box-border-width").value/b;B.lineWidth=R,B.fillStyle="rgba("+m.core("selection-box-color").value[0]+","+m.core("selection-box-color").value[1]+","+m.core("selection-box-color").value[2]+","+m.core("selection-box-opacity").value+")",B.fillRect(o.selection[0],o.selection[1],o.selection[2]-o.selection[0],o.selection[3]-o.selection[1]),R>0&&(B.strokeStyle="rgba("+m.core("selection-box-border-color").value[0]+","+m.core("selection-box-border-color").value[1]+","+m.core("selection-box-border-color").value[2]+","+m.core("selection-box-opacity").value+")",B.strokeRect(o.selection[0],o.selection[1],o.selection[2]-o.selection[0],o.selection[3]-o.selection[1]))}if(u.bgActivePosistion&&!o.hoverData.selecting){b=o.cy.zoom();var V=u.bgActivePosistion;B.fillStyle="rgba("+m.core("active-bg-color").value[0]+","+m.core("active-bg-color").value[1]+","+m.core("active-bg-color").value[2]+","+m.core("active-bg-opacity").value+")",B.beginPath(),B.arc(V.x,V.y,m.core("active-bg-size").pfValue/b,0,2*Math.PI),B.fill()}var F=o.lastRedrawTime;if(o.showFps&&F){F=Math.round(F);var q=Math.round(1e3/F);B.setTransform(1,0,0,1,0,0),B.fillStyle="rgba(255, 0, 0, 0.75)",B.strokeStyle="rgba(255, 0, 0, 0.75)",B.lineWidth=1,B.fillText("1 frame = "+F+" ms = "+q+" fps",0,20);B.strokeRect(0,30,250,20),B.fillRect(0,30,250*Math.min(q/60,1),20)}n||(c[o.SELECT_BOX]=!1)}if(d&&1!==p){var Y=u.contexts[o.NODE],j=o.data.bufferCanvases[o.MOTIONBLUR_BUFFER_NODE],X=u.contexts[o.DRAG],W=o.data.bufferCanvases[o.MOTIONBLUR_BUFFER_DRAG],H=function(e,t,n){e.setTransform(1,0,0,1,0,0),n||!y?e.clearRect(0,0,o.canvasWidth,o.canvasHeight):D(e,0,0,o.canvasWidth,o.canvasHeight);var r=p;e.drawImage(t,0,0,o.canvasWidth*r,o.canvasHeight*r,0,0,o.canvasWidth,o.canvasHeight)};(c[o.NODE]||A[o.NODE])&&(H(Y,j,A[o.NODE]),c[o.NODE]=!1),(c[o.DRAG]||A[o.DRAG])&&(H(X,W,A[o.DRAG]),c[o.DRAG]=!1)}o.prevViewport=k,o.clearingMotionBlur&&(o.clearingMotionBlur=!1,o.motionBlurCleared=!0,o.motionBlur=!0),d&&(o.motionBlurTimeout=setTimeout(function(){o.motionBlurTimeout=null,o.clearedForMotionBlur[o.NODE]=!1,o.clearedForMotionBlur[o.DRAG]=!1,o.motionBlur=!1,o.clearingMotionBlur=!h,o.mbFrames=0,c[o.NODE]=!0,c[o.DRAG]=!0,o.redraw()},100)),t||l.emit("render")};for(var Is={drawPolygonPath:function(e,t,n,r,i,a){var o=r/2,s=i/2;e.beginPath&&e.beginPath(),e.moveTo(t+o*a[0],n+s*a[1]);for(var l=1;l0&&a>0){d.clearRect(0,0,i,a),d.globalCompositeOperation="source-over";var p=this.getCachedZSortedEles();if(e.full)d.translate(-n.x1*l,-n.y1*l),d.scale(l,l),this.drawElements(d,p),d.scale(1/l,1/l),d.translate(n.x1*l,n.y1*l);else{var f=t.pan(),g={x:f.x*l,y:f.y*l};l*=t.zoom(),d.translate(g.x,g.y),d.scale(l,l),this.drawElements(d,p),d.scale(1/l,1/l),d.translate(-g.x,-g.y)}e.bg&&(d.globalCompositeOperation="destination-over",d.fillStyle=e.bg,d.rect(0,0,i,a),d.fill())}return h},qs.png=function(e){return js(e,this.bufferCanvasImage(e),"image/png")},qs.jpg=function(e){return js(e,this.bufferCanvasImage(e),"image/jpeg")};var Xs={nodeShapeImpl:function(e,t,n,r,i,a,o){switch(e){case"ellipse":return this.drawEllipsePath(t,n,r,i,a);case"polygon":return this.drawPolygonPath(t,n,r,i,a,o);case"roundrectangle":case"round-rectangle":return this.drawRoundRectanglePath(t,n,r,i,a);case"cutrectangle":case"cut-rectangle":return this.drawCutRectanglePath(t,n,r,i,a);case"bottomroundrectangle":case"bottom-round-rectangle":return this.drawBottomRoundRectanglePath(t,n,r,i,a);case"barrel":return this.drawBarrelPath(t,n,r,i,a)}}},Ws=Ks,Hs=Ks.prototype;function Ks(e){var t=this;t.data={canvases:new Array(Hs.CANVAS_LAYERS),contexts:new Array(Hs.CANVAS_LAYERS),canvasNeedsRedraw:new Array(Hs.CANVAS_LAYERS),bufferCanvases:new Array(Hs.BUFFER_COUNT),bufferContexts:new Array(Hs.CANVAS_LAYERS)};t.data.canvasContainer=document.createElement("div");var n=t.data.canvasContainer.style;t.data.canvasContainer.style["-webkit-tap-highlight-color"]="rgba(0,0,0,0)",n.position="relative",n.zIndex="0",n.overflow="hidden";var r=e.cy.container();r.appendChild(t.data.canvasContainer),r.style["-webkit-tap-highlight-color"]="rgba(0,0,0,0)";var i={"-webkit-user-select":"none","-moz-user-select":"-moz-none","user-select":"none","-webkit-tap-highlight-color":"rgba(0,0,0,0)","outline-style":"none"};S()&&(i["-ms-touch-action"]="none",i["touch-action"]="none");for(var a=0;a