forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webcola.d.ts
1096 lines (1096 loc) · 39.4 KB
/
webcola.d.ts
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
// Type definitions for webcola 3.1.1
// Project: https://github.com/tgdwyer/WebCola
// Definitions by: Qinfeng Chen <https://github.com/qinfchen>, Tim Dwyer <https://github.com/tgdwyer>, Noah Chen <https://github.com/nchen63>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module cola {
function applyPacking(graphs: Array<any>, w: any, h: any, node_size: any, desired_ratio?: number): void;
/**
* connected components of graph
* returns an array of {}
*/
function separateGraphs(nodes: any, links: any): any[];
}
declare module cola.vpsc {
class PositionStats {
scale: number;
AB: number;
AD: number;
A2: number;
constructor(scale: number);
addVariable(v: Variable): void;
getPosn(): number;
}
class Constraint {
left: Variable;
right: Variable;
gap: number;
equality: boolean;
lm: number;
active: boolean;
unsatisfiable: boolean;
constructor(left: Variable, right: Variable, gap: number, equality?: boolean);
slack(): number;
}
class Variable {
desiredPosition: number;
weight: number;
scale: number;
offset: number;
block: Block;
cIn: Constraint[];
cOut: Constraint[];
constructor(desiredPosition: number, weight?: number, scale?: number);
dfdv(): number;
position(): number;
visitNeighbours(prev: Variable, f: (c: Constraint, next: Variable) => void): void;
}
class Block {
vars: Variable[];
posn: number;
ps: PositionStats;
blockInd: number;
constructor(v: Variable);
private addVariable(v);
updateWeightedPosition(): void;
private compute_lm(v, u, postAction);
private populateSplitBlock(v, prev);
traverse(visit: (c: Constraint) => any, acc: any[], v?: Variable, prev?: Variable): void;
findMinLM(): Constraint;
private findMinLMBetween(lv, rv);
private findPath(v, prev, to, visit);
isActiveDirectedPathBetween(u: Variable, v: Variable): boolean;
static split(c: Constraint): Block[];
private static createSplitBlock(startVar);
splitBetween(vl: Variable, vr: Variable): {
constraint: Constraint;
lb: Block;
rb: Block;
};
mergeAcross(b: Block, c: Constraint, dist: number): void;
cost(): number;
}
class Blocks {
vs: Variable[];
private list;
constructor(vs: Variable[]);
cost(): number;
insert(b: Block): void;
remove(b: Block): void;
merge(c: Constraint): void;
forEach(f: (b: Block, i: number) => void): void;
updateBlockPositions(): void;
split(inactive: Constraint[]): void;
}
class Solver {
vs: Variable[];
cs: Constraint[];
bs: Blocks;
inactive: Constraint[];
static LAGRANGIAN_TOLERANCE: number;
static ZERO_UPPERBOUND: number;
constructor(vs: Variable[], cs: Constraint[]);
cost(): number;
setStartingPositions(ps: number[]): void;
setDesiredPositions(ps: number[]): void;
private mostViolated();
satisfy(): void;
solve(): number;
}
}
declare module cola.vpsc {
class TreeBase {
_root: any;
size: any;
_comparator: any;
clear(): void;
find(data: any): any;
findIter: (data: any) => any;
lowerBound(data: any): Iterator;
upperBound(data: any): Iterator;
min(): any;
max(): any;
iterator(): Iterator;
each(cb: any): void;
reach(cb: any): void;
_bound(data: any, cmp: any): Iterator;
}
class Iterator {
_tree: any;
_ancestors: any;
_cursor: any;
constructor(tree: any);
data(): any;
next(): any;
prev(): any;
_minNode(start: any): void;
_maxNode(start: any): void;
}
class RBTree<T> extends TreeBase {
_root: any;
_comparator: any;
size: any;
constructor(comparator: (a: T, b: T) => number);
insert(data: any): boolean;
remove(data: any): boolean;
static is_red(node: any): any;
static single_rotate(root: any, dir: any): any;
static double_rotate(root: any, dir: any): any;
}
}
/// <reference path="vpsc.d.ts" />
/// <reference path="rbtree.d.ts" />
declare module cola.vpsc {
interface Point {
x: number;
y: number;
}
interface Leaf {
bounds: Rectangle;
variable: Variable;
}
interface Group {
bounds: Rectangle;
padding: number;
stiffness: number;
leaves: Leaf[];
groups: Group[];
minVar: Variable;
maxVar: Variable;
}
function computeGroupBounds(g: Group): Rectangle;
class Rectangle {
x: number;
X: number;
y: number;
Y: number;
constructor(x: number, X: number, y: number, Y: number);
static empty(): Rectangle;
cx(): number;
cy(): number;
overlapX(r: Rectangle): number;
overlapY(r: Rectangle): number;
setXCentre(cx: number): void;
setYCentre(cy: number): void;
width(): number;
height(): number;
union(r: Rectangle): Rectangle;
/**
* return any intersection points between the given line and the sides of this rectangle
* @method lineIntersection
* @param x1 number first x coord of line
* @param y1 number first y coord of line
* @param x2 number second x coord of line
* @param y2 number second y coord of line
* @return any intersection points found
*/
lineIntersections(x1: number, y1: number, x2: number, y2: number): Array<Point>;
/**
* return any intersection points between a line extending from the centre of this rectangle to the given point,
* and the sides of this rectangle
* @method lineIntersection
* @param x2 number second x coord of line
* @param y2 number second y coord of line
* @return any intersection points found
*/
rayIntersection(x2: number, y2: number): Point;
vertices(): Point[];
static lineIntersection(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number): Point;
inflate(pad: number): Rectangle;
}
function makeEdgeBetween(source: Rectangle, target: Rectangle, ah: number): {
sourceIntersection: Point;
targetIntersection: Point;
arrowStart: Point;
};
function makeEdgeTo(s: {
x: number;
y: number;
}, target: Rectangle, ah: number): Point;
function generateXConstraints(rs: Rectangle[], vars: Variable[]): Constraint[];
function generateYConstraints(rs: Rectangle[], vars: Variable[]): Constraint[];
function generateXGroupConstraints(root: Group): Constraint[];
function generateYGroupConstraints(root: Group): Constraint[];
function removeOverlaps(rs: Rectangle[]): void;
interface GraphNode extends Leaf {
fixed: boolean;
fixedWeight?: number;
width: number;
height: number;
x: number;
y: number;
px: number;
py: number;
}
class IndexedVariable extends Variable {
index: number;
constructor(index: number, w: number);
}
class Projection {
private nodes;
private groups;
private rootGroup;
private avoidOverlaps;
private xConstraints;
private yConstraints;
private variables;
constructor(nodes: GraphNode[], groups: Group[], rootGroup?: Group, constraints?: any[], avoidOverlaps?: boolean);
private createSeparation(c);
private makeFeasible(c);
private createAlignment(c);
private createConstraints(constraints);
private setupVariablesAndBounds(x0, y0, desired, getDesired);
xProject(x0: number[], y0: number[], x: number[]): void;
yProject(x0: number[], y0: number[], y: number[]): void;
projectFunctions(): {
(x0: number[], y0: number[], r: number[]): void;
}[];
private project(x0, y0, start, desired, getDesired, cs, generateConstraints, updateNodeBounds, updateGroupBounds);
private solve(vs, cs, starting, desired);
}
}
/// <reference path="vpsc.d.ts" />
/// <reference path="rectangle.d.ts" />
declare module cola.geom {
class Point {
x: number;
y: number;
}
class LineSegment {
x1: number;
y1: number;
x2: number;
y2: number;
constructor(x1: number, y1: number, x2: number, y2: number);
}
class PolyPoint extends Point {
polyIndex: number;
}
/** tests if a point is Left|On|Right of an infinite line.
* @param points P0, P1, and P2
* @return >0 for P2 left of the line through P0 and P1
* =0 for P2 on the line
* <0 for P2 right of the line
*/
function isLeft(P0: Point, P1: Point, P2: Point): number;
/**
* returns the convex hull of a set of points using Andrew's monotone chain algorithm
* see: http://geomalgorithms.com/a10-_hull-1.html#Monotone%20Chain
* @param S array of points
* @return the convex hull as an array of points
*/
function ConvexHull(S: Point[]): Point[];
function clockwiseRadialSweep(p: Point, P: Point[], f: (p: Point) => void): void;
function tangent_PolyPolyC(V: Point[], W: Point[], t1: (a: Point, b: Point[]) => number, t2: (a: Point, b: Point[]) => number, cmp1: (a: Point, b: Point, c: Point) => boolean, cmp2: (a: Point, b: Point, c: Point) => boolean): {
t1: number;
t2: number;
};
function LRtangent_PolyPolyC(V: Point[], W: Point[]): {
t1: number;
t2: number;
};
function RLtangent_PolyPolyC(V: Point[], W: Point[]): {
t1: number;
t2: number;
};
function LLtangent_PolyPolyC(V: Point[], W: Point[]): {
t1: number;
t2: number;
};
function RRtangent_PolyPolyC(V: Point[], W: Point[]): {
t1: number;
t2: number;
};
class BiTangent {
t1: number;
t2: number;
constructor(t1: number, t2: number);
}
class BiTangents {
rl: BiTangent;
lr: BiTangent;
ll: BiTangent;
rr: BiTangent;
}
class TVGPoint extends Point {
vv: VisibilityVertex;
}
class VisibilityVertex {
id: number;
polyid: number;
polyvertid: number;
p: TVGPoint;
constructor(id: number, polyid: number, polyvertid: number, p: TVGPoint);
}
class VisibilityEdge {
source: VisibilityVertex;
target: VisibilityVertex;
constructor(source: VisibilityVertex, target: VisibilityVertex);
length(): number;
}
class TangentVisibilityGraph {
P: TVGPoint[][];
V: VisibilityVertex[];
E: VisibilityEdge[];
constructor(P: TVGPoint[][], g0?: {
V: VisibilityVertex[];
E: VisibilityEdge[];
});
addEdgeIfVisible(u: TVGPoint, v: TVGPoint, i1: number, i2: number): void;
addPoint(p: TVGPoint, i1: number): VisibilityVertex;
private intersectsPolys(l, i1, i2);
}
function tangents(V: Point[], W: Point[]): BiTangents;
function polysOverlap(p: Point[], q: Point[]): boolean;
}
/**
* @module cola
*/
declare module cola {
/**
* Descent respects a collection of locks over nodes that should not move
* @class Locks
*/
class Locks {
locks: any;
/**
* add a lock on the node at index id
* @method add
* @param id index of node to be locked
* @param x required position for node
*/
add(id: number, x: number[]): void;
/**
* @method clear clear all locks
*/
clear(): void;
/**
* @isEmpty
* @returns false if no locks exist
*/
isEmpty(): boolean;
/**
* perform an operation on each lock
* @apply
*/
apply(f: (id: number, x: number[]) => void): void;
}
/**
* Uses a gradient descent approach to reduce a stress or p-stress goal function over a graph with specified ideal edge lengths or a square matrix of dissimilarities.
* The standard stress function over a graph nodes with position vectors x,y,z is (mathematica input):
* stress[x_,y_,z_,D_,w_]:=Sum[w[[i,j]] (length[x[[i]],y[[i]],z[[i]],x[[j]],y[[j]],z[[j]]]-d[[i,j]])^2,{i,Length[x]-1},{j,i+1,Length[x]}]
* where: D is a square matrix of ideal separations between nodes, w is matrix of weights for those separations
* length[x1_, y1_, z1_, x2_, y2_, z2_] = Sqrt[(x1 - x2)^2 + (y1 - y2)^2 + (z1 - z2)^2]
* below, we use wij = 1/(Dij^2)
*
* @class Descent
*/
class Descent {
D: number[][];
G: number[][];
threshold: number;
/** Hessian Matrix
* @property H {number[][][]}
*/
H: number[][][];
/** gradient vector
* @property G {number[][]}
*/
g: number[][];
/** positions vector
* @property x {number[][]}
*/
x: number[][];
/**
* @property k {number} dimensionality
*/
k: number;
/**
* number of data-points / nodes / size of vectors/matrices
* @property n {number}
*/
n: number;
locks: Locks;
private static zeroDistance;
private minD;
private Hd;
private a;
private b;
private c;
private d;
private e;
private ia;
private ib;
private xtmp;
numGridSnapNodes: number;
snapGridSize: number;
snapStrength: number;
scaleSnapByMaxH: boolean;
private random;
project: {
(x0: number[], y0: number[], r: number[]): void;
}[];
/**
* @method constructor
* @param x {number[][]} initial coordinates for nodes
* @param D {number[][]} matrix of desired distances between pairs of nodes
* @param G {number[][]} [default=null] if specified, G is a matrix of weights for goal terms between pairs of nodes.
* If G[i][j] > 1 and the separation between nodes i and j is greater than their ideal distance, then there is no contribution for this pair to the goal
* If G[i][j] <= 1 then it is used as a weighting on the contribution of the variance between ideal and actual separation between i and j to the goal function
*/
constructor(x: number[][], D: number[][], G?: number[][]);
static createSquareMatrix(n: number, f: (i: number, j: number) => number): number[][];
private offsetDir();
computeDerivatives(x: number[][]): void;
private static dotProd(a, b);
private static rightMultiply(m, v, r);
computeStepSize(d: number[][]): number;
reduceStress(): number;
private static copy(a, b);
private stepAndProject(x0, r, d, stepSize);
private static mApply(m, n, f);
private matrixApply(f);
private computeNextPosition(x0, r);
run(iterations: number): number;
rungeKutta(): number;
private static mid(a, b, m);
takeDescentStep(x: number[], d: number[], stepSize: number): void;
computeStress(): number;
}
class PseudoRandom {
seed: number;
private a;
private c;
private m;
private range;
constructor(seed?: number);
getNext(): number;
getNextBetween(min: number, max: number): number;
}
}
declare module cola.powergraph {
interface LinkAccessor<Link> {
getSourceIndex(l: Link): number;
getTargetIndex(l: Link): number;
getType(l: Link): number;
}
class PowerEdge {
source: any;
target: any;
type: number;
constructor(source: any, target: any, type: number);
}
class Configuration<Link> {
private linkAccessor;
modules: Module[];
roots: ModuleSet[];
R: number;
constructor(n: number, edges: Link[], linkAccessor: LinkAccessor<Link>, rootGroup?: any[]);
private initModulesFromGroup(group);
merge(a: Module, b: Module, k?: number): Module;
private rootMerges(k?);
greedyMerge(): boolean;
private nEdges(a, b);
getGroupHierarchy(retargetedEdges: PowerEdge[]): any[];
allEdges(): PowerEdge[];
static getEdges(modules: ModuleSet, es: PowerEdge[]): void;
}
class Module {
id: number;
outgoing: LinkSets;
incoming: LinkSets;
children: ModuleSet;
definition: any;
gid: number;
constructor(id: number, outgoing?: LinkSets, incoming?: LinkSets, children?: ModuleSet, definition?: any);
getEdges(es: PowerEdge[]): void;
isLeaf(): boolean;
isIsland(): boolean;
isPredefined(): boolean;
}
class ModuleSet {
table: any;
count(): number;
intersection(other: ModuleSet): ModuleSet;
intersectionCount(other: ModuleSet): number;
contains(id: number): boolean;
add(m: Module): void;
remove(m: Module): void;
forAll(f: (m: Module) => void): void;
modules(): Module[];
}
class LinkSets {
sets: any;
n: number;
count(): number;
contains(id: number): boolean;
add(linktype: number, m: Module): void;
remove(linktype: number, m: Module): void;
forAll(f: (ms: ModuleSet, linktype: number) => void): void;
forAllModules(f: (m: Module) => void): void;
intersection(other: LinkSets): LinkSets;
}
function getGroups<Link>(nodes: any[], links: Link[], la: LinkAccessor<Link>, rootGroup?: any[]): {
groups: any[];
powerEdges: PowerEdge[];
};
}
/**
* @module cola
*/
declare module cola {
interface LinkAccessor<Link> {
getSourceIndex(l: Link): number;
getTargetIndex(l: Link): number;
}
interface LinkLengthAccessor<Link> extends LinkAccessor<Link> {
setLength(l: Link, value: number): void;
}
/** modify the specified link lengths based on the symmetric difference of their neighbours
* @class symmetricDiffLinkLengths
*/
function symmetricDiffLinkLengths<Link>(links: Link[], la: LinkLengthAccessor<Link>, w?: number): void;
/** modify the specified links lengths based on the jaccard difference between their neighbours
* @class jaccardLinkLengths
*/
function jaccardLinkLengths<Link>(links: Link[], la: LinkLengthAccessor<Link>, w?: number): void;
interface IConstraint {
left: number;
right: number;
gap: number;
}
interface DirectedEdgeConstraints {
axis: string;
gap: number;
}
interface LinkSepAccessor<Link> extends LinkAccessor<Link> {
getMinSeparation(l: Link): number;
}
/** generate separation constraints for all edges unless both their source and sink are in the same strongly connected component
* @class generateDirectedEdgeConstraints
*/
function generateDirectedEdgeConstraints<Link>(n: number, links: Link[], axis: string, la: LinkSepAccessor<Link>): IConstraint[];
/**
* Tarjan's strongly connected components algorithm for directed graphs
* returns an array of arrays of node indicies in each of the strongly connected components.
* a vertex not in a SCC of two or more nodes is it's own SCC.
* adaptation of https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
*/
function stronglyConnectedComponents<Link>(numVertices: number, edges: Link[], la: LinkAccessor<Link>): number[][];
}
declare class PairingHeap<T> {
elem: T;
private subheaps;
constructor(elem: T);
toString(selector: any): string;
forEach(f: any): void;
count(): number;
min(): T;
empty(): boolean;
contains(h: PairingHeap<T>): boolean;
isHeap(lessThan: (a: T, b: T) => boolean): boolean;
insert(obj: T, lessThan: any): PairingHeap<T>;
merge(heap2: PairingHeap<T>, lessThan: any): PairingHeap<T>;
removeMin(lessThan: (a: T, b: T) => boolean): PairingHeap<T>;
mergePairs(lessThan: (a: T, b: T) => boolean): PairingHeap<T>;
decreaseKey(subheap: PairingHeap<T>, newValue: T, setHeapNode: (e: T, h: PairingHeap<T>) => void, lessThan: (a: T, b: T) => boolean): PairingHeap<T>;
}
/**
* @class PriorityQueue a min priority queue backed by a pairing heap
*/
declare class PriorityQueue<T> {
private lessThan;
private root;
constructor(lessThan: (a: T, b: T) => boolean);
/**
* @method top
* @return the top element (the min element as defined by lessThan)
*/
top(): T;
/**
* @method push
* put things on the heap
*/
push(...args: T[]): PairingHeap<T>;
/**
* @method empty
* @return true if no more elements in queue
*/
empty(): boolean;
/**
* @method isHeap check heap condition (for testing)
* @return true if queue is in valid state
*/
isHeap(): boolean;
/**
* @method forEach apply f to each element of the queue
* @param f function to apply
*/
forEach(f: any): void;
/**
* @method pop remove and return the min element from the queue
*/
pop(): T;
/**
* @method reduceKey reduce the key value of the specified heap node
*/
reduceKey(heapNode: PairingHeap<T>, newKey: T, setHeapNode?: (e: T, h: PairingHeap<T>) => void): void;
toString(selector: any): string;
/**
* @method count
* @return number of elements in queue
*/
count(): number;
}
/// <reference path="pqueue.d.ts" />
/**
* @module shortestpaths
*/
declare module cola.shortestpaths {
/**
* calculates all-pairs shortest paths or shortest paths from a single node
* @class Calculator
* @constructor
* @param n {number} number of nodes
* @param es {Edge[]} array of edges
*/
class Calculator<Link> {
n: number;
es: Link[];
private neighbours;
constructor(n: number, es: Link[], getSourceIndex: (l: Link) => number, getTargetIndex: (l: Link) => number, getLength: (l: Link) => number);
/**
* compute shortest paths for graph over n nodes with edges an array of source/target pairs
* edges may optionally have a length attribute. 1 is the default.
* Uses Johnson's algorithm.
*
* @method DistanceMatrix
* @return the distance matrix
*/
DistanceMatrix(): number[][];
/**
* get shortest paths from a specified start node
* @method DistancesFromNode
* @param start node index
* @return array of path lengths
*/
DistancesFromNode(start: number): number[];
PathFromNodeToNode(start: number, end: number): number[];
PathFromNodeToNodeWithPrevCost(start: number, end: number, prevCost: (u: number, v: number, w: number) => number): number[];
private dijkstraNeighbours(start, dest?);
}
}
/// <reference path="handledisconnected.d.ts" />
/// <reference path="geom.d.ts" />
/// <reference path="descent.d.ts" />
/// <reference path="powergraph.d.ts" />
/// <reference path="linklengths.d.ts" />
/// <reference path="shortestpaths.d.ts" />
/**
* @module cola
*/
declare module cola {
/**
* The layout process fires three events:
* - start: layout iterations started
* - tick: fired once per iteration, listen to this to animate
* - end: layout converged, you might like to zoom-to-fit or something at notification of this event
*/
enum EventType {
start = 0,
tick = 1,
end = 2,
}
interface Event {
type: EventType;
alpha: number;
stress?: number;
listener?: () => void;
}
interface Node {
/**
* x and y will be computed by layout as the Node's centroid
*/
x: number;
/**
* x and y will be computed by layout as the Node's centroid
*/
y: number;
/**
* specify a width and height of the node's bounding box if you turn on avoidOverlaps
*/
width?: number;
/**
* specify a width and height of the node's bounding box if you turn on avoidOverlaps
*/
height?: any;
number: any;
}
interface Link<NodeType> {
source: NodeType;
target: NodeType;
length?: number;
weight?: number;
}
/**
* Main interface to cola layout.
* @class Layout
*/
class Layout {
private _canvasSize;
private _linkDistance;
private _defaultNodeSize;
private _linkLengthCalculator;
private _linkType;
private _avoidOverlaps;
private _handleDisconnected;
private _alpha;
private _lastStress;
private _running;
private _nodes;
private _groups;
private _rootGroup;
private _links;
private _constraints;
private _distanceMatrix;
private _descent;
private _directedLinkConstraints;
private _threshold;
private _visibilityGraph;
private _groupCompactness;
protected event: any;
on(e: EventType | string, listener: (event: Event) => void): Layout;
protected trigger(e: Event): void;
protected kick(): void;
/**
* iterate the layout. Returns true when layout converged.
*/
protected tick(): boolean;
private updateNodePositions();
/**
* the list of nodes.
* If nodes has not been set, but links has, then we instantiate a nodes list here, of the correct size,
* before returning it.
* @property nodes {Array}
* @default empty list
*/
nodes(): Array<Node>;
nodes(v: Array<Node>): Layout;
/**
* a list of hierarchical groups defined over nodes
* @property groups {Array}
* @default empty list
*/
groups(): Array<any>;
groups(x: Array<any>): Layout;
powerGraphGroups(f: Function): Layout;
/**
* if true, the layout will not permit overlaps of the node bounding boxes (defined by the width and height properties on nodes)
* @property avoidOverlaps
* @type bool
* @default false
*/
avoidOverlaps(): boolean;
avoidOverlaps(v: boolean): Layout;
/**
* if true, the final step of the start method will be to nicely pack connected components of the graph.
* works best if start() is called with a reasonable number of iterations specified and
* each node has a bounding box (defined by the width and height properties on nodes).
* @property handleDisconnected
* @type bool
* @default true
*/
handleDisconnected(): boolean;
handleDisconnected(v: boolean): Layout;
/**
* causes constraints to be generated such that directed graphs are laid out either from left-to-right or top-to-bottom.
* a separation constraint is generated in the selected axis for each edge that is not involved in a cycle (part of a strongly connected component)
* @param axis {string} 'x' for left-to-right, 'y' for top-to-bottom
* @param minSeparation {number|link=>number} either a number specifying a minimum spacing required across all links or a function to return the minimum spacing for each link
*/
flowLayout(axis: string, minSeparation: number | ((t: any) => number)): Layout;
/**
* links defined as source, target pairs over nodes
* @property links {array}
* @default empty list
*/
links(): Array<Link<Node | number>>;
links(x: Array<Link<Node | number>>): Layout;
/**
* list of constraints of various types
* @property constraints
* @type {array}
* @default empty list
*/
constraints(): Array<any>;
constraints(c: Array<any>): Layout;
/**
* Matrix of ideal distances between all pairs of nodes.
* If unspecified, the ideal distances for pairs of nodes will be based on the shortest path distance between them.
* @property distanceMatrix
* @type {Array of Array of Number}
* @default null
*/
distanceMatrix(): Array<Array<number>>;
distanceMatrix(d: Array<Array<number>>): Layout;
/**
* Size of the layout canvas dimensions [x,y]. Currently only used to determine the midpoint which is taken as the starting position
* for nodes with no preassigned x and y.
* @property size
* @type {Array of Number}
*/
size(): Array<number>;
size(x: Array<number>): Layout;
/**
* Default size (assume nodes are square so both width and height) to use in packing if node width/height are not specified.
* @property defaultNodeSize
* @type {Number}
*/
defaultNodeSize(): number;
defaultNodeSize(x: number): Layout;
/**
* The strength of attraction between the group boundaries to each other.
* @property defaultNodeSize
* @type {Number}
*/
groupCompactness(): number;
groupCompactness(x: number): Layout;
/**
* links have an ideal distance, The automatic layout will compute layout that tries to keep links (AKA edges) as close as possible to this length.
*/
linkDistance(): number;
linkDistance(): (t: any) => number;
linkDistance(x: number): Layout;
linkDistance(x: (t: any) => number): Layout;
linkType(f: Function | number): Layout;
convergenceThreshold(): number;
convergenceThreshold(x: number): Layout;
alpha(): number;
alpha(x: number): Layout;
getLinkLength(link: any): number;
static setLinkLength(link: any, length: number): void;
getLinkType(link: any): number;
linkAccessor: {
getSourceIndex: (e: any) => any;
getTargetIndex: (e: any) => any;
setLength: (link: any, length: number) => void;
getType: (l: any) => any;
};
/**
* compute an ideal length for each link based on the graph structure around that link.
* you can use this (for example) to create extra space around hub-nodes in dense graphs.
* In particular this calculation is based on the "symmetric difference" in the neighbour sets of the source and target:
* i.e. if neighbours of source is a and neighbours of target are b then calculation is: sqrt(|a union b| - |a intersection b|)
* Actual computation based on inspection of link structure occurs in start(), so links themselves
* don't have to have been assigned before invoking this function.
* @param {number} [idealLength] the base length for an edge when its source and start have no other common neighbours (e.g. 40)
* @param {number} [w] a multiplier for the effect of the length adjustment (e.g. 0.7)
*/
symmetricDiffLinkLengths(idealLength: number, w?: number): Layout;
/**
* compute an ideal length for each link based on the graph structure around that link.
* you can use this (for example) to create extra space around hub-nodes in dense graphs.
* In particular this calculation is based on the "symmetric difference" in the neighbour sets of the source and target:
* i.e. if neighbours of source is a and neighbours of target are b then calculation is: |a intersection b|/|a union b|
* Actual computation based on inspection of link structure occurs in start(), so links themselves
* don't have to have been assigned before invoking this function.
* @param {number} [idealLength] the base length for an edge when its source and start have no other common neighbours (e.g. 40)
* @param {number} [w] a multiplier for the effect of the length adjustment (e.g. 0.7)
*/
jaccardLinkLengths(idealLength: number, w?: number): Layout;
/**
* start the layout process
* @method start
* @param {number} [initialUnconstrainedIterations=0] unconstrained initial layout iterations
* @param {number} [initialUserConstraintIterations=0] initial layout iterations with user-specified constraints
* @param {number} [initialAllConstraintsIterations=0] initial layout iterations with all constraints including non-overlap
* @param {number} [gridSnapIterations=0] iterations of "grid snap", which pulls nodes towards grid cell centers - grid of size node[0].width - only really makes sense if all nodes have the same width and height
* @param [keepRunning=true] keep iterating asynchronously via the tick method
*/
start(initialUnconstrainedIterations?: number, initialUserConstraintIterations?: number, initialAllConstraintsIterations?: number, gridSnapIterations?: number, keepRunning?: boolean): Layout;
private separateOverlappingComponents(width, height);
resume(): Layout;
stop(): Layout;
prepareEdgeRouting(nodeMargin?: number): void;
routeEdge(edge: any, draw: any): any[];
static getSourceIndex(e: any): any;
static getTargetIndex(e: any): any;
static linkId(e: any): string;
static dragStart(d: any): void;
static dragEnd(d: any): void;
static mouseOver(d: any): void;
static mouseOut(d: any): void;
}
}
/// <reference path="layout.d.ts" />
declare module cola {
class LayoutAdaptor extends Layout {
trigger(e: Event): void;
kick(): void;
drag(): void;
on(eventType: EventType | string, listener: () => void): LayoutAdaptor;
dragstart: (d: any) => void;
dragStart: (d: any) => void;
dragend: (d: any) => void;
dragEnd: (d: any) => void;
constructor(options: any);
}
/**
* provides an interface for use with any external graph system (e.g. Cytoscape.js):
*/
function adaptor(options: any): LayoutAdaptor;
}
declare module cola {
function gridify(pgLayout: any, nudgeGap: any, margin: any, groupMargin: any): geom.Point[][][];
function powerGraphGridLayout(graph: {
nodes: Node[];
links: Link<Node>[];
}, size: number[], grouppadding: number, margin: number, groupMargin: number): {
cola: Layout;
powerGraph: any;
};
}
/// <reference path="layout.d.ts" />
declare module cola {
class D3StyleLayoutAdaptor extends Layout {
event: any;
trigger(e: Event): void;
kick(): void;
drag: () => any;
constructor();
on(eventType: EventType | string, listener: () => void): D3StyleLayoutAdaptor;
}
/**
* provides an interface for use with d3:
* - uses the d3 event system to dispatch layout events such as:
* o "start" (start layout process)
* o "tick" (after each layout iteration)
* o "end" (layout converged and complete).
* - uses the d3 timer to queue layout iterations.
* - sets up d3.behavior.drag to drag nodes
* o use `node.call(<the returned instance of Layout>.drag)` to make nodes draggable
* returns an instance of the cola.Layout itself with which the user
* can interact directly.
*/
function d3adaptor(): D3StyleLayoutAdaptor;
}
/// <reference path="rectangle.d.ts" />
/// <reference path="shortestpaths.d.ts" />
/// <reference path="geom.d.ts" />
/// <reference path="vpsc.d.ts" />
declare module cola {
interface NodeAccessor<Node> {
getChildren(v: Node): number[];
getBounds(v: Node): cola.vpsc.Rectangle;
}
class NodeWrapper {
id: number;
rect: cola.vpsc.Rectangle;
children: number[];
leaf: boolean;
parent: NodeWrapper;
ports: Vert[];
constructor(id: number, rect: cola.vpsc.Rectangle, children: number[]);
}
class Vert {
id: number;
x: number;
y: number;
node: NodeWrapper;
line: any;
constructor(id: number, x: number, y: number, node?: NodeWrapper, line?: any);