@8btc/xcanvas 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +70 -0
  2. package/dist/Tableau10-BqnYsPR6.js +9 -0
  3. package/dist/XCanvas-BxdLBkBz.js +27732 -0
  4. package/dist/_commonjs-dynamic-modules-TGKdzP3c.js +6 -0
  5. package/dist/ar-SA-G6X2FPQ2-DjqDLLYL.js +41 -0
  6. package/dist/arc-D1qX5GFf.js +132 -0
  7. package/dist/array-DgktLKBx.js +6 -0
  8. package/dist/az-AZ-76LH7QW2-D7LOsF3_.js +32 -0
  9. package/dist/bg-BG-XCXSNQG7-WI4tFn23.js +36 -0
  10. package/dist/blockDiagram-38ab4fdb-DtemKfEh.js +1811 -0
  11. package/dist/bn-BD-2XOGV67Q-Bugx_8fy.js +36 -0
  12. package/dist/c4Diagram-3d4e48cf-Byd2vU9K.js +2463 -0
  13. package/dist/ca-ES-6MX7JW3Y-6rFwKGsQ.js +39 -0
  14. package/dist/channel-BT_3Ze-Y.js +7 -0
  15. package/dist/chunk-EIO257PC-C7qD7hGu.js +1641 -0
  16. package/dist/classDiagram-70f12bd4-CwfYadk-.js +354 -0
  17. package/dist/classDiagram-v2-f2320105-B28MuM8f.js +284 -0
  18. package/dist/clone-D2FUK8WY.js +8 -0
  19. package/dist/createText-2e5e7dd3-Ca1JfQaJ.js +4914 -0
  20. package/dist/cs-CZ-2BRQDIVT-Dhd8XszK.js +42 -0
  21. package/dist/da-DK-5WZEPLOC-BhL87sSs.js +36 -0
  22. package/dist/de-DE-XR44H4JA-xSrZSV0J.js +39 -0
  23. package/dist/directory-open-01563666-XowynPwH.js +14 -0
  24. package/dist/directory-open-4ed118d0-BwYbu9dw.js +55 -0
  25. package/dist/edges-e0da2a9e-9VbVapWU.js +1840 -0
  26. package/dist/el-GR-BZB4AONW-DQORZ_pY.js +41 -0
  27. package/dist/en-B4ZKOASM-D2BVbEdz.js +39 -0
  28. package/dist/erDiagram-9861fffd-D4S9QDes.js +1318 -0
  29. package/dist/es-ES-U4NZUMDT-C0Q89-0V.js +40 -0
  30. package/dist/eu-ES-A7QVB2H4-BwBW3cEw.js +42 -0
  31. package/dist/fa-IR-HGAKTJCU-DtZ74rm4.js +39 -0
  32. package/dist/fi-FI-Z5N7JZ37-QvQan48z.js +37 -0
  33. package/dist/file-open-002ab408-BNIYSKAV.js +18 -0
  34. package/dist/file-open-7c801643-B_l1UXdI.js +15 -0
  35. package/dist/file-save-3189631c-vzijizFw.js +23 -0
  36. package/dist/file-save-745eba88-B5-wM56X.js +25 -0
  37. package/dist/flowDb-956e92f1-S6T8ppJw.js +1713 -0
  38. package/dist/flowDiagram-66a62f08-C6TTwS5_.js +1264 -0
  39. package/dist/flowDiagram-v2-96b9c2cf-CzfeUNGP.js +24 -0
  40. package/dist/flowchart-elk-definition-4a651766-CRv1kWtk.js +92922 -0
  41. package/dist/fr-FR-RHASNOE6-CZFiweNU.js +40 -0
  42. package/dist/ganttDiagram-c361ad54-CAnfd8Sw.js +3420 -0
  43. package/dist/gitGraphDiagram-72cf32ee-CSGI-xRI.js +1790 -0
  44. package/dist/gl-ES-HMX3MZ6V-Bqv2xL-V.js +41 -0
  45. package/dist/graph-Ct2tKpKj.js +1253 -0
  46. package/dist/he-IL-6SHJWFNN-kso30jhn.js +41 -0
  47. package/dist/hi-IN-IWLTKZ5I-Busk5oaa.js +35 -0
  48. package/dist/hu-HU-A5ZG7DT2-xSR2C2H0.js +38 -0
  49. package/dist/id-ID-SAP4L64H-BQQZYm1L.js +41 -0
  50. package/dist/image-EDRW2JGV-Cx7o2kxD.js +6 -0
  51. package/dist/image-blob-reduce.esm-BKPqMdie.js +2396 -0
  52. package/dist/index-3862675e-B3j3w-v_.js +663 -0
  53. package/dist/index-CLOU2Ikr.js +14364 -0
  54. package/dist/index.css +450 -0
  55. package/dist/index.d.ts +40 -0
  56. package/dist/index.js +7 -0
  57. package/dist/index.umd.cjs +235477 -0
  58. package/dist/infoDiagram-f8f76790-NqA75uBo.js +510 -0
  59. package/dist/init-ZxktEp_H.js +16 -0
  60. package/dist/it-IT-JPQ66NNP-CAMVZrYt.js +42 -0
  61. package/dist/ja-JP-DBVTYXUO-CAX8A_Uj.js +39 -0
  62. package/dist/journeyDiagram-49397b02-By5oBzsZ.js +1182 -0
  63. package/dist/kaa-6HZHGXH3-4-o94cPY.js +32 -0
  64. package/dist/kab-KAB-ZGHBKWFO-CgyjjBvZ.js +39 -0
  65. package/dist/katex-C-jAQc2m.js +14516 -0
  66. package/dist/kk-KZ-P5N5QNE5-BEqZcwLA.js +32 -0
  67. package/dist/km-KH-HSX4SM5Z-DvKDbeH4.js +42 -0
  68. package/dist/ko-KR-MTYHY66A-DKCuAbKE.js +40 -0
  69. package/dist/ku-TR-6OUDTVRD-CNUs4cCe.js +40 -0
  70. package/dist/layout-AJxYKqQV.js +2292 -0
  71. package/dist/line-DJIf5OM8.js +45 -0
  72. package/dist/linear-Cfj4s4vI.js +539 -0
  73. package/dist/lt-LT-XHIRWOB4-gouzGdoW.js +34 -0
  74. package/dist/lv-LV-5QDEKY6T-CTvg1XFv.js +38 -0
  75. package/dist/mindmap-definition-fc14e90a-CBlwH_UF.js +35283 -0
  76. package/dist/mr-IN-CRQNXWMA-QeYm06Kq.js +44 -0
  77. package/dist/my-MM-5M5IBNSE-DG3k9ORf.js +32 -0
  78. package/dist/nb-NO-T6EIAALU-Cj995Nmg.js +41 -0
  79. package/dist/nl-NL-IS3SIHDZ-B-2H7xey.js +39 -0
  80. package/dist/nn-NO-6E72VCQL-DrAwKKTN.js +39 -0
  81. package/dist/oc-FR-POXYY2M6-CeyJD7tq.js +39 -0
  82. package/dist/ordinal-DSZU4PqD.js +76 -0
  83. package/dist/pa-IN-N4M65BXN-DHzi6mjo.js +35 -0
  84. package/dist/path-Cp2qmpkd.js +109 -0
  85. package/dist/percentages-BXMCSKIN-CDYsTuua.js +6 -0
  86. package/dist/pica-CzzcRNRD.js +1702 -0
  87. package/dist/pieDiagram-8a3498a8-DueGoZOh.js +768 -0
  88. package/dist/pl-PL-T2D74RX3-BBNEV2c6.js +40 -0
  89. package/dist/pt-BR-5N22H2LF-D2cTx_F0.js +40 -0
  90. package/dist/pt-PT-UZXXM6DQ-BddvLLsF.js +40 -0
  91. package/dist/quadrantDiagram-120e2f19-Tb6_oGIn.js +1198 -0
  92. package/dist/requirementDiagram-deff3bca-CEeg0ep-.js +1089 -0
  93. package/dist/ro-RO-JPDTUUEW-DynuW50i.js +42 -0
  94. package/dist/roundRect-CjfubgrN.js +152 -0
  95. package/dist/ru-RU-B4JR7IUQ-B5Hecrew.js +40 -0
  96. package/dist/sankeyDiagram-04a897e0-CGTLQ8Gm.js +1172 -0
  97. package/dist/sequenceDiagram-704730f1-CZ72D-Nd.js +3336 -0
  98. package/dist/si-LK-N5RQ5JYF-BGMa93tc.js +32 -0
  99. package/dist/sk-SK-C5VTKIMK-BttCAlBm.js +37 -0
  100. package/dist/sl-SI-NN7IZMDC-DTC59nzG.js +37 -0
  101. package/dist/stateDiagram-587899a1-XISZzz_f.js +451 -0
  102. package/dist/stateDiagram-v2-d93cdb3a-DbCcmzTc.js +319 -0
  103. package/dist/styles-6aaf32cf-CyfdkEib.js +1363 -0
  104. package/dist/styles-9a916d00-zQ92RrTB.js +1483 -0
  105. package/dist/styles-c10674c1-BWmkigmR.js +571 -0
  106. package/dist/subset-shared.chunk-BuFt2PpZ.js +8 -0
  107. package/dist/subset-worker.chunk-CgaFXU4O.js +14 -0
  108. package/dist/sv-SE-XGPEYMSR-BPDlPxC1.js +41 -0
  109. package/dist/svgDrawCommon-08f97a94-CJ0lufOi.js +100 -0
  110. package/dist/ta-IN-2NMHFXQM-CI1ZsNk9.js +40 -0
  111. package/dist/th-TH-HPSO5L25-CUM-w2Qt.js +33 -0
  112. package/dist/timeline-definition-85554ec2-DV6084Gl.js +1210 -0
  113. package/dist/tr-TR-DEFEU3FU-CGpyf_vD.js +38 -0
  114. package/dist/uk-UA-QMV73CPH-Bg15Mv3J.js +37 -0
  115. package/dist/vi-VN-M7AON7JQ-AYmca9so.js +36 -0
  116. package/dist/vite.svg +1 -0
  117. package/dist/xychartDiagram-e933f94c-P1e6EEaH.js +1796 -0
  118. package/dist/zh-CN-LNUGB5OW-Dem2Cc-c.js +41 -0
  119. package/dist/zh-HK-E62DVLB3-BjsDyiLI.js +32 -0
  120. package/dist/zh-TW-RAJ6MFWO-IDAsc9Pz.js +40 -0
  121. package/package.json +52 -0
@@ -0,0 +1,2292 @@
1
+ import { a as isSymbol, c as baseFlatten, b as baseClone, d as baseIteratee, k as keys, e as baseFindIndex, g as baseEach, j as arrayMap, l as castFunction, m as baseForOwn, n as castPath, t as toKey, o as baseGet, p as hasIn, q as toString, G as Graph, f as forEach, h as has, i as isUndefined, r as filter, v as values, s as reduce } from "./graph-Ct2tKpKj.js";
2
+ import { as as isObject, at as setToString, au as overRest, av as baseRest, aw as isIterateeCall, ax as keysIn, ay as eq, az as isArrayLike, aA as isArray, aB as baseFor, aC as baseAssignValue, aD as identity, aE as isIndex, aF as assignValue, aG as baseUnary, aH as constant, aI as merge } from "./index-CLOU2Ikr.js";
3
+ var reWhitespace = /\s/;
4
+ function trimmedEndIndex(string) {
5
+ var index = string.length;
6
+ while (index-- && reWhitespace.test(string.charAt(index))) {
7
+ }
8
+ return index;
9
+ }
10
+ var reTrimStart = /^\s+/;
11
+ function baseTrim(string) {
12
+ return string ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, "") : string;
13
+ }
14
+ var NAN = 0 / 0;
15
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
16
+ var reIsBinary = /^0b[01]+$/i;
17
+ var reIsOctal = /^0o[0-7]+$/i;
18
+ var freeParseInt = parseInt;
19
+ function toNumber(value) {
20
+ if (typeof value == "number") {
21
+ return value;
22
+ }
23
+ if (isSymbol(value)) {
24
+ return NAN;
25
+ }
26
+ if (isObject(value)) {
27
+ var other = typeof value.valueOf == "function" ? value.valueOf() : value;
28
+ value = isObject(other) ? other + "" : other;
29
+ }
30
+ if (typeof value != "string") {
31
+ return value === 0 ? value : +value;
32
+ }
33
+ value = baseTrim(value);
34
+ var isBinary = reIsBinary.test(value);
35
+ return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
36
+ }
37
+ var INFINITY = 1 / 0, MAX_INTEGER = 17976931348623157e292;
38
+ function toFinite(value) {
39
+ if (!value) {
40
+ return value === 0 ? value : 0;
41
+ }
42
+ value = toNumber(value);
43
+ if (value === INFINITY || value === -INFINITY) {
44
+ var sign = value < 0 ? -1 : 1;
45
+ return sign * MAX_INTEGER;
46
+ }
47
+ return value === value ? value : 0;
48
+ }
49
+ function toInteger(value) {
50
+ var result = toFinite(value), remainder = result % 1;
51
+ return result === result ? remainder ? result - remainder : result : 0;
52
+ }
53
+ function flatten(array) {
54
+ var length = array == null ? 0 : array.length;
55
+ return length ? baseFlatten(array) : [];
56
+ }
57
+ function flatRest(func) {
58
+ return setToString(overRest(func, void 0, flatten), func + "");
59
+ }
60
+ var CLONE_DEEP_FLAG = 1, CLONE_SYMBOLS_FLAG = 4;
61
+ function cloneDeep(value) {
62
+ return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
63
+ }
64
+ var objectProto = Object.prototype;
65
+ var hasOwnProperty = objectProto.hasOwnProperty;
66
+ var defaults = baseRest(function(object, sources) {
67
+ object = Object(object);
68
+ var index = -1;
69
+ var length = sources.length;
70
+ var guard = length > 2 ? sources[2] : void 0;
71
+ if (guard && isIterateeCall(sources[0], sources[1], guard)) {
72
+ length = 1;
73
+ }
74
+ while (++index < length) {
75
+ var source = sources[index];
76
+ var props = keysIn(source);
77
+ var propsIndex = -1;
78
+ var propsLength = props.length;
79
+ while (++propsIndex < propsLength) {
80
+ var key = props[propsIndex];
81
+ var value = object[key];
82
+ if (value === void 0 || eq(value, objectProto[key]) && !hasOwnProperty.call(object, key)) {
83
+ object[key] = source[key];
84
+ }
85
+ }
86
+ }
87
+ return object;
88
+ });
89
+ function last(array) {
90
+ var length = array == null ? 0 : array.length;
91
+ return length ? array[length - 1] : void 0;
92
+ }
93
+ function createFind(findIndexFunc) {
94
+ return function(collection, predicate, fromIndex) {
95
+ var iterable = Object(collection);
96
+ if (!isArrayLike(collection)) {
97
+ var iteratee = baseIteratee(predicate);
98
+ collection = keys(collection);
99
+ predicate = function(key) {
100
+ return iteratee(iterable[key], key, iterable);
101
+ };
102
+ }
103
+ var index = findIndexFunc(collection, predicate, fromIndex);
104
+ return index > -1 ? iterable[iteratee ? collection[index] : index] : void 0;
105
+ };
106
+ }
107
+ var nativeMax$1 = Math.max;
108
+ function findIndex(array, predicate, fromIndex) {
109
+ var length = array == null ? 0 : array.length;
110
+ if (!length) {
111
+ return -1;
112
+ }
113
+ var index = fromIndex == null ? 0 : toInteger(fromIndex);
114
+ if (index < 0) {
115
+ index = nativeMax$1(length + index, 0);
116
+ }
117
+ return baseFindIndex(array, baseIteratee(predicate), index);
118
+ }
119
+ var find = createFind(findIndex);
120
+ function baseMap(collection, iteratee) {
121
+ var index = -1, result = isArrayLike(collection) ? Array(collection.length) : [];
122
+ baseEach(collection, function(value, key, collection2) {
123
+ result[++index] = iteratee(value, key, collection2);
124
+ });
125
+ return result;
126
+ }
127
+ function map(collection, iteratee) {
128
+ var func = isArray(collection) ? arrayMap : baseMap;
129
+ return func(collection, baseIteratee(iteratee));
130
+ }
131
+ function forIn(object, iteratee) {
132
+ return object == null ? object : baseFor(object, castFunction(iteratee), keysIn);
133
+ }
134
+ function forOwn(object, iteratee) {
135
+ return object && baseForOwn(object, castFunction(iteratee));
136
+ }
137
+ function baseGt(value, other) {
138
+ return value > other;
139
+ }
140
+ function baseLt(value, other) {
141
+ return value < other;
142
+ }
143
+ function mapValues(object, iteratee) {
144
+ var result = {};
145
+ iteratee = baseIteratee(iteratee);
146
+ baseForOwn(object, function(value, key, object2) {
147
+ baseAssignValue(result, key, iteratee(value, key, object2));
148
+ });
149
+ return result;
150
+ }
151
+ function baseExtremum(array, iteratee, comparator) {
152
+ var index = -1, length = array.length;
153
+ while (++index < length) {
154
+ var value = array[index], current = iteratee(value);
155
+ if (current != null && (computed === void 0 ? current === current && !isSymbol(current) : comparator(current, computed))) {
156
+ var computed = current, result = value;
157
+ }
158
+ }
159
+ return result;
160
+ }
161
+ function max(array) {
162
+ return array && array.length ? baseExtremum(array, identity, baseGt) : void 0;
163
+ }
164
+ function min(array) {
165
+ return array && array.length ? baseExtremum(array, identity, baseLt) : void 0;
166
+ }
167
+ function minBy(array, iteratee) {
168
+ return array && array.length ? baseExtremum(array, baseIteratee(iteratee), baseLt) : void 0;
169
+ }
170
+ function baseSet(object, path, value, customizer) {
171
+ if (!isObject(object)) {
172
+ return object;
173
+ }
174
+ path = castPath(path, object);
175
+ var index = -1, length = path.length, lastIndex = length - 1, nested = object;
176
+ while (nested != null && ++index < length) {
177
+ var key = toKey(path[index]), newValue = value;
178
+ if (key === "__proto__" || key === "constructor" || key === "prototype") {
179
+ return object;
180
+ }
181
+ if (index != lastIndex) {
182
+ var objValue = nested[key];
183
+ newValue = void 0;
184
+ if (newValue === void 0) {
185
+ newValue = isObject(objValue) ? objValue : isIndex(path[index + 1]) ? [] : {};
186
+ }
187
+ }
188
+ assignValue(nested, key, newValue);
189
+ nested = nested[key];
190
+ }
191
+ return object;
192
+ }
193
+ function basePickBy(object, paths, predicate) {
194
+ var index = -1, length = paths.length, result = {};
195
+ while (++index < length) {
196
+ var path = paths[index], value = baseGet(object, path);
197
+ if (predicate(value, path)) {
198
+ baseSet(result, castPath(path, object), value);
199
+ }
200
+ }
201
+ return result;
202
+ }
203
+ function baseSortBy(array, comparer) {
204
+ var length = array.length;
205
+ array.sort(comparer);
206
+ while (length--) {
207
+ array[length] = array[length].value;
208
+ }
209
+ return array;
210
+ }
211
+ function compareAscending(value, other) {
212
+ if (value !== other) {
213
+ var valIsDefined = value !== void 0, valIsNull = value === null, valIsReflexive = value === value, valIsSymbol = isSymbol(value);
214
+ var othIsDefined = other !== void 0, othIsNull = other === null, othIsReflexive = other === other, othIsSymbol = isSymbol(other);
215
+ if (!othIsNull && !othIsSymbol && !valIsSymbol && value > other || valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol || valIsNull && othIsDefined && othIsReflexive || !valIsDefined && othIsReflexive || !valIsReflexive) {
216
+ return 1;
217
+ }
218
+ if (!valIsNull && !valIsSymbol && !othIsSymbol && value < other || othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol || othIsNull && valIsDefined && valIsReflexive || !othIsDefined && valIsReflexive || !othIsReflexive) {
219
+ return -1;
220
+ }
221
+ }
222
+ return 0;
223
+ }
224
+ function compareMultiple(object, other, orders) {
225
+ var index = -1, objCriteria = object.criteria, othCriteria = other.criteria, length = objCriteria.length, ordersLength = orders.length;
226
+ while (++index < length) {
227
+ var result = compareAscending(objCriteria[index], othCriteria[index]);
228
+ if (result) {
229
+ if (index >= ordersLength) {
230
+ return result;
231
+ }
232
+ var order2 = orders[index];
233
+ return result * (order2 == "desc" ? -1 : 1);
234
+ }
235
+ }
236
+ return object.index - other.index;
237
+ }
238
+ function baseOrderBy(collection, iteratees, orders) {
239
+ if (iteratees.length) {
240
+ iteratees = arrayMap(iteratees, function(iteratee) {
241
+ if (isArray(iteratee)) {
242
+ return function(value) {
243
+ return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
244
+ };
245
+ }
246
+ return iteratee;
247
+ });
248
+ } else {
249
+ iteratees = [identity];
250
+ }
251
+ var index = -1;
252
+ iteratees = arrayMap(iteratees, baseUnary(baseIteratee));
253
+ var result = baseMap(collection, function(value, key, collection2) {
254
+ var criteria = arrayMap(iteratees, function(iteratee) {
255
+ return iteratee(value);
256
+ });
257
+ return { "criteria": criteria, "index": ++index, "value": value };
258
+ });
259
+ return baseSortBy(result, function(object, other) {
260
+ return compareMultiple(object, other, orders);
261
+ });
262
+ }
263
+ function basePick(object, paths) {
264
+ return basePickBy(object, paths, function(value, path) {
265
+ return hasIn(object, path);
266
+ });
267
+ }
268
+ var pick = flatRest(function(object, paths) {
269
+ return object == null ? {} : basePick(object, paths);
270
+ });
271
+ var nativeCeil = Math.ceil, nativeMax = Math.max;
272
+ function baseRange(start, end, step, fromRight) {
273
+ var index = -1, length = nativeMax(nativeCeil((end - start) / (step || 1)), 0), result = Array(length);
274
+ while (length--) {
275
+ result[++index] = start;
276
+ start += step;
277
+ }
278
+ return result;
279
+ }
280
+ function createRange(fromRight) {
281
+ return function(start, end, step) {
282
+ if (step && typeof step != "number" && isIterateeCall(start, end, step)) {
283
+ end = step = void 0;
284
+ }
285
+ start = toFinite(start);
286
+ if (end === void 0) {
287
+ end = start;
288
+ start = 0;
289
+ } else {
290
+ end = toFinite(end);
291
+ }
292
+ step = step === void 0 ? start < end ? 1 : -1 : toFinite(step);
293
+ return baseRange(start, end, step);
294
+ };
295
+ }
296
+ var range = createRange();
297
+ var sortBy = baseRest(function(collection, iteratees) {
298
+ if (collection == null) {
299
+ return [];
300
+ }
301
+ var length = iteratees.length;
302
+ if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
303
+ iteratees = [];
304
+ } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
305
+ iteratees = [iteratees[0]];
306
+ }
307
+ return baseOrderBy(collection, baseFlatten(iteratees), []);
308
+ });
309
+ var idCounter = 0;
310
+ function uniqueId(prefix) {
311
+ var id = ++idCounter;
312
+ return toString(prefix) + id;
313
+ }
314
+ function baseZipObject(props, values2, assignFunc) {
315
+ var index = -1, length = props.length, valsLength = values2.length, result = {};
316
+ while (++index < length) {
317
+ var value = index < valsLength ? values2[index] : void 0;
318
+ assignFunc(result, props[index], value);
319
+ }
320
+ return result;
321
+ }
322
+ function zipObject(props, values2) {
323
+ return baseZipObject(props || [], values2 || [], assignValue);
324
+ }
325
+ class List {
326
+ constructor() {
327
+ var sentinel = {};
328
+ sentinel._next = sentinel._prev = sentinel;
329
+ this._sentinel = sentinel;
330
+ }
331
+ dequeue() {
332
+ var sentinel = this._sentinel;
333
+ var entry = sentinel._prev;
334
+ if (entry !== sentinel) {
335
+ unlink(entry);
336
+ return entry;
337
+ }
338
+ }
339
+ enqueue(entry) {
340
+ var sentinel = this._sentinel;
341
+ if (entry._prev && entry._next) {
342
+ unlink(entry);
343
+ }
344
+ entry._next = sentinel._next;
345
+ sentinel._next._prev = entry;
346
+ sentinel._next = entry;
347
+ entry._prev = sentinel;
348
+ }
349
+ toString() {
350
+ var strs = [];
351
+ var sentinel = this._sentinel;
352
+ var curr = sentinel._prev;
353
+ while (curr !== sentinel) {
354
+ strs.push(JSON.stringify(curr, filterOutLinks));
355
+ curr = curr._prev;
356
+ }
357
+ return "[" + strs.join(", ") + "]";
358
+ }
359
+ }
360
+ function unlink(entry) {
361
+ entry._prev._next = entry._next;
362
+ entry._next._prev = entry._prev;
363
+ delete entry._next;
364
+ delete entry._prev;
365
+ }
366
+ function filterOutLinks(k, v) {
367
+ if (k !== "_next" && k !== "_prev") {
368
+ return v;
369
+ }
370
+ }
371
+ var DEFAULT_WEIGHT_FN = constant(1);
372
+ function greedyFAS(g, weightFn) {
373
+ if (g.nodeCount() <= 1) {
374
+ return [];
375
+ }
376
+ var state = buildState(g, weightFn || DEFAULT_WEIGHT_FN);
377
+ var results = doGreedyFAS(state.graph, state.buckets, state.zeroIdx);
378
+ return flatten(
379
+ map(results, function(e) {
380
+ return g.outEdges(e.v, e.w);
381
+ })
382
+ );
383
+ }
384
+ function doGreedyFAS(g, buckets, zeroIdx) {
385
+ var results = [];
386
+ var sources = buckets[buckets.length - 1];
387
+ var sinks = buckets[0];
388
+ var entry;
389
+ while (g.nodeCount()) {
390
+ while (entry = sinks.dequeue()) {
391
+ removeNode(g, buckets, zeroIdx, entry);
392
+ }
393
+ while (entry = sources.dequeue()) {
394
+ removeNode(g, buckets, zeroIdx, entry);
395
+ }
396
+ if (g.nodeCount()) {
397
+ for (var i = buckets.length - 2; i > 0; --i) {
398
+ entry = buckets[i].dequeue();
399
+ if (entry) {
400
+ results = results.concat(removeNode(g, buckets, zeroIdx, entry, true));
401
+ break;
402
+ }
403
+ }
404
+ }
405
+ }
406
+ return results;
407
+ }
408
+ function removeNode(g, buckets, zeroIdx, entry, collectPredecessors) {
409
+ var results = collectPredecessors ? [] : void 0;
410
+ forEach(g.inEdges(entry.v), function(edge) {
411
+ var weight = g.edge(edge);
412
+ var uEntry = g.node(edge.v);
413
+ if (collectPredecessors) {
414
+ results.push({ v: edge.v, w: edge.w });
415
+ }
416
+ uEntry.out -= weight;
417
+ assignBucket(buckets, zeroIdx, uEntry);
418
+ });
419
+ forEach(g.outEdges(entry.v), function(edge) {
420
+ var weight = g.edge(edge);
421
+ var w = edge.w;
422
+ var wEntry = g.node(w);
423
+ wEntry["in"] -= weight;
424
+ assignBucket(buckets, zeroIdx, wEntry);
425
+ });
426
+ g.removeNode(entry.v);
427
+ return results;
428
+ }
429
+ function buildState(g, weightFn) {
430
+ var fasGraph = new Graph();
431
+ var maxIn = 0;
432
+ var maxOut = 0;
433
+ forEach(g.nodes(), function(v) {
434
+ fasGraph.setNode(v, { v, in: 0, out: 0 });
435
+ });
436
+ forEach(g.edges(), function(e) {
437
+ var prevWeight = fasGraph.edge(e.v, e.w) || 0;
438
+ var weight = weightFn(e);
439
+ var edgeWeight = prevWeight + weight;
440
+ fasGraph.setEdge(e.v, e.w, edgeWeight);
441
+ maxOut = Math.max(maxOut, fasGraph.node(e.v).out += weight);
442
+ maxIn = Math.max(maxIn, fasGraph.node(e.w)["in"] += weight);
443
+ });
444
+ var buckets = range(maxOut + maxIn + 3).map(function() {
445
+ return new List();
446
+ });
447
+ var zeroIdx = maxIn + 1;
448
+ forEach(fasGraph.nodes(), function(v) {
449
+ assignBucket(buckets, zeroIdx, fasGraph.node(v));
450
+ });
451
+ return { graph: fasGraph, buckets, zeroIdx };
452
+ }
453
+ function assignBucket(buckets, zeroIdx, entry) {
454
+ if (!entry.out) {
455
+ buckets[0].enqueue(entry);
456
+ } else if (!entry["in"]) {
457
+ buckets[buckets.length - 1].enqueue(entry);
458
+ } else {
459
+ buckets[entry.out - entry["in"] + zeroIdx].enqueue(entry);
460
+ }
461
+ }
462
+ function run$2(g) {
463
+ var fas = g.graph().acyclicer === "greedy" ? greedyFAS(g, weightFn(g)) : dfsFAS(g);
464
+ forEach(fas, function(e) {
465
+ var label = g.edge(e);
466
+ g.removeEdge(e);
467
+ label.forwardName = e.name;
468
+ label.reversed = true;
469
+ g.setEdge(e.w, e.v, label, uniqueId("rev"));
470
+ });
471
+ function weightFn(g2) {
472
+ return function(e) {
473
+ return g2.edge(e).weight;
474
+ };
475
+ }
476
+ }
477
+ function dfsFAS(g) {
478
+ var fas = [];
479
+ var stack = {};
480
+ var visited = {};
481
+ function dfs2(v) {
482
+ if (has(visited, v)) {
483
+ return;
484
+ }
485
+ visited[v] = true;
486
+ stack[v] = true;
487
+ forEach(g.outEdges(v), function(e) {
488
+ if (has(stack, e.w)) {
489
+ fas.push(e);
490
+ } else {
491
+ dfs2(e.w);
492
+ }
493
+ });
494
+ delete stack[v];
495
+ }
496
+ forEach(g.nodes(), dfs2);
497
+ return fas;
498
+ }
499
+ function undo$2(g) {
500
+ forEach(g.edges(), function(e) {
501
+ var label = g.edge(e);
502
+ if (label.reversed) {
503
+ g.removeEdge(e);
504
+ var forwardName = label.forwardName;
505
+ delete label.reversed;
506
+ delete label.forwardName;
507
+ g.setEdge(e.w, e.v, label, forwardName);
508
+ }
509
+ });
510
+ }
511
+ function addDummyNode(g, type, attrs, name) {
512
+ var v;
513
+ do {
514
+ v = uniqueId(name);
515
+ } while (g.hasNode(v));
516
+ attrs.dummy = type;
517
+ g.setNode(v, attrs);
518
+ return v;
519
+ }
520
+ function simplify(g) {
521
+ var simplified = new Graph().setGraph(g.graph());
522
+ forEach(g.nodes(), function(v) {
523
+ simplified.setNode(v, g.node(v));
524
+ });
525
+ forEach(g.edges(), function(e) {
526
+ var simpleLabel = simplified.edge(e.v, e.w) || { weight: 0, minlen: 1 };
527
+ var label = g.edge(e);
528
+ simplified.setEdge(e.v, e.w, {
529
+ weight: simpleLabel.weight + label.weight,
530
+ minlen: Math.max(simpleLabel.minlen, label.minlen)
531
+ });
532
+ });
533
+ return simplified;
534
+ }
535
+ function asNonCompoundGraph(g) {
536
+ var simplified = new Graph({ multigraph: g.isMultigraph() }).setGraph(g.graph());
537
+ forEach(g.nodes(), function(v) {
538
+ if (!g.children(v).length) {
539
+ simplified.setNode(v, g.node(v));
540
+ }
541
+ });
542
+ forEach(g.edges(), function(e) {
543
+ simplified.setEdge(e, g.edge(e));
544
+ });
545
+ return simplified;
546
+ }
547
+ function intersectRect(rect, point) {
548
+ var x = rect.x;
549
+ var y = rect.y;
550
+ var dx = point.x - x;
551
+ var dy = point.y - y;
552
+ var w = rect.width / 2;
553
+ var h = rect.height / 2;
554
+ if (!dx && !dy) {
555
+ throw new Error("Not possible to find intersection inside of the rectangle");
556
+ }
557
+ var sx, sy;
558
+ if (Math.abs(dy) * w > Math.abs(dx) * h) {
559
+ if (dy < 0) {
560
+ h = -h;
561
+ }
562
+ sx = h * dx / dy;
563
+ sy = h;
564
+ } else {
565
+ if (dx < 0) {
566
+ w = -w;
567
+ }
568
+ sx = w;
569
+ sy = w * dy / dx;
570
+ }
571
+ return { x: x + sx, y: y + sy };
572
+ }
573
+ function buildLayerMatrix(g) {
574
+ var layering = map(range(maxRank(g) + 1), function() {
575
+ return [];
576
+ });
577
+ forEach(g.nodes(), function(v) {
578
+ var node = g.node(v);
579
+ var rank2 = node.rank;
580
+ if (!isUndefined(rank2)) {
581
+ layering[rank2][node.order] = v;
582
+ }
583
+ });
584
+ return layering;
585
+ }
586
+ function normalizeRanks(g) {
587
+ var min$1 = min(
588
+ map(g.nodes(), function(v) {
589
+ return g.node(v).rank;
590
+ })
591
+ );
592
+ forEach(g.nodes(), function(v) {
593
+ var node = g.node(v);
594
+ if (has(node, "rank")) {
595
+ node.rank -= min$1;
596
+ }
597
+ });
598
+ }
599
+ function removeEmptyRanks(g) {
600
+ var offset = min(
601
+ map(g.nodes(), function(v) {
602
+ return g.node(v).rank;
603
+ })
604
+ );
605
+ var layers = [];
606
+ forEach(g.nodes(), function(v) {
607
+ var rank2 = g.node(v).rank - offset;
608
+ if (!layers[rank2]) {
609
+ layers[rank2] = [];
610
+ }
611
+ layers[rank2].push(v);
612
+ });
613
+ var delta = 0;
614
+ var nodeRankFactor = g.graph().nodeRankFactor;
615
+ forEach(layers, function(vs, i) {
616
+ if (isUndefined(vs) && i % nodeRankFactor !== 0) {
617
+ --delta;
618
+ } else if (delta) {
619
+ forEach(vs, function(v) {
620
+ g.node(v).rank += delta;
621
+ });
622
+ }
623
+ });
624
+ }
625
+ function addBorderNode$1(g, prefix, rank2, order2) {
626
+ var node = {
627
+ width: 0,
628
+ height: 0
629
+ };
630
+ if (arguments.length >= 4) {
631
+ node.rank = rank2;
632
+ node.order = order2;
633
+ }
634
+ return addDummyNode(g, "border", node, prefix);
635
+ }
636
+ function maxRank(g) {
637
+ return max(
638
+ map(g.nodes(), function(v) {
639
+ var rank2 = g.node(v).rank;
640
+ if (!isUndefined(rank2)) {
641
+ return rank2;
642
+ }
643
+ })
644
+ );
645
+ }
646
+ function partition(collection, fn) {
647
+ var result = { lhs: [], rhs: [] };
648
+ forEach(collection, function(value) {
649
+ if (fn(value)) {
650
+ result.lhs.push(value);
651
+ } else {
652
+ result.rhs.push(value);
653
+ }
654
+ });
655
+ return result;
656
+ }
657
+ function notime(name, fn) {
658
+ return fn();
659
+ }
660
+ function addBorderSegments(g) {
661
+ function dfs2(v) {
662
+ var children = g.children(v);
663
+ var node = g.node(v);
664
+ if (children.length) {
665
+ forEach(children, dfs2);
666
+ }
667
+ if (has(node, "minRank")) {
668
+ node.borderLeft = [];
669
+ node.borderRight = [];
670
+ for (var rank2 = node.minRank, maxRank2 = node.maxRank + 1; rank2 < maxRank2; ++rank2) {
671
+ addBorderNode(g, "borderLeft", "_bl", v, node, rank2);
672
+ addBorderNode(g, "borderRight", "_br", v, node, rank2);
673
+ }
674
+ }
675
+ }
676
+ forEach(g.children(), dfs2);
677
+ }
678
+ function addBorderNode(g, prop, prefix, sg, sgNode, rank2) {
679
+ var label = { width: 0, height: 0, rank: rank2, borderType: prop };
680
+ var prev = sgNode[prop][rank2 - 1];
681
+ var curr = addDummyNode(g, "border", label, prefix);
682
+ sgNode[prop][rank2] = curr;
683
+ g.setParent(curr, sg);
684
+ if (prev) {
685
+ g.setEdge(prev, curr, { weight: 1 });
686
+ }
687
+ }
688
+ function adjust(g) {
689
+ var rankDir = g.graph().rankdir.toLowerCase();
690
+ if (rankDir === "lr" || rankDir === "rl") {
691
+ swapWidthHeight(g);
692
+ }
693
+ }
694
+ function undo$1(g) {
695
+ var rankDir = g.graph().rankdir.toLowerCase();
696
+ if (rankDir === "bt" || rankDir === "rl") {
697
+ reverseY(g);
698
+ }
699
+ if (rankDir === "lr" || rankDir === "rl") {
700
+ swapXY(g);
701
+ swapWidthHeight(g);
702
+ }
703
+ }
704
+ function swapWidthHeight(g) {
705
+ forEach(g.nodes(), function(v) {
706
+ swapWidthHeightOne(g.node(v));
707
+ });
708
+ forEach(g.edges(), function(e) {
709
+ swapWidthHeightOne(g.edge(e));
710
+ });
711
+ }
712
+ function swapWidthHeightOne(attrs) {
713
+ var w = attrs.width;
714
+ attrs.width = attrs.height;
715
+ attrs.height = w;
716
+ }
717
+ function reverseY(g) {
718
+ forEach(g.nodes(), function(v) {
719
+ reverseYOne(g.node(v));
720
+ });
721
+ forEach(g.edges(), function(e) {
722
+ var edge = g.edge(e);
723
+ forEach(edge.points, reverseYOne);
724
+ if (has(edge, "y")) {
725
+ reverseYOne(edge);
726
+ }
727
+ });
728
+ }
729
+ function reverseYOne(attrs) {
730
+ attrs.y = -attrs.y;
731
+ }
732
+ function swapXY(g) {
733
+ forEach(g.nodes(), function(v) {
734
+ swapXYOne(g.node(v));
735
+ });
736
+ forEach(g.edges(), function(e) {
737
+ var edge = g.edge(e);
738
+ forEach(edge.points, swapXYOne);
739
+ if (has(edge, "x")) {
740
+ swapXYOne(edge);
741
+ }
742
+ });
743
+ }
744
+ function swapXYOne(attrs) {
745
+ var x = attrs.x;
746
+ attrs.x = attrs.y;
747
+ attrs.y = x;
748
+ }
749
+ function run$1(g) {
750
+ g.graph().dummyChains = [];
751
+ forEach(g.edges(), function(edge) {
752
+ normalizeEdge(g, edge);
753
+ });
754
+ }
755
+ function normalizeEdge(g, e) {
756
+ var v = e.v;
757
+ var vRank = g.node(v).rank;
758
+ var w = e.w;
759
+ var wRank = g.node(w).rank;
760
+ var name = e.name;
761
+ var edgeLabel = g.edge(e);
762
+ var labelRank = edgeLabel.labelRank;
763
+ if (wRank === vRank + 1) return;
764
+ g.removeEdge(e);
765
+ var dummy, attrs, i;
766
+ for (i = 0, ++vRank; vRank < wRank; ++i, ++vRank) {
767
+ edgeLabel.points = [];
768
+ attrs = {
769
+ width: 0,
770
+ height: 0,
771
+ edgeLabel,
772
+ edgeObj: e,
773
+ rank: vRank
774
+ };
775
+ dummy = addDummyNode(g, "edge", attrs, "_d");
776
+ if (vRank === labelRank) {
777
+ attrs.width = edgeLabel.width;
778
+ attrs.height = edgeLabel.height;
779
+ attrs.dummy = "edge-label";
780
+ attrs.labelpos = edgeLabel.labelpos;
781
+ }
782
+ g.setEdge(v, dummy, { weight: edgeLabel.weight }, name);
783
+ if (i === 0) {
784
+ g.graph().dummyChains.push(dummy);
785
+ }
786
+ v = dummy;
787
+ }
788
+ g.setEdge(v, w, { weight: edgeLabel.weight }, name);
789
+ }
790
+ function undo(g) {
791
+ forEach(g.graph().dummyChains, function(v) {
792
+ var node = g.node(v);
793
+ var origLabel = node.edgeLabel;
794
+ var w;
795
+ g.setEdge(node.edgeObj, origLabel);
796
+ while (node.dummy) {
797
+ w = g.successors(v)[0];
798
+ g.removeNode(v);
799
+ origLabel.points.push({ x: node.x, y: node.y });
800
+ if (node.dummy === "edge-label") {
801
+ origLabel.x = node.x;
802
+ origLabel.y = node.y;
803
+ origLabel.width = node.width;
804
+ origLabel.height = node.height;
805
+ }
806
+ v = w;
807
+ node = g.node(v);
808
+ }
809
+ });
810
+ }
811
+ function longestPath(g) {
812
+ var visited = {};
813
+ function dfs2(v) {
814
+ var label = g.node(v);
815
+ if (has(visited, v)) {
816
+ return label.rank;
817
+ }
818
+ visited[v] = true;
819
+ var rank2 = min(
820
+ map(g.outEdges(v), function(e) {
821
+ return dfs2(e.w) - g.edge(e).minlen;
822
+ })
823
+ );
824
+ if (rank2 === Number.POSITIVE_INFINITY || // return value of _.map([]) for Lodash 3
825
+ rank2 === void 0 || // return value of _.map([]) for Lodash 4
826
+ rank2 === null) {
827
+ rank2 = 0;
828
+ }
829
+ return label.rank = rank2;
830
+ }
831
+ forEach(g.sources(), dfs2);
832
+ }
833
+ function slack(g, e) {
834
+ return g.node(e.w).rank - g.node(e.v).rank - g.edge(e).minlen;
835
+ }
836
+ function feasibleTree(g) {
837
+ var t = new Graph({ directed: false });
838
+ var start = g.nodes()[0];
839
+ var size = g.nodeCount();
840
+ t.setNode(start, {});
841
+ var edge, delta;
842
+ while (tightTree(t, g) < size) {
843
+ edge = findMinSlackEdge(t, g);
844
+ delta = t.hasNode(edge.v) ? slack(g, edge) : -slack(g, edge);
845
+ shiftRanks(t, g, delta);
846
+ }
847
+ return t;
848
+ }
849
+ function tightTree(t, g) {
850
+ function dfs2(v) {
851
+ forEach(g.nodeEdges(v), function(e) {
852
+ var edgeV = e.v, w = v === edgeV ? e.w : edgeV;
853
+ if (!t.hasNode(w) && !slack(g, e)) {
854
+ t.setNode(w, {});
855
+ t.setEdge(v, w, {});
856
+ dfs2(w);
857
+ }
858
+ });
859
+ }
860
+ forEach(t.nodes(), dfs2);
861
+ return t.nodeCount();
862
+ }
863
+ function findMinSlackEdge(t, g) {
864
+ return minBy(g.edges(), function(e) {
865
+ if (t.hasNode(e.v) !== t.hasNode(e.w)) {
866
+ return slack(g, e);
867
+ }
868
+ });
869
+ }
870
+ function shiftRanks(t, g, delta) {
871
+ forEach(t.nodes(), function(v) {
872
+ g.node(v).rank += delta;
873
+ });
874
+ }
875
+ function CycleException() {
876
+ }
877
+ CycleException.prototype = new Error();
878
+ function dfs$1(g, vs, order2) {
879
+ if (!isArray(vs)) {
880
+ vs = [vs];
881
+ }
882
+ var navigation = (g.isDirected() ? g.successors : g.neighbors).bind(g);
883
+ var acc = [];
884
+ var visited = {};
885
+ forEach(vs, function(v) {
886
+ if (!g.hasNode(v)) {
887
+ throw new Error("Graph does not have node: " + v);
888
+ }
889
+ doDfs(g, v, order2 === "post", visited, navigation, acc);
890
+ });
891
+ return acc;
892
+ }
893
+ function doDfs(g, v, postorder2, visited, navigation, acc) {
894
+ if (!has(visited, v)) {
895
+ visited[v] = true;
896
+ if (!postorder2) {
897
+ acc.push(v);
898
+ }
899
+ forEach(navigation(v), function(w) {
900
+ doDfs(g, w, postorder2, visited, navigation, acc);
901
+ });
902
+ if (postorder2) {
903
+ acc.push(v);
904
+ }
905
+ }
906
+ }
907
+ function postorder$1(g, vs) {
908
+ return dfs$1(g, vs, "post");
909
+ }
910
+ function preorder(g, vs) {
911
+ return dfs$1(g, vs, "pre");
912
+ }
913
+ networkSimplex.initLowLimValues = initLowLimValues;
914
+ networkSimplex.initCutValues = initCutValues;
915
+ networkSimplex.calcCutValue = calcCutValue;
916
+ networkSimplex.leaveEdge = leaveEdge;
917
+ networkSimplex.enterEdge = enterEdge;
918
+ networkSimplex.exchangeEdges = exchangeEdges;
919
+ function networkSimplex(g) {
920
+ g = simplify(g);
921
+ longestPath(g);
922
+ var t = feasibleTree(g);
923
+ initLowLimValues(t);
924
+ initCutValues(t, g);
925
+ var e, f;
926
+ while (e = leaveEdge(t)) {
927
+ f = enterEdge(t, g, e);
928
+ exchangeEdges(t, g, e, f);
929
+ }
930
+ }
931
+ function initCutValues(t, g) {
932
+ var vs = postorder$1(t, t.nodes());
933
+ vs = vs.slice(0, vs.length - 1);
934
+ forEach(vs, function(v) {
935
+ assignCutValue(t, g, v);
936
+ });
937
+ }
938
+ function assignCutValue(t, g, child) {
939
+ var childLab = t.node(child);
940
+ var parent = childLab.parent;
941
+ t.edge(child, parent).cutvalue = calcCutValue(t, g, child);
942
+ }
943
+ function calcCutValue(t, g, child) {
944
+ var childLab = t.node(child);
945
+ var parent = childLab.parent;
946
+ var childIsTail = true;
947
+ var graphEdge = g.edge(child, parent);
948
+ var cutValue = 0;
949
+ if (!graphEdge) {
950
+ childIsTail = false;
951
+ graphEdge = g.edge(parent, child);
952
+ }
953
+ cutValue = graphEdge.weight;
954
+ forEach(g.nodeEdges(child), function(e) {
955
+ var isOutEdge = e.v === child, other = isOutEdge ? e.w : e.v;
956
+ if (other !== parent) {
957
+ var pointsToHead = isOutEdge === childIsTail, otherWeight = g.edge(e).weight;
958
+ cutValue += pointsToHead ? otherWeight : -otherWeight;
959
+ if (isTreeEdge(t, child, other)) {
960
+ var otherCutValue = t.edge(child, other).cutvalue;
961
+ cutValue += pointsToHead ? -otherCutValue : otherCutValue;
962
+ }
963
+ }
964
+ });
965
+ return cutValue;
966
+ }
967
+ function initLowLimValues(tree, root) {
968
+ if (arguments.length < 2) {
969
+ root = tree.nodes()[0];
970
+ }
971
+ dfsAssignLowLim(tree, {}, 1, root);
972
+ }
973
+ function dfsAssignLowLim(tree, visited, nextLim, v, parent) {
974
+ var low = nextLim;
975
+ var label = tree.node(v);
976
+ visited[v] = true;
977
+ forEach(tree.neighbors(v), function(w) {
978
+ if (!has(visited, w)) {
979
+ nextLim = dfsAssignLowLim(tree, visited, nextLim, w, v);
980
+ }
981
+ });
982
+ label.low = low;
983
+ label.lim = nextLim++;
984
+ if (parent) {
985
+ label.parent = parent;
986
+ } else {
987
+ delete label.parent;
988
+ }
989
+ return nextLim;
990
+ }
991
+ function leaveEdge(tree) {
992
+ return find(tree.edges(), function(e) {
993
+ return tree.edge(e).cutvalue < 0;
994
+ });
995
+ }
996
+ function enterEdge(t, g, edge) {
997
+ var v = edge.v;
998
+ var w = edge.w;
999
+ if (!g.hasEdge(v, w)) {
1000
+ v = edge.w;
1001
+ w = edge.v;
1002
+ }
1003
+ var vLabel = t.node(v);
1004
+ var wLabel = t.node(w);
1005
+ var tailLabel = vLabel;
1006
+ var flip = false;
1007
+ if (vLabel.lim > wLabel.lim) {
1008
+ tailLabel = wLabel;
1009
+ flip = true;
1010
+ }
1011
+ var candidates = filter(g.edges(), function(edge2) {
1012
+ return flip === isDescendant(t, t.node(edge2.v), tailLabel) && flip !== isDescendant(t, t.node(edge2.w), tailLabel);
1013
+ });
1014
+ return minBy(candidates, function(edge2) {
1015
+ return slack(g, edge2);
1016
+ });
1017
+ }
1018
+ function exchangeEdges(t, g, e, f) {
1019
+ var v = e.v;
1020
+ var w = e.w;
1021
+ t.removeEdge(v, w);
1022
+ t.setEdge(f.v, f.w, {});
1023
+ initLowLimValues(t);
1024
+ initCutValues(t, g);
1025
+ updateRanks(t, g);
1026
+ }
1027
+ function updateRanks(t, g) {
1028
+ var root = find(t.nodes(), function(v) {
1029
+ return !g.node(v).parent;
1030
+ });
1031
+ var vs = preorder(t, root);
1032
+ vs = vs.slice(1);
1033
+ forEach(vs, function(v) {
1034
+ var parent = t.node(v).parent, edge = g.edge(v, parent), flipped = false;
1035
+ if (!edge) {
1036
+ edge = g.edge(parent, v);
1037
+ flipped = true;
1038
+ }
1039
+ g.node(v).rank = g.node(parent).rank + (flipped ? edge.minlen : -edge.minlen);
1040
+ });
1041
+ }
1042
+ function isTreeEdge(tree, u, v) {
1043
+ return tree.hasEdge(u, v);
1044
+ }
1045
+ function isDescendant(tree, vLabel, rootLabel) {
1046
+ return rootLabel.low <= vLabel.lim && vLabel.lim <= rootLabel.lim;
1047
+ }
1048
+ function rank(g) {
1049
+ switch (g.graph().ranker) {
1050
+ case "network-simplex":
1051
+ networkSimplexRanker(g);
1052
+ break;
1053
+ case "tight-tree":
1054
+ tightTreeRanker(g);
1055
+ break;
1056
+ case "longest-path":
1057
+ longestPathRanker(g);
1058
+ break;
1059
+ default:
1060
+ networkSimplexRanker(g);
1061
+ }
1062
+ }
1063
+ var longestPathRanker = longestPath;
1064
+ function tightTreeRanker(g) {
1065
+ longestPath(g);
1066
+ feasibleTree(g);
1067
+ }
1068
+ function networkSimplexRanker(g) {
1069
+ networkSimplex(g);
1070
+ }
1071
+ function run(g) {
1072
+ var root = addDummyNode(g, "root", {}, "_root");
1073
+ var depths = treeDepths(g);
1074
+ var height = max(values(depths)) - 1;
1075
+ var nodeSep = 2 * height + 1;
1076
+ g.graph().nestingRoot = root;
1077
+ forEach(g.edges(), function(e) {
1078
+ g.edge(e).minlen *= nodeSep;
1079
+ });
1080
+ var weight = sumWeights(g) + 1;
1081
+ forEach(g.children(), function(child) {
1082
+ dfs(g, root, nodeSep, weight, height, depths, child);
1083
+ });
1084
+ g.graph().nodeRankFactor = nodeSep;
1085
+ }
1086
+ function dfs(g, root, nodeSep, weight, height, depths, v) {
1087
+ var children = g.children(v);
1088
+ if (!children.length) {
1089
+ if (v !== root) {
1090
+ g.setEdge(root, v, { weight: 0, minlen: nodeSep });
1091
+ }
1092
+ return;
1093
+ }
1094
+ var top = addBorderNode$1(g, "_bt");
1095
+ var bottom = addBorderNode$1(g, "_bb");
1096
+ var label = g.node(v);
1097
+ g.setParent(top, v);
1098
+ label.borderTop = top;
1099
+ g.setParent(bottom, v);
1100
+ label.borderBottom = bottom;
1101
+ forEach(children, function(child) {
1102
+ dfs(g, root, nodeSep, weight, height, depths, child);
1103
+ var childNode = g.node(child);
1104
+ var childTop = childNode.borderTop ? childNode.borderTop : child;
1105
+ var childBottom = childNode.borderBottom ? childNode.borderBottom : child;
1106
+ var thisWeight = childNode.borderTop ? weight : 2 * weight;
1107
+ var minlen = childTop !== childBottom ? 1 : height - depths[v] + 1;
1108
+ g.setEdge(top, childTop, {
1109
+ weight: thisWeight,
1110
+ minlen,
1111
+ nestingEdge: true
1112
+ });
1113
+ g.setEdge(childBottom, bottom, {
1114
+ weight: thisWeight,
1115
+ minlen,
1116
+ nestingEdge: true
1117
+ });
1118
+ });
1119
+ if (!g.parent(v)) {
1120
+ g.setEdge(root, top, { weight: 0, minlen: height + depths[v] });
1121
+ }
1122
+ }
1123
+ function treeDepths(g) {
1124
+ var depths = {};
1125
+ function dfs2(v, depth) {
1126
+ var children = g.children(v);
1127
+ if (children && children.length) {
1128
+ forEach(children, function(child) {
1129
+ dfs2(child, depth + 1);
1130
+ });
1131
+ }
1132
+ depths[v] = depth;
1133
+ }
1134
+ forEach(g.children(), function(v) {
1135
+ dfs2(v, 1);
1136
+ });
1137
+ return depths;
1138
+ }
1139
+ function sumWeights(g) {
1140
+ return reduce(
1141
+ g.edges(),
1142
+ function(acc, e) {
1143
+ return acc + g.edge(e).weight;
1144
+ },
1145
+ 0
1146
+ );
1147
+ }
1148
+ function cleanup(g) {
1149
+ var graphLabel = g.graph();
1150
+ g.removeNode(graphLabel.nestingRoot);
1151
+ delete graphLabel.nestingRoot;
1152
+ forEach(g.edges(), function(e) {
1153
+ var edge = g.edge(e);
1154
+ if (edge.nestingEdge) {
1155
+ g.removeEdge(e);
1156
+ }
1157
+ });
1158
+ }
1159
+ function addSubgraphConstraints(g, cg, vs) {
1160
+ var prev = {}, rootPrev;
1161
+ forEach(vs, function(v) {
1162
+ var child = g.parent(v), parent, prevChild;
1163
+ while (child) {
1164
+ parent = g.parent(child);
1165
+ if (parent) {
1166
+ prevChild = prev[parent];
1167
+ prev[parent] = child;
1168
+ } else {
1169
+ prevChild = rootPrev;
1170
+ rootPrev = child;
1171
+ }
1172
+ if (prevChild && prevChild !== child) {
1173
+ cg.setEdge(prevChild, child);
1174
+ return;
1175
+ }
1176
+ child = parent;
1177
+ }
1178
+ });
1179
+ }
1180
+ function buildLayerGraph(g, rank2, relationship) {
1181
+ var root = createRootNode(g), result = new Graph({ compound: true }).setGraph({ root }).setDefaultNodeLabel(function(v) {
1182
+ return g.node(v);
1183
+ });
1184
+ forEach(g.nodes(), function(v) {
1185
+ var node = g.node(v), parent = g.parent(v);
1186
+ if (node.rank === rank2 || node.minRank <= rank2 && rank2 <= node.maxRank) {
1187
+ result.setNode(v);
1188
+ result.setParent(v, parent || root);
1189
+ forEach(g[relationship](v), function(e) {
1190
+ var u = e.v === v ? e.w : e.v, edge = result.edge(u, v), weight = !isUndefined(edge) ? edge.weight : 0;
1191
+ result.setEdge(u, v, { weight: g.edge(e).weight + weight });
1192
+ });
1193
+ if (has(node, "minRank")) {
1194
+ result.setNode(v, {
1195
+ borderLeft: node.borderLeft[rank2],
1196
+ borderRight: node.borderRight[rank2]
1197
+ });
1198
+ }
1199
+ }
1200
+ });
1201
+ return result;
1202
+ }
1203
+ function createRootNode(g) {
1204
+ var v;
1205
+ while (g.hasNode(v = uniqueId("_root"))) ;
1206
+ return v;
1207
+ }
1208
+ function crossCount(g, layering) {
1209
+ var cc = 0;
1210
+ for (var i = 1; i < layering.length; ++i) {
1211
+ cc += twoLayerCrossCount(g, layering[i - 1], layering[i]);
1212
+ }
1213
+ return cc;
1214
+ }
1215
+ function twoLayerCrossCount(g, northLayer, southLayer) {
1216
+ var southPos = zipObject(
1217
+ southLayer,
1218
+ map(southLayer, function(v, i) {
1219
+ return i;
1220
+ })
1221
+ );
1222
+ var southEntries = flatten(
1223
+ map(northLayer, function(v) {
1224
+ return sortBy(
1225
+ map(g.outEdges(v), function(e) {
1226
+ return { pos: southPos[e.w], weight: g.edge(e).weight };
1227
+ }),
1228
+ "pos"
1229
+ );
1230
+ })
1231
+ );
1232
+ var firstIndex = 1;
1233
+ while (firstIndex < southLayer.length) firstIndex <<= 1;
1234
+ var treeSize = 2 * firstIndex - 1;
1235
+ firstIndex -= 1;
1236
+ var tree = map(new Array(treeSize), function() {
1237
+ return 0;
1238
+ });
1239
+ var cc = 0;
1240
+ forEach(
1241
+ // @ts-expect-error
1242
+ southEntries.forEach(function(entry) {
1243
+ var index = entry.pos + firstIndex;
1244
+ tree[index] += entry.weight;
1245
+ var weightSum = 0;
1246
+ while (index > 0) {
1247
+ if (index % 2) {
1248
+ weightSum += tree[index + 1];
1249
+ }
1250
+ index = index - 1 >> 1;
1251
+ tree[index] += entry.weight;
1252
+ }
1253
+ cc += entry.weight * weightSum;
1254
+ })
1255
+ );
1256
+ return cc;
1257
+ }
1258
+ function initOrder(g) {
1259
+ var visited = {};
1260
+ var simpleNodes = filter(g.nodes(), function(v) {
1261
+ return !g.children(v).length;
1262
+ });
1263
+ var maxRank2 = max(
1264
+ map(simpleNodes, function(v) {
1265
+ return g.node(v).rank;
1266
+ })
1267
+ );
1268
+ var layers = map(range(maxRank2 + 1), function() {
1269
+ return [];
1270
+ });
1271
+ function dfs2(v) {
1272
+ if (has(visited, v)) return;
1273
+ visited[v] = true;
1274
+ var node = g.node(v);
1275
+ layers[node.rank].push(v);
1276
+ forEach(g.successors(v), dfs2);
1277
+ }
1278
+ var orderedVs = sortBy(simpleNodes, function(v) {
1279
+ return g.node(v).rank;
1280
+ });
1281
+ forEach(orderedVs, dfs2);
1282
+ return layers;
1283
+ }
1284
+ function barycenter(g, movable) {
1285
+ return map(movable, function(v) {
1286
+ var inV = g.inEdges(v);
1287
+ if (!inV.length) {
1288
+ return { v };
1289
+ } else {
1290
+ var result = reduce(
1291
+ inV,
1292
+ function(acc, e) {
1293
+ var edge = g.edge(e), nodeU = g.node(e.v);
1294
+ return {
1295
+ sum: acc.sum + edge.weight * nodeU.order,
1296
+ weight: acc.weight + edge.weight
1297
+ };
1298
+ },
1299
+ { sum: 0, weight: 0 }
1300
+ );
1301
+ return {
1302
+ v,
1303
+ barycenter: result.sum / result.weight,
1304
+ weight: result.weight
1305
+ };
1306
+ }
1307
+ });
1308
+ }
1309
+ function resolveConflicts(entries, cg) {
1310
+ var mappedEntries = {};
1311
+ forEach(entries, function(entry, i) {
1312
+ var tmp = mappedEntries[entry.v] = {
1313
+ indegree: 0,
1314
+ in: [],
1315
+ out: [],
1316
+ vs: [entry.v],
1317
+ i
1318
+ };
1319
+ if (!isUndefined(entry.barycenter)) {
1320
+ tmp.barycenter = entry.barycenter;
1321
+ tmp.weight = entry.weight;
1322
+ }
1323
+ });
1324
+ forEach(cg.edges(), function(e) {
1325
+ var entryV = mappedEntries[e.v];
1326
+ var entryW = mappedEntries[e.w];
1327
+ if (!isUndefined(entryV) && !isUndefined(entryW)) {
1328
+ entryW.indegree++;
1329
+ entryV.out.push(mappedEntries[e.w]);
1330
+ }
1331
+ });
1332
+ var sourceSet = filter(mappedEntries, function(entry) {
1333
+ return !entry.indegree;
1334
+ });
1335
+ return doResolveConflicts(sourceSet);
1336
+ }
1337
+ function doResolveConflicts(sourceSet) {
1338
+ var entries = [];
1339
+ function handleIn(vEntry) {
1340
+ return function(uEntry) {
1341
+ if (uEntry.merged) {
1342
+ return;
1343
+ }
1344
+ if (isUndefined(uEntry.barycenter) || isUndefined(vEntry.barycenter) || uEntry.barycenter >= vEntry.barycenter) {
1345
+ mergeEntries(vEntry, uEntry);
1346
+ }
1347
+ };
1348
+ }
1349
+ function handleOut(vEntry) {
1350
+ return function(wEntry) {
1351
+ wEntry["in"].push(vEntry);
1352
+ if (--wEntry.indegree === 0) {
1353
+ sourceSet.push(wEntry);
1354
+ }
1355
+ };
1356
+ }
1357
+ while (sourceSet.length) {
1358
+ var entry = sourceSet.pop();
1359
+ entries.push(entry);
1360
+ forEach(entry["in"].reverse(), handleIn(entry));
1361
+ forEach(entry.out, handleOut(entry));
1362
+ }
1363
+ return map(
1364
+ filter(entries, function(entry2) {
1365
+ return !entry2.merged;
1366
+ }),
1367
+ function(entry2) {
1368
+ return pick(entry2, ["vs", "i", "barycenter", "weight"]);
1369
+ }
1370
+ );
1371
+ }
1372
+ function mergeEntries(target, source) {
1373
+ var sum = 0;
1374
+ var weight = 0;
1375
+ if (target.weight) {
1376
+ sum += target.barycenter * target.weight;
1377
+ weight += target.weight;
1378
+ }
1379
+ if (source.weight) {
1380
+ sum += source.barycenter * source.weight;
1381
+ weight += source.weight;
1382
+ }
1383
+ target.vs = source.vs.concat(target.vs);
1384
+ target.barycenter = sum / weight;
1385
+ target.weight = weight;
1386
+ target.i = Math.min(source.i, target.i);
1387
+ source.merged = true;
1388
+ }
1389
+ function sort(entries, biasRight) {
1390
+ var parts = partition(entries, function(entry) {
1391
+ return has(entry, "barycenter");
1392
+ });
1393
+ var sortable = parts.lhs, unsortable = sortBy(parts.rhs, function(entry) {
1394
+ return -entry.i;
1395
+ }), vs = [], sum = 0, weight = 0, vsIndex = 0;
1396
+ sortable.sort(compareWithBias(!!biasRight));
1397
+ vsIndex = consumeUnsortable(vs, unsortable, vsIndex);
1398
+ forEach(sortable, function(entry) {
1399
+ vsIndex += entry.vs.length;
1400
+ vs.push(entry.vs);
1401
+ sum += entry.barycenter * entry.weight;
1402
+ weight += entry.weight;
1403
+ vsIndex = consumeUnsortable(vs, unsortable, vsIndex);
1404
+ });
1405
+ var result = { vs: flatten(vs) };
1406
+ if (weight) {
1407
+ result.barycenter = sum / weight;
1408
+ result.weight = weight;
1409
+ }
1410
+ return result;
1411
+ }
1412
+ function consumeUnsortable(vs, unsortable, index) {
1413
+ var last$1;
1414
+ while (unsortable.length && (last$1 = last(unsortable)).i <= index) {
1415
+ unsortable.pop();
1416
+ vs.push(last$1.vs);
1417
+ index++;
1418
+ }
1419
+ return index;
1420
+ }
1421
+ function compareWithBias(bias) {
1422
+ return function(entryV, entryW) {
1423
+ if (entryV.barycenter < entryW.barycenter) {
1424
+ return -1;
1425
+ } else if (entryV.barycenter > entryW.barycenter) {
1426
+ return 1;
1427
+ }
1428
+ return !bias ? entryV.i - entryW.i : entryW.i - entryV.i;
1429
+ };
1430
+ }
1431
+ function sortSubgraph(g, v, cg, biasRight) {
1432
+ var movable = g.children(v);
1433
+ var node = g.node(v);
1434
+ var bl = node ? node.borderLeft : void 0;
1435
+ var br = node ? node.borderRight : void 0;
1436
+ var subgraphs = {};
1437
+ if (bl) {
1438
+ movable = filter(movable, function(w) {
1439
+ return w !== bl && w !== br;
1440
+ });
1441
+ }
1442
+ var barycenters = barycenter(g, movable);
1443
+ forEach(barycenters, function(entry) {
1444
+ if (g.children(entry.v).length) {
1445
+ var subgraphResult = sortSubgraph(g, entry.v, cg, biasRight);
1446
+ subgraphs[entry.v] = subgraphResult;
1447
+ if (has(subgraphResult, "barycenter")) {
1448
+ mergeBarycenters(entry, subgraphResult);
1449
+ }
1450
+ }
1451
+ });
1452
+ var entries = resolveConflicts(barycenters, cg);
1453
+ expandSubgraphs(entries, subgraphs);
1454
+ var result = sort(entries, biasRight);
1455
+ if (bl) {
1456
+ result.vs = flatten([bl, result.vs, br]);
1457
+ if (g.predecessors(bl).length) {
1458
+ var blPred = g.node(g.predecessors(bl)[0]), brPred = g.node(g.predecessors(br)[0]);
1459
+ if (!has(result, "barycenter")) {
1460
+ result.barycenter = 0;
1461
+ result.weight = 0;
1462
+ }
1463
+ result.barycenter = (result.barycenter * result.weight + blPred.order + brPred.order) / (result.weight + 2);
1464
+ result.weight += 2;
1465
+ }
1466
+ }
1467
+ return result;
1468
+ }
1469
+ function expandSubgraphs(entries, subgraphs) {
1470
+ forEach(entries, function(entry) {
1471
+ entry.vs = flatten(
1472
+ entry.vs.map(function(v) {
1473
+ if (subgraphs[v]) {
1474
+ return subgraphs[v].vs;
1475
+ }
1476
+ return v;
1477
+ })
1478
+ );
1479
+ });
1480
+ }
1481
+ function mergeBarycenters(target, other) {
1482
+ if (!isUndefined(target.barycenter)) {
1483
+ target.barycenter = (target.barycenter * target.weight + other.barycenter * other.weight) / (target.weight + other.weight);
1484
+ target.weight += other.weight;
1485
+ } else {
1486
+ target.barycenter = other.barycenter;
1487
+ target.weight = other.weight;
1488
+ }
1489
+ }
1490
+ function order(g) {
1491
+ var maxRank$1 = maxRank(g), downLayerGraphs = buildLayerGraphs(g, range(1, maxRank$1 + 1), "inEdges"), upLayerGraphs = buildLayerGraphs(g, range(maxRank$1 - 1, -1, -1), "outEdges");
1492
+ var layering = initOrder(g);
1493
+ assignOrder(g, layering);
1494
+ var bestCC = Number.POSITIVE_INFINITY, best;
1495
+ for (var i = 0, lastBest = 0; lastBest < 4; ++i, ++lastBest) {
1496
+ sweepLayerGraphs(i % 2 ? downLayerGraphs : upLayerGraphs, i % 4 >= 2);
1497
+ layering = buildLayerMatrix(g);
1498
+ var cc = crossCount(g, layering);
1499
+ if (cc < bestCC) {
1500
+ lastBest = 0;
1501
+ best = cloneDeep(layering);
1502
+ bestCC = cc;
1503
+ }
1504
+ }
1505
+ assignOrder(g, best);
1506
+ }
1507
+ function buildLayerGraphs(g, ranks, relationship) {
1508
+ return map(ranks, function(rank2) {
1509
+ return buildLayerGraph(g, rank2, relationship);
1510
+ });
1511
+ }
1512
+ function sweepLayerGraphs(layerGraphs, biasRight) {
1513
+ var cg = new Graph();
1514
+ forEach(layerGraphs, function(lg) {
1515
+ var root = lg.graph().root;
1516
+ var sorted = sortSubgraph(lg, root, cg, biasRight);
1517
+ forEach(sorted.vs, function(v, i) {
1518
+ lg.node(v).order = i;
1519
+ });
1520
+ addSubgraphConstraints(lg, cg, sorted.vs);
1521
+ });
1522
+ }
1523
+ function assignOrder(g, layering) {
1524
+ forEach(layering, function(layer) {
1525
+ forEach(layer, function(v, i) {
1526
+ g.node(v).order = i;
1527
+ });
1528
+ });
1529
+ }
1530
+ function parentDummyChains(g) {
1531
+ var postorderNums = postorder(g);
1532
+ forEach(g.graph().dummyChains, function(v) {
1533
+ var node = g.node(v);
1534
+ var edgeObj = node.edgeObj;
1535
+ var pathData = findPath(g, postorderNums, edgeObj.v, edgeObj.w);
1536
+ var path = pathData.path;
1537
+ var lca = pathData.lca;
1538
+ var pathIdx = 0;
1539
+ var pathV = path[pathIdx];
1540
+ var ascending = true;
1541
+ while (v !== edgeObj.w) {
1542
+ node = g.node(v);
1543
+ if (ascending) {
1544
+ while ((pathV = path[pathIdx]) !== lca && g.node(pathV).maxRank < node.rank) {
1545
+ pathIdx++;
1546
+ }
1547
+ if (pathV === lca) {
1548
+ ascending = false;
1549
+ }
1550
+ }
1551
+ if (!ascending) {
1552
+ while (pathIdx < path.length - 1 && g.node(pathV = path[pathIdx + 1]).minRank <= node.rank) {
1553
+ pathIdx++;
1554
+ }
1555
+ pathV = path[pathIdx];
1556
+ }
1557
+ g.setParent(v, pathV);
1558
+ v = g.successors(v)[0];
1559
+ }
1560
+ });
1561
+ }
1562
+ function findPath(g, postorderNums, v, w) {
1563
+ var vPath = [];
1564
+ var wPath = [];
1565
+ var low = Math.min(postorderNums[v].low, postorderNums[w].low);
1566
+ var lim = Math.max(postorderNums[v].lim, postorderNums[w].lim);
1567
+ var parent;
1568
+ var lca;
1569
+ parent = v;
1570
+ do {
1571
+ parent = g.parent(parent);
1572
+ vPath.push(parent);
1573
+ } while (parent && (postorderNums[parent].low > low || lim > postorderNums[parent].lim));
1574
+ lca = parent;
1575
+ parent = w;
1576
+ while ((parent = g.parent(parent)) !== lca) {
1577
+ wPath.push(parent);
1578
+ }
1579
+ return { path: vPath.concat(wPath.reverse()), lca };
1580
+ }
1581
+ function postorder(g) {
1582
+ var result = {};
1583
+ var lim = 0;
1584
+ function dfs2(v) {
1585
+ var low = lim;
1586
+ forEach(g.children(v), dfs2);
1587
+ result[v] = { low, lim: lim++ };
1588
+ }
1589
+ forEach(g.children(), dfs2);
1590
+ return result;
1591
+ }
1592
+ function findType1Conflicts(g, layering) {
1593
+ var conflicts = {};
1594
+ function visitLayer(prevLayer, layer) {
1595
+ var k0 = 0, scanPos = 0, prevLayerLength = prevLayer.length, lastNode = last(layer);
1596
+ forEach(layer, function(v, i) {
1597
+ var w = findOtherInnerSegmentNode(g, v), k1 = w ? g.node(w).order : prevLayerLength;
1598
+ if (w || v === lastNode) {
1599
+ forEach(layer.slice(scanPos, i + 1), function(scanNode) {
1600
+ forEach(g.predecessors(scanNode), function(u) {
1601
+ var uLabel = g.node(u), uPos = uLabel.order;
1602
+ if ((uPos < k0 || k1 < uPos) && !(uLabel.dummy && g.node(scanNode).dummy)) {
1603
+ addConflict(conflicts, u, scanNode);
1604
+ }
1605
+ });
1606
+ });
1607
+ scanPos = i + 1;
1608
+ k0 = k1;
1609
+ }
1610
+ });
1611
+ return layer;
1612
+ }
1613
+ reduce(layering, visitLayer);
1614
+ return conflicts;
1615
+ }
1616
+ function findType2Conflicts(g, layering) {
1617
+ var conflicts = {};
1618
+ function scan(south, southPos, southEnd, prevNorthBorder, nextNorthBorder) {
1619
+ var v;
1620
+ forEach(range(southPos, southEnd), function(i) {
1621
+ v = south[i];
1622
+ if (g.node(v).dummy) {
1623
+ forEach(g.predecessors(v), function(u) {
1624
+ var uNode = g.node(u);
1625
+ if (uNode.dummy && (uNode.order < prevNorthBorder || uNode.order > nextNorthBorder)) {
1626
+ addConflict(conflicts, u, v);
1627
+ }
1628
+ });
1629
+ }
1630
+ });
1631
+ }
1632
+ function visitLayer(north, south) {
1633
+ var prevNorthPos = -1, nextNorthPos, southPos = 0;
1634
+ forEach(south, function(v, southLookahead) {
1635
+ if (g.node(v).dummy === "border") {
1636
+ var predecessors = g.predecessors(v);
1637
+ if (predecessors.length) {
1638
+ nextNorthPos = g.node(predecessors[0]).order;
1639
+ scan(south, southPos, southLookahead, prevNorthPos, nextNorthPos);
1640
+ southPos = southLookahead;
1641
+ prevNorthPos = nextNorthPos;
1642
+ }
1643
+ }
1644
+ scan(south, southPos, south.length, nextNorthPos, north.length);
1645
+ });
1646
+ return south;
1647
+ }
1648
+ reduce(layering, visitLayer);
1649
+ return conflicts;
1650
+ }
1651
+ function findOtherInnerSegmentNode(g, v) {
1652
+ if (g.node(v).dummy) {
1653
+ return find(g.predecessors(v), function(u) {
1654
+ return g.node(u).dummy;
1655
+ });
1656
+ }
1657
+ }
1658
+ function addConflict(conflicts, v, w) {
1659
+ if (v > w) {
1660
+ var tmp = v;
1661
+ v = w;
1662
+ w = tmp;
1663
+ }
1664
+ var conflictsV = conflicts[v];
1665
+ if (!conflictsV) {
1666
+ conflicts[v] = conflictsV = {};
1667
+ }
1668
+ conflictsV[w] = true;
1669
+ }
1670
+ function hasConflict(conflicts, v, w) {
1671
+ if (v > w) {
1672
+ var tmp = v;
1673
+ v = w;
1674
+ w = tmp;
1675
+ }
1676
+ return has(conflicts[v], w);
1677
+ }
1678
+ function verticalAlignment(g, layering, conflicts, neighborFn) {
1679
+ var root = {}, align = {}, pos = {};
1680
+ forEach(layering, function(layer) {
1681
+ forEach(layer, function(v, order2) {
1682
+ root[v] = v;
1683
+ align[v] = v;
1684
+ pos[v] = order2;
1685
+ });
1686
+ });
1687
+ forEach(layering, function(layer) {
1688
+ var prevIdx = -1;
1689
+ forEach(layer, function(v) {
1690
+ var ws = neighborFn(v);
1691
+ if (ws.length) {
1692
+ ws = sortBy(ws, function(w2) {
1693
+ return pos[w2];
1694
+ });
1695
+ var mp = (ws.length - 1) / 2;
1696
+ for (var i = Math.floor(mp), il = Math.ceil(mp); i <= il; ++i) {
1697
+ var w = ws[i];
1698
+ if (align[v] === v && prevIdx < pos[w] && !hasConflict(conflicts, v, w)) {
1699
+ align[w] = v;
1700
+ align[v] = root[v] = root[w];
1701
+ prevIdx = pos[w];
1702
+ }
1703
+ }
1704
+ }
1705
+ });
1706
+ });
1707
+ return { root, align };
1708
+ }
1709
+ function horizontalCompaction(g, layering, root, align, reverseSep) {
1710
+ var xs = {}, blockG = buildBlockGraph(g, layering, root, reverseSep), borderType = reverseSep ? "borderLeft" : "borderRight";
1711
+ function iterate(setXsFunc, nextNodesFunc) {
1712
+ var stack = blockG.nodes();
1713
+ var elem = stack.pop();
1714
+ var visited = {};
1715
+ while (elem) {
1716
+ if (visited[elem]) {
1717
+ setXsFunc(elem);
1718
+ } else {
1719
+ visited[elem] = true;
1720
+ stack.push(elem);
1721
+ stack = stack.concat(nextNodesFunc(elem));
1722
+ }
1723
+ elem = stack.pop();
1724
+ }
1725
+ }
1726
+ function pass1(elem) {
1727
+ xs[elem] = blockG.inEdges(elem).reduce(function(acc, e) {
1728
+ return Math.max(acc, xs[e.v] + blockG.edge(e));
1729
+ }, 0);
1730
+ }
1731
+ function pass2(elem) {
1732
+ var min2 = blockG.outEdges(elem).reduce(function(acc, e) {
1733
+ return Math.min(acc, xs[e.w] - blockG.edge(e));
1734
+ }, Number.POSITIVE_INFINITY);
1735
+ var node = g.node(elem);
1736
+ if (min2 !== Number.POSITIVE_INFINITY && node.borderType !== borderType) {
1737
+ xs[elem] = Math.max(xs[elem], min2);
1738
+ }
1739
+ }
1740
+ iterate(pass1, blockG.predecessors.bind(blockG));
1741
+ iterate(pass2, blockG.successors.bind(blockG));
1742
+ forEach(align, function(v) {
1743
+ xs[v] = xs[root[v]];
1744
+ });
1745
+ return xs;
1746
+ }
1747
+ function buildBlockGraph(g, layering, root, reverseSep) {
1748
+ var blockGraph = new Graph(), graphLabel = g.graph(), sepFn = sep(graphLabel.nodesep, graphLabel.edgesep, reverseSep);
1749
+ forEach(layering, function(layer) {
1750
+ var u;
1751
+ forEach(layer, function(v) {
1752
+ var vRoot = root[v];
1753
+ blockGraph.setNode(vRoot);
1754
+ if (u) {
1755
+ var uRoot = root[u], prevMax = blockGraph.edge(uRoot, vRoot);
1756
+ blockGraph.setEdge(uRoot, vRoot, Math.max(sepFn(g, v, u), prevMax || 0));
1757
+ }
1758
+ u = v;
1759
+ });
1760
+ });
1761
+ return blockGraph;
1762
+ }
1763
+ function findSmallestWidthAlignment(g, xss) {
1764
+ return minBy(values(xss), function(xs) {
1765
+ var max2 = Number.NEGATIVE_INFINITY;
1766
+ var min2 = Number.POSITIVE_INFINITY;
1767
+ forIn(xs, function(x, v) {
1768
+ var halfWidth = width(g, v) / 2;
1769
+ max2 = Math.max(x + halfWidth, max2);
1770
+ min2 = Math.min(x - halfWidth, min2);
1771
+ });
1772
+ return max2 - min2;
1773
+ });
1774
+ }
1775
+ function alignCoordinates(xss, alignTo) {
1776
+ var alignToVals = values(alignTo), alignToMin = min(alignToVals), alignToMax = max(alignToVals);
1777
+ forEach(["u", "d"], function(vert) {
1778
+ forEach(["l", "r"], function(horiz) {
1779
+ var alignment = vert + horiz, xs = xss[alignment], delta;
1780
+ if (xs === alignTo) return;
1781
+ var xsVals = values(xs);
1782
+ delta = horiz === "l" ? alignToMin - min(xsVals) : alignToMax - max(xsVals);
1783
+ if (delta) {
1784
+ xss[alignment] = mapValues(xs, function(x) {
1785
+ return x + delta;
1786
+ });
1787
+ }
1788
+ });
1789
+ });
1790
+ }
1791
+ function balance(xss, align) {
1792
+ return mapValues(xss.ul, function(ignore, v) {
1793
+ if (align) {
1794
+ return xss[align.toLowerCase()][v];
1795
+ } else {
1796
+ var xs = sortBy(map(xss, v));
1797
+ return (xs[1] + xs[2]) / 2;
1798
+ }
1799
+ });
1800
+ }
1801
+ function positionX(g) {
1802
+ var layering = buildLayerMatrix(g);
1803
+ var conflicts = merge(findType1Conflicts(g, layering), findType2Conflicts(g, layering));
1804
+ var xss = {};
1805
+ var adjustedLayering;
1806
+ forEach(["u", "d"], function(vert) {
1807
+ adjustedLayering = vert === "u" ? layering : values(layering).reverse();
1808
+ forEach(["l", "r"], function(horiz) {
1809
+ if (horiz === "r") {
1810
+ adjustedLayering = map(adjustedLayering, function(inner) {
1811
+ return values(inner).reverse();
1812
+ });
1813
+ }
1814
+ var neighborFn = (vert === "u" ? g.predecessors : g.successors).bind(g);
1815
+ var align = verticalAlignment(g, adjustedLayering, conflicts, neighborFn);
1816
+ var xs = horizontalCompaction(g, adjustedLayering, align.root, align.align, horiz === "r");
1817
+ if (horiz === "r") {
1818
+ xs = mapValues(xs, function(x) {
1819
+ return -x;
1820
+ });
1821
+ }
1822
+ xss[vert + horiz] = xs;
1823
+ });
1824
+ });
1825
+ var smallestWidth = findSmallestWidthAlignment(g, xss);
1826
+ alignCoordinates(xss, smallestWidth);
1827
+ return balance(xss, g.graph().align);
1828
+ }
1829
+ function sep(nodeSep, edgeSep, reverseSep) {
1830
+ return function(g, v, w) {
1831
+ var vLabel = g.node(v);
1832
+ var wLabel = g.node(w);
1833
+ var sum = 0;
1834
+ var delta;
1835
+ sum += vLabel.width / 2;
1836
+ if (has(vLabel, "labelpos")) {
1837
+ switch (vLabel.labelpos.toLowerCase()) {
1838
+ case "l":
1839
+ delta = -vLabel.width / 2;
1840
+ break;
1841
+ case "r":
1842
+ delta = vLabel.width / 2;
1843
+ break;
1844
+ }
1845
+ }
1846
+ if (delta) {
1847
+ sum += reverseSep ? delta : -delta;
1848
+ }
1849
+ delta = 0;
1850
+ sum += (vLabel.dummy ? edgeSep : nodeSep) / 2;
1851
+ sum += (wLabel.dummy ? edgeSep : nodeSep) / 2;
1852
+ sum += wLabel.width / 2;
1853
+ if (has(wLabel, "labelpos")) {
1854
+ switch (wLabel.labelpos.toLowerCase()) {
1855
+ case "l":
1856
+ delta = wLabel.width / 2;
1857
+ break;
1858
+ case "r":
1859
+ delta = -wLabel.width / 2;
1860
+ break;
1861
+ }
1862
+ }
1863
+ if (delta) {
1864
+ sum += reverseSep ? delta : -delta;
1865
+ }
1866
+ delta = 0;
1867
+ return sum;
1868
+ };
1869
+ }
1870
+ function width(g, v) {
1871
+ return g.node(v).width;
1872
+ }
1873
+ function position(g) {
1874
+ g = asNonCompoundGraph(g);
1875
+ positionY(g);
1876
+ forOwn(positionX(g), function(x, v) {
1877
+ g.node(v).x = x;
1878
+ });
1879
+ }
1880
+ function positionY(g) {
1881
+ var layering = buildLayerMatrix(g);
1882
+ var rankSep = g.graph().ranksep;
1883
+ var prevY = 0;
1884
+ forEach(layering, function(layer) {
1885
+ var maxHeight = max(
1886
+ map(layer, function(v) {
1887
+ return g.node(v).height;
1888
+ })
1889
+ );
1890
+ forEach(layer, function(v) {
1891
+ g.node(v).y = prevY + maxHeight / 2;
1892
+ });
1893
+ prevY += maxHeight + rankSep;
1894
+ });
1895
+ }
1896
+ function layout(g, opts) {
1897
+ var time = notime;
1898
+ time("layout", function() {
1899
+ var layoutGraph = time(" buildLayoutGraph", function() {
1900
+ return buildLayoutGraph(g);
1901
+ });
1902
+ time(" runLayout", function() {
1903
+ runLayout(layoutGraph, time);
1904
+ });
1905
+ time(" updateInputGraph", function() {
1906
+ updateInputGraph(g, layoutGraph);
1907
+ });
1908
+ });
1909
+ }
1910
+ function runLayout(g, time) {
1911
+ time(" makeSpaceForEdgeLabels", function() {
1912
+ makeSpaceForEdgeLabels(g);
1913
+ });
1914
+ time(" removeSelfEdges", function() {
1915
+ removeSelfEdges(g);
1916
+ });
1917
+ time(" acyclic", function() {
1918
+ run$2(g);
1919
+ });
1920
+ time(" nestingGraph.run", function() {
1921
+ run(g);
1922
+ });
1923
+ time(" rank", function() {
1924
+ rank(asNonCompoundGraph(g));
1925
+ });
1926
+ time(" injectEdgeLabelProxies", function() {
1927
+ injectEdgeLabelProxies(g);
1928
+ });
1929
+ time(" removeEmptyRanks", function() {
1930
+ removeEmptyRanks(g);
1931
+ });
1932
+ time(" nestingGraph.cleanup", function() {
1933
+ cleanup(g);
1934
+ });
1935
+ time(" normalizeRanks", function() {
1936
+ normalizeRanks(g);
1937
+ });
1938
+ time(" assignRankMinMax", function() {
1939
+ assignRankMinMax(g);
1940
+ });
1941
+ time(" removeEdgeLabelProxies", function() {
1942
+ removeEdgeLabelProxies(g);
1943
+ });
1944
+ time(" normalize.run", function() {
1945
+ run$1(g);
1946
+ });
1947
+ time(" parentDummyChains", function() {
1948
+ parentDummyChains(g);
1949
+ });
1950
+ time(" addBorderSegments", function() {
1951
+ addBorderSegments(g);
1952
+ });
1953
+ time(" order", function() {
1954
+ order(g);
1955
+ });
1956
+ time(" insertSelfEdges", function() {
1957
+ insertSelfEdges(g);
1958
+ });
1959
+ time(" adjustCoordinateSystem", function() {
1960
+ adjust(g);
1961
+ });
1962
+ time(" position", function() {
1963
+ position(g);
1964
+ });
1965
+ time(" positionSelfEdges", function() {
1966
+ positionSelfEdges(g);
1967
+ });
1968
+ time(" removeBorderNodes", function() {
1969
+ removeBorderNodes(g);
1970
+ });
1971
+ time(" normalize.undo", function() {
1972
+ undo(g);
1973
+ });
1974
+ time(" fixupEdgeLabelCoords", function() {
1975
+ fixupEdgeLabelCoords(g);
1976
+ });
1977
+ time(" undoCoordinateSystem", function() {
1978
+ undo$1(g);
1979
+ });
1980
+ time(" translateGraph", function() {
1981
+ translateGraph(g);
1982
+ });
1983
+ time(" assignNodeIntersects", function() {
1984
+ assignNodeIntersects(g);
1985
+ });
1986
+ time(" reversePoints", function() {
1987
+ reversePointsForReversedEdges(g);
1988
+ });
1989
+ time(" acyclic.undo", function() {
1990
+ undo$2(g);
1991
+ });
1992
+ }
1993
+ function updateInputGraph(inputGraph, layoutGraph) {
1994
+ forEach(inputGraph.nodes(), function(v) {
1995
+ var inputLabel = inputGraph.node(v);
1996
+ var layoutLabel = layoutGraph.node(v);
1997
+ if (inputLabel) {
1998
+ inputLabel.x = layoutLabel.x;
1999
+ inputLabel.y = layoutLabel.y;
2000
+ if (layoutGraph.children(v).length) {
2001
+ inputLabel.width = layoutLabel.width;
2002
+ inputLabel.height = layoutLabel.height;
2003
+ }
2004
+ }
2005
+ });
2006
+ forEach(inputGraph.edges(), function(e) {
2007
+ var inputLabel = inputGraph.edge(e);
2008
+ var layoutLabel = layoutGraph.edge(e);
2009
+ inputLabel.points = layoutLabel.points;
2010
+ if (has(layoutLabel, "x")) {
2011
+ inputLabel.x = layoutLabel.x;
2012
+ inputLabel.y = layoutLabel.y;
2013
+ }
2014
+ });
2015
+ inputGraph.graph().width = layoutGraph.graph().width;
2016
+ inputGraph.graph().height = layoutGraph.graph().height;
2017
+ }
2018
+ var graphNumAttrs = ["nodesep", "edgesep", "ranksep", "marginx", "marginy"];
2019
+ var graphDefaults = { ranksep: 50, edgesep: 20, nodesep: 50, rankdir: "tb" };
2020
+ var graphAttrs = ["acyclicer", "ranker", "rankdir", "align"];
2021
+ var nodeNumAttrs = ["width", "height"];
2022
+ var nodeDefaults = { width: 0, height: 0 };
2023
+ var edgeNumAttrs = ["minlen", "weight", "width", "height", "labeloffset"];
2024
+ var edgeDefaults = {
2025
+ minlen: 1,
2026
+ weight: 1,
2027
+ width: 0,
2028
+ height: 0,
2029
+ labeloffset: 10,
2030
+ labelpos: "r"
2031
+ };
2032
+ var edgeAttrs = ["labelpos"];
2033
+ function buildLayoutGraph(inputGraph) {
2034
+ var g = new Graph({ multigraph: true, compound: true });
2035
+ var graph = canonicalize(inputGraph.graph());
2036
+ g.setGraph(
2037
+ merge({}, graphDefaults, selectNumberAttrs(graph, graphNumAttrs), pick(graph, graphAttrs))
2038
+ );
2039
+ forEach(inputGraph.nodes(), function(v) {
2040
+ var node = canonicalize(inputGraph.node(v));
2041
+ g.setNode(v, defaults(selectNumberAttrs(node, nodeNumAttrs), nodeDefaults));
2042
+ g.setParent(v, inputGraph.parent(v));
2043
+ });
2044
+ forEach(inputGraph.edges(), function(e) {
2045
+ var edge = canonicalize(inputGraph.edge(e));
2046
+ g.setEdge(
2047
+ e,
2048
+ merge({}, edgeDefaults, selectNumberAttrs(edge, edgeNumAttrs), pick(edge, edgeAttrs))
2049
+ );
2050
+ });
2051
+ return g;
2052
+ }
2053
+ function makeSpaceForEdgeLabels(g) {
2054
+ var graph = g.graph();
2055
+ graph.ranksep /= 2;
2056
+ forEach(g.edges(), function(e) {
2057
+ var edge = g.edge(e);
2058
+ edge.minlen *= 2;
2059
+ if (edge.labelpos.toLowerCase() !== "c") {
2060
+ if (graph.rankdir === "TB" || graph.rankdir === "BT") {
2061
+ edge.width += edge.labeloffset;
2062
+ } else {
2063
+ edge.height += edge.labeloffset;
2064
+ }
2065
+ }
2066
+ });
2067
+ }
2068
+ function injectEdgeLabelProxies(g) {
2069
+ forEach(g.edges(), function(e) {
2070
+ var edge = g.edge(e);
2071
+ if (edge.width && edge.height) {
2072
+ var v = g.node(e.v);
2073
+ var w = g.node(e.w);
2074
+ var label = { rank: (w.rank - v.rank) / 2 + v.rank, e };
2075
+ addDummyNode(g, "edge-proxy", label, "_ep");
2076
+ }
2077
+ });
2078
+ }
2079
+ function assignRankMinMax(g) {
2080
+ var maxRank2 = 0;
2081
+ forEach(g.nodes(), function(v) {
2082
+ var node = g.node(v);
2083
+ if (node.borderTop) {
2084
+ node.minRank = g.node(node.borderTop).rank;
2085
+ node.maxRank = g.node(node.borderBottom).rank;
2086
+ maxRank2 = max(maxRank2, node.maxRank);
2087
+ }
2088
+ });
2089
+ g.graph().maxRank = maxRank2;
2090
+ }
2091
+ function removeEdgeLabelProxies(g) {
2092
+ forEach(g.nodes(), function(v) {
2093
+ var node = g.node(v);
2094
+ if (node.dummy === "edge-proxy") {
2095
+ g.edge(node.e).labelRank = node.rank;
2096
+ g.removeNode(v);
2097
+ }
2098
+ });
2099
+ }
2100
+ function translateGraph(g) {
2101
+ var minX = Number.POSITIVE_INFINITY;
2102
+ var maxX = 0;
2103
+ var minY = Number.POSITIVE_INFINITY;
2104
+ var maxY = 0;
2105
+ var graphLabel = g.graph();
2106
+ var marginX = graphLabel.marginx || 0;
2107
+ var marginY = graphLabel.marginy || 0;
2108
+ function getExtremes(attrs) {
2109
+ var x = attrs.x;
2110
+ var y = attrs.y;
2111
+ var w = attrs.width;
2112
+ var h = attrs.height;
2113
+ minX = Math.min(minX, x - w / 2);
2114
+ maxX = Math.max(maxX, x + w / 2);
2115
+ minY = Math.min(minY, y - h / 2);
2116
+ maxY = Math.max(maxY, y + h / 2);
2117
+ }
2118
+ forEach(g.nodes(), function(v) {
2119
+ getExtremes(g.node(v));
2120
+ });
2121
+ forEach(g.edges(), function(e) {
2122
+ var edge = g.edge(e);
2123
+ if (has(edge, "x")) {
2124
+ getExtremes(edge);
2125
+ }
2126
+ });
2127
+ minX -= marginX;
2128
+ minY -= marginY;
2129
+ forEach(g.nodes(), function(v) {
2130
+ var node = g.node(v);
2131
+ node.x -= minX;
2132
+ node.y -= minY;
2133
+ });
2134
+ forEach(g.edges(), function(e) {
2135
+ var edge = g.edge(e);
2136
+ forEach(edge.points, function(p) {
2137
+ p.x -= minX;
2138
+ p.y -= minY;
2139
+ });
2140
+ if (has(edge, "x")) {
2141
+ edge.x -= minX;
2142
+ }
2143
+ if (has(edge, "y")) {
2144
+ edge.y -= minY;
2145
+ }
2146
+ });
2147
+ graphLabel.width = maxX - minX + marginX;
2148
+ graphLabel.height = maxY - minY + marginY;
2149
+ }
2150
+ function assignNodeIntersects(g) {
2151
+ forEach(g.edges(), function(e) {
2152
+ var edge = g.edge(e);
2153
+ var nodeV = g.node(e.v);
2154
+ var nodeW = g.node(e.w);
2155
+ var p1, p2;
2156
+ if (!edge.points) {
2157
+ edge.points = [];
2158
+ p1 = nodeW;
2159
+ p2 = nodeV;
2160
+ } else {
2161
+ p1 = edge.points[0];
2162
+ p2 = edge.points[edge.points.length - 1];
2163
+ }
2164
+ edge.points.unshift(intersectRect(nodeV, p1));
2165
+ edge.points.push(intersectRect(nodeW, p2));
2166
+ });
2167
+ }
2168
+ function fixupEdgeLabelCoords(g) {
2169
+ forEach(g.edges(), function(e) {
2170
+ var edge = g.edge(e);
2171
+ if (has(edge, "x")) {
2172
+ if (edge.labelpos === "l" || edge.labelpos === "r") {
2173
+ edge.width -= edge.labeloffset;
2174
+ }
2175
+ switch (edge.labelpos) {
2176
+ case "l":
2177
+ edge.x -= edge.width / 2 + edge.labeloffset;
2178
+ break;
2179
+ case "r":
2180
+ edge.x += edge.width / 2 + edge.labeloffset;
2181
+ break;
2182
+ }
2183
+ }
2184
+ });
2185
+ }
2186
+ function reversePointsForReversedEdges(g) {
2187
+ forEach(g.edges(), function(e) {
2188
+ var edge = g.edge(e);
2189
+ if (edge.reversed) {
2190
+ edge.points.reverse();
2191
+ }
2192
+ });
2193
+ }
2194
+ function removeBorderNodes(g) {
2195
+ forEach(g.nodes(), function(v) {
2196
+ if (g.children(v).length) {
2197
+ var node = g.node(v);
2198
+ var t = g.node(node.borderTop);
2199
+ var b = g.node(node.borderBottom);
2200
+ var l = g.node(last(node.borderLeft));
2201
+ var r = g.node(last(node.borderRight));
2202
+ node.width = Math.abs(r.x - l.x);
2203
+ node.height = Math.abs(b.y - t.y);
2204
+ node.x = l.x + node.width / 2;
2205
+ node.y = t.y + node.height / 2;
2206
+ }
2207
+ });
2208
+ forEach(g.nodes(), function(v) {
2209
+ if (g.node(v).dummy === "border") {
2210
+ g.removeNode(v);
2211
+ }
2212
+ });
2213
+ }
2214
+ function removeSelfEdges(g) {
2215
+ forEach(g.edges(), function(e) {
2216
+ if (e.v === e.w) {
2217
+ var node = g.node(e.v);
2218
+ if (!node.selfEdges) {
2219
+ node.selfEdges = [];
2220
+ }
2221
+ node.selfEdges.push({ e, label: g.edge(e) });
2222
+ g.removeEdge(e);
2223
+ }
2224
+ });
2225
+ }
2226
+ function insertSelfEdges(g) {
2227
+ var layers = buildLayerMatrix(g);
2228
+ forEach(layers, function(layer) {
2229
+ var orderShift = 0;
2230
+ forEach(layer, function(v, i) {
2231
+ var node = g.node(v);
2232
+ node.order = i + orderShift;
2233
+ forEach(node.selfEdges, function(selfEdge) {
2234
+ addDummyNode(
2235
+ g,
2236
+ "selfedge",
2237
+ {
2238
+ width: selfEdge.label.width,
2239
+ height: selfEdge.label.height,
2240
+ rank: node.rank,
2241
+ order: i + ++orderShift,
2242
+ e: selfEdge.e,
2243
+ label: selfEdge.label
2244
+ },
2245
+ "_se"
2246
+ );
2247
+ });
2248
+ delete node.selfEdges;
2249
+ });
2250
+ });
2251
+ }
2252
+ function positionSelfEdges(g) {
2253
+ forEach(g.nodes(), function(v) {
2254
+ var node = g.node(v);
2255
+ if (node.dummy === "selfedge") {
2256
+ var selfNode = g.node(node.e.v);
2257
+ var x = selfNode.x + selfNode.width / 2;
2258
+ var y = selfNode.y;
2259
+ var dx = node.x - x;
2260
+ var dy = selfNode.height / 2;
2261
+ g.setEdge(node.e, node.label);
2262
+ g.removeNode(v);
2263
+ node.label.points = [
2264
+ { x: x + 2 * dx / 3, y: y - dy },
2265
+ { x: x + 5 * dx / 6, y: y - dy },
2266
+ { x: x + dx, y },
2267
+ { x: x + 5 * dx / 6, y: y + dy },
2268
+ { x: x + 2 * dx / 3, y: y + dy }
2269
+ ];
2270
+ node.label.x = node.x;
2271
+ node.label.y = node.y;
2272
+ }
2273
+ });
2274
+ }
2275
+ function selectNumberAttrs(obj, attrs) {
2276
+ return mapValues(pick(obj, attrs), Number);
2277
+ }
2278
+ function canonicalize(attrs) {
2279
+ var newAttrs = {};
2280
+ forEach(attrs, function(v, k) {
2281
+ newAttrs[k.toLowerCase()] = v;
2282
+ });
2283
+ return newAttrs;
2284
+ }
2285
+ export {
2286
+ defaults as d,
2287
+ layout as l,
2288
+ map as m,
2289
+ pick as p,
2290
+ range as r,
2291
+ uniqueId as u
2292
+ };