-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCreate.js
More file actions
2713 lines (2395 loc) · 149 KB
/
Copy pathCreate.js
File metadata and controls
2713 lines (2395 loc) · 149 KB
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
var viewport = document.getElementById("viewport");
var workspace = document.getElementById("workspace");
var svgNS = workspace.getAttribute('xmlns');
var xlinkNS = workspace.getAttribute('xmlns:xlink');
var pt = workspace.createSVGPoint();
var scaleFactor = 100;
//Monitoring and performance variables
var positionItemCount=0;
//Global Settings
var globalSettings = {};
globalSettings.lodEnabled = 0; //Disable for now. Default should be enabled
///////////////////////////////
///////////////////////////////
// Templates for items
///////////////////////////////
///////////////////////////////
var itemTemplate={
"cluster":{"visibility":"hidden","padding":350,"itemsperrow":5,"type":"cluster","class":"cluster","height":5,"width":5,"fill":"white","fill-opacity":0.2,"stroke":"green","stroke-width":0.2},
//"cluster":{"visibility":"visible","padding":350,"itemsperrow":5,"type":"cluster","class":"cluster","height":5,"width":5,"fill":"none","fill-opacity":0.2,"stroke":"black","stroke-width":2},
"serverContainer":{"visibility":"hidden","pointer-events":"all","padding":550,"itemsperrow":5,"type":"servers","class":"nodeContainer","height":5,"width":5,"fill":"white","fill-opacity":0.2,"stroke":"blue","stroke-width":0.2},
"server":{"visibility":"visible","padding":140,"itemsperrow":1,"ry":0.5,"fpadding":0,"type":"server","class":"node","height":10,"width":10,"fill":"gray","fill-opacity":0.1,"stroke":"black","stroke-width":1},
"storage":{"visibility":"visible","padding":140,"itemsperrow":1,"ry":0.5,"fpadding":0,"type":"server","class":"node","height":10,"width":10,"fill":"gray","fill-opacity":0.1,"stroke":"black","stroke-width":1},
"clientContainer":{"visibility":"hidden","pointer-events":"all","padding":550,"itemsperrow":5,"type":"clients","class":"nodeContainer","height":5,"width":5,"fill":"white","fill-opacity":0.2,"stroke":"blue","stroke-width":0.2},
"client":{"visibility":"visible","padding":140,"itemsperrow":1,"ry":0.5,"type":"client","class":"node","height":10,"width":10,"fill":"gray","fill-opacity":0.1,"stroke":"black","stroke-width":1},
"componentContainer":{"visibility":"hidden","padding":40,"itemsperrow":10,"ry":0.5,"type":"tbd","class":"compContainer","bw":9,"height":5,"width":5,"fill":"gray","fill-opacity":0,"stroke":"black","stroke-width":0.2},
"bond":{"visibility":"visible","padding":15,"itemsperrow":1,"ry":0.5,"type":"bond","class":"nic","bw":30,"height":30,"width":5,"fill":"blue","fill-opacity":0.1,"stroke":"black","stroke-width":0.2},
"nic":{"visibility":"visible","padding":5,"itemsperrow":1,"ry":0.5,"type":"nic","class":"nic","bw":30,"height":30,"width":5,"fill":"blue","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"socket":{"visibility":"visible","padding":1,"itemsperrow":1,"type":"socket","class":"socket","height":0,"width":0,"fill":"green","fill-opacity":0.5,"stroke":"black","stroke-width":0},
"vnic":{"visibility":"visible","padding":15,"itemsperrow":1,"ry":0.5,"type":"vnic","class":"vnic","bw":30,"height":30,"width":5,"fill":"blue","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"cpu":{"visibility":"visible","padding":20,"itemsperrow":1,"ry":0.5,"type":"cpu","class":"cpu","height":15,"width":15,"fill":"gray","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"cpuCore":{"visibility":"visible","padding":15,"itemsperrow":1,"ry":0.5,"type":"cpuCore","class":"cpuCore","height":50,"width":50,"fill":"gray","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"proccpu":{"visibility":"visible","padding":1,"itemsperrow":1,"type":"cpuprocess","class":"cpuprocess","height":0,"width":0,"fill":"green","fill-opacity":0.5,"stroke":"black","stroke-width":0},
"ram":{"visibility":"visible","padding":10,"itemsperrow":1,"ry":0.5,"type":"ram","class":"ram","height":0,"width":0,"fill":"gray","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"procmem":{"visibility":"visible","padding":1,"itemsperrow":1,"type":"ramprocess","class":"ramprocess","height":0,"width":0,"fill":"green","fill-opacity":0.5,"stroke":"black","stroke-width":0},
"vms":{"visibility":"visible","padding":0,"itemsperrow":1,"ry":0.5,"type":"vms","class":"vms","height":630,"width":240,"fill":"none","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"vmserver":{"visibility":"visible","padding":140,"itemsperrow":1,"ry":0.5,"fpadding":0,"type":"vmserver","class":"vmnode","height":10,"width":10,"fill":"gray","fill-opacity":0,"stroke":"black","stroke-width":2,"stroke-opacity":0.5,"fixed":1},
"vmclient":{"visibility":"visible","padding":140,"itemsperrow":1,"ry":0.5,"type":"vmclient","class":"vmnode","height":10,"width":10,"fill":"gray","fill-opacity":0,"stroke":"black","stroke-width":0.2,"fixed":1},
"vols":{"visibility":"visible","padding":0,"itemsperrow":1,"ry":0.5,"type":"vols","class":"vols","fill":"gray","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
//"vg":{"visibility":"visible","padding":100,"ry":2,"itemsperrow":1,"type":"vol","class":"vol","height":0,"width":0,"fill":"gray","fill-opacity":0.1,"stroke":"black","stroke-width":0.2,"stack":1},
"vg":{"visibility":"visible","padding":100,"ry":2,"itemsperrow":1,"type":"vg","class":"vg","height":0,"width":0,"fill":"gray","fill-opacity":0.1,"stroke":"black","stroke-width":0.2,"stack":1},
"vgvol":{"visibility":"visible","padding":100,"ry":2,"itemsperrow":1,"type":"vgvol","class":"vgvol","height":0,"width":0,"fill":"gray","fill-opacity":0.2,"stroke":"black","stroke-width":0.2,"stack":1},
"vol":{"visibility":"visible","padding":100,"ry":2,"itemsperrow":1,"type":"vol","class":"vol","height":0,"width":0,"fill":"gray","fill-opacity":0.2,"stroke":"black","stroke-width":0.2,"stack":1},
"procvol":{"visibility":"visible","padding":1,"itemsperrow":1,"type":"volprocess","class":"volprocess","height":0,"width":0,"fill":"green","fill-opacity":0.5,"stroke":"black","stroke-width":0},
"raids":{"visibility":"visible","padding":0,"itemsperrow":1,"ry":0.5,"type":"raids","class":"raids","height":0,"width":0,"fill":"gray","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"lun":{"visibility":"visible","padding":1,"itemsperrow":1,"ry":0.5,"type":"lun","class":"lun","bw":25,"height":0,"width":0,"fill":"gray","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"disk":{"visibility":"inherit","padding":30,"itemsperrow":1,"ry":0.5,"type":"disk","class":"disk","bw":30,"height":40,"width":25,"fixed":1,"stroke":"#000000","fill":"gray","fill-opacity":0.2,"stroke-width":0.2},
"partition":{"visibility":"visible","padding":115,"ry":2,"itemsperrow":1,"type":"partition","class":"partition","height":0,"width":0,"stroke":"#000000","fill":"red","fill-opacity":0.2,"stroke-width":0.2,"stack":1},
"procdisk":{"visibility":"visible","padding":1,"itemsperrow":1,"type":"diskprocess","class":"diskprocess","height":0,"width":0,"fill":"green","fill-opacity":0.5,"stroke":"black","stroke-width":0},
"hba":{"visibility":"visible","padding":15,"itemsperrow":1,"ry":0.5,"type":"hba","class":"hba","bw":30,"height":30,"width":5,"fill":"orange","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"controller":{"visibility":"visible","padding":15,"itemsperrow":4,"ry":0.5,"type":"controller","class":"controller","bw":30,"height":30,"width":5,"fill":"orange","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"externalPipe":{"visibility":"visible","type":"externalPipe","class":"pipe","stroke-width":0.005,"stroke":"red","fill":"green","fill-opacity":"0.5","stroke-opacity":"1","template":"externalPipe"},
"arcPipe":{"visibility":"visible","type":"arcPipe","class":"pipe","stroke-width":0.01,"stroke":"red","fill":"steelblue","fill-opacity":"0.5","stroke-opacity":"1","template":"arcPipe"},
"internalPipe":{"visibility":"visible","type":"internalPipe","class":"pipe","stroke-width":0.01,"stroke":"red","fill":"steelblue","fill-opacity":"0.5","stroke-opacity":"1","template":"internalPipe"},
"label":{"visibility":"inherit"}
};
///////////////////////////////
///////////////////////////////
// Other Attributes
///////////////////////////////
///////////////////////////////
var itemAttrs={
"cluster":{"visibility":"hidden","padding":350,"itemsperrow":5,"type":"cluster","class":"cluster","height":5,"width":5,"fill":"white","fill-opacity":0.2,"stroke":"green","stroke-width":0.2},
"serverContainer":{"visibility":"hidden","pointer-events":"all","padding":550,"itemsperrow":5,"type":"servers","class":"nodeContainer","height":5,"width":5,"fill":"white","fill-opacity":0.2,"stroke":"blue","stroke-width":0.2},
"server":{"padding":140,"itemsperrow":1,"fpadding":0,"type":"server","class":"node","height":10,"width":10,"fill":"gray","fill-opacity":0,"stroke":"black","stroke-width":2,"stroke-opacity":0.5},
"storage":{"padding":140,"itemsperrow":1,"fpadding":0,"type":"server","class":"node","height":10,"width":10,"fill":"gray","fill-opacity":0,"stroke":"black","stroke-width":2,"stroke-opacity":0.5},
"clientContainer":{"visibility":"hidden","pointer-events":"all","padding":550,"itemsperrow":5,"type":"clients","class":"nodeContainer","height":5,"width":5,"fill":"white","fill-opacity":0.2,"stroke":"blue","stroke-width":0.2},
"client":{"padding":140,"itemsperrow":1,"ry":0.5,"type":"client","class":"node","height":10,"width":10,"fill":"gray","fill-opacity":0,"stroke":"black","stroke-width":0.2},
"componentContainer":{"padding":40,"itemsperrow":10,"ry":0.5,"type":"tbd","class":"compContainer","bw":9,"height":5,"width":5,"fill":"gray","fill-opacity":0,"stroke":"black","stroke-width":0.2},
"bond":{"padding":15,"itemsperrow":1,"ry":0.5,"type":"bond","class":"nic","bw":30,"height":30,"width":5,"fill":"blue","fill-opacity":0.1,"stroke":"black","stroke-width":0.2},
"nic":{"padding":5,"itemsperrow":1,"ry":0.5,"type":"nic","class":"nic","bw":30,"height":30,"width":5,"fill":"blue","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"socket":{"visibility":"visible","padding":1,"itemsperrow":1,"type":"socket","class":"socket","height":0,"width":0,"fill":"green","fill-opacity":0.2,"stroke":"black","stroke-width":0,"selectedAttrs":{"stroke-width":0.05,"fill-opacity":0.5}},
"vnic":{"padding":15,"itemsperrow":1,"ry":0.5,"type":"vnic","class":"vnic","bw":30,"height":30,"width":5,"fill":"blue","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"cpu":{"padding":20,"itemsperrow":1,"ry":0.5,"type":"cpu","class":"cpu","height":15,"width":15,"fill":"gray","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"cpuCore":{"padding":15,"itemsperrow":1,"ry":0.5,"type":"cpuCore","class":"cpuCore","height":50,"width":50,"fill":"gray","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"proccpu":{"visibility":"visible","padding":1,"itemsperrow":1,"type":"cpuprocess","class":"cpuprocess","height":0,"width":0,"fill":"green","fill-opacity":0.2,"stroke":"black","stroke-width":0,"selectedAttrs":{"stroke-width":0.05,"fill-opacity":0.5}},
"ram":{"padding":10,"itemsperrow":1,"ry":0.5,"type":"ram","class":"ram","height":0,"width":0,"fill":"gray","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"procmem":{"visibility":"visible","padding":1,"itemsperrow":1,"type":"ramprocess","class":"ramprocess","height":0,"width":0,"fill":"green","fill-opacity":0.2,"stroke":"black","stroke-width":0,"selectedAttrs":{"stroke-width":0.05,"fill-opacity":0.5}},
"vms":{"padding":0,"itemsperrow":1,"ry":0.5,"type":"vms","class":"vms","height":630,"width":240,"fill":"none","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"vmserver":{"padding":140,"itemsperrow":1,"ry":0.5,"fpadding":0,"type":"vmserver","class":"vmnode","height":10,"width":10,"fill":"gray","fill-opacity":0,"stroke":"black","stroke-width":2,"stroke-opacity":0.5,"fixed":1},
"vmclient":{"padding":140,"itemsperrow":1,"ry":0.5,"type":"vmclient","class":"vmnode","height":10,"width":10,"fill":"gray","fill-opacity":0,"stroke":"black","stroke-width":0.2,"fixed":1},
"vols":{"padding":0,"itemsperrow":1,"ry":0.5,"type":"vols","class":"vols","fill":"gray","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
//"vg":{"visibility":"visible","padding":100,"ry":2,"itemsperrow":1,"type":"vol","class":"vol","height":0,"width":0,"fill":"gray","fill-opacity":0.1,"stroke":"black","stroke-width":0.2,"stack":1,"selectedAttrs":{"stroke-width":0.5,"fill-opacity":0.5}},
"vg":{"visibility":"visible","padding":100,"ry":2,"itemsperrow":1,"type":"vg","class":"vg","height":0,"width":0,"fill":"gray","fill-opacity":0.1,"stroke":"black","stroke-width":0.2,"stack":1,"selectedAttrs":{"stroke-width":0.5,"fill-opacity":0.5}},
"vol":{"visibility":"visible","padding":100,"ry":2,"itemsperrow":1,"type":"vol","class":"vol","height":0,"width":0,"fill":"gray","fill-opacity":0.2,"stroke":"black","stroke-width":0.2,"stack":1,"selectedAttrs":{"stroke-width":0.5,"fill-opacity":0.5}},
"procvol":{"visibility":"visible","padding":1,"itemsperrow":1,"type":"volprocess","class":"volprocess","height":0,"width":0,"fill":"green","fill-opacity":0.2,"stroke":"black","stroke-width":0,"selectedAttrs":{"stroke-width":0.05,"fill-opacity":0.5}},
"raids":{"padding":0,"itemsperrow":1,"ry":0.5,"type":"raids","class":"raids","height":0,"width":0,"fill":"gray","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"lun":{"visibility":"visible","padding":1,"itemsperrow":1,"ry":0.5,"type":"lun","class":"lun","bw":25,"height":0,"width":0,"fill":"gray","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"disk":{"visibility":"inherit","padding":30,"itemsperrow":1,"ry":0.5,"type":"disk","class":"disk","bw":30,"height":40,"width":25,"fixed":1,"stroke":"#000000","fill":"gray","fill-opacity":0.2,"stroke-width":0.2,"selectedAttrs":{"stroke-width":0.5,"fill-opacity":0.5}},
"partition":{"visibility":"visible","padding":115,"ry":2,"itemsperrow":1,"type":"partition","class":"partition","height":0,"width":0,"stroke":"#000000","fill":"red","fill-opacity":0.2,"stroke-width":0.2,"stack":1,"selectedAttrs":{"stroke-width":0.5,"fill-opacity":0.5}},
"procdisk":{"visibility":"visible","padding":1,"itemsperrow":1,"type":"diskprocess","class":"diskprocess","height":0,"width":0,"fill":"green","fill-opacity":0.2,"stroke":"black","stroke-width":0,"selectedAttrs":{"stroke-width":0.05,"fill-opacity":0.5}},
"hba":{"padding":15,"itemsperrow":1,"ry":0.5,"type":"hba","class":"hba","bw":30,"height":30,"width":5,"fill":"orange","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"controller":{"padding":15,"itemsperrow":4,"ry":0.5,"type":"controller","class":"controller","bw":30,"height":30,"width":5,"fill":"orange","fill-opacity":0.2,"stroke":"black","stroke-width":0.2},
"externalPipe":{"type":"externalPipe","class":"pipe","stroke-width":0.005,"stroke":"red","fill":"green","fill-opacity":"0.1","stroke-opacity":"1","template":"externalPipe","selectedAttrs":{"stroke-width":0.05,"fill-opacity":"0.5"}},
"arcPipe":{"type":"arcPipe","class":"pipe","stroke-width":0.01,"stroke":"red","fill":"steelblue","fill-opacity":"0.1","stroke-opacity":"1","template":"arcPipe","selectedAttrs":{"stroke-width":0.05,"fill-opacity":"0.5"}},
"label":{"visibility":"inherit"}
};
///////////////////////////////
///////////////////////////////
// LOD Levels
///////////////////////////////
///////////////////////////////
var maxLodLevel =0,minLodLevel = 0;
//Device LOD 0 LOD 1 LOD 2 LOD 3 LOD 4
var lodMatrix = {'cluster':[ true, true, true, true, true],
'serverContainer':[ true, true, true, true, true],
'server':[ true, true, true, true, true],
'storage':[ true, true, true, true, true],
'clientContainer':[ true, true, true, true, true],
'client':[ true, true, true, true, true],
'componentContainer':[ true, true, true, true, false],
'bond':[ true, true, false, false, false],
'nic':[ true, true, false, false, false],
//'socket':[ true, false, false, false, false],
'vnic':[ true, true, false, false, false],
'cpu':[ true, true, true, false, false],
'cpuCore':[ true, true, false, false, false],
//'proccpu':[ true, false, false, false, false],
'ram':[ true, true, true, false, false],
//'procmem':[ true, false, false, false, false],
'vms':[ true, true, true, false, false],
'vmserver':[ true, true, true, false, false],
'vmclient':[ true, true, true, false, false],
'vols':[ true, true, true, false, false],
'vg':[ true, true, true, false, false],
'vgvol':[ true, true, false, false, false],
'vol':[ true, true, true, false, false],
//'procvol':[ true, false, false, false, false],
'raids':[ true, true, true, false, false],
'lun':[ true, true, true, false, false],
'disk':[ true, true, true, false, false],
'partition':[ true, true, false, false, false],
//'procdisk':[ true, false, false, false, false],
'hba':[ true, true, false, false, false],
'controller':[ true, true, false, false, false]};
initLodMatrix();
function createElement(name,prop){
var element = document.createElementNS(svgNS,name);
for (var a in prop) if (prop.hasOwnProperty(a)) element.setAttribute(a,prop[a]);
return element;
}
function appendElement(root,element){
root.appendChild(element);
}
function removeLabel(item){
//Item is a group
//var labels=item.querySelectorAll("g#"+item.id+" > text[type='label']");
d3.selectAll("g#"+item.id+" > text[type='label']").remove();
//for (var a=0,ll=labels.length;a<ll;a++){
// item.removeChild(labels[a]);
//}
}
function createLabel(item,label){
//Disable for now
//return;
removeLabel(item.parentNode);
var maxFontSize=48;
//Get actual item scale, regardless of MAP scale
var itemScale=item.getCTM().a/mapMatrix.a;
//
if(label==null){
label=item.getAttribute("label");
if(label==null){label=item.id}
}
var box=item.getBBox();
//console.log("Label item: "+item.id)
//Try to figure out how to position the label:
var orientation = 0; //How many degrees to rotate the label. Default - horizontal
if (box.width < box.height) {
orientation = 270;
}
//var fontSize=(Math.min(box.width,box.height))/label.length;
if (orientation == 0) {
var fontSize = box.width / label.length; //This makes sure font is small enough to fit width-wise (horizontally)
if (fontSize >= box.height * 0.6) {
fontSize = box.height * 0.6; //This makes sure font is small enough to fit inside the item vertically
}
}
else{
var fontSize = box.height / label.length; //This makes sure font is small enough to fit height-wise (vertically)
if (fontSize >= box.width * 0.6) {
fontSize = box.width * 0.6; //This makes sure font is small enough not to stick outside the item
}
}
//var fontSize=1;
//Limit font size:
fontSize=Math.min(fontSize,maxFontSize);
//console.log(box);
//console.log(label)
//console.log("Font size: "+fontSize)
//if (fontSize>=box.height){fontSize=box.height/4}
var scaledFontSize=fontSize*itemScale;
//Calculate Map Scale at which the label becomes first visible
if(minVisTextSize/scaledFontSize>1){
var mapScaleFactor=Math.floor(minVisTextSize/scaledFontSize);
}
else if(minVisTextSize/scaledFontSize<1){
var mapScaleFactor=Math.floor((scaledFontSize/minVisTextSize))*-1;
}
else{var mapScaleFactor=1};
var visibility="inherit";
if (orientation == 0) {
var x=box.width/2;//console.log("X: ",x)
var y=fontSize//+(fontSize/2);//console.log("Y: ",y)
}
else{
var y=box.height/2;//console.log("X: ",x)
var x=fontSize//+(fontSize/2);//console.log("Y: ",y)
}
var text=createElement("text");
var level=item.getAttribute("level")
//setAttributes(text,{"id":item.id+"label","x":x,"y":y,"fill-opacity":1,"fill":"steelblue","text-anchor":"middle","font-size":fontSize,"level":level});
setAttributes(text,{"id":item.id+"_label","parent":item.id,//"x":x,"y":y,//"transform":"translate("+x+","+y+")",
"fill-opacity":1,"fill":"steelblue","text-anchor":"middle",
"font-size":fontSize,"level":level,"showscale":mapScaleFactor,"visibility":visibility,"type":"label","template":"label"});
//Rotate text:
//if (orientation != 0) {
setAttributes(text,{"transform":"translate("+x+","+y+"),rotate("+ orientation +")"})
//}
var textNode=document.createTextNode(label);
text.appendChild(textNode);
item.parentNode.appendChild(text);
//var aaaaTmpbox = item.getBBox();
//var aaabTmpbox = text.getBBox();
}
function pipeManager(action,args){
//A dispatcher function to be used by D3 calls.
//action could be one of the following: create,update,remove
//args is an object:
//Create arguments: uId,origin,parentB,rateA,rateB,streamId
//Update arguments:uId,bw,bw1,props -- props is an object with new attributes
//Remove arguments:uId
var pipe=document.getElementById(args.name);
if(pipe.getAttribute("rightparent") && action=="create"){//Pipe exists, update attributes and morph
//console.log("Updating Pipe... function pipeManager.");
//var props={"name":uId,"lbw":rateA,"rbw":rateB};
//pipeManager("update",props)
//return null;
action="update";
}
switch(action){
case "create":
//console.log("creating pipe uId ",args.name)
//var origin=args.origin;
//var parentB=args.rightparent;
//if(parentB==origin){parentB=args.leftparent}
connect(args.name,args.origin,args.leftparent,args.rightparent,false,0.01,0.01,args.stream);
break;
//case "update":
// //console.log("updating pipe uId",args.name)
// //pipe.setAttribute("stream",args.stream);
// updatePipes(pipe,d);
// break;
case "remove":
//console.log("removing pipe uId ",args.name)
removePipes(args.name);
break;
default:
//console.log("Action not specified. Function pipeManager")
return;
}
return;
}
function updatePipes(pipe,d){
//This function checks if there's old data attached to the pipe, and if any of the key attributes are different
//This is necessary in case a pipe is now connected to a different endpoint
if (!pipe.__olddata__) {
return;
}
var id = d3.select(pipe).attr("id");
var leftparent = pipe.__olddata__.leftparent;
var rightparent = pipe.__olddata__.rightparent;
var origin = pipe.__olddata__.origin;
if (!d || !d.leftparent || !d.rightparent || !d.origin) {
console.log("Need to refresh pipe, but no data attached...");
debugger;
return;
}
if (leftparent != d.leftparent || rightparent != d.rightparent || origin != d.origin) {
//Refresh pipe
connect(id,d.origin,d.leftparent,d.rightparent,true);
}
}
function connect(uId,origin,parentA,parentB,refresh,rateA,rateB,streamId){
if(document.getElementById(uId)){//UID exists, let's check if the pipe is not new and needs to be updated
//console.log("Pipe Exists... function connect.");
var pipe=document.getElementById(uId);
//if(pipe.getAttribute("rightparent")){//Pipe exists, update attributes and morph
// console.log("Updating Pipe... function connect.");
// var props={"name":uId,"lbw":rateA,"rbw":rateB};
// pipeManager("update",props)
// return null;
//}
}
//var parentA=origin;
var type,vectorA,vectorB,ownerA,ownerB,matrixA,matrixB,seqA,seqB,connectorA,connectorB,boxA,boxB,vm=0;
if (typeof(parentA)=="string"){
var parentA_id = parentA;
parentA=document.getElementById(parentA);
}
if (typeof(parentB)=="string"){
var parentB_id = parentB;
parentB=document.getElementById(parentB);
}
if (!parentA || !parentB) {
console.log('Parent not found, skipping pipe for now... pipe: ',uId);
console.log('Parent A: ',parentA_id);
console.log('Parent B: ',parentB_id);
return;
}
vectorA=parentA.getAttribute("vector");
vectorB=parentB.getAttribute("vector");
ownerA=document.getElementById(parentA.getAttribute("owner"));
ownerB=document.getElementById(parentB.getAttribute("owner"));
//Figure out if it's a VM:
if(ownerA.getAttribute("owner")==ownerB.id || ownerB.getAttribute("owner")==ownerA.id){
vm=1;
}
ownerVectorA=ownerA.getAttribute("vector");
ownerVectorB=ownerB.getAttribute("vector");
matrixA=parentA.getCTM();
matrixB=parentB.getCTM();
//console.log("x-A: "+matrixA.e)
//console.log("x-B: "+matrixB.e)
//IE Fix: can't modify BBox()
var boxA={};
var tmpBoxA=parentA.getBBox();
var boxB={};
var tmpBoxB=parentB.getBBox();
boxA.x=tmpBoxA.x;boxA.y=tmpBoxA.y;boxA.width=tmpBoxA.width;boxA.height=tmpBoxA.height;
boxB.x=tmpBoxB.x;boxB.y=tmpBoxB.y;boxB.width=tmpBoxB.width;boxB.height=tmpBoxB.height;
//boxA=parentA.getBBox();boxA.width=boxA.width*matrixA.a;boxA.height=boxA.height*matrixA.d;
//boxB=parentB.getBBox();boxB.width=boxB.width*matrixB.a;boxB.height=boxB.height*matrixB.d;
boxA.width=boxA.width*matrixA.a;boxA.height=boxA.height*matrixA.d;
boxB.width=boxB.width*matrixB.a;boxB.height=boxB.height*matrixB.d;
//console.log("box A width: "+boxA.width)
//console.log("box B width: "+boxB.width)
//If same owner AND same direction:
if(ownerA.id==ownerB.id && vectorA==vectorB || vm==1){
//First handle an "internal pipe" case
if(parentA.getAttribute("parent")==parentB.id){
//Internal pipe
if(matrixA.e>matrixB.e){
seqA=0;seqB=1;
}
else if(matrixB.e>matrixA.e){
if(vectorA==1){seqA=0;seqB=3;}
else if (vectorA==-1){seqA=3;seqB=0;}
}
}
else if(parentB.getAttribute("parent")==parentA.id){
//Internal pipe
if(matrixA.e>matrixB.e){
if(vectorA==1){seqA=3;seqB=0;}
else if (vectorA==-1){seqA=0;seqB=3;}
}
else if(matrixB.e>matrixA.e){
seqA=1;seqB=0;
}
}
//If X position is the same
else if(matrixA.e==matrixB.e){
//console.log("ping")
//Arc Pipe
type="arcPipe";
seqA=0;seqB=0;
}
//If parentA to the right of parentB
else if(matrixA.e>matrixB.e){
//If it's too close...
if(matrixA.e-matrixB.e<boxB.width){type="arcPipe";seqA=0;seqB=0;}
//If it's further to the right..
else if(matrixA.e-matrixB.e>boxB.width){type="externalPipe";
//Fix: determine which way it's facing
if(vectorA==1){seqA=3;seqB=0;}
else if (vectorA==-1){seqA=0;seqB=3;}
}
}
//If parentB to the right of parentA
else if(matrixB.e>matrixA.e){
if(matrixB.e-matrixA.e<boxA.width){type="arcPipe";seqA=0;seqB=0;}
else if(matrixB.e-matrixA.e>boxA.width){type="externalPipe";
//Fix: determine which way it's facing
if(vectorA==1){seqA=0;seqB=3;}
else if (vectorA==-1){seqA=3;seqB=0;}
}
}
}
//If same owner AND OPPOSITE direction - e.g. HBAs have reverse direction:
if(ownerA.id==ownerB.id && vectorA!=vectorB){
type="externalPipe";
seqA=3;seqB=3;
}
//##########DIFFERENT OWNERS
//If DIFFERENT owners, facing SAME direction:
if(ownerA.id!=ownerB.id && vectorA==vectorB && vm===0){//BUG HERE... WHAT if it's a VM?
type="arcPipe";
seqA=0;seqB=0;
}
//If DIFFERENT owners, facing OPPOSITE directions:
if(ownerA.id!=ownerB.id && vectorA!=vectorB){
type="externalPipe";
seqA=0;seqB=0;
}
connectorA=parentA.parentNode.querySelector(".connector[seq='"+seqA+"']").id;//console.log(connectorA);
connectorB=parentB.parentNode.querySelector(".connector[seq='"+seqB+"']").id;//console.log(connectorB);
//uId=parentA.id+"_"+parentB.id+"_"+Math.random();//console.log(uId);
if(origin==parentA.id){origin=connectorA}else if(origin==parentB.id){origin=connectorB};
//If only refresh is needed - don't create new pipe, just update parents
if (refresh == true) {
d3.select(pipe)
.attr("leftparent",connectorA)
.attr("rightparent",connectorB)
.attr("origin",origin);
var lp = d3.select("#"+connectorA);
var rp = d3.select("#"+connectorB);
if(lp.attr("pipes") === null){
lp.attr("pipes",'1');
}
else{
var lppipes=lp.attr("pipes");
lppipes++;
lp.attr("pipes",lppipes);
}
if(rp.attr("pipes") == null){
rp.attr("pipes",'1');
}
else{
var rppipes=rp.attr("pipes");
rppipes++;
rp.attr("pipes",rppipes);
}
return;
}
var e=createPipe(uId,connectorA,connectorB,origin,type,rateA,rateB,streamId);
return e;
}
function createPipe(pipeUid,parentUidA,parentUidB,origin,type,rate1,rate2,streamId){
//console.log("creating pipe...function create; uId ",pipeUid)
var parentA,parentB,leftParent,rightParent,ownerA,ownerB,level=0;
var e;
if(document.getElementById(pipeUid)){
//console.log("Pipe Exists... function createPipe.");
e = document.getElementById(pipeUid);
}
else{
e = createElement("path",{id:pipeUid});
}
//console.log("Pipe: "+pipeUid+" ParentA: "+parentUidA);console.log("ParentB: "+parentUidB);
if(parentUidA==parentUidB){console.log("Trying to connect to itself - parentA "+parentUidA+" ParentUidB "+parentUidB+"; pipe "+pipeUid+" not created. Exiting function.");return -1;}
parentA=document.getElementById(parentUidA); parentB=document.getElementById(parentUidB);
leftParent=parentA;rightParent=parentB;
lSeq=leftParent.getAttribute("seq");rSeq=rightParent.getAttribute("seq");
var pair=[leftParent.id,rightParent.id];pair.sort();pair=pair.join("_");pair=pair+"_pipe";
ownerA=document.getElementById(parentA.getAttribute("owner"));ownerB=document.getElementById(parentB.getAttribute("owner"));
//Get common owner:
if(parentA.id=="viewport"||parentB.id=="viewport"){var commonParent=document.getElementById("viewport");var commonParentG=commonParent;}
else if(parentA.id==parentB.id){var commonParent=parentA;var commonParentG=commonParent.parentNode}
else{
var parentsA=new Array();
parentsA.push(parentA.id);var lp=parentA;
while(lp.id!="viewport"){
lp=document.getElementById(lp.getAttribute("parent"));
parentsA.push(lp.id);
//console.log(parentsA.length)
}
//console.log(parentsA);
var rp=parentB;
while(rp.id!="viewport"){
//asdf++;console.log(rp.id);console.log(asdf); if(asdf>100){break};
rp=document.getElementById(rp.getAttribute("parent"));
if(parentsA.indexOf(rp.id)!=-1){var commonParent=rp;var commonParentG=commonParent.parentNode;break;}
}
}
commonOwner=document.getElementById(commonParent.getAttribute("owner"));commonOwnerG=commonOwner.parentNode;
//commonParentG=document.getElementById("viewport")
//Find which parent has lower bandwidth - this is your pipe width
var bw=0;var bw1=0;//maxBw = Math.min((leftParent.y2.animVal.value-leftParent.y1.animVal.value),(rightParent.y2.animVal.value-rightParent.y1.animVal.value))
if (typeof(rate1)=='undefined') {bw = Math.min((leftParent.y2.animVal.value-leftParent.y1.animVal.value),(rightParent.y2.animVal.value-rightParent.y1.animVal.value));}
//else if(rate1>maxBw){bw=maxBw}
else{bw=rate1};
if(rate2==null){bw1=bw}else{bw1=rate2}
if(streamId==null){streamId=0}
if(leftParent.getAttribute("pipes")==null){
leftParent.setAttribute("pipes",'1');
leftPipes=1;
}
else{
leftPipes=leftParent.getAttribute("pipes");
leftPipes++;
leftParent.setAttribute("pipes",(leftPipes));
}
if(rightParent.getAttribute("pipes")==null){
rightParent.setAttribute("pipes",'1')
rightPipes=1;
}
else{
rightPipes=rightParent.getAttribute("pipes");
rightPipes++;
rightParent.setAttribute("pipes",(rightPipes));
}
//pPair=[leftParent.id.id,rightParent.id];pPair.sort();pPair=pPair.join("_");pPair=pPair+"_pipe";
if(type=="internalPipe"){
//Pipe-specific settings
setAttributes(e,{id:pipeUid,d:"M0,0","pair":pair,"origin":origin,"bw":bw,"bw1":bw1,"leftparent":leftParent.id,"rightparent":rightParent.id,"level":level,"stream":streamId});
//Presentation settings from the template
setAttributes(e,itemTemplate['internalPipe']);
//setAttributes(e,{id:pipeUid,d:"M0,0","type":"internalPipe","class":"pipe","pair":pair,"origin":origin,
// "stroke-width":0.01,stroke:"black","fill":"green","fill-opacity":"0.4","stroke-opacity":"1",
// "bw":bw,"bw1":bw1,"leftparent":leftParent.id,"rightparent":rightParent.id,"level":level,"stream":streamId,"template":"internalPipe"});//console.log(e)
if(ownerA.id==ownerB.id){e.setAttribute("owner",commonOwner.id);}//appendElement(commonOwnerG,e);}
else{console.log("Doesn't look like an internal pipe... the owners are different: OwnerA: "+ownerA.id+" OwnerB: "+ownerB.id);e.setAttribute("owner",commonOwner.id);}//appendElement(commonOwnerG,e);}
rightParent.parentNode.setAttribute("connected","true");leftParent.parentNode.setAttribute("connected","true");
}
else if(type=="arcPipe"){
//Pipe-specific settings
setAttributes(e,{id:pipeUid,d:"M0,0","pair":pair,"origin":origin,"bw":bw,"bw1":bw1,"leftparent":leftParent.id,"rightparent":rightParent.id,"level":level,"stream":streamId});
//Presentation settings from the template
setAttributes(e,itemTemplate['arcPipe']);
//setAttributes(e,{id:pipeUid,d:"M0,0","type":type,"class":"pipe","pair":pair,"origin":origin,
// "stroke-width":0.01,stroke:"red","fill":"steelblue","fill-opacity":"0.4","stroke-opacity":"1",
// "bw":bw,"bw1":bw1,"leftparent":leftParent.id,"rightparent":rightParent.id,"level":level,"stream":streamId,"template":"arcPipe"});//console.log(e)
//Next statement tries to figure out if pipes belong to the same server - adds them to the server group to prevent unnecessary calulations
e.setAttribute("owner",commonOwner.id);
rightParent.parentNode.setAttribute("connected","true");leftParent.parentNode.setAttribute("connected","true");
}
else{
//Pipe-specific settings
setAttributes(e,{id:pipeUid,d:"M0,0","pair":pair,"origin":origin,"bw":bw,"bw1":bw1,"leftparent":leftParent.id,"rightparent":rightParent.id,"level":level,"stream":streamId});
//Presentation settings from the template
setAttributes(e,itemTemplate['externalPipe']);
//setAttributes(e,{id:pipeUid,d:"M0,0","type":"externalPipe","class":"pipe","pair":pair,"origin":origin,
// "stroke-width":0.005,stroke:"red","fill":"green","fill-opacity":"0.4","stroke-opacity":"1",
// "bw":bw,"bw1":bw1,"leftparent":leftParent.id,"rightparent":rightParent.id,"level":level,"stream":streamId,"template":"externalPipe"});//console.log(e)
e.setAttribute("owner",commonOwner.id);
}
var leftParentGroupNode=leftParent.parentNode;var rightParentGroupNode=rightParent.parentNode;
leftParentGroupNode.setAttribute("connected","true");rightParentGroupNode.setAttribute("connected","true");
while (true){
if (leftParentGroupNode.id!=commonOwnerG.id){
leftParentGroupNode=leftParentGroupNode.parentNode;
leftParentGroupNode.setAttribute("connected","true");
}
if (rightParentGroupNode.id!=commonOwnerG.id){
rightParentGroupNode=rightParentGroupNode.parentNode;
rightParentGroupNode.setAttribute("connected","true");
}
if(leftParentGroupNode.id==commonOwnerG.id && rightParentGroupNode.id==commonOwnerG.id){
appendElement(commonParentG,e);break;
}
}
appendElement(commonParentG,e)
d3.select(e).datum(function(d){if(!d || d.name==null){
var obj=new Object();obj.name=this.id;return obj;}
else return d;});
//Reshuffle existing pipes to evenly distribute them
//collectedConns=collectConns(document.getElementById(origin));
//collectedConns=positionPipesNew(collectedConns);
//dragPipes(collectedConns.pipes);
//updatePipes(pipeUid,bw,bw1);
return e;
}
function createPipeObject(pipeUid,conn,loc){
//console.log(pipeUid)
var mPipe=new Object();
mPipe.pipe=document.getElementById(pipeUid)//set an array member with pipe element
//mPipe.pipeUid=mPipe.pipe.id;
mPipe.id=mPipe.pipe.id;
mPipe.origin=mPipe.pipe.getAttribute("origin");
var lpattr = mPipe.pipe.getAttribute("leftparent");
var rpattr = mPipe.pipe.getAttribute("rightparent");
//console.log("Connected pipe: "+pipes[x].id)
var lp=document.getElementById(lpattr);
var rp=document.getElementById(rpattr);
if (lp == null) {
//Endpoint is potentially marked for removal
var lp=document.getElementById(lpattr+"_dead");
if (lp == null) {
console.log("One of pipe parents can't be found...");
//Endpoint is potentially marked for removal
}
else{
mPipe.pipe.setAttribute("leftparent",lpattr+"_dead")
if (mPipe.origin == lpattr) {
mPipe.origin = lpattr+"_dead";
mPipe.pipe.setAttribute("origin",lpattr+"_dead")
}
}
}
if (rp == null) {
//Endpoint is potentially marked for removal
var rp=document.getElementById(rpattr+"_dead");
if (rp == null) {
console.log("One of pipe parents can't be found...");
//Endpoint is potentially marked for removal
}
else{
mPipe.pipe.setAttribute("rightparent",rpattr+"_dead")
if (mPipe.origin == rpattr) {
mPipe.origin = rpattr+"_dead";
mPipe.pipe.setAttribute("origin",rpattr+"_dead")
}
}
}
//console.log("Left,Right, and Conns");console.log(lp.id);console.log(rp.id);;console.log(sConns[i]);
if(loc==1 || loc==3){
//console.log("Location 1 or 3")
if(lp==conn){mPipe.movingConnector=lp;mPipe.staticConnector=rp;mPipe.movingConnectorId=mPipe.movingConnector.id;mPipe.staticConnectorId=mPipe.staticConnector.id;}
else if(rp==conn){mPipe.movingConnector=rp;mPipe.staticConnector=lp;mPipe.movingConnectorId=mPipe.movingConnector.id;mPipe.staticConnectorId=mPipe.staticConnector.id;}
}
if(loc==2){
//console.log("Location 2")
if(lp==conn){mPipe.movingConnector=rp;mPipe.staticConnector=lp;mPipe.movingConnectorId=mPipe.movingConnector.id;mPipe.staticConnectorId=mPipe.staticConnector.id;}
else if(rp==conn){mPipe.movingConnector=lp;mPipe.staticConnector=rp;mPipe.movingConnectorId=mPipe.movingConnector.id;mPipe.staticConnectorId=mPipe.staticConnector.id;}
}
var mp=root.createSVGPoint();var sp=root.createSVGPoint();var start=root.createSVGPoint();var end=root.createSVGPoint();
start.x=mPipe.pipe.raw_start_x || '';
start.y=mPipe.pipe.raw_start_y || '';
//console.log(start.y)
end.x=mPipe.pipe.raw_end_x || '';
end.y=mPipe.pipe.raw_end_y || '';
mPipe.pipeScale=mPipe.pipe.parentNode.getCTM().a/mapMatrix.a;
if(mPipe.origin==mPipe.staticConnectorId){
//start=start.matrixTransform(mPipe.staticConnector.getCTM()).matrixTransform(mapMatrix.inverse());
//end=end.matrixTransform(mPipe.movingConnector.getCTM()).matrixTransform(mapMatrix.inverse());
start=start.matrixTransform(mPipe.staticConnector.getCTM()).matrixTransform(mPipe.pipe.getCTM().inverse());
end=end.matrixTransform(mPipe.movingConnector.getCTM()).matrixTransform(mPipe.pipe.getCTM().inverse());
//console.log(end.y)
mPipe.scale=mPipe.staticConnector.getCTM().a/mapMatrix.a;
mPipe.scale1=mPipe.movingConnector.getCTM().a/mapMatrix.a;
if(mPipe.pipeScale==mPipe.scale && mPipe.pipeScale==mPipe.scale1){
//console.log("Same scale: pipe "+mPipe.id);
mPipe.scale=1;mPipe.scale1=1;
//mPipe.pipe.setAttribute("transform","scale(8,8)")
}
mPipe.staticConnectorBw=mPipe.staticConnector.getAttribute("bw")*mPipe.scale;
mPipe.movingConnectorBw=mPipe.movingConnector.getAttribute("bw")*mPipe.scale1;
mp.x=mPipe.movingConnector.x1.animVal.value;mp.y=mPipe.movingConnector.y1.animVal.value+(mPipe.movingConnectorBw/2/mPipe.scale1);
sp.x=mPipe.staticConnector.x1.animVal.value;sp.y=mPipe.staticConnector.y1.animVal.value+(mPipe.staticConnectorBw/2/mPipe.scale);
mPipe.bw=Number(mPipe.pipe.getAttribute("bw"))*mPipe.scale;
//console.log(mPipe.bw)
mPipe.bw1=Number(mPipe.pipe.getAttribute("bw1"))*mPipe.scale1;
//console.log(mPipe.bw1)
if (mPipe.bw>mPipe.staticConnectorBw){
//console.log("Too much bw for this connector! Shrinking pipe bw... Pipe: "+mPipe.id);
nBw=mPipe.staticConnectorBw;
//mPipe.pipe.setAttribute("bw",nBw);
mPipe.bw=nBw;
}
if (mPipe.bw1>mPipe.movingConnectorBw){
//console.log("Too much bw for this connector! Shrinking pipe bw... Pipe: "+mPipe.id);
nBw=mPipe.movingConnectorBw;
//mPipe.pipe.setAttribute("bw1",nBw);
mPipe.bw1=nBw;
}
}
else if(mPipe.origin==mPipe.movingConnectorId){
//start=start.matrixTransform(mPipe.movingConnector.getCTM()).matrixTransform(mapMatrix.inverse());
//end=end.matrixTransform(mPipe.staticConnector.getCTM()).matrixTransform(mapMatrix.inverse());
start=start.matrixTransform(mPipe.movingConnector.getCTM()).matrixTransform(mPipe.pipe.getCTM().inverse());
end=end.matrixTransform(mPipe.staticConnector.getCTM()).matrixTransform(mPipe.pipe.getCTM().inverse());
//console.log(end.y)
mPipe.scale1=mPipe.staticConnector.getCTM().a/mapMatrix.a;
mPipe.scale=mPipe.movingConnector.getCTM().a/mapMatrix.a;
if(mPipe.pipeScale==mPipe.scale && mPipe.pipeScale==mPipe.scale1){
//console.log("Same scale: pipe "+mPipe.id);
mPipe.scale=1;mPipe.scale1=1;
//mPipe.pipe.setAttribute("transform","scale(8,8)")
}
mPipe.staticConnectorBw=mPipe.staticConnector.getAttribute("bw")*mPipe.scale1;
mPipe.movingConnectorBw=mPipe.movingConnector.getAttribute("bw")*mPipe.scale;
mp.x=mPipe.movingConnector.x1.animVal.value;mp.y=mPipe.movingConnector.y1.animVal.value+(mPipe.movingConnectorBw/2/mPipe.scale);
sp.x=mPipe.staticConnector.x1.animVal.value;sp.y=mPipe.staticConnector.y1.animVal.value+(mPipe.staticConnectorBw/2/mPipe.scale1);
mPipe.bw=Number(mPipe.pipe.getAttribute("bw"))*mPipe.scale;
//console.log(mPipe.bw)
mPipe.bw1=Number(mPipe.pipe.getAttribute("bw1"))*mPipe.scale1;
//console.log(mPipe.bw1)
if (mPipe.bw>mPipe.movingConnectorBw){
//console.log("Too much bw for this connector! Shrinking pipe bw... Pipe: "+mPipe.id);
nBw=mPipe.movingConnectorBw;
//mPipe.pipe.setAttribute("bw",nBw);
mPipe.bw=nBw;
}
if (mPipe.bw1>mPipe.staticConnectorBw){
//console.log("Too much bw for this connector! Shrinking pipe bw... Pipe: "+mPipe.id);
nBw=mPipe.staticConnectorBw;
//mPipe.pipe.setAttribute("bw1",nBw);
mPipe.bw1=nBw;
}
}
mPipe.movingXYPoint=mp;mPipe.staticXYPoint=sp;
mPipe.movingPoint=mp.matrixTransform(mPipe.movingConnector.getCTM()).matrixTransform(mapMatrix.inverse());
mPipe.staticPoint=sp.matrixTransform(mPipe.staticConnector.getCTM()).matrixTransform(mapMatrix.inverse());
//console.log(start);console.log(end);
mPipe.pipe.start_x=start.x;mPipe.pipe.start_y=start.y;
mPipe.pipe.end_x=end.x;mPipe.pipe.end_y=end.y;
mPipe.staticSiblings=mPipe.staticConnector.getAttribute("pipes");
mPipe.movingSiblings=mPipe.movingConnector.getAttribute("pipes");
//if(mPipe.movingPoint.y<mPipe.staticPoint.y) {mPipe.topBorder=viewportTop;mPipe.bottomBorder=mPipe.staticPoint.y};
//if(mPipe.movingPoint.y>mPipe.staticPoint.y) {mPipe.topBorder=mPipe.staticPoint.y;mPipe.bottomBorder=viewportBottom};
mPipe.type=mPipe.pipe.getAttribute("type");
if(mPipe.type=="arcPipe"){
mPipe.vector=mPipe.movingConnector.getAttribute("vector");
mPipe.pipe.vector = mPipe.vector;
}
mPipe.flip=0;
//Try to control scale
//Test scaled down bw
//mConns[i][k].q=mConns[i][k].movingConnector.getCTM().a*mapMatrix.inverse().a;
mPipe.q=1;
mPipe.pipe.bw=mPipe.bw;
mPipe.pipe.bw1=mPipe.bw1;
return mPipe;
}
function collectConns(evtTarget){
//This function prepares lists of connections and associated pipes for move/reshuffle.
connected="true";//console.log("connected");//the group has connections to other groups
var x = 0;var u=0;var m=0;//var sc=0;
var p=new Array();var s = new Array();
var mConns = new Array();var sConns = new Array();var sConnsR = new Array();var pipes = new Array();
pipes.length=0;p.length=0;mConns.length=0;sConns.length=0;sConnsR.length=0;
//console.log(evtTarget.parentNode)
var connectors=evtTarget.parentNode.querySelectorAll(".connector[pipes]");//console.log(connectorClass);
//console.log("This many connectors: ",connectors.length)
//console.log("Connectors: ",connectors)
//for (var n=0,cl=connectorClass.length;n<cl;n++){connectors[n]=connectorClass[n]}
for (var i=0,cl=connectors.length;i<cl;i++){
if(connectors[i].hasAttribute("pipes")){
//find connectors with pipes
var l=1;
var pp=document.querySelectorAll("path[rightparent="+connectors[i].id+"],path[leftparent="+connectors[i].id+"]");//console.log(pp);
for(var z=0,cp=pp.length;z<cp;z++){
//determine how many pipes the connector has and cycle through them - min one pipe
var ppo=pp[z].getAttribute("owner");
var pplp=pp[z].getAttribute("leftparent");
var pprp=pp[z].getAttribute("rightparent");
//console.log(evtTarget.parentNode.querySelector("#"+ppo))
if(evtTarget.parentNode.querySelector("#"+ppo)==null){l=0}//If the owner of the pipe doesn't belong to event target - the pipe isn't local
if(evtTarget.parentNode.querySelector("#"+pplp)!=null){
if(evtTarget.parentNode.querySelector("#"+pprp)!=null){l=1}//if both left and right parents are under target - the pipe is local
}
}
if(mConns.indexOf(connectors[i].id)==-1 && l==0){mConns.push(connectors[i].id)};
}
}
for (var i=0,cl=mConns.length;i<cl;i++){
var mc=document.getElementById(mConns[i]);
var mp=document.querySelectorAll("path[rightparent="+mc.id+"],path[leftparent="+mc.id+"]");
for (var e=0,mcp=mp.length;e<mcp;e++){
if(p.indexOf(mp[e].id)==-1){
p.push(mp[e].id);var px=pipes.push(createPipeObject(mp[e].id,mc,1));px=px-1;
var lp=pipes[px].pipe.getAttribute("leftparent");var rp=pipes[px].pipe.getAttribute("rightparent");
var sc=lp;if(lp==mc.id){sc=rp;}
if(sConns.indexOf(sc)==-1){sConns.push(sc)}//Note: could be arc connected to another sConn
}
}
}
//This creates a second array of static connectors ids
for (var i=0,cl=sConns.length;i<cl;i++){
var sc=document.getElementById(sConns[i]);
var sp=document.querySelectorAll("path[rightparent="+sc.id+"],path[leftparent="+sc.id+"]");
for (var e=0,scp=sp.length;e<scp;e++){
if(p.indexOf(sp[e].id)==-1){
p.push(sp[e].id);var px=pipes.push(createPipeObject(sp[e].id,sc,2));px=px-1;
var lp=pipes[px].pipe.getAttribute("leftparent");var rp=pipes[px].pipe.getAttribute("rightparent");
var scr=lp;if(lp==sc.id){scr=rp;}
if(sConnsR.indexOf(scr)==-1 && mConns.indexOf(scr)==-1){sConnsR.push(scr)}//Note: could be arc connected to another sConn
}
}
}
//This creates a third array of remote static connectors ids
for (var i=0,cl=sConnsR.length;i<cl;i++){
var rsc=document.getElementById(sConnsR[i]);
var rsp=document.querySelectorAll("path[rightparent="+rsc.id+"],path[leftparent="+rsc.id+"]");
for(var z=0,cp=rsp.length;z<cp;z++){
if(p.indexOf(rsp[z].id)==-1){//This pipe will not have endx,y calculated. Need to do it now.
p.push(rsp[z].id);var idx=pipes.push(createPipeObject(rsp[z].id,rsc,3));idx=idx-1;//console.log(pipes[idx])
var lp=pipes[idx].pipe.getAttribute("leftparent");var rp=pipes[idx].pipe.getAttribute("rightparent");
var scr=lp;if(lp==rsc.id){scr=rp;}
//if(sConnsR.indexOf(scr)!=-1){pipes[idx].loop=1;}
pipes[idx].start_x=pipes[idx].pipe.start_x;pipes[idx].start_y=pipes[idx].pipe.start_y;//console.log(pipes[idx].start_y)
pipes[idx].end_x=pipes[idx].pipe.end_x;pipes[idx].end_y=pipes[idx].pipe.end_y;//console.log(pipes[idx].end_y);console.log(pipes[idx])
}
}
}
//Test scaled down bw
//mConns[i][k].q=mConns[i][k].movingConnector.getCTM().a*mapMatrix.inverse().a;
//Create three actual arrays with cross-reference to shared pipes
for (var i=0,cl=mConns.length;i<cl;i++){
var pp=document.getElementById(mConns[i]);
mConns[i]=new Array;mConns[i].id=pp.id;mConns[i].scale=pp.getCTM().a*mapMatrix.inverse().a;mConns[i].bw=pp.getAttribute("bw")/**mConns[i].scale*/;mConns[i].actualBw=0;
var pn=document.querySelectorAll("path[rightparent="+pp.id+"],path[leftparent="+pp.id+"]");
for(var z=0,cp=pn.length;z<cp;z++){
mConns[i][z]=pipes[p.indexOf(pn[z].id)];//console.log(mConns[i][z-1])
if(mConns[i][z].origin==mConns[i].id){var pBw=mConns[i][z].bw}else{var pBw=mConns[i][z].bw1}
mConns[i].actualBw=mConns[i].actualBw+pBw;
}
}
for (var i=0,cl=sConns.length;i<cl;i++){
var pp=document.getElementById(sConns[i]);
sConns[i]=new Array;sConns[i].id=pp.id;sConns[i].scale=pp.getCTM().a*mapMatrix.inverse().a;sConns[i].bw=pp.getAttribute("bw")/**sConns[i].scale*/;sConns[i].actualBw=0;
var pn=document.querySelectorAll("path[rightparent="+pp.id+"],path[leftparent="+pp.id+"]");
for(var z=0,cp=pn.length;z<cp;z++){
sConns[i][z]=pipes[p.indexOf(pn[z].id)];//console.log(mConns[i][z-1])
if(sConns[i][z].origin==sConns[i].id){var pBw=sConns[i][z].bw}else{var pBw=sConns[i][z].bw1}
sConns[i].actualBw=sConns[i].actualBw+pBw;
}
}
for (var i=0,cl=sConnsR.length;i<cl;i++){
var pp=document.getElementById(sConnsR[i]);
sConnsR[i]=new Array;sConnsR[i].id=pp.id;sConnsR[i].scale=pp.getCTM().a*mapMatrix.inverse().a;sConnsR[i].bw=pp.getAttribute("bw")/**sConnsR[i].scale*/;sConnsR[i].actualBw=0;
var pn=document.querySelectorAll("path[rightparent="+pp.id+"],path[leftparent="+pp.id+"]");
for(var z=0,cp=pn.length;z<cp;z++){
sConnsR[i][z]=pipes[p.indexOf(pn[z].id)];//console.log(mConns[i][z-1])
if(sConnsR[i][z].origin==sConnsR[i].id){var pBw=sConnsR[i][z].bw}else{var pBw=sConnsR[i][z].bw1}
sConnsR[i].actualBw=sConnsR[i].actualBw+pBw;
}
}
var collectedConns=new Object();
collectedConns.mConns=mConns;
collectedConns.sConns=sConns;
collectedConns.sConnsR=sConnsR;
collectedConns.pipes=pipes;
return collectedConns;
}
function collectConnsUpdate(connectors){
//This function prepares lists of connections and associated pipes for move/reshuffle.
connected="true";//console.log("connected");//the group has connections to other groups
var x = 0;var u=0;var m=0;//var sc=0;
var p=new Array();var s = new Array();
var mConns = new Array();var sConns = new Array();var sConnsR = new Array();var pipes = new Array();
pipes.length=0;p.length=0;mConns.length=0;sConns.length=0;sConnsR.length=0;
//console.log(evtTarget.parentNode)
//var connectors=evtTarget.parentNode.querySelectorAll(".connector[pipes]");//console.log(connectorClass);
//for (var n=0,cl=connectorClass.length;n<cl;n++){connectors[n]=connectorClass[n]}
for (var i=0,cl=connectors.length;i<cl;i++){
if(connectors[i] && connectors[i].hasAttribute("pipes")){//Confirm that connector exists
//find connectors with pipes
var l=0;
var pp=document.querySelectorAll("path[rightparent="+connectors[i].id+"],path[leftparent="+connectors[i].id+"]");//console.log(pp);
for(var z=0,cp=pp.length;z<cp;z++){
//determine how many pipes the connector has and cycle through them - min one pipe
var ppo=pp[z].getAttribute("owner");
var pplp=pp[z].getAttribute("leftparent");
var pprp=pp[z].getAttribute("rightparent");
//console.log(evtTarget.parentNode.querySelector("#"+ppo))
//if(evtTarget.parentNode.querySelector("#"+ppo)==null){l=0}//If the owner of the pipe doesn't belong to event target - the pipe isn't local
//if(evtTarget.parentNode.querySelector("#"+pplp)!=null){
// if(evtTarget.parentNode.querySelector("#"+pprp)!=null){l=1}//if both left and right parents are under target - the pipe is local
//}
}
if(mConns.indexOf(connectors[i].id)==-1 && l==0){mConns.push(connectors[i].id)};
}
}
for (var i=0,cl=mConns.length;i<cl;i++){
var mc=document.getElementById(mConns[i]);
var mp=document.querySelectorAll("path[rightparent="+mc.id+"],path[leftparent="+mc.id+"]");
for (var e=0,mcp=mp.length;e<mcp;e++){
if(p.indexOf(mp[e].id)==-1){
p.push(mp[e].id);var px=pipes.push(createPipeObject(mp[e].id,mc,1));px=px-1;
var lp=pipes[px].pipe.getAttribute("leftparent");var rp=pipes[px].pipe.getAttribute("rightparent");
var sc=lp;if(lp==mc.id){sc=rp;}
if(sConns.indexOf(sc)==-1){sConns.push(sc)}//Note: could be arc connected to another sConn
}