@dagrejs/dagre 1.1.1 → 1.1.2
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.
- package/dist/dagre.js +147 -147
- package/dist/dagre.min.js +58 -58
- package/lib/version.js +1 -1
- package/package.json +2 -2
package/dist/dagre.js
CHANGED
|
@@ -2959,7 +2959,7 @@ function zipObject(props, values) {
|
|
|
2959
2959
|
}
|
|
2960
2960
|
|
|
2961
2961
|
},{"@dagrejs/graphlib":29}],28:[function(require,module,exports){
|
|
2962
|
-
module.exports = "1.1.
|
|
2962
|
+
module.exports = "1.1.2";
|
|
2963
2963
|
|
|
2964
2964
|
},{}],29:[function(require,module,exports){
|
|
2965
2965
|
/**
|
|
@@ -3422,28 +3422,28 @@ topsort.CycleException = CycleException;
|
|
|
3422
3422
|
* have its priority decreased in O(log n) time.
|
|
3423
3423
|
*/
|
|
3424
3424
|
class PriorityQueue {
|
|
3425
|
-
|
|
3426
|
-
|
|
3425
|
+
_arr = [];
|
|
3426
|
+
_keyIndices = {};
|
|
3427
3427
|
|
|
3428
3428
|
/**
|
|
3429
3429
|
* Returns the number of elements in the queue. Takes `O(1)` time.
|
|
3430
3430
|
*/
|
|
3431
3431
|
size() {
|
|
3432
|
-
return this
|
|
3432
|
+
return this._arr.length;
|
|
3433
3433
|
}
|
|
3434
3434
|
|
|
3435
3435
|
/**
|
|
3436
3436
|
* Returns the keys that are in the queue. Takes `O(n)` time.
|
|
3437
3437
|
*/
|
|
3438
3438
|
keys() {
|
|
3439
|
-
return this
|
|
3439
|
+
return this._arr.map(function(x) { return x.key; });
|
|
3440
3440
|
}
|
|
3441
3441
|
|
|
3442
3442
|
/**
|
|
3443
3443
|
* Returns `true` if **key** is in the queue and `false` if not.
|
|
3444
3444
|
*/
|
|
3445
3445
|
has(key) {
|
|
3446
|
-
return this
|
|
3446
|
+
return this._keyIndices.hasOwnProperty(key);
|
|
3447
3447
|
}
|
|
3448
3448
|
|
|
3449
3449
|
/**
|
|
@@ -3453,9 +3453,9 @@ class PriorityQueue {
|
|
|
3453
3453
|
* @param {Object} key
|
|
3454
3454
|
*/
|
|
3455
3455
|
priority(key) {
|
|
3456
|
-
var index = this
|
|
3456
|
+
var index = this._keyIndices[key];
|
|
3457
3457
|
if (index !== undefined) {
|
|
3458
|
-
return this
|
|
3458
|
+
return this._arr[index].priority;
|
|
3459
3459
|
}
|
|
3460
3460
|
}
|
|
3461
3461
|
|
|
@@ -3467,7 +3467,7 @@ class PriorityQueue {
|
|
|
3467
3467
|
if (this.size() === 0) {
|
|
3468
3468
|
throw new Error("Queue underflow");
|
|
3469
3469
|
}
|
|
3470
|
-
return this
|
|
3470
|
+
return this._arr[0].key;
|
|
3471
3471
|
}
|
|
3472
3472
|
|
|
3473
3473
|
/**
|
|
@@ -3479,14 +3479,14 @@ class PriorityQueue {
|
|
|
3479
3479
|
* @param {Number} priority the initial priority for the key
|
|
3480
3480
|
*/
|
|
3481
3481
|
add(key, priority) {
|
|
3482
|
-
var keyIndices = this
|
|
3482
|
+
var keyIndices = this._keyIndices;
|
|
3483
3483
|
key = String(key);
|
|
3484
3484
|
if (!keyIndices.hasOwnProperty(key)) {
|
|
3485
|
-
var arr = this
|
|
3485
|
+
var arr = this._arr;
|
|
3486
3486
|
var index = arr.length;
|
|
3487
3487
|
keyIndices[key] = index;
|
|
3488
3488
|
arr.push({key: key, priority: priority});
|
|
3489
|
-
this
|
|
3489
|
+
this._decrease(index);
|
|
3490
3490
|
return true;
|
|
3491
3491
|
}
|
|
3492
3492
|
return false;
|
|
@@ -3496,10 +3496,10 @@ class PriorityQueue {
|
|
|
3496
3496
|
* Removes and returns the smallest key in the queue. Takes `O(log n)` time.
|
|
3497
3497
|
*/
|
|
3498
3498
|
removeMin() {
|
|
3499
|
-
this
|
|
3500
|
-
var min = this
|
|
3501
|
-
delete this
|
|
3502
|
-
this
|
|
3499
|
+
this._swap(0, this._arr.length - 1);
|
|
3500
|
+
var min = this._arr.pop();
|
|
3501
|
+
delete this._keyIndices[min.key];
|
|
3502
|
+
this._heapify(0);
|
|
3503
3503
|
return min.key;
|
|
3504
3504
|
}
|
|
3505
3505
|
|
|
@@ -3511,17 +3511,17 @@ class PriorityQueue {
|
|
|
3511
3511
|
* @param {Number} priority the new priority for the key
|
|
3512
3512
|
*/
|
|
3513
3513
|
decrease(key, priority) {
|
|
3514
|
-
var index = this
|
|
3515
|
-
if (priority > this
|
|
3514
|
+
var index = this._keyIndices[key];
|
|
3515
|
+
if (priority > this._arr[index].priority) {
|
|
3516
3516
|
throw new Error("New priority is greater than current priority. " +
|
|
3517
|
-
"Key: " + key + " Old: " + this
|
|
3517
|
+
"Key: " + key + " Old: " + this._arr[index].priority + " New: " + priority);
|
|
3518
3518
|
}
|
|
3519
|
-
this
|
|
3520
|
-
this
|
|
3519
|
+
this._arr[index].priority = priority;
|
|
3520
|
+
this._decrease(index);
|
|
3521
3521
|
}
|
|
3522
3522
|
|
|
3523
|
-
|
|
3524
|
-
var arr = this
|
|
3523
|
+
_heapify(i) {
|
|
3524
|
+
var arr = this._arr;
|
|
3525
3525
|
var l = 2 * i;
|
|
3526
3526
|
var r = l + 1;
|
|
3527
3527
|
var largest = i;
|
|
@@ -3531,14 +3531,14 @@ class PriorityQueue {
|
|
|
3531
3531
|
largest = arr[r].priority < arr[largest].priority ? r : largest;
|
|
3532
3532
|
}
|
|
3533
3533
|
if (largest !== i) {
|
|
3534
|
-
this
|
|
3535
|
-
this
|
|
3534
|
+
this._swap(i, largest);
|
|
3535
|
+
this._heapify(largest);
|
|
3536
3536
|
}
|
|
3537
3537
|
}
|
|
3538
3538
|
}
|
|
3539
3539
|
|
|
3540
|
-
|
|
3541
|
-
var arr = this
|
|
3540
|
+
_decrease(index) {
|
|
3541
|
+
var arr = this._arr;
|
|
3542
3542
|
var priority = arr[index].priority;
|
|
3543
3543
|
var parent;
|
|
3544
3544
|
while (index !== 0) {
|
|
@@ -3546,14 +3546,14 @@ class PriorityQueue {
|
|
|
3546
3546
|
if (arr[parent].priority < priority) {
|
|
3547
3547
|
break;
|
|
3548
3548
|
}
|
|
3549
|
-
this
|
|
3549
|
+
this._swap(index, parent);
|
|
3550
3550
|
index = parent;
|
|
3551
3551
|
}
|
|
3552
3552
|
}
|
|
3553
3553
|
|
|
3554
|
-
|
|
3555
|
-
var arr = this
|
|
3556
|
-
var keyIndices = this
|
|
3554
|
+
_swap(i, j) {
|
|
3555
|
+
var arr = this._arr;
|
|
3556
|
+
var keyIndices = this._keyIndices;
|
|
3557
3557
|
var origArrI = arr[i];
|
|
3558
3558
|
var origArrJ = arr[j];
|
|
3559
3559
|
arr[i] = origArrJ;
|
|
@@ -3583,64 +3583,64 @@ var EDGE_KEY_DELIM = "\x01";
|
|
|
3583
3583
|
// we're going to get to a performant hashtable in JavaScript.
|
|
3584
3584
|
|
|
3585
3585
|
class Graph {
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3586
|
+
_isDirected = true;
|
|
3587
|
+
_isMultigraph = false;
|
|
3588
|
+
_isCompound = false;
|
|
3589
3589
|
|
|
3590
3590
|
// Label for the graph itself
|
|
3591
|
-
|
|
3591
|
+
_label;
|
|
3592
3592
|
|
|
3593
3593
|
// Defaults to be set when creating a new node
|
|
3594
|
-
|
|
3594
|
+
_defaultNodeLabelFn = () => undefined;
|
|
3595
3595
|
|
|
3596
3596
|
// Defaults to be set when creating a new edge
|
|
3597
|
-
|
|
3597
|
+
_defaultEdgeLabelFn = () => undefined;
|
|
3598
3598
|
|
|
3599
3599
|
// v -> label
|
|
3600
|
-
|
|
3600
|
+
_nodes = {};
|
|
3601
3601
|
|
|
3602
3602
|
// v -> edgeObj
|
|
3603
|
-
|
|
3603
|
+
_in = {};
|
|
3604
3604
|
|
|
3605
3605
|
// u -> v -> Number
|
|
3606
|
-
|
|
3606
|
+
_preds = {};
|
|
3607
3607
|
|
|
3608
3608
|
// v -> edgeObj
|
|
3609
|
-
|
|
3609
|
+
_out = {};
|
|
3610
3610
|
|
|
3611
3611
|
// v -> w -> Number
|
|
3612
|
-
|
|
3612
|
+
_sucs = {};
|
|
3613
3613
|
|
|
3614
3614
|
// e -> edgeObj
|
|
3615
|
-
|
|
3615
|
+
_edgeObjs = {};
|
|
3616
3616
|
|
|
3617
3617
|
// e -> label
|
|
3618
|
-
|
|
3618
|
+
_edgeLabels = {};
|
|
3619
3619
|
|
|
3620
3620
|
/* Number of nodes in the graph. Should only be changed by the implementation. */
|
|
3621
|
-
|
|
3621
|
+
_nodeCount = 0;
|
|
3622
3622
|
|
|
3623
3623
|
/* Number of edges in the graph. Should only be changed by the implementation. */
|
|
3624
|
-
|
|
3624
|
+
_edgeCount = 0;
|
|
3625
3625
|
|
|
3626
|
-
|
|
3626
|
+
_parent;
|
|
3627
3627
|
|
|
3628
|
-
|
|
3628
|
+
_children;
|
|
3629
3629
|
|
|
3630
3630
|
constructor(opts) {
|
|
3631
3631
|
if (opts) {
|
|
3632
|
-
this
|
|
3633
|
-
this
|
|
3634
|
-
this
|
|
3632
|
+
this._isDirected = opts.hasOwnProperty("directed") ? opts.directed : true;
|
|
3633
|
+
this._isMultigraph = opts.hasOwnProperty("multigraph") ? opts.multigraph : false;
|
|
3634
|
+
this._isCompound = opts.hasOwnProperty("compound") ? opts.compound : false;
|
|
3635
3635
|
}
|
|
3636
3636
|
|
|
3637
|
-
if (this
|
|
3637
|
+
if (this._isCompound) {
|
|
3638
3638
|
// v -> parent
|
|
3639
|
-
this
|
|
3639
|
+
this._parent = {};
|
|
3640
3640
|
|
|
3641
3641
|
// v -> children
|
|
3642
|
-
this
|
|
3643
|
-
this
|
|
3642
|
+
this._children = {};
|
|
3643
|
+
this._children[GRAPH_NODE] = {};
|
|
3644
3644
|
}
|
|
3645
3645
|
}
|
|
3646
3646
|
|
|
@@ -3650,28 +3650,28 @@ class Graph {
|
|
|
3650
3650
|
* Whether graph was created with 'directed' flag set to true or not.
|
|
3651
3651
|
*/
|
|
3652
3652
|
isDirected() {
|
|
3653
|
-
return this
|
|
3653
|
+
return this._isDirected;
|
|
3654
3654
|
}
|
|
3655
3655
|
|
|
3656
3656
|
/**
|
|
3657
3657
|
* Whether graph was created with 'multigraph' flag set to true or not.
|
|
3658
3658
|
*/
|
|
3659
3659
|
isMultigraph() {
|
|
3660
|
-
return this
|
|
3660
|
+
return this._isMultigraph;
|
|
3661
3661
|
}
|
|
3662
3662
|
|
|
3663
3663
|
/**
|
|
3664
3664
|
* Whether graph was created with 'compound' flag set to true or not.
|
|
3665
3665
|
*/
|
|
3666
3666
|
isCompound() {
|
|
3667
|
-
return this
|
|
3667
|
+
return this._isCompound;
|
|
3668
3668
|
}
|
|
3669
3669
|
|
|
3670
3670
|
/**
|
|
3671
3671
|
* Sets the label of the graph.
|
|
3672
3672
|
*/
|
|
3673
3673
|
setGraph(label) {
|
|
3674
|
-
this
|
|
3674
|
+
this._label = label;
|
|
3675
3675
|
return this;
|
|
3676
3676
|
}
|
|
3677
3677
|
|
|
@@ -3679,7 +3679,7 @@ class Graph {
|
|
|
3679
3679
|
* Gets the graph label.
|
|
3680
3680
|
*/
|
|
3681
3681
|
graph() {
|
|
3682
|
-
return this
|
|
3682
|
+
return this._label;
|
|
3683
3683
|
}
|
|
3684
3684
|
|
|
3685
3685
|
|
|
@@ -3693,9 +3693,9 @@ class Graph {
|
|
|
3693
3693
|
* Complexity: O(1).
|
|
3694
3694
|
*/
|
|
3695
3695
|
setDefaultNodeLabel(newDefault) {
|
|
3696
|
-
this
|
|
3696
|
+
this._defaultNodeLabelFn = newDefault;
|
|
3697
3697
|
if (typeof newDefault !== 'function') {
|
|
3698
|
-
this
|
|
3698
|
+
this._defaultNodeLabelFn = () => newDefault;
|
|
3699
3699
|
}
|
|
3700
3700
|
|
|
3701
3701
|
return this;
|
|
@@ -3706,7 +3706,7 @@ class Graph {
|
|
|
3706
3706
|
* Complexity: O(1).
|
|
3707
3707
|
*/
|
|
3708
3708
|
nodeCount() {
|
|
3709
|
-
return this
|
|
3709
|
+
return this._nodeCount;
|
|
3710
3710
|
}
|
|
3711
3711
|
|
|
3712
3712
|
/**
|
|
@@ -3715,7 +3715,7 @@ class Graph {
|
|
|
3715
3715
|
* Complexity: O(1).
|
|
3716
3716
|
*/
|
|
3717
3717
|
nodes() {
|
|
3718
|
-
return Object.keys(this
|
|
3718
|
+
return Object.keys(this._nodes);
|
|
3719
3719
|
}
|
|
3720
3720
|
|
|
3721
3721
|
/**
|
|
@@ -3724,7 +3724,7 @@ class Graph {
|
|
|
3724
3724
|
*/
|
|
3725
3725
|
sources() {
|
|
3726
3726
|
var self = this;
|
|
3727
|
-
return this.nodes().filter(v => Object.keys(self
|
|
3727
|
+
return this.nodes().filter(v => Object.keys(self._in[v]).length === 0);
|
|
3728
3728
|
}
|
|
3729
3729
|
|
|
3730
3730
|
/**
|
|
@@ -3733,7 +3733,7 @@ class Graph {
|
|
|
3733
3733
|
*/
|
|
3734
3734
|
sinks() {
|
|
3735
3735
|
var self = this;
|
|
3736
|
-
return this.nodes().filter(v => Object.keys(self
|
|
3736
|
+
return this.nodes().filter(v => Object.keys(self._out[v]).length === 0);
|
|
3737
3737
|
}
|
|
3738
3738
|
|
|
3739
3739
|
/**
|
|
@@ -3760,24 +3760,24 @@ class Graph {
|
|
|
3760
3760
|
* Complexity: O(1).
|
|
3761
3761
|
*/
|
|
3762
3762
|
setNode(v, value) {
|
|
3763
|
-
if (this
|
|
3763
|
+
if (this._nodes.hasOwnProperty(v)) {
|
|
3764
3764
|
if (arguments.length > 1) {
|
|
3765
|
-
this
|
|
3765
|
+
this._nodes[v] = value;
|
|
3766
3766
|
}
|
|
3767
3767
|
return this;
|
|
3768
3768
|
}
|
|
3769
3769
|
|
|
3770
|
-
this
|
|
3771
|
-
if (this
|
|
3772
|
-
this
|
|
3773
|
-
this
|
|
3774
|
-
this
|
|
3770
|
+
this._nodes[v] = arguments.length > 1 ? value : this._defaultNodeLabelFn(v);
|
|
3771
|
+
if (this._isCompound) {
|
|
3772
|
+
this._parent[v] = GRAPH_NODE;
|
|
3773
|
+
this._children[v] = {};
|
|
3774
|
+
this._children[GRAPH_NODE][v] = true;
|
|
3775
3775
|
}
|
|
3776
|
-
this
|
|
3777
|
-
this
|
|
3778
|
-
this
|
|
3779
|
-
this
|
|
3780
|
-
++this
|
|
3776
|
+
this._in[v] = {};
|
|
3777
|
+
this._preds[v] = {};
|
|
3778
|
+
this._out[v] = {};
|
|
3779
|
+
this._sucs[v] = {};
|
|
3780
|
+
++this._nodeCount;
|
|
3781
3781
|
return this;
|
|
3782
3782
|
}
|
|
3783
3783
|
|
|
@@ -3786,14 +3786,14 @@ class Graph {
|
|
|
3786
3786
|
* Complexity: O(|V|).
|
|
3787
3787
|
*/
|
|
3788
3788
|
node(v) {
|
|
3789
|
-
return this
|
|
3789
|
+
return this._nodes[v];
|
|
3790
3790
|
}
|
|
3791
3791
|
|
|
3792
3792
|
/**
|
|
3793
3793
|
* Detects whether graph has a node with specified name or not.
|
|
3794
3794
|
*/
|
|
3795
3795
|
hasNode(v) {
|
|
3796
|
-
return this
|
|
3796
|
+
return this._nodes.hasOwnProperty(v);
|
|
3797
3797
|
}
|
|
3798
3798
|
|
|
3799
3799
|
/**
|
|
@@ -3804,24 +3804,24 @@ class Graph {
|
|
|
3804
3804
|
*/
|
|
3805
3805
|
removeNode(v) {
|
|
3806
3806
|
var self = this;
|
|
3807
|
-
if (this
|
|
3808
|
-
var removeEdge = e => self.removeEdge(self
|
|
3809
|
-
delete this
|
|
3810
|
-
if (this
|
|
3811
|
-
this
|
|
3812
|
-
delete this
|
|
3807
|
+
if (this._nodes.hasOwnProperty(v)) {
|
|
3808
|
+
var removeEdge = e => self.removeEdge(self._edgeObjs[e]);
|
|
3809
|
+
delete this._nodes[v];
|
|
3810
|
+
if (this._isCompound) {
|
|
3811
|
+
this._removeFromParentsChildList(v);
|
|
3812
|
+
delete this._parent[v];
|
|
3813
3813
|
this.children(v).forEach(function(child) {
|
|
3814
3814
|
self.setParent(child);
|
|
3815
3815
|
});
|
|
3816
|
-
delete this
|
|
3816
|
+
delete this._children[v];
|
|
3817
3817
|
}
|
|
3818
|
-
Object.keys(this
|
|
3819
|
-
delete this
|
|
3820
|
-
delete this
|
|
3821
|
-
Object.keys(this
|
|
3822
|
-
delete this
|
|
3823
|
-
delete this
|
|
3824
|
-
--this
|
|
3818
|
+
Object.keys(this._in[v]).forEach(removeEdge);
|
|
3819
|
+
delete this._in[v];
|
|
3820
|
+
delete this._preds[v];
|
|
3821
|
+
Object.keys(this._out[v]).forEach(removeEdge);
|
|
3822
|
+
delete this._out[v];
|
|
3823
|
+
delete this._sucs[v];
|
|
3824
|
+
--this._nodeCount;
|
|
3825
3825
|
}
|
|
3826
3826
|
return this;
|
|
3827
3827
|
}
|
|
@@ -3833,7 +3833,7 @@ class Graph {
|
|
|
3833
3833
|
* Average-case complexity: O(1).
|
|
3834
3834
|
*/
|
|
3835
3835
|
setParent(v, parent) {
|
|
3836
|
-
if (!this
|
|
3836
|
+
if (!this._isCompound) {
|
|
3837
3837
|
throw new Error("Cannot set parent in a non-compound graph");
|
|
3838
3838
|
}
|
|
3839
3839
|
|
|
@@ -3853,14 +3853,14 @@ class Graph {
|
|
|
3853
3853
|
}
|
|
3854
3854
|
|
|
3855
3855
|
this.setNode(v);
|
|
3856
|
-
this
|
|
3857
|
-
this
|
|
3858
|
-
this
|
|
3856
|
+
this._removeFromParentsChildList(v);
|
|
3857
|
+
this._parent[v] = parent;
|
|
3858
|
+
this._children[parent][v] = true;
|
|
3859
3859
|
return this;
|
|
3860
3860
|
}
|
|
3861
3861
|
|
|
3862
|
-
|
|
3863
|
-
delete this
|
|
3862
|
+
_removeFromParentsChildList(v) {
|
|
3863
|
+
delete this._children[this._parent[v]][v];
|
|
3864
3864
|
}
|
|
3865
3865
|
|
|
3866
3866
|
/**
|
|
@@ -3868,8 +3868,8 @@ class Graph {
|
|
|
3868
3868
|
* Complexity: O(1).
|
|
3869
3869
|
*/
|
|
3870
3870
|
parent(v) {
|
|
3871
|
-
if (this
|
|
3872
|
-
var parent = this
|
|
3871
|
+
if (this._isCompound) {
|
|
3872
|
+
var parent = this._parent[v];
|
|
3873
3873
|
if (parent !== GRAPH_NODE) {
|
|
3874
3874
|
return parent;
|
|
3875
3875
|
}
|
|
@@ -3881,8 +3881,8 @@ class Graph {
|
|
|
3881
3881
|
* Complexity: O(1).
|
|
3882
3882
|
*/
|
|
3883
3883
|
children(v = GRAPH_NODE) {
|
|
3884
|
-
if (this
|
|
3885
|
-
var children = this
|
|
3884
|
+
if (this._isCompound) {
|
|
3885
|
+
var children = this._children[v];
|
|
3886
3886
|
if (children) {
|
|
3887
3887
|
return Object.keys(children);
|
|
3888
3888
|
}
|
|
@@ -3899,7 +3899,7 @@ class Graph {
|
|
|
3899
3899
|
* Complexity: O(|V|).
|
|
3900
3900
|
*/
|
|
3901
3901
|
predecessors(v) {
|
|
3902
|
-
var predsV = this
|
|
3902
|
+
var predsV = this._preds[v];
|
|
3903
3903
|
if (predsV) {
|
|
3904
3904
|
return Object.keys(predsV);
|
|
3905
3905
|
}
|
|
@@ -3911,7 +3911,7 @@ class Graph {
|
|
|
3911
3911
|
* Complexity: O(|V|).
|
|
3912
3912
|
*/
|
|
3913
3913
|
successors(v) {
|
|
3914
|
-
var sucsV = this
|
|
3914
|
+
var sucsV = this._sucs[v];
|
|
3915
3915
|
if (sucsV) {
|
|
3916
3916
|
return Object.keys(sucsV);
|
|
3917
3917
|
}
|
|
@@ -3952,21 +3952,21 @@ class Graph {
|
|
|
3952
3952
|
*/
|
|
3953
3953
|
filterNodes(filter) {
|
|
3954
3954
|
var copy = new this.constructor({
|
|
3955
|
-
directed: this
|
|
3956
|
-
multigraph: this
|
|
3957
|
-
compound: this
|
|
3955
|
+
directed: this._isDirected,
|
|
3956
|
+
multigraph: this._isMultigraph,
|
|
3957
|
+
compound: this._isCompound
|
|
3958
3958
|
});
|
|
3959
3959
|
|
|
3960
3960
|
copy.setGraph(this.graph());
|
|
3961
3961
|
|
|
3962
3962
|
var self = this;
|
|
3963
|
-
Object.entries(this
|
|
3963
|
+
Object.entries(this._nodes).forEach(function([v, value]) {
|
|
3964
3964
|
if (filter(v)) {
|
|
3965
3965
|
copy.setNode(v, value);
|
|
3966
3966
|
}
|
|
3967
3967
|
});
|
|
3968
3968
|
|
|
3969
|
-
Object.values(this
|
|
3969
|
+
Object.values(this._edgeObjs).forEach(function(e) {
|
|
3970
3970
|
if (copy.hasNode(e.v) && copy.hasNode(e.w)) {
|
|
3971
3971
|
copy.setEdge(e, self.edge(e));
|
|
3972
3972
|
}
|
|
@@ -3985,7 +3985,7 @@ class Graph {
|
|
|
3985
3985
|
}
|
|
3986
3986
|
}
|
|
3987
3987
|
|
|
3988
|
-
if (this
|
|
3988
|
+
if (this._isCompound) {
|
|
3989
3989
|
copy.nodes().forEach(v => copy.setParent(v, findParent(v)));
|
|
3990
3990
|
}
|
|
3991
3991
|
|
|
@@ -4002,9 +4002,9 @@ class Graph {
|
|
|
4002
4002
|
* Complexity: O(1).
|
|
4003
4003
|
*/
|
|
4004
4004
|
setDefaultEdgeLabel(newDefault) {
|
|
4005
|
-
this
|
|
4005
|
+
this._defaultEdgeLabelFn = newDefault;
|
|
4006
4006
|
if (typeof newDefault !== 'function') {
|
|
4007
|
-
this
|
|
4007
|
+
this._defaultEdgeLabelFn = () => newDefault;
|
|
4008
4008
|
}
|
|
4009
4009
|
|
|
4010
4010
|
return this;
|
|
@@ -4015,7 +4015,7 @@ class Graph {
|
|
|
4015
4015
|
* Complexity: O(1).
|
|
4016
4016
|
*/
|
|
4017
4017
|
edgeCount() {
|
|
4018
|
-
return this
|
|
4018
|
+
return this._edgeCount;
|
|
4019
4019
|
}
|
|
4020
4020
|
|
|
4021
4021
|
/**
|
|
@@ -4023,7 +4023,7 @@ class Graph {
|
|
|
4023
4023
|
* Complexity: O(|E|).
|
|
4024
4024
|
*/
|
|
4025
4025
|
edges() {
|
|
4026
|
-
return Object.values(this
|
|
4026
|
+
return Object.values(this._edgeObjs);
|
|
4027
4027
|
}
|
|
4028
4028
|
|
|
4029
4029
|
/**
|
|
@@ -4081,15 +4081,15 @@ class Graph {
|
|
|
4081
4081
|
name = "" + name;
|
|
4082
4082
|
}
|
|
4083
4083
|
|
|
4084
|
-
var e = edgeArgsToId(this
|
|
4085
|
-
if (this
|
|
4084
|
+
var e = edgeArgsToId(this._isDirected, v, w, name);
|
|
4085
|
+
if (this._edgeLabels.hasOwnProperty(e)) {
|
|
4086
4086
|
if (valueSpecified) {
|
|
4087
|
-
this
|
|
4087
|
+
this._edgeLabels[e] = value;
|
|
4088
4088
|
}
|
|
4089
4089
|
return this;
|
|
4090
4090
|
}
|
|
4091
4091
|
|
|
4092
|
-
if (name !== undefined && !this
|
|
4092
|
+
if (name !== undefined && !this._isMultigraph) {
|
|
4093
4093
|
throw new Error("Cannot set a named edge when isMultigraph = false");
|
|
4094
4094
|
}
|
|
4095
4095
|
|
|
@@ -4098,20 +4098,20 @@ class Graph {
|
|
|
4098
4098
|
this.setNode(v);
|
|
4099
4099
|
this.setNode(w);
|
|
4100
4100
|
|
|
4101
|
-
this
|
|
4101
|
+
this._edgeLabels[e] = valueSpecified ? value : this._defaultEdgeLabelFn(v, w, name);
|
|
4102
4102
|
|
|
4103
|
-
var edgeObj = edgeArgsToObj(this
|
|
4103
|
+
var edgeObj = edgeArgsToObj(this._isDirected, v, w, name);
|
|
4104
4104
|
// Ensure we add undirected edges in a consistent way.
|
|
4105
4105
|
v = edgeObj.v;
|
|
4106
4106
|
w = edgeObj.w;
|
|
4107
4107
|
|
|
4108
4108
|
Object.freeze(edgeObj);
|
|
4109
|
-
this
|
|
4110
|
-
incrementOrInitEntry(this
|
|
4111
|
-
incrementOrInitEntry(this
|
|
4112
|
-
this
|
|
4113
|
-
this
|
|
4114
|
-
this
|
|
4109
|
+
this._edgeObjs[e] = edgeObj;
|
|
4110
|
+
incrementOrInitEntry(this._preds[w], v);
|
|
4111
|
+
incrementOrInitEntry(this._sucs[v], w);
|
|
4112
|
+
this._in[w][e] = edgeObj;
|
|
4113
|
+
this._out[v][e] = edgeObj;
|
|
4114
|
+
this._edgeCount++;
|
|
4115
4115
|
return this;
|
|
4116
4116
|
}
|
|
4117
4117
|
|
|
@@ -4121,9 +4121,9 @@ class Graph {
|
|
|
4121
4121
|
*/
|
|
4122
4122
|
edge(v, w, name) {
|
|
4123
4123
|
var e = (arguments.length === 1
|
|
4124
|
-
? edgeObjToId(this
|
|
4125
|
-
: edgeArgsToId(this
|
|
4126
|
-
return this
|
|
4124
|
+
? edgeObjToId(this._isDirected, arguments[0])
|
|
4125
|
+
: edgeArgsToId(this._isDirected, v, w, name));
|
|
4126
|
+
return this._edgeLabels[e];
|
|
4127
4127
|
}
|
|
4128
4128
|
|
|
4129
4129
|
/**
|
|
@@ -4145,9 +4145,9 @@ class Graph {
|
|
|
4145
4145
|
*/
|
|
4146
4146
|
hasEdge(v, w, name) {
|
|
4147
4147
|
var e = (arguments.length === 1
|
|
4148
|
-
? edgeObjToId(this
|
|
4149
|
-
: edgeArgsToId(this
|
|
4150
|
-
return this
|
|
4148
|
+
? edgeObjToId(this._isDirected, arguments[0])
|
|
4149
|
+
: edgeArgsToId(this._isDirected, v, w, name));
|
|
4150
|
+
return this._edgeLabels.hasOwnProperty(e);
|
|
4151
4151
|
}
|
|
4152
4152
|
|
|
4153
4153
|
/**
|
|
@@ -4156,19 +4156,19 @@ class Graph {
|
|
|
4156
4156
|
*/
|
|
4157
4157
|
removeEdge(v, w, name) {
|
|
4158
4158
|
var e = (arguments.length === 1
|
|
4159
|
-
? edgeObjToId(this
|
|
4160
|
-
: edgeArgsToId(this
|
|
4161
|
-
var edge = this
|
|
4159
|
+
? edgeObjToId(this._isDirected, arguments[0])
|
|
4160
|
+
: edgeArgsToId(this._isDirected, v, w, name));
|
|
4161
|
+
var edge = this._edgeObjs[e];
|
|
4162
4162
|
if (edge) {
|
|
4163
4163
|
v = edge.v;
|
|
4164
4164
|
w = edge.w;
|
|
4165
|
-
delete this
|
|
4166
|
-
delete this
|
|
4167
|
-
decrementOrRemoveEntry(this
|
|
4168
|
-
decrementOrRemoveEntry(this
|
|
4169
|
-
delete this
|
|
4170
|
-
delete this
|
|
4171
|
-
this
|
|
4165
|
+
delete this._edgeLabels[e];
|
|
4166
|
+
delete this._edgeObjs[e];
|
|
4167
|
+
decrementOrRemoveEntry(this._preds[w], v);
|
|
4168
|
+
decrementOrRemoveEntry(this._sucs[v], w);
|
|
4169
|
+
delete this._in[w][e];
|
|
4170
|
+
delete this._out[v][e];
|
|
4171
|
+
this._edgeCount--;
|
|
4172
4172
|
}
|
|
4173
4173
|
return this;
|
|
4174
4174
|
}
|
|
@@ -4179,7 +4179,7 @@ class Graph {
|
|
|
4179
4179
|
* Complexity: O(|E|).
|
|
4180
4180
|
*/
|
|
4181
4181
|
inEdges(v, u) {
|
|
4182
|
-
var inV = this
|
|
4182
|
+
var inV = this._in[v];
|
|
4183
4183
|
if (inV) {
|
|
4184
4184
|
var edges = Object.values(inV);
|
|
4185
4185
|
if (!u) {
|
|
@@ -4195,7 +4195,7 @@ class Graph {
|
|
|
4195
4195
|
* Complexity: O(|E|).
|
|
4196
4196
|
*/
|
|
4197
4197
|
outEdges(v, w) {
|
|
4198
|
-
var outV = this
|
|
4198
|
+
var outV = this._out[v];
|
|
4199
4199
|
if (outV) {
|
|
4200
4200
|
var edges = Object.values(outV);
|
|
4201
4201
|
if (!w) {
|
|
@@ -4353,7 +4353,7 @@ function read(json) {
|
|
|
4353
4353
|
}
|
|
4354
4354
|
|
|
4355
4355
|
},{"./graph":44}],47:[function(require,module,exports){
|
|
4356
|
-
module.exports = '2.2.
|
|
4356
|
+
module.exports = '2.2.2';
|
|
4357
4357
|
|
|
4358
4358
|
},{}]},{},[1])(1)
|
|
4359
4359
|
});
|
package/dist/dagre.min.js
CHANGED
|
@@ -495,7 +495,7 @@ let offset=Math.min(...g.nodes().map(v=>g.node(v).rank));let layers=[];g.nodes()
|
|
|
495
495
|
/*
|
|
496
496
|
* Returns a new function that wraps `fn` with a timer. The wrapper logs the
|
|
497
497
|
* time it takes to execute the function.
|
|
498
|
-
*/function time(name,fn){let start=Date.now();try{return fn()}finally{console.log(name+" time: "+(Date.now()-start)+"ms")}}function notime(name,fn){return fn()}let idCounter=0;function uniqueId(prefix){var id=++idCounter;return toString(prefix)+id}function range(start,limit,step=1){if(limit==null){limit=start;start=0}let endCon=i=>i<limit;if(step<0){endCon=i=>limit<i}const range=[];for(let i=start;endCon(i);i+=step){range.push(i)}return range}function pick(source,keys){const dest={};for(const key of keys){if(source[key]!==undefined){dest[key]=source[key]}}return dest}function mapValues(obj,funcOrProp){let func=funcOrProp;if(typeof funcOrProp==="string"){func=val=>val[funcOrProp]}return Object.entries(obj).reduce((acc,[k,v])=>{acc[k]=func(v,k);return acc},{})}function zipObject(props,values){return props.reduce((acc,key,i)=>{acc[key]=values[i];return acc},{})}},{"@dagrejs/graphlib":29}],28:[function(require,module,exports){module.exports="1.1.
|
|
498
|
+
*/function time(name,fn){let start=Date.now();try{return fn()}finally{console.log(name+" time: "+(Date.now()-start)+"ms")}}function notime(name,fn){return fn()}let idCounter=0;function uniqueId(prefix){var id=++idCounter;return toString(prefix)+id}function range(start,limit,step=1){if(limit==null){limit=start;start=0}let endCon=i=>i<limit;if(step<0){endCon=i=>limit<i}const range=[];for(let i=start;endCon(i);i+=step){range.push(i)}return range}function pick(source,keys){const dest={};for(const key of keys){if(source[key]!==undefined){dest[key]=source[key]}}return dest}function mapValues(obj,funcOrProp){let func=funcOrProp;if(typeof funcOrProp==="string"){func=val=>val[funcOrProp]}return Object.entries(obj).reduce((acc,[k,v])=>{acc[k]=func(v,k);return acc},{})}function zipObject(props,values){return props.reduce((acc,key,i)=>{acc[key]=values[i];return acc},{})}},{"@dagrejs/graphlib":29}],28:[function(require,module,exports){module.exports="1.1.2"},{}],29:[function(require,module,exports){
|
|
499
499
|
/**
|
|
500
500
|
* Copyright (c) 2014, Chris Pettitt
|
|
501
501
|
* All rights reserved.
|
|
@@ -544,26 +544,26 @@ var results=[];function dfs(v){var entry=visited[v]={onStack:true,lowlink:index,
|
|
|
544
544
|
* the queue. Adding and removing elements takes O(log n) time. A key can
|
|
545
545
|
* have its priority decreased in O(log n) time.
|
|
546
546
|
*/
|
|
547
|
-
class PriorityQueue{
|
|
547
|
+
class PriorityQueue{_arr=[];_keyIndices={};
|
|
548
548
|
/**
|
|
549
549
|
* Returns the number of elements in the queue. Takes `O(1)` time.
|
|
550
|
-
*/size(){return this
|
|
550
|
+
*/size(){return this._arr.length}
|
|
551
551
|
/**
|
|
552
552
|
* Returns the keys that are in the queue. Takes `O(n)` time.
|
|
553
|
-
*/keys(){return this
|
|
553
|
+
*/keys(){return this._arr.map(function(x){return x.key})}
|
|
554
554
|
/**
|
|
555
555
|
* Returns `true` if **key** is in the queue and `false` if not.
|
|
556
|
-
*/has(key){return this
|
|
556
|
+
*/has(key){return this._keyIndices.hasOwnProperty(key)}
|
|
557
557
|
/**
|
|
558
558
|
* Returns the priority for **key**. If **key** is not present in the queue
|
|
559
559
|
* then this function returns `undefined`. Takes `O(1)` time.
|
|
560
560
|
*
|
|
561
561
|
* @param {Object} key
|
|
562
|
-
*/priority(key){var index=this
|
|
562
|
+
*/priority(key){var index=this._keyIndices[key];if(index!==undefined){return this._arr[index].priority}}
|
|
563
563
|
/**
|
|
564
564
|
* Returns the key for the minimum element in this queue. If the queue is
|
|
565
565
|
* empty this function throws an Error. Takes `O(1)` time.
|
|
566
|
-
*/min(){if(this.size()===0){throw new Error("Queue underflow")}return this
|
|
566
|
+
*/min(){if(this.size()===0){throw new Error("Queue underflow")}return this._arr[0].key}
|
|
567
567
|
/**
|
|
568
568
|
* Inserts a new key into the priority queue. If the key already exists in
|
|
569
569
|
* the queue this function returns `false`; otherwise it will return `true`.
|
|
@@ -571,17 +571,17 @@ class PriorityQueue{#arr=[];#keyIndices={};
|
|
|
571
571
|
*
|
|
572
572
|
* @param {Object} key the key to add
|
|
573
573
|
* @param {Number} priority the initial priority for the key
|
|
574
|
-
*/add(key,priority){var keyIndices=this
|
|
574
|
+
*/add(key,priority){var keyIndices=this._keyIndices;key=String(key);if(!keyIndices.hasOwnProperty(key)){var arr=this._arr;var index=arr.length;keyIndices[key]=index;arr.push({key:key,priority:priority});this._decrease(index);return true}return false}
|
|
575
575
|
/**
|
|
576
576
|
* Removes and returns the smallest key in the queue. Takes `O(log n)` time.
|
|
577
|
-
*/removeMin(){this
|
|
577
|
+
*/removeMin(){this._swap(0,this._arr.length-1);var min=this._arr.pop();delete this._keyIndices[min.key];this._heapify(0);return min.key}
|
|
578
578
|
/**
|
|
579
579
|
* Decreases the priority for **key** to **priority**. If the new priority is
|
|
580
580
|
* greater than the previous priority, this function will throw an Error.
|
|
581
581
|
*
|
|
582
582
|
* @param {Object} key the key for which to raise priority
|
|
583
583
|
* @param {Number} priority the new priority for the key
|
|
584
|
-
*/decrease(key,priority){var index=this
|
|
584
|
+
*/decrease(key,priority){var index=this._keyIndices[key];if(priority>this._arr[index].priority){throw new Error("New priority is greater than current priority. "+"Key: "+key+" Old: "+this._arr[index].priority+" New: "+priority)}this._arr[index].priority=priority;this._decrease(index)}_heapify(i){var arr=this._arr;var l=2*i;var r=l+1;var largest=i;if(l<arr.length){largest=arr[l].priority<arr[largest].priority?l:largest;if(r<arr.length){largest=arr[r].priority<arr[largest].priority?r:largest}if(largest!==i){this._swap(i,largest);this._heapify(largest)}}}_decrease(index){var arr=this._arr;var priority=arr[index].priority;var parent;while(index!==0){parent=index>>1;if(arr[parent].priority<priority){break}this._swap(index,parent);index=parent}}_swap(i,j){var arr=this._arr;var keyIndices=this._keyIndices;var origArrI=arr[i];var origArrJ=arr[j];arr[i]=origArrJ;arr[j]=origArrI;keyIndices[origArrJ.key]=i;keyIndices[origArrI.key]=j}}module.exports=PriorityQueue},{}],44:[function(require,module,exports){"use strict";var DEFAULT_EDGE_NAME="\0";var GRAPH_NODE="\0";var EDGE_KEY_DELIM="";
|
|
585
585
|
// Implementation notes:
|
|
586
586
|
//
|
|
587
587
|
// * Node id query functions should return string ids for the nodes
|
|
@@ -591,49 +591,49 @@ class PriorityQueue{#arr=[];#keyIndices={};
|
|
|
591
591
|
// reference edges. This is because we need a performant way to look these
|
|
592
592
|
// edges up and, object properties, which have string keys, are the closest
|
|
593
593
|
// we're going to get to a performant hashtable in JavaScript.
|
|
594
|
-
class Graph{
|
|
594
|
+
class Graph{_isDirected=true;_isMultigraph=false;_isCompound=false;
|
|
595
595
|
// Label for the graph itself
|
|
596
|
-
|
|
596
|
+
_label;
|
|
597
597
|
// Defaults to be set when creating a new node
|
|
598
|
-
|
|
598
|
+
_defaultNodeLabelFn=()=>undefined;
|
|
599
599
|
// Defaults to be set when creating a new edge
|
|
600
|
-
|
|
600
|
+
_defaultEdgeLabelFn=()=>undefined;
|
|
601
601
|
// v -> label
|
|
602
|
-
|
|
602
|
+
_nodes={};
|
|
603
603
|
// v -> edgeObj
|
|
604
|
-
|
|
604
|
+
_in={};
|
|
605
605
|
// u -> v -> Number
|
|
606
|
-
|
|
606
|
+
_preds={};
|
|
607
607
|
// v -> edgeObj
|
|
608
|
-
|
|
608
|
+
_out={};
|
|
609
609
|
// v -> w -> Number
|
|
610
|
-
|
|
610
|
+
_sucs={};
|
|
611
611
|
// e -> edgeObj
|
|
612
|
-
|
|
612
|
+
_edgeObjs={};
|
|
613
613
|
// e -> label
|
|
614
|
-
|
|
615
|
-
/* Number of nodes in the graph. Should only be changed by the implementation.
|
|
616
|
-
/* Number of edges in the graph. Should only be changed by the implementation.
|
|
614
|
+
_edgeLabels={};
|
|
615
|
+
/* Number of nodes in the graph. Should only be changed by the implementation. */_nodeCount=0;
|
|
616
|
+
/* Number of edges in the graph. Should only be changed by the implementation. */_edgeCount=0;_parent;_children;constructor(opts){if(opts){this._isDirected=opts.hasOwnProperty("directed")?opts.directed:true;this._isMultigraph=opts.hasOwnProperty("multigraph")?opts.multigraph:false;this._isCompound=opts.hasOwnProperty("compound")?opts.compound:false}if(this._isCompound){
|
|
617
617
|
// v -> parent
|
|
618
|
-
this
|
|
618
|
+
this._parent={};
|
|
619
619
|
// v -> children
|
|
620
|
-
this
|
|
620
|
+
this._children={};this._children[GRAPH_NODE]={}}}
|
|
621
621
|
/* === Graph functions ========= */
|
|
622
622
|
/**
|
|
623
623
|
* Whether graph was created with 'directed' flag set to true or not.
|
|
624
|
-
*/isDirected(){return this
|
|
624
|
+
*/isDirected(){return this._isDirected}
|
|
625
625
|
/**
|
|
626
626
|
* Whether graph was created with 'multigraph' flag set to true or not.
|
|
627
|
-
*/isMultigraph(){return this
|
|
627
|
+
*/isMultigraph(){return this._isMultigraph}
|
|
628
628
|
/**
|
|
629
629
|
* Whether graph was created with 'compound' flag set to true or not.
|
|
630
|
-
*/isCompound(){return this
|
|
630
|
+
*/isCompound(){return this._isCompound}
|
|
631
631
|
/**
|
|
632
632
|
* Sets the label of the graph.
|
|
633
|
-
*/setGraph(label){this
|
|
633
|
+
*/setGraph(label){this._label=label;return this}
|
|
634
634
|
/**
|
|
635
635
|
* Gets the graph label.
|
|
636
|
-
*/graph(){return this
|
|
636
|
+
*/graph(){return this._label}
|
|
637
637
|
/* === Node functions ========== */
|
|
638
638
|
/**
|
|
639
639
|
* Sets the default node label. If newDefault is a function, it will be
|
|
@@ -641,24 +641,24 @@ this.#children={};this.#children[GRAPH_NODE]={}}}
|
|
|
641
641
|
* will be assigned as default label in case if no label was specified while
|
|
642
642
|
* setting a node.
|
|
643
643
|
* Complexity: O(1).
|
|
644
|
-
*/setDefaultNodeLabel(newDefault){this
|
|
644
|
+
*/setDefaultNodeLabel(newDefault){this._defaultNodeLabelFn=newDefault;if(typeof newDefault!=="function"){this._defaultNodeLabelFn=()=>newDefault}return this}
|
|
645
645
|
/**
|
|
646
646
|
* Gets the number of nodes in the graph.
|
|
647
647
|
* Complexity: O(1).
|
|
648
|
-
*/nodeCount(){return this
|
|
648
|
+
*/nodeCount(){return this._nodeCount}
|
|
649
649
|
/**
|
|
650
650
|
* Gets all nodes of the graph. Note, the in case of compound graph subnodes are
|
|
651
651
|
* not included in list.
|
|
652
652
|
* Complexity: O(1).
|
|
653
|
-
*/nodes(){return Object.keys(this
|
|
653
|
+
*/nodes(){return Object.keys(this._nodes)}
|
|
654
654
|
/**
|
|
655
655
|
* Gets list of nodes without in-edges.
|
|
656
656
|
* Complexity: O(|V|).
|
|
657
|
-
*/sources(){var self=this;return this.nodes().filter(v=>Object.keys(self
|
|
657
|
+
*/sources(){var self=this;return this.nodes().filter(v=>Object.keys(self._in[v]).length===0)}
|
|
658
658
|
/**
|
|
659
659
|
* Gets list of nodes without out-edges.
|
|
660
660
|
* Complexity: O(|V|).
|
|
661
|
-
*/sinks(){var self=this;return this.nodes().filter(v=>Object.keys(self
|
|
661
|
+
*/sinks(){var self=this;return this.nodes().filter(v=>Object.keys(self._out[v]).length===0)}
|
|
662
662
|
/**
|
|
663
663
|
* Invokes setNode method for each node in names list.
|
|
664
664
|
* Complexity: O(|names|).
|
|
@@ -668,46 +668,46 @@ this.#children={};this.#children[GRAPH_NODE]={}}}
|
|
|
668
668
|
* it is set as the value for the node. If label is not supplied and the node was
|
|
669
669
|
* created by this call then the default node label will be assigned.
|
|
670
670
|
* Complexity: O(1).
|
|
671
|
-
*/setNode(v,value){if(this
|
|
671
|
+
*/setNode(v,value){if(this._nodes.hasOwnProperty(v)){if(arguments.length>1){this._nodes[v]=value}return this}this._nodes[v]=arguments.length>1?value:this._defaultNodeLabelFn(v);if(this._isCompound){this._parent[v]=GRAPH_NODE;this._children[v]={};this._children[GRAPH_NODE][v]=true}this._in[v]={};this._preds[v]={};this._out[v]={};this._sucs[v]={};++this._nodeCount;return this}
|
|
672
672
|
/**
|
|
673
673
|
* Gets the label of node with specified name.
|
|
674
674
|
* Complexity: O(|V|).
|
|
675
|
-
*/node(v){return this
|
|
675
|
+
*/node(v){return this._nodes[v]}
|
|
676
676
|
/**
|
|
677
677
|
* Detects whether graph has a node with specified name or not.
|
|
678
|
-
*/hasNode(v){return this
|
|
678
|
+
*/hasNode(v){return this._nodes.hasOwnProperty(v)}
|
|
679
679
|
/**
|
|
680
680
|
* Remove the node with the name from the graph or do nothing if the node is not in
|
|
681
681
|
* the graph. If the node was removed this function also removes any incident
|
|
682
682
|
* edges.
|
|
683
683
|
* Complexity: O(1).
|
|
684
|
-
*/removeNode(v){var self=this;if(this
|
|
684
|
+
*/removeNode(v){var self=this;if(this._nodes.hasOwnProperty(v)){var removeEdge=e=>self.removeEdge(self._edgeObjs[e]);delete this._nodes[v];if(this._isCompound){this._removeFromParentsChildList(v);delete this._parent[v];this.children(v).forEach(function(child){self.setParent(child)});delete this._children[v]}Object.keys(this._in[v]).forEach(removeEdge);delete this._in[v];delete this._preds[v];Object.keys(this._out[v]).forEach(removeEdge);delete this._out[v];delete this._sucs[v];--this._nodeCount}return this}
|
|
685
685
|
/**
|
|
686
686
|
* Sets node p as a parent for node v if it is defined, or removes the
|
|
687
687
|
* parent for v if p is undefined. Method throws an exception in case of
|
|
688
688
|
* invoking it in context of noncompound graph.
|
|
689
689
|
* Average-case complexity: O(1).
|
|
690
|
-
*/setParent(v,parent){if(!this
|
|
690
|
+
*/setParent(v,parent){if(!this._isCompound){throw new Error("Cannot set parent in a non-compound graph")}if(parent===undefined){parent=GRAPH_NODE}else{
|
|
691
691
|
// Coerce parent to string
|
|
692
|
-
parent+="";for(var ancestor=parent;ancestor!==undefined;ancestor=this.parent(ancestor)){if(ancestor===v){throw new Error("Setting "+parent+" as parent of "+v+" would create a cycle")}}this.setNode(parent)}this.setNode(v);this
|
|
692
|
+
parent+="";for(var ancestor=parent;ancestor!==undefined;ancestor=this.parent(ancestor)){if(ancestor===v){throw new Error("Setting "+parent+" as parent of "+v+" would create a cycle")}}this.setNode(parent)}this.setNode(v);this._removeFromParentsChildList(v);this._parent[v]=parent;this._children[parent][v]=true;return this}_removeFromParentsChildList(v){delete this._children[this._parent[v]][v]}
|
|
693
693
|
/**
|
|
694
694
|
* Gets parent node for node v.
|
|
695
695
|
* Complexity: O(1).
|
|
696
|
-
*/parent(v){if(this
|
|
696
|
+
*/parent(v){if(this._isCompound){var parent=this._parent[v];if(parent!==GRAPH_NODE){return parent}}}
|
|
697
697
|
/**
|
|
698
698
|
* Gets list of direct children of node v.
|
|
699
699
|
* Complexity: O(1).
|
|
700
|
-
*/children(v=GRAPH_NODE){if(this
|
|
700
|
+
*/children(v=GRAPH_NODE){if(this._isCompound){var children=this._children[v];if(children){return Object.keys(children)}}else if(v===GRAPH_NODE){return this.nodes()}else if(this.hasNode(v)){return[]}}
|
|
701
701
|
/**
|
|
702
702
|
* Return all nodes that are predecessors of the specified node or undefined if node v is not in
|
|
703
703
|
* the graph. Behavior is undefined for undirected graphs - use neighbors instead.
|
|
704
704
|
* Complexity: O(|V|).
|
|
705
|
-
*/predecessors(v){var predsV=this
|
|
705
|
+
*/predecessors(v){var predsV=this._preds[v];if(predsV){return Object.keys(predsV)}}
|
|
706
706
|
/**
|
|
707
707
|
* Return all nodes that are successors of the specified node or undefined if node v is not in
|
|
708
708
|
* the graph. Behavior is undefined for undirected graphs - use neighbors instead.
|
|
709
709
|
* Complexity: O(|V|).
|
|
710
|
-
*/successors(v){var sucsV=this
|
|
710
|
+
*/successors(v){var sucsV=this._sucs[v];if(sucsV){return Object.keys(sucsV)}}
|
|
711
711
|
/**
|
|
712
712
|
* Return all nodes that are predecessors or successors of the specified node or undefined if
|
|
713
713
|
* node v is not in the graph.
|
|
@@ -718,7 +718,7 @@ parent+="";for(var ancestor=parent;ancestor!==undefined;ancestor=this.parent(anc
|
|
|
718
718
|
* are also removed. In case of compound graph, if parent is rejected by filter,
|
|
719
719
|
* than all its children are rejected too.
|
|
720
720
|
* Average-case complexity: O(|E|+|V|).
|
|
721
|
-
*/filterNodes(filter){var copy=new this.constructor({directed:this
|
|
721
|
+
*/filterNodes(filter){var copy=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});copy.setGraph(this.graph());var self=this;Object.entries(this._nodes).forEach(function([v,value]){if(filter(v)){copy.setNode(v,value)}});Object.values(this._edgeObjs).forEach(function(e){if(copy.hasNode(e.v)&©.hasNode(e.w)){copy.setEdge(e,self.edge(e))}});var parents={};function findParent(v){var parent=self.parent(v);if(parent===undefined||copy.hasNode(parent)){parents[v]=parent;return parent}else if(parent in parents){return parents[parent]}else{return findParent(parent)}}if(this._isCompound){copy.nodes().forEach(v=>copy.setParent(v,findParent(v)))}return copy}
|
|
722
722
|
/* === Edge functions ========== */
|
|
723
723
|
/**
|
|
724
724
|
* Sets the default edge label or factory function. This label will be
|
|
@@ -726,15 +726,15 @@ parent+="";for(var ancestor=parent;ancestor!==undefined;ancestor=this.parent(anc
|
|
|
726
726
|
* an edge or this function will be invoked each time when setting an edge
|
|
727
727
|
* with no label specified and returned value * will be used as a label for edge.
|
|
728
728
|
* Complexity: O(1).
|
|
729
|
-
*/setDefaultEdgeLabel(newDefault){this
|
|
729
|
+
*/setDefaultEdgeLabel(newDefault){this._defaultEdgeLabelFn=newDefault;if(typeof newDefault!=="function"){this._defaultEdgeLabelFn=()=>newDefault}return this}
|
|
730
730
|
/**
|
|
731
731
|
* Gets the number of edges in the graph.
|
|
732
732
|
* Complexity: O(1).
|
|
733
|
-
*/edgeCount(){return this
|
|
733
|
+
*/edgeCount(){return this._edgeCount}
|
|
734
734
|
/**
|
|
735
735
|
* Gets edges of the graph. In case of compound graph subgraphs are not considered.
|
|
736
736
|
* Complexity: O(|E|).
|
|
737
|
-
*/edges(){return Object.values(this
|
|
737
|
+
*/edges(){return Object.values(this._edgeObjs)}
|
|
738
738
|
/**
|
|
739
739
|
* Establish an edges path over the nodes in nodes list. If some edge is already
|
|
740
740
|
* exists, it will update its label, otherwise it will create an edge between pair
|
|
@@ -746,16 +746,16 @@ parent+="";for(var ancestor=parent;ancestor!==undefined;ancestor=this.parent(anc
|
|
|
746
746
|
* name. If label is supplied it is set as the value for the edge. If label is not
|
|
747
747
|
* supplied and the edge was created by this call then the default edge label will
|
|
748
748
|
* be assigned. The name parameter is only useful with multigraphs.
|
|
749
|
-
*/setEdge(){var v,w,name,value;var valueSpecified=false;var arg0=arguments[0];if(typeof arg0==="object"&&arg0!==null&&"v"in arg0){v=arg0.v;w=arg0.w;name=arg0.name;if(arguments.length===2){value=arguments[1];valueSpecified=true}}else{v=arg0;w=arguments[1];name=arguments[3];if(arguments.length>2){value=arguments[2];valueSpecified=true}}v=""+v;w=""+w;if(name!==undefined){name=""+name}var e=edgeArgsToId(this
|
|
749
|
+
*/setEdge(){var v,w,name,value;var valueSpecified=false;var arg0=arguments[0];if(typeof arg0==="object"&&arg0!==null&&"v"in arg0){v=arg0.v;w=arg0.w;name=arg0.name;if(arguments.length===2){value=arguments[1];valueSpecified=true}}else{v=arg0;w=arguments[1];name=arguments[3];if(arguments.length>2){value=arguments[2];valueSpecified=true}}v=""+v;w=""+w;if(name!==undefined){name=""+name}var e=edgeArgsToId(this._isDirected,v,w,name);if(this._edgeLabels.hasOwnProperty(e)){if(valueSpecified){this._edgeLabels[e]=value}return this}if(name!==undefined&&!this._isMultigraph){throw new Error("Cannot set a named edge when isMultigraph = false")}
|
|
750
750
|
// It didn't exist, so we need to create it.
|
|
751
751
|
// First ensure the nodes exist.
|
|
752
|
-
this.setNode(v);this.setNode(w);this
|
|
752
|
+
this.setNode(v);this.setNode(w);this._edgeLabels[e]=valueSpecified?value:this._defaultEdgeLabelFn(v,w,name);var edgeObj=edgeArgsToObj(this._isDirected,v,w,name);
|
|
753
753
|
// Ensure we add undirected edges in a consistent way.
|
|
754
|
-
v=edgeObj.v;w=edgeObj.w;Object.freeze(edgeObj);this
|
|
754
|
+
v=edgeObj.v;w=edgeObj.w;Object.freeze(edgeObj);this._edgeObjs[e]=edgeObj;incrementOrInitEntry(this._preds[w],v);incrementOrInitEntry(this._sucs[v],w);this._in[w][e]=edgeObj;this._out[v][e]=edgeObj;this._edgeCount++;return this}
|
|
755
755
|
/**
|
|
756
756
|
* Gets the label for the specified edge.
|
|
757
757
|
* Complexity: O(1).
|
|
758
|
-
*/edge(v,w,name){var e=arguments.length===1?edgeObjToId(this
|
|
758
|
+
*/edge(v,w,name){var e=arguments.length===1?edgeObjToId(this._isDirected,arguments[0]):edgeArgsToId(this._isDirected,v,w,name);return this._edgeLabels[e]}
|
|
759
759
|
/**
|
|
760
760
|
* Gets the label for the specified edge and converts it to an object.
|
|
761
761
|
* Complexity: O(1)
|
|
@@ -763,21 +763,21 @@ v=edgeObj.v;w=edgeObj.w;Object.freeze(edgeObj);this.#edgeObjs[e]=edgeObj;increme
|
|
|
763
763
|
/**
|
|
764
764
|
* Detects whether the graph contains specified edge or not. No subgraphs are considered.
|
|
765
765
|
* Complexity: O(1).
|
|
766
|
-
*/hasEdge(v,w,name){var e=arguments.length===1?edgeObjToId(this
|
|
766
|
+
*/hasEdge(v,w,name){var e=arguments.length===1?edgeObjToId(this._isDirected,arguments[0]):edgeArgsToId(this._isDirected,v,w,name);return this._edgeLabels.hasOwnProperty(e)}
|
|
767
767
|
/**
|
|
768
768
|
* Removes the specified edge from the graph. No subgraphs are considered.
|
|
769
769
|
* Complexity: O(1).
|
|
770
|
-
*/removeEdge(v,w,name){var e=arguments.length===1?edgeObjToId(this
|
|
770
|
+
*/removeEdge(v,w,name){var e=arguments.length===1?edgeObjToId(this._isDirected,arguments[0]):edgeArgsToId(this._isDirected,v,w,name);var edge=this._edgeObjs[e];if(edge){v=edge.v;w=edge.w;delete this._edgeLabels[e];delete this._edgeObjs[e];decrementOrRemoveEntry(this._preds[w],v);decrementOrRemoveEntry(this._sucs[v],w);delete this._in[w][e];delete this._out[v][e];this._edgeCount--}return this}
|
|
771
771
|
/**
|
|
772
772
|
* Return all edges that point to the node v. Optionally filters those edges down to just those
|
|
773
773
|
* coming from node u. Behavior is undefined for undirected graphs - use nodeEdges instead.
|
|
774
774
|
* Complexity: O(|E|).
|
|
775
|
-
*/inEdges(v,u){var inV=this
|
|
775
|
+
*/inEdges(v,u){var inV=this._in[v];if(inV){var edges=Object.values(inV);if(!u){return edges}return edges.filter(edge=>edge.v===u)}}
|
|
776
776
|
/**
|
|
777
777
|
* Return all edges that are pointed at by node v. Optionally filters those edges down to just
|
|
778
778
|
* those point to w. Behavior is undefined for undirected graphs - use nodeEdges instead.
|
|
779
779
|
* Complexity: O(|E|).
|
|
780
|
-
*/outEdges(v,w){var outV=this
|
|
780
|
+
*/outEdges(v,w){var outV=this._out[v];if(outV){var edges=Object.values(outV);if(!w){return edges}return edges.filter(edge=>edge.w===w)}}
|
|
781
781
|
/**
|
|
782
782
|
* Returns all edges to or from node v regardless of direction. Optionally filters those edges
|
|
783
783
|
* down to just those between nodes v and w regardless of direction.
|
|
@@ -798,4 +798,4 @@ module.exports={Graph:require("./graph"),version:require("./version")}},{"./grap
|
|
|
798
798
|
* // ['a', 'b']
|
|
799
799
|
* g2.edges()
|
|
800
800
|
* // [ { v: 'a', w: 'b' } ]
|
|
801
|
-
*/function read(json){var g=new Graph(json.options).setGraph(json.value);json.nodes.forEach(function(entry){g.setNode(entry.v,entry.value);if(entry.parent){g.setParent(entry.v,entry.parent)}});json.edges.forEach(function(entry){g.setEdge({v:entry.v,w:entry.w,name:entry.name},entry.value)});return g}},{"./graph":44}],47:[function(require,module,exports){module.exports="2.2.
|
|
801
|
+
*/function read(json){var g=new Graph(json.options).setGraph(json.value);json.nodes.forEach(function(entry){g.setNode(entry.v,entry.value);if(entry.parent){g.setParent(entry.v,entry.parent)}});json.edges.forEach(function(entry){g.setEdge({v:entry.v,w:entry.w,name:entry.name},entry.value)});return g}},{"./graph":44}],47:[function(require,module,exports){module.exports="2.2.2"},{}]},{},[1])(1)});
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = "1.1.
|
|
1
|
+
module.exports = "1.1.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dagrejs/dagre",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Graph layout for JavaScript",
|
|
5
5
|
"author": "Chris Pettitt <cpettitt@gmail.com>",
|
|
6
6
|
"contributors": [
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"layout"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@dagrejs/graphlib": "2.2.
|
|
27
|
+
"@dagrejs/graphlib": "2.2.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"benchmark": "2.1.4",
|