-
Notifications
You must be signed in to change notification settings - Fork 13
/
cytoscape-cise.js
4496 lines (3616 loc) · 156 KB
/
cytoscape-cise.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("avsdf-base"), require("cose-base"));
else if(typeof define === 'function' && define.amd)
define(["avsdf-base", "cose-base"], factory);
else if(typeof exports === 'object')
exports["cytoscapeCise"] = factory(require("avsdf-base"), require("cose-base"));
else
root["cytoscapeCise"] = factory(root["avsdfBase"], root["coseBase"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_0__, __WEBPACK_EXTERNAL_MODULE_22__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 14);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_0__;
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* This class maintains the constants used by CiSE layout.
*
*
* Copyright: i-Vis Research Group, Bilkent University, 2007 - present
*/
var FDLayoutConstants = __webpack_require__(0).layoutBase.FDLayoutConstants;
function CiSEConstants() {}
for (var prop in FDLayoutConstants) {
CiSEConstants[prop] = FDLayoutConstants[prop];
}
// -----------------------------------------------------------------------------
// Section: CiSE layout user options
// -----------------------------------------------------------------------------
CiSEConstants.DEFAULT_SPRING_STRENGTH = 1.5 * FDLayoutConstants.DEFAULT_SPRING_STRENGTH;
// Amount of separation of nodes on the associated circle
CiSEConstants.DEFAULT_NODE_SEPARATION = FDLayoutConstants.DEFAULT_EDGE_LENGTH / 4;
// Inter-cluster edge length factor (2.0 means inter-cluster edges should be
// twice as long as intra-cluster edges)
CiSEConstants.DEFAULT_IDEAL_INTER_CLUSTER_EDGE_LENGTH_COEFF = 1.4;
// Whether to enable pulling nodes inside of the circles
CiSEConstants.DEFAULT_ALLOW_NODES_INSIDE_CIRCLE = false;
// Max percentage of the nodes in a circle that can be inside the circle
CiSEConstants.DEFAULT_MAX_RATIO_OF_NODES_INSIDE_CIRCLE = 0.1;
// -----------------------------------------------------------------------------
// Section: CiSE layout remaining constants
// -----------------------------------------------------------------------------
// Ideal length of an edge incident with an inner-node
CiSEConstants.DEFAULT_INNER_EDGE_LENGTH = FDLayoutConstants.DEFAULT_EDGE_LENGTH / 3;
// Maximum rotation angle
CiSEConstants.MAX_ROTATION_ANGLE = Math.PI / 36.0;
// Minimum rotation angle
CiSEConstants.MIN_ROTATION_ANGLE = -CiSEConstants.MAX_ROTATION_ANGLE;
// Number of iterations without swap or swap prepartion
CiSEConstants.SWAP_IDLE_DURATION = 45;
// Number of iterations required for collecting information about swapping
CiSEConstants.SWAP_PREPERATION_DURATION = 5;
// Number of iterations that should be done in between two swaps.
CiSEConstants.SWAP_PERIOD = CiSEConstants.SWAP_IDLE_DURATION + CiSEConstants.SWAP_PREPERATION_DURATION;
// Number of iterations during which history (of pairs swapped) kept
CiSEConstants.SWAP_HISTORY_CLEARANCE_PERIOD = 6 * CiSEConstants.SWAP_PERIOD;
// Buffer for swapping
CiSEConstants.MIN_DISPLACEMENT_FOR_SWAP = 6;
// Number of iterations that should be done in between two flips.
CiSEConstants.REVERSE_PERIOD = 25;
CiSEConstants.CLUSTER_ENLARGEMENT_CHECK_PERIOD = 50;
CiSEConstants.DEFAULT_USE_SMART_REPULSION_RANGE_CALCULATION = true;
module.exports = CiSEConstants;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
// Simple, internal Object.assign() polyfill for options objects etc.
module.exports = Object.assign != null ? Object.assign.bind(Object) : function (tgt) {
for (var _len = arguments.length, srcs = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
srcs[_key - 1] = arguments[_key];
}
srcs.forEach(function (src) {
Object.keys(src).forEach(function (k) {
return tgt[k] = src[k];
});
});
return tgt;
};
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
*
* Choose the type of layout that best suits your usecase as a starting point.
*
* A discrete layout is one that algorithmically sets resultant positions. It
* does not have intermediate positions.
*
* A continuous layout is one that updates positions continuously, like a force-
* directed / physics simulation layout.
*/
module.exports = __webpack_require__(15);
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* This class implements data and functionality required for CiSE layout per
* cluster.
*
*
* Copyright: i-Vis Research Group, Bilkent University, 2007 - present
*/
var LGraph = __webpack_require__(0).layoutBase.LGraph;
var IGeometry = __webpack_require__(0).layoutBase.IGeometry;
var NeedlemanWunsch = __webpack_require__(0).layoutBase.NeedlemanWunsch;
var CircularForce = __webpack_require__(13);
var CiSEConstants = __webpack_require__(1);
var CiSEInterClusterEdgeInfo = __webpack_require__(7);
var CiSEInterClusterEdgeSort = __webpack_require__(8);
function CiSECircle(parent, graphMgr, vNode) {
LGraph.call(this, parent, graphMgr, vNode);
// Holds the intra-cluster edges of this circle, initially it is null. It
// will be calculated and stored when getIntraClusterEdges method is first
// called.
this.intraClusterEdges = null;
// Holds the inter-cluster edges of this circle, initially it is null. It
// will be calculated and stored when getInterClusterEdges method is first
// called.
this.interClusterEdges = null;
// Holds the nodes which don't have neighbors outside this circle
this.inNodes = [];
// Holds the nodes which have neighbors outside this circle
this.outNodes = [];
// Holds the nodes which are on the circle
this.onCircleNodes = [];
// Holds the nodes which are inside the circle
this.inCircleNodes = [];
// The additional node seperation value is used to store the value of extra space
// induced by adding more inner nodes than the circle can fit in. Although the circle
// is enlarged by increasing the radius, the positions of the on-circle nodes
// have to be recalculated with respect to the proportion of increase in circumference.
this.additionalNodeSeparation = null;
// The radius of this circle, calculated with respect to the dimensions of
// the nodes on this circle and node separation options
this.radius = 0;
// Holds the pairwise ordering of on-circle nodes computed in earlier stages
// of layout. Value at i,j means the following assuming u and v are
// on-circle nodes with orderIndex i and j, respectively. Value at i,j is
// true (false) if u and v are closer when we go from u to v in clockwise
// (counter-clockwise) direction. Here we base distance on the angles of the
// two nodes as opposed to their order indices (this might make a difference
// due to non-uniform node sizes).
this.orderMatrix = null;
// Whether or not this circle may be reserved for the purpose of improving
// inter-cluster edge crossing number as we do not want to redundantly
// reverse clusters and end up in oscillating situtations. Clusters with
// special circumstances (e.g. less than two inter-cluster edge) are set as
// may not be reversed as well.
this.mayBeReversed = true;
// Holds the total amount of prevented displacement of inner nodes that try
// to escape the inner boundaries.
this.innerNodePushCount = null;
}
CiSECircle.prototype = Object.create(LGraph.prototype);
for (var prop in LGraph) {
CiSECircle[prop] = LGraph[prop];
}
// -----------------------------------------------------------------------------
// Section: Accessors and mutators
// -----------------------------------------------------------------------------
// This method returns the radius of this circle.
CiSECircle.prototype.setRadius = function (radius) {
this.radius = radius;
};
// This method sets the radius of this circle.
CiSECircle.prototype.getRadius = function () {
return this.radius;
};
// This method sets the additional node seperation value.
CiSECircle.prototype.setAdditionalNodeSeparation = function (additionalNodeSeparation) {
this.additionalNodeSeparation = additionalNodeSeparation;
};
// This method returns the additional node seperation value.
CiSECircle.prototype.getAdditionalNodeSeparation = function () {
if (this.additionalNodeSeparation === null) //If this is called the first time
{
this.setAdditionalNodeSeparation(0.0);
}
return this.additionalNodeSeparation;
};
CiSECircle.prototype.setInnerNodePushCount = function (innerNodePushCount) {
this.innerNodePushCount = innerNodePushCount;
};
CiSECircle.prototype.getInnerNodePushCount = function () {
if (this.innerNodePushCount === null) {
this.setInnerNodePushCount(0);
}
return this.innerNodePushCount;
};
// This method returns nodes that don't have neighbors outside this circle.
CiSECircle.prototype.getInNodes = function () {
return this.inNodes;
};
// This method returns nodes that have neighbors outside this circle.
CiSECircle.prototype.getOutNodes = function () {
return this.outNodes;
};
// This method returns nodes that reside on the circle.
CiSECircle.prototype.getOnCircleNodes = function () {
return this.onCircleNodes;
};
// This method returns nodes that don't have neighbors outside this circle.
CiSECircle.prototype.getInCircleNodes = function () {
return this.inCircleNodes;
};
CiSECircle.prototype.setMayNotBeReversed = function () {
this.mayBeReversed = false;
};
// This method returns whether or not this circle has been reversed.
CiSECircle.prototype.getMayBeReversed = function () {
return this.mayBeReversed;
};
// This method downcasts and returns the child at given index.
CiSECircle.prototype.getChildAt = function (index) {
return this.onCircleNodes[index];
};
/**
* This method returns the inter-cluster edges whose one end is in this
* cluster.
*/
CiSECircle.prototype.getInterClusterEdges = function () {
var self = this;
if (this.interClusterEdges === null) //If this is called the first time
{
this.interClusterEdges = [];
this.outNodes.forEach(function (node) {
var edgesToAdd = node.getOnCircleNodeExt().getInterClusterEdges();
for (var i = 0; i < edgesToAdd.length; i++) {
self.interClusterEdges.push(edgesToAdd[i]);
}
});
}
return this.interClusterEdges;
};
/**
* This method returns the intra cluster edges of this circle
*/
CiSECircle.prototype.getIntraClusterEdges = function () {
var self = this;
if (this.intraClusterEdges === null) //If this is called the first time
{
this.intraClusterEdges = [];
var allEdges = this.getEdges();
allEdges.forEach(function (edge) {
if (edge.isIntraEdge()) self.intraClusterEdges.push(edge);
});
}
return this.intraClusterEdges;
};
// -----------------------------------------------------------------------------
// Section: Other methods
// -----------------------------------------------------------------------------
// This method calculates and sets dimensions of the parent node of this
// circle. Parent node is centered to be at the same location of the
// associated circle but its dimensions are larger than the circle by a
// factor (must be >= 1 to ensure all nodes are enclosed within its
// rectangle) of the largest dimension (width or height) of on-circle nodes
// so that it completely encapsulates the nodes on this circle.
CiSECircle.prototype.calculateParentNodeDimension = function () {
var self = this;
var maxOnCircleNodeDimension = Number.MIN_SAFE_INTEGER;
for (var i = 0; i < this.onCircleNodes.length; i++) {
var node = this.onCircleNodes[i];
if (node.getWidth() > maxOnCircleNodeDimension) {
maxOnCircleNodeDimension = node.getWidth();
}
if (node.getHeight() > maxOnCircleNodeDimension) {
maxOnCircleNodeDimension = node.getHeight();
}
}
var dimension = 2.0 * (self.radius + self.margin) + maxOnCircleNodeDimension;
var parentNode = self.getParent();
parentNode.setHeight(dimension);
parentNode.setWidth(dimension);
};
/*
* This method computes the order matrix of this circle. This should be
* called only once at early stages of layout and is used to hold the order
* of on-circle nodes as specified.
*/
CiSECircle.prototype.computeOrderMatrix = function () {
var N = this.onCircleNodes.length;
// 'Two Dimensional array' (array of arrays in JS) with bool cell values
this.orderMatrix = new Array(N);
for (var i = 0; i < this.orderMatrix.length; i++) {
this.orderMatrix[i] = new Array(N);
}
for (var _i = 0; _i < N; _i++) {
for (var j = 0; j < N; j++) {
if (j > _i) {
var angleDiff = this.onCircleNodes[j].getOnCircleNodeExt().getAngle() - this.onCircleNodes[_i].getOnCircleNodeExt().getAngle();
if (angleDiff < 0) {
angleDiff += IGeometry.TWO_PI;
}
if (angleDiff <= Math.PI) {
this.orderMatrix[_i][j] = true;
this.orderMatrix[j][_i] = false;
} else {
this.orderMatrix[_i][j] = false;
this.orderMatrix[j][_i] = true;
}
}
}
}
};
/**
* This method rotates this circle by iterating over and adjusting the
* relative positioning of all nodes on this circle by the calculated angle
* with respect to the rotation amount of the owner node.
*/
CiSECircle.prototype.rotate = function () {
// Take size into account when reflecting total force into rotation!
var parentNode = this.getParent();
var noOfNodes = this.getOnCircleNodes().length;
var rotationAmount = parentNode.rotationAmount / noOfNodes; // Think about the momentum
var layout = this.getGraphManager().getLayout();
if (rotationAmount !== 0.0) {
// The angle (θ) of rotation applied to each node
var theta = rotationAmount / this.radius;
if (theta > CiSEConstants.MAX_ROTATION_ANGLE) theta = CiSEConstants.MAX_ROTATION_ANGLE;else if (theta < CiSEConstants.MIN_ROTATION_ANGLE) theta = CiSEConstants.MIN_ROTATION_ANGLE;
for (var i = 0; i < noOfNodes; i++) {
var onCircleNode = this.getChildAt(i);
var onCircleNodeExt = onCircleNode.getOnCircleNodeExt();
onCircleNodeExt.setAngle(onCircleNodeExt.getAngle() + theta); // Change the angle
onCircleNodeExt.updatePosition(); // Apply the above angle change to its position
}
// Update CiSELayout displacement
layout.totalDisplacement += parentNode.rotationAmount;
// Reset rotationAmount
parentNode.rotationAmount = 0.0;
}
};
/**
* This method returns the pairwise order of the input nodes as computed and
* held in orderMatrix.
*/
CiSECircle.prototype.getOrder = function (nodeA, nodeB) {
return this.orderMatrix[nodeA.getOnCircleNodeExt().getIndex()][nodeB.getOnCircleNodeExt().getIndex()];
};
/**
* This method gets the end node of the input inter-cluster edge in this
* cluster.
*/
CiSECircle.prototype.getThisEnd = function (edge) {
var sourceNode = edge.getSource();
var targetNode = edge.getTarget();
if (sourceNode.getOwner() === this) return sourceNode;else return targetNode;
};
/**
* This method gets the end node of the input inter-cluster edge not in this
* cluster.
*/
CiSECircle.prototype.getOtherEnd = function (edge) {
var sourceNode = edge.getSource();
var targetNode = edge.getTarget();
if (sourceNode.getOwner() === this) return targetNode;else return sourceNode;
};
/**
* This method calculates and returns rotational and translational parts of
* the total force calculated for the given node. The translational part is
* composed of components in x and y directions.
*/
CiSECircle.prototype.decomposeForce = function (node) {
var circularForce = void 0;
if (node.displacementX !== 0.0 || node.displacementY !== 0.0) {
var ownerNode = this.getParent();
var Cx = ownerNode.getCenterX();
var Cy = ownerNode.getCenterY();
var Nx = node.getCenterX();
var Ny = node.getCenterY();
var Fx = node.displacementX;
var Fy = node.displacementY;
var C_angle = IGeometry.angleOfVector(Cx, Cy, Nx, Ny);
var F_angle = IGeometry.angleOfVector(0.0, 0.0, Fx, Fy);
var C_rev_angle = C_angle + Math.PI;
// Check whether F lies between C and its opposite angle C-reverse;
// if so, rotation is +ve (clockwise); otherwise, it's -ve.
// We handle angles greater than 360 specially in the else part.
var isRotationClockwise = void 0;
if (Math.PI <= C_rev_angle && C_rev_angle < IGeometry.TWO_PI) {
isRotationClockwise = C_angle <= F_angle && F_angle < C_rev_angle;
} else {
C_rev_angle -= IGeometry.TWO_PI;
isRotationClockwise = !(C_rev_angle <= F_angle && F_angle < C_angle);
}
var angle_diff = Math.abs(C_angle - F_angle);
var F_magnitude = Math.sqrt(Fx * Fx + Fy * Fy);
var R_magnitude = Math.abs(Math.sin(angle_diff) * F_magnitude);
if (!isRotationClockwise) {
R_magnitude = -R_magnitude;
}
circularForce = new CircularForce(R_magnitude, Fx, Fy);
} else {
circularForce = new CircularForce(0.0, 0.0, 0.0);
}
return circularForce;
};
/**
* This method swaps the nodes given as parameter and make necessary angle
* and positioning updates.
*/
CiSECircle.prototype.swapNodes = function (first, second) {
// Determine which node has smaller index
var smallIndexNode = first;
var bigIndexNode = second;
var firstExt = first.getOnCircleNodeExt();
var secondExt = second.getOnCircleNodeExt();
if (smallIndexNode.getOnCircleNodeExt().getIndex() > second.getOnCircleNodeExt().getIndex()) {
smallIndexNode = second;
bigIndexNode = first;
}
// Check the exceptional case where the small index node is at 0 index
// and the big index node is at the last index of the circle. In this
// case, we treat smaller index node as bigger index node and vice versa
if (smallIndexNode.getOnCircleNodeExt().getPrevNode() === bigIndexNode) {
var tempNode = bigIndexNode;
bigIndexNode = smallIndexNode;
smallIndexNode = tempNode;
}
var smallIndexNodeExt = smallIndexNode.getOnCircleNodeExt();
var bigIndexNodeExt = bigIndexNode.getOnCircleNodeExt();
// Calculate the angle for the big index node
var smallIndexPrevNode = smallIndexNodeExt.getPrevNode();
var layout = this.getGraphManager().getLayout();
var nodeSeparation = layout.getNodeSeparation() + this.getAdditionalNodeSeparation();
var angle = (smallIndexPrevNode.getOnCircleNodeExt().getAngle() + (smallIndexPrevNode.getHalfTheDiagonal() + bigIndexNode.getHalfTheDiagonal() + nodeSeparation) / this.radius) % (2 * Math.PI);
bigIndexNodeExt.setAngle(angle);
// Calculate the angle for the small index node
angle = (bigIndexNodeExt.getAngle() + (bigIndexNode.getHalfTheDiagonal() + smallIndexNode.getHalfTheDiagonal() + nodeSeparation) / this.radius) % (2 * Math.PI);
smallIndexNodeExt.setAngle(angle);
smallIndexNodeExt.updatePosition();
bigIndexNodeExt.updatePosition();
var tempIndex = firstExt.getIndex();
firstExt.setIndex(secondExt.getIndex());
secondExt.setIndex(tempIndex);
this.getOnCircleNodes()[firstExt.getIndex()] = first;
this.getOnCircleNodes()[secondExt.getIndex()] = second;
firstExt.updateSwappingConditions();
secondExt.updateSwappingConditions();
if (firstExt.getNextNode() === second) {
firstExt.getPrevNode().getOnCircleNodeExt().updateSwappingConditions();
secondExt.getNextNode().getOnCircleNodeExt().updateSwappingConditions();
} else {
firstExt.getNextNode().getOnCircleNodeExt().updateSwappingConditions();
secondExt.getPrevNode().getOnCircleNodeExt().updateSwappingConditions();
}
};
/*
* This method checks to see for each cluster (in no particular order)
* whether or not reversing the order of the cluster would reduce
* inter-cluster edge crossings. The decision is based on global sequence
* alignment of the order of the nodes in the cluster vs. the order of their
* neighbors in other clusters. A cluster that was reversed earlier is not
* reversed again to avoid oscillations. It returns true if reverse order
* is adapted.
*/
CiSECircle.prototype.checkAndReverseIfReverseIsBetter = function () {
// First form the list of inter cluster edges of this cluster
var interClusterEdges = this.getInterClusterEdges();
var interClusterEdgeInfos = new Array(interClusterEdges.length);
// Now form the info array that contains not only the inter-cluster
// edges but also other information such as the angle they make w.r.t.
// the cluster center and neighboring node center.
// In the meantime, calculate how many inter-cluster edge each on-circle
// node is incident with. This information will be used to duplicate
// char codes of those nodes with 2 or more inter-graph edge.
var angle = void 0;
var clusterCenter = this.getParent().getCenter();
var interClusterEdge = void 0;
var endInThisCluster = void 0;
var endInOtherCluster = void 0;
var centerOfEndInOtherCluster = void 0;
var nodeCount = this.onCircleNodes.length;
var interClusterEdgeDegree = new Array(nodeCount);
for (var i = 0; i < nodeCount; i++) {
interClusterEdgeDegree[i] = 0;
}
var noOfOnCircleNodesToBeRepeated = 0;
for (var _i2 = 0; _i2 < interClusterEdges.length; _i2++) {
interClusterEdge = interClusterEdges[_i2];
endInOtherCluster = this.getOtherEnd(interClusterEdge);
centerOfEndInOtherCluster = endInOtherCluster.getCenter();
angle = IGeometry.angleOfVector(clusterCenter.x, clusterCenter.y, centerOfEndInOtherCluster.x, centerOfEndInOtherCluster.y);
interClusterEdgeInfos[_i2] = new CiSEInterClusterEdgeInfo(interClusterEdge, angle);
endInThisCluster = this.getThisEnd(interClusterEdge);
interClusterEdgeDegree[endInThisCluster.getOnCircleNodeExt().getIndex()]++;
if (interClusterEdgeDegree[endInThisCluster.getOnCircleNodeExt().getIndex()] > 1) {
noOfOnCircleNodesToBeRepeated++;
}
}
// On circle nodes will be ordered by their indices in this array
var onCircleNodes = this.onCircleNodes;
// Form arrays for current and reversed order of nodes of this cluster
// Take any repetitions into account (if node with char code 'b' is
// incident with 3 inter-cluster edges, then repeat 'b' 2 times)
var nodeCountWithRepetitions = nodeCount + noOfOnCircleNodesToBeRepeated;
var clusterNodes = new Array(2 * nodeCountWithRepetitions);
var reversedClusterNodes = new Array(2 * nodeCountWithRepetitions);
var node = void 0;
var index = -1;
for (var _i3 = 0; _i3 < nodeCount; _i3++) {
node = onCircleNodes[_i3];
// on circle nodes with no inter-cluster edges are also considered
if (interClusterEdgeDegree[_i3] === 0) interClusterEdgeDegree[_i3] = 1;
for (var j = 0; j < interClusterEdgeDegree[_i3]; j++) {
index++;
clusterNodes[index] = clusterNodes[nodeCountWithRepetitions + index] = reversedClusterNodes[nodeCountWithRepetitions - 1 - index] = reversedClusterNodes[2 * nodeCountWithRepetitions - 1 - index] = node.getOnCircleNodeExt().getCharCode();
}
}
// Now sort the inter-cluster edges w.r.t. their angles
var edgeSorter = new CiSEInterClusterEdgeSort(this, interClusterEdgeInfos);
// Form an array for order of neighboring nodes of this cluster
var neighborNodes = new Array(interClusterEdgeInfos.length);
for (var _i4 = 0; _i4 < interClusterEdgeInfos.length; _i4++) {
interClusterEdge = interClusterEdgeInfos[_i4].getEdge();
endInThisCluster = this.getThisEnd(interClusterEdge);
neighborNodes[_i4] = endInThisCluster.getOnCircleNodeExt().getCharCode();
}
// Now calculate a score for the alignment of the current order of the
// nodes of this cluster w.r.t. to their neighbors order
var alignmentScoreCurrent = this.computeAlignmentScore(clusterNodes, neighborNodes);
// Then calculate a score for the alignment of the reversed order of the
// nodes of this cluster w.r.t. to their neighbors order
if (alignmentScoreCurrent !== -1) {
var alignmentScoreReversed = this.computeAlignmentScore(reversedClusterNodes, neighborNodes);
// Check if reversed order is *substantially* better aligned with
// the order of the neighbors of this cluster around the cluster; if
// so, reverse the order
if (alignmentScoreReversed !== -1) {
if (alignmentScoreReversed > alignmentScoreCurrent) {
this.reverseNodes();
this.setMayNotBeReversed();
return true;
}
}
}
return false;
};
/**
* This method computes an alignment for the two input char arrays and
* returns the alignment amount. If alignment is unsuccessful for some
* reason, it returns -1.
*/
CiSECircle.prototype.computeAlignmentScore = function (charArrayReader1, charArrayReader2) {
var aligner = new NeedlemanWunsch(charArrayReader1, charArrayReader2, 20, -1, -2);
return aligner.getScore();
};
/**
* This method reverses the nodes on this circle.
*/
CiSECircle.prototype.reverseNodes = function () {
var onCircleNodes = this.getOnCircleNodes();
var noOfNodesOnCircle = this.getOnCircleNodes().length;
for (var i = 0; i < noOfNodesOnCircle; i++) {
var node = onCircleNodes[i];
var nodeExt = node.getOnCircleNodeExt();
nodeExt.setIndex((noOfNodesOnCircle - nodeExt.getIndex()) % noOfNodesOnCircle);
}
this.reCalculateNodeAnglesAndPositions();
};
/**
* This method removes given on-circle node from the circle and pushes it
* to its inner node list. It also readjusts the indexing of remaining on circle nodes.
* Should be called when an inner node is found and to be moved
* inside the circle.
* @param node
*/
CiSECircle.prototype.setOnCircleNodeInner = function (node) {
// Remove the node from on-circle nodes list and add it to in-circle
// nodes list
// Make sure it has not been already moved to the out node list
var index = this.onCircleNodes.indexOf(node);
if (index > -1) {
this.onCircleNodes.splice(index, 1);
}
this.inCircleNodes.push(node);
// Re-adjust all order indices of remaining on circle nodes.
for (var i = 0; i < this.onCircleNodes.length; i++) {
var onCircleNode = this.onCircleNodes[i];
onCircleNode.getOnCircleNodeExt().setIndex(i);
}
// De-register extension
node.setAsNonOnCircleNode();
};
/**
* This method calls reCalculateCircleSizeAndRadius and
* reCalculateNodeAnglesAndPositions and moves the innernodes inside the circle.
* This method should be called when an inner node is found and to be moved
* inside the circle.
* @param {Object[]} nodeList - array of nodes that are to be moved inside the circle
*/
CiSECircle.prototype.moveOnCircleNodeInside = function (nodeList) {
// calculateRadius
this.reCalculateCircleSizeAndRadius(true);
//calculateNodePositions
this.reCalculateNodeAnglesAndPositions();
var randomX = void 0,
randomY = void 0;
for (var i = 0; i < nodeList.length; i++) {
var node = nodeList[i];
randomX = (Math.random() - 0.5) / 10;
randomY = (Math.random() - 0.5) / 10;
node.setCenter(this.getParent().getCenterX() + randomX, this.getParent().getCenterY() + randomY);
}
};
/**
* This method calculates the size and radius of this circle with respect
* to the sizes of the vertices and the node separation parameter.
*/
CiSECircle.prototype.reCalculateCircleSizeAndRadius = function () {
var firstCall = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
var totalDiagonal = 0;
var onCircleNodes = this.getOnCircleNodes();
for (var i = 0; i < onCircleNodes.length; i++) {
var node = onCircleNodes[i];
var temp = node.getWidth() * node.getWidth() + node.getHeight() * node.getHeight();
totalDiagonal += Math.sqrt(temp);
}
var layout = this.getGraphManager().getLayout();
var nodeSeparation = layout.getNodeSeparation() + this.getAdditionalNodeSeparation();
var perimeter = totalDiagonal + this.getOnCircleNodes().length * nodeSeparation;
if (firstCall) {
var largestDiagonal = 0;
var nodeList = this.getOnCircleNodes();
for (var _i5 = 0; _i5 < nodeList.length; _i5++) {
if (nodeList[_i5].getDiagonal() > largestDiagonal) largestDiagonal = nodeList[_i5].getDiagonal();
}
largestDiagonal += CiSEConstants.DEFAULT_INNER_EDGE_LENGTH;
var diameter = perimeter / Math.PI - largestDiagonal;
nodeList = this.getInCircleNodes();
largestDiagonal = 0;
for (var _i6 = 0; _i6 < nodeList.length; _i6++) {
if (nodeList[_i6].getDiagonal() > largestDiagonal) largestDiagonal = nodeList[_i6].getDiagonal();
}
largestDiagonal = 1.2 * largestDiagonal + CiSEConstants.DEFAULT_INNER_EDGE_LENGTH;
diameter -= largestDiagonal;
if (diameter < largestDiagonal * Math.ceil(Math.sqrt(nodeList.length)) + CiSEConstants.DEFAULT_INNER_EDGE_LENGTH) {
var additionalNodeSep = (largestDiagonal * Math.ceil(Math.sqrt(nodeList.length)) - diameter) / this.getOnCircleNodes().length;
this.setAdditionalNodeSeparation(additionalNodeSep);
nodeSeparation = layout.getNodeSeparation() + this.getAdditionalNodeSeparation();
perimeter = totalDiagonal + this.getOnCircleNodes().length * nodeSeparation;
}
}
this.radius = perimeter / (2 * Math.PI);
this.calculateParentNodeDimension();
};
//
// This method recalculates the node positions
// when the circle's radius changes.
// It is called when additional node seperation is increased.
//
CiSECircle.prototype.reCalculateNodePositions = function () {
var layout = this.getGraphManager().getLayout();
var nodeSeparation = layout.getNodeSeparation() + this.getAdditionalNodeSeparation();
var inOrderCopy = this.onCircleNodes;
inOrderCopy.sort(function (a, b) {
return a.getOnCircleNodeExt().getIndex() - b.getOnCircleNodeExt().getIndex();
});
var parentCenterX = this.getParent().getCenterX();
var parentCenterY = this.getParent().getCenterY();
for (var i = 0; i < inOrderCopy.length; i++) {
var node = inOrderCopy[i];
var angle = void 0;
if (i === 0) {
angle = node.getOnCircleNodeExt().getAngle();
} else {
var previousNode = inOrderCopy[i - 1];
// => angle in radian = (2*PI)*(circular distance/(2*PI*r))
angle = previousNode.getOnCircleNodeExt().getAngle() + (node.getHalfTheDiagonal() + nodeSeparation + previousNode.getHalfTheDiagonal()) / this.radius;
}
node.getOnCircleNodeExt().setAngle(angle);
node.setCenter(parentCenterX + this.radius * Math.cos(angle), parentCenterY + this.radius * Math.sin(angle));
}
this.updateBounds(true);
this.getParent().updateBounds(false);
this.getGraphManager().rootGraph.updateBounds(false);
};
/**
* This method goes over all on-circle nodes and re-calculates their angles
* and corresponding positions. This method should be called when on-circle
* nodes (content or order) have been changed for this circle.
*/
CiSECircle.prototype.reCalculateNodeAnglesAndPositions = function () {
var layout = this.getGraphManager().getLayout();
var nodeSeparation = layout.getNodeSeparation() + this.getAdditionalNodeSeparation();
// It is important that we sort these on-circle nodes in place.
var inOrderCopy = this.onCircleNodes;
inOrderCopy.sort(function (a, b) {
return a.getOnCircleNodeExt().getIndex() - b.getOnCircleNodeExt().getIndex();
});
var parentCenterX = this.getParent().getCenterX();
var parentCenterY = this.getParent().getCenterY();
for (var i = 0; i < inOrderCopy.length; i++) {
var node = inOrderCopy[i];
var angle = void 0;
if (i === 0) {
angle = 0.0;
} else {
var previousNode = inOrderCopy[i - 1];
// => angle in radian = (2*PI)*(circular distance/(2*PI*r))
angle = previousNode.getOnCircleNodeExt().getAngle() + (node.getHalfTheDiagonal() + nodeSeparation + previousNode.getHalfTheDiagonal()) / this.radius;
}
node.getOnCircleNodeExt().setAngle(angle);
node.setCenter(parentCenterX + this.radius * Math.cos(angle), parentCenterY + this.radius * Math.sin(angle));
}
this.updateBounds(true);
this.getParent().updateBounds(false);
this.getGraphManager().rootGraph.updateBounds(false);
};
module.exports = CiSECircle;
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* This class implements data and functionality required for CiSE layout per
* edge.
*
*
* Copyright: i-Vis Research Group, Bilkent University, 2007 - present
*/
var FDLayoutEdge = __webpack_require__(0).layoutBase.FDLayoutEdge;