-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbayespilesML.html
2294 lines (1955 loc) · 74.6 KB
/
bayespilesML.html
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
<!DOCTYPE html>
<html
>
<head>
<link rel="stylesheet" type="text/css" href="bayespiles-styles.css">
</head>
<title>BayesPiles</title>
<body>
<div id="mainMenu">
<div id="sessions">
<div id="bpc">
<!--
<button type="button" onclick="saveSession()">Save Session</button>
<button type="button" onclick="exportSession()">Export Session</button>
<button type="button" onclick="undo()" hidden>Undo</button>
<button type="button" onclick="redo()" hidden>Redo</button>
Animate: <input id="animateCheckBox"type="checkbox" checked/>
Zoom: <input id="cellSizeBox" type="range" name="cellSizeBox" min="1" max="20" onchange="updateCellSize()" value="4"/>
TV Commented-->
<!-- <br/> -->
<!-- <label>Session Name: </label><input type="text" id="sessionName" size="80"> -->
<!-- </div> -->
<!-- <br/> -->
<!-- <div id="pileMenu"> -->
<label class="sliderLabel">Sorted by:</label>
<input type = "radio"
name = "sortBy"
onchange = "sortNetworks(this);"
id = "sort_run_id"
value = "run" />
<!-- TVchecked = "checked" /> -->
<label for = "sort_run_id" class="sliderLabel">run ID</label>
<input type = "radio"
name = "sortBy"
onchange = "sortNetworks(this);"
id = "sort_desc"
value = "descending" />
<label for = "sort_desc" class="sliderLabel">score</label>
<input type = "radio"
name = "sortBy"
onchange = "sortNetworks(this);"
id = "sort_iteration"
value = "ascending" />
<label for = "sort_iteration" class="sliderLabel">iteration</label>
<label class="sliderLabel">Node Order:</label>
<select id="allNodeOrder" onchange="allNodeOrderChanged()">
<option class="sliderLabel">Data: As indicated in data</option>
<option class="sliderLabel">Global: Same for all matrices </option>
<option class="sliderLabel" hidden>Individual: Optimized for each pile</option>
</select>
<label class="sliderLabel">Cover Matrix:</label>
<select id="allCover" onchange="allCoverChanged()">
<option class="sliderLabel">Summary</option>
<option hidden>Bar Charts</option>
<option hidden>Trend</option>
<option hidden>Variability</option>
<option class="sliderLabel" hidden>Sequential Difference</option>
<option class="sliderLabel">Direct Difference (to hovered matrix)</option>
</select>
<!-- TV </div> -->
<!-- TV
<div>
<button class="descend">sort descending</button>
<button class="byDataSet">sort by data set</button>
</div>
-->
<!-- TV
<label class="sliderLabel">Sorted by:</label>
<select id="allSort" onchange="sortNets();">
<option class="sliderLabel">run ID</option>
<option class="sliderLabel">score</option>
<option class="sliderLabel">iteration</option>
</select>
-->
<text class="sliderLabel">Zoom:</text> <input id="cellSizeBox" type="range" name="cellSizeBox" min="1" max="20" onchange="updateCellSize();updateZoomPercentage(this.value);" value="6"/><input type="text" style="width: 30px; class="sliderLabel" id="zoomPerc" value="" readonly>
<label for = "gr_id" class="sliderLabel">Grid:</label>
<input type="checkbox" id="gr_id" name="grid_checkbox" onchange="redrawPiles(piles);"/>
<!-- TV <form id="filterNodesForm"> -->
<text class="sliderLabel">Filter nodes:<text> <input type="checkbox" id="cbox4" name="node_filter_checkbox" onchange="updateControls(this);redrawPiles(piles);"/><input id="connectivityThresSlider" type="range" name="connectivityThres" min="0" max="100" onchange="redrawPiles(piles);updateConnectivity(this.value);" value="0" disabled="true"/><input type="text" style="width: 30px;" class="sliderLabel" id="textCon" value="" readonly>
<!-- TV </form> -->
<!-- TV<form id="filterEdgesForm">-->
<text class="sliderLabel">Filter edges:<text> <input type="checkbox" id="cbox" name="edge_filter_checkbox" onchange="updateControls(this);redrawPiles(piles);"/><input id="percentageThresSlider" type="range" name="percentageThres" min="0" max="100" onchange="redrawPiles(piles);updatePercentage(this.value);" value="0" disabled="true"/><input type="text" style="width: 30px;" class="sliderLabel" id="textPerc" value="" readonly>
<!-- TV</form> -->
<label class="sliderLabel">Mode:</label>
<input hidden type = "radio"
name = "modeOf"
onchange = "redrawPiles(piles);timeline.updateLayout(0,false);allCoverChanged();"
id = "top-down_id"
value = "top-down"
checked = "checked" />
<label hidden for = "top-down_id" class="sliderLabel">Top-Down</label>
<input hidden type = "radio"
name = "modeOf"
onchange = "redrawPiles(piles);timeline.updateLayout(0,false);allCoverChanged();"
id = "dim_id"
value = "ascending" />
<label hidden for = "dim_id" class="sliderLabel">Diamond</label>
<input hidden type = "radio"
name = "modeOf"
onchange = "redrawPiles(piles);timeline.updateLayout(0,false);allCoverChanged();"
id = "sk_id"
value = "descending" />
<label hidden for = "sk_id" class="sliderLabel">Skeleton</label>
<!-- ML related modes -->
<input hidden type = "radio"
name = "modeOf"
onchange = "redrawPiles(piles);timeline.updateLayout(0,false);allCoverChanged();"
id = "order_id"
value = "order"
checked = "checked" />
<label hidden for = "order_id" class="sliderLabel">Order</label> <!-- ML related -->
<input hidden type = "radio"
name = "modeOf"
onchange = "redrawPiles(piles);timeline.updateLayout(0,false);allCoverChanged();"
id = "orderCol_id"
value = "order"
checked = "checked" />
<label hidden for = "orderCol_id" class="sliderLabel">Order+Colour</label> <!-- ML related -->
<input hidden type = "radio"
name = "modeOf"
onchange = "redrawPiles(piles);timeline.updateLayout(0,false);allCoverChanged();"
id = "orien_id"
value = "descending" />
<label hidden for = "orien_id" class="sliderLabel">Orientation</label>
<input type = "radio"
name = "modeOf"
onchange = "redrawPiles(piles);timeline.updateLayout(0,false);allCoverChanged();"
id = "orien2_id"
value = "descending"
checked = "checked" />
<label for = "orien2_id" class="sliderLabel">Orientation</label>
<input type = "radio"
name = "modeOf"
onchange = "redrawPiles(piles);timeline.updateLayout(0,false);allCoverChanged();"
id = "orienCol_id"
value = "descending" />
<label for = "orienCol_id" class="sliderLabel">Orientation+Colour</label>
<input type="textarea" rows="1" id="filteredNodesList" placeholder="filtered nodes appear here." value="" readonly>
<!--TV
<table class="fixed">
<col width="10%" />
<col width="3%" />
<col width="23%" />
<col width="6%" />
<tr>
<td><text class="sliderLabel">Zoom:</text></td><td> </td><td> <input id="cellSizeBox" type="range" name="cellSizeBox" min="1" max="20" onchange="updateCellSize()" value="6"/></td><td></td><td></td>
</tr>
<tr>
<form id="filterEdgesForm">
<td><text class="sliderLabel">Filter edges:<text></td><td> <input type="checkbox" id="cbox" name="edge_filter_checkbox" onchange="updateControls(this);redrawPiles(piles);"/></td><td><input id="percentageThresSlider" type="range" name="percentageThres" min="0" max="100" onchange="redrawPiles(piles);updatePercentage(this.value);" value="0" disabled="true"/></td><td style="width: 100%;"><input type="text" class="sliderLabel" id="textPerc" value="" readonly></td><td></td>
</form>
</tr>
<tr>
<form id="filterNodesForm">
<td><text class="sliderLabel">Filter nodes:<text></td><td> <input type="checkbox" id="cbox4" name="node_filter_checkbox" onchange="updateControls(this);redrawPiles(piles);"/></td><td><input id="connectivityThresSlider" type="range" name="connectivityThres" min="0" max="100" onchange="redrawPiles(piles);updateConnectivity(this.value);" value="0" disabled="true"/></td><td><input type="text" id="textCon" value="" readonly></td><td><input type="textarea" rows="1" id="filteredNodesList" placeholder="filtered nodes appear here." value="" readonly></td>
</form>
</tr>
-->
<!--TV
<tr>
<form id="showAAH">
<td><text class="sliderLabel">Diamond mode:<text></td><td> <input type="checkbox" id="cbox2" name="direction_checkbox" onchange="updateControls(this);redrawPiles(piles);"/></td><td></td></td><td></td>
</form>
</tr>
<tr>
<form id="skelMode">
<td><text class="sliderLabel">Skeleton mode:<text></td><td> <input type="checkbox" id="cbox3" name="skeleton_checkbox" onchange="updateControls(this);redrawPiles(piles);timeline.updateLayout(0,false);"/></td><td></td></td><td></td>
</form>
</tr>
-->
<!--TV </table> -->
</div>
<!--TV <div>
<label class="sliderLabel">Mode:</label>
<input type = "radio"
name = "modeOf"
onchange = "redrawPiles(piles);timeline.updateLayout(0,false);allCoverChanged();"
id = "top-down_id"
value = "top-down"
checked = "checked" />
<label for = "top-down_id" class="sliderLabel">Top-Down</label>
<input type = "radio"
name = "modeOf"
onchange = "redrawPiles(piles);timeline.updateLayout(0,false);allCoverChanged();"
id = "dim_id"
value = "ascending" />
<label for = "dim_id" class="sliderLabel">Diamond</label>
<input type = "radio"
name = "modeOf"
onchange = "redrawPiles(piles);timeline.updateLayout(0,false);allCoverChanged();"
id = "sk_id"
value = "descending" />
<label for = "sk_id" class="sliderLabel">Skeleton</label>
</div>
-->
<div id="chartTimeline" style="margin-top:10px"></div>
<div id="pilesPlot" height="1000"></div>
<!--TV </div> -->
<script src="lib/d3.min.js"></script>
<script src="lib/jquery.js"></script>
<script src="lib/colors.js"></script>
<script src="lib/science.js"></script>
<script src="lib/reorder.js"></script>
<script src="lib/jstorage.js"></script>
<script src="lib/three.min.js"></script>
<script src="lib/glUtilsML.js"></script>
<script src="lib/OrbitControls.js"></script>
<script src="classes/pileML.js"></script>
<script src="classes/matrixML.js"></script>
<script src="classes/timelineML.js"></script>
<script src="classes/slider.js"></script>
<script src="classes/PileTools.js"></script>
<script src="classes/sessions.js"></script>
<script src="classes/pileutilsML.js"></script>
<script src="classes/animations.js"></script>
<script src="fonts/gentilis_bold.typeface.js"></script>
<script src="fonts/gentilis_regular.typeface.js"></script>
<script src="fonts/optimer_bold.typeface.js"></script>
<script src="fonts/optimer_regular.typeface.js"></script>
<script src="fonts/helvetiker_bold.typeface.js"></script>
<script src="fonts/helvetiker_regular.typeface.js"></script>
<script src="fonts/droid/droid_sans_regular.typeface.js"></script>
<script src="fonts/droid/droid_sans_bold.typeface.js"></script>
<script src="fonts/droid/droid_serif_regular.typeface.js"></script>
<script src="fonts/droid/droid_serif_bold.typeface.js"></script>
<!-- TV <script src="http://www.macwright.org/simple-statistics/simple_statistics.js"></script> -->
<script type="x-shader/x-vertex" id="vertexshader">
attribute vec3 customColor;
varying vec3 vColor;
void main() {
vColor = customColor;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
</script>
<script type="x-shader/x-fragment" id="fragmentshader">
varying vec3 vColor;
void main() {
gl_FragColor = vec4( vColor, 1);
}
</script>
<script>
// SETTINGS
var SHOW_MATRICES = 1000;
var FILE = "data/Parkinsons_Patient_RC4101_1_graphdat.json"
var SHOW_ANTICORRELATION = false;
var PRE_PILE = false;
var CELL_THRESHOLD = 0.0; // only cells above are shown
var SNAKE = true;
var TIMELINE_HEIGHT = 180; //130; TV
// var TIMELINE_HEIGHT = 0;
var DIAGONAL_VALUE = 0.11;
var SVG_MENU_HEIGHT = 30;
var LABEL_DIST = 60;
var LABEL_WIDTH = 130;
// var CELL_SIZE = 10
var CELL_SIZE = 6
var CELL_SIZE_HALF = CELL_SIZE/2;
var PREVIEW_SIZE = 3
var MARGIN_TOP = 70;
var MARGIN_BOTTOM = 30;
var MARGIN_RIGHT = 20;
var MARGIN_LEFT = 80;
var MATRIX_GAP_VERTICAL = 30;
var MATRIX_GAP_HORIZONTAL = 10;
var PILE_TOOL_SIZE = 15
var svg, svgTimeline, svgMenu;
// Animation
var FPS = 20
var DURATION = 500
var waitWindow // shown when server calculates similarity
// var _courseWidth = $(window).width() - MARGIN_LEFT - MARGIN_RIGHT;
// var _courseHeight = $(window).height() +200//- MARGIN_LEFT - MARGIN_RIGHT;
var _courseWidth = $(window).width() - 40
var _courseHeight = $(window).height()
var dynamicdata;
var graphMatrices // graph matrices
var adjacentDistances;
var maxDistance = 0;
var pilingMethod = 'clustered'
var matrixStrings = ''
var piles = []; // contains all piles. Each pile contains matrices, not indices
var matrixPos = []; // index of pile in layout array
var matrices = []; // contains all matrices
var matricesPileIndex = []; // contains pile index for each matrix.
// TV a pile of consensus matrices
var consensus = [];
var consensusPile; //TV = new Pile(0, scene, allPileOrdering[orderMenu.selectedIndex], _zoomFac);
var hoveredMatrix;
var draggingMatrix; // index of currently dragged matrix (for matrices[])
var selectedMatrices = [];
var dragActive = false;
var hoveredGapPile = undefined
var openedPileRoot = undefined
var openedPileMatrices = []
var activePile; // pile that contains last mouse hovered matrix
var activeMatrixInPileIndex; // index of last hovered matrix in pile
var matrixGapMouseover = false;
var timeline;
var nodes = [];
var focusNodes = [] // currently visible nodes (changed by the user)
var _matrixWidth
var _matrixWidthHalf
var rightClick = false;
var _cols;
var shiftDown = false;
var _isLoadedSession = false
var _isSavedSession = false
// var START_ROW = 0;
// var END_ROW = 0;
// var START_COL = 0;
// var END_COL = 0;
var MODE_SUMMARY = 0
var MODE_BARCHART = 1
var MODE_TREND = 2
var MODE_VARIABILITY = 3
var MODE_DIFFERENCE = 4
var MODE_DIRECT_DIFFERENCE = 5
var ORDER_DATA = 0
var ORDER_GLOBAL = 1
var ORDER_LOCAL = 2
var orderMenu = document.getElementById('allNodeOrder')
var sortMenu = document.getElementById('allSort')
var coverMatrixMenu = document.getElementById('allCover')
var allPileOrdering = []
var focusNodeAllPileOrdering = [] // array containing the orderings for all piles, when not all nodes are focused on
var _zoomFac = 1
var slider;
var pileIDCount = 1; //TV changed from 0 to allocate 0 to consensus pile
var startPile = 0;
// var this.zoomedMatrix = null;
var maxValue = 0
var cellValue = d3.scale
.linear()
// .log()
.range([0,1])
.nice()
var SESSION_NAME;
// var _pileToolsVisible = true
labelTextSpec.size = CELL_SIZE-1
// Load available files
// var csvRequest
var fileNames = [];
$.get('data', function( data ) {
var list = data.split('href="')
for(var i=0 ; i<list.length ; i++){
if(list[i].indexOf('.dyjson') == -1) continue
$("#fileSelection")
.append('<option>data/' + list[i].split('"')[0] + '</option>')
}
});
// If the user changes the focus nodes, matrix similarity must be recalculated before automatic piling. Distance calculation is performed on the server.
var dMat = [];
var pdMat = []; // contains similarity between piles
var pdMax = 0;
var pileDistanceColor // value range for similarity
//TV: connectivity does not take into account autocorrelation
var connectivity = []
var COLOUR = ['#000000','#8dd3c7','#fb8072','#80b1d3','#fdb462','#fccde5','#ccebc5','#bc80bd','#ffed6f','#d9d9d9','#ffffb3','#bebada']
retrieveSessions();
// find an ordering for all nodes that shows clustering across the
// sum of all individual time step matrices.
function calculateGlobalOrder(graph) {
var max = 0;
var globalMatrix = [];
for (var i=0 ; i<graph.times[0].matrix.length ;i++) {
globalMatrix[i] = [];
//TV for (var j=0 ; j< graph.times[0].matrix[i].length; j++) {
for (var j=0 ; j< graph.times[0].matrix.length; j++) {
globalMatrix[i][j] = 0;
}
}
for (var t=0 ;t < Math.min(SHOW_MATRICES,graph.times.length) ;t++) {
for (var i=0 ;i < graph.times[t].matrix.length ;i++) {
//TV for (var j=0; j < graph.times[t].matrix[i].length ;j++) {
for (var j=0; j < graph.times[t].matrix.length ;j++) {
//console.log(graph.times[t].matrix[i].length);
for (var ml=0; ml < graph.times[t].matrix[i].length; ml++){
if(graph.times[t].matrix[i][ml][j] > CELL_THRESHOLD){
// graph.times[t].matrix[i][j]++
// graph.times[t].matrix[j][i]++
globalMatrix[i][j] += Math.abs(graph.times[t].matrix[i][ml][j])
//TV globalMatrix[j][i] += Math.abs(graph.times[t].matrix[j][i])
max = Math.max(max, graph.times[t].matrix[i][ml][j]);
}
}
}
}
}
// CELL_THRESHOLD++
cellValue.domain([CELL_THRESHOLD, max])
// 2) Reorder
var leafOrder = reorder.leafOrder()
.distance(science.stats.distance.manhattan)(globalMatrix);
var order = []
leafOrder.forEach(function (lo, i) {
order[i] = lo;
});
return order;
}
function init(){
FILE = location.search.split('data=')[1]
var d=new Date();
SESSION_NAME = FILE + "-"
+ d.getDate()
+ "/" + (d.getMonth()+1)
+ "/" + d.getYear()
+ "-" + d.getHours() + ":" + d.getMinutes();
loadFile(FILE)
}
function exportSession(){
if(!SESSION_NAME){
var menu = $('#sessionSelection')[0];
SESSION_NAME = menu.options[menu.selectedIndex].text;
}
// save before export
saveSession()
var dump = getSessionDump(SESSION_NAME);
var url = 'data:text/json;charset=utf8,' + encodeURIComponent(dump);
window.open(url, '_blank');
window.focus();
}
function exportPileMeasures(){
var mean
var dump = ""
dump += '"Data name "' + SESSION_NAME + '\n'
dump += '"Number of piles", ' + piles.length + '\n'
for(var p=0 ; p<piles.length ; p++){
mean = 0
for(var t=0 ; t<piles[p].size() ; t++){
for(var i=0 ; i<nodes.length ; i++){
//TV for(var j=i ; j<nodes.length ; j++){
for(var j=0 ; j<nodes.length ; j++){
console.log(graph.times[t].matrix[0].length);
for (var ml=0; ml < graph.times[t].matrix[0].length; ml++){
mean += piles[p].getMatrix(t).matrix[i][ml][j]
}
}
}
}
mean /= ((nodes.length * nodes.length + nodes.length) / 2) * piles[p].size()
dump += '"Pile ' + p + '", ' + piles[p].size() + ', ' + mean + '\n'
}
var url = 'data:text/csv;charset=utf8,' + encodeURIComponent(dump);
window.open(url, '_blank');
window.focus();
}
// WebGL setup:
// _courseHeight = 5000
var scene = new THREE.Scene();
var w = _courseWidth;
var h = _courseHeight;
var camera = new THREE.OrthographicCamera(
_courseWidth / - 2,
_courseWidth / 2,
_courseHeight / 2,
_courseHeight / - 2,
1, 11)
scene.add(camera);
camera.position.z = 10;
camera.position.x = _courseWidth/2 - 120; //TV was -50 leave more space for user defined consensus pile.
var topScrollLimit = MARGIN_TOP -_courseHeight/2
camera.position.y = topScrollLimit - 60; //TV added -60 to leave less space from the histogram
var renderer = new THREE.WebGLRenderer({antialias: true})
renderer.setSize(_courseWidth, _courseHeight)
renderer.setClearColor( 0xffffff, 1);
//TV renderer.setClearColor( 0xffffff, 1);
var canvas = renderer.domElement;
canvas.addEventListener('click', function(e){
clickCanvas(e)
})
canvas.addEventListener('dblclick', function(e){
doubleClickCanvas(e)
}) //TV on double click add/remove matrix/pile in/from the consensus pile and annotate addition/deletion in timeline adding a dot over the score bar.
//TV canvas.addEventListener('mousedown', function(e){
//TV canvasMouseDown(e)
//TV })
//TV canvas.addEventListener('mouseup', function(e){
//TV canvasMouseUp(e)
//TV })
canvas.addEventListener('mousemove', function(e){
mouseMove(e)
})
canvas.addEventListener('mousewheel', mouseWheelChanged, false );
var origin = new THREE.Vector3()
var raycaster = new THREE.Raycaster()
var pileMeshes = []
init()
function render(){
var d = new Date();
var begin = d.getTime()
renderer.render(scene, camera)
d = new Date();
// console.log('>>>> RENDERED ', (d.getTime() - begin), ' ms.')
for(var i=0 ; i<visiblePileTools.length ; i++){
scene.remove(visiblePileTools[i])
}
}
function loadFile(file){
console.log('loadFile')
$('#pilesPlot').append(canvas)
// $('#sessionName').val(SESSION_NAME)
SNAKE = false
FILE = file;
console.log(file);
$('#menuLoadData').remove();
$('#sessions').css({ opacity: 1});
d3.json(file,function (graph)
{
svgTimeline = d3.select("#chartTimeline")
.append("svg")
.attr("width", _courseWidth)
.attr("height", TIMELINE_HEIGHT + 52); //20); TV
console.log("t");
// TV sort matrices on scores rather than as they appear in JSON
//console.log(graph.times[0]);
console.log(document.getElementById("sort_run_id").checked);
setOrder();
//TV if (document.getElementById("sort_asc").checked)
//TV {
//TV graph.times = graph.times.sort(function(x, y){
//TV return d3.ascending(x.score, y.score);
//TV })
//TV }
if (document.getElementById("sort_desc").checked)
{
graph.times = graph.times.sort(function(x, y){
return d3.ascending(y.score, x.score);
})
} else if (document.getElementById("sort_iteration").checked)
{
graph.times = graph.times.sort(function(x, y){
return d3.ascending(y.iteration, x.iteration);
})
graph.times = graph.times.sort(function(x, y){
return d3.ascending(x.run_id, y.run_id);
})
}
// READ DATA
dynamicdata = graph;
nodes = graph.nodes;
var s
for(var i=0 ; i<nodes.length ; i++){
focusNodes.push(i)
s = nodes[i].name +''
nodes[i].name = s.trim()
}
// TV matrices stored in an array
graphMatrices = []
for(var i=0 ;i<graph.times.length && i<SHOW_MATRICES;i++){
graphMatrices.push(graph.times[i].matrix)
}
//TV also store scores in an array needed in timeline.js
graphScores = []
for(var i=0 ;i<graph.times.length && i<SHOW_MATRICES;i++){
graphScores.push(graph.times[i].score)
}
// TV TODO: update to consider the full matrix not just upper triangle
calculateDistanceMatrix()
// INIT LAYOUT
var n = graph.nodes.length;
_matrixWidth = n * CELL_SIZE;
_matrixWidthHalf = _matrixWidth/2;
highlightFrame = GLUtils.createRectFrame(_matrixWidth, _matrixWidth, 0xff8100, 10)
_cols = Math.floor(
(_courseWidth - MARGIN_LEFT - MARGIN_RIGHT) / (_matrixWidth + MATRIX_GAP_HORIZONTAL)
)-1
// console.log('cols',_cols)
// _cols = 12
END_ROW = n-1;
END_COL = n-1;
allPileOrdering[ORDER_DATA] = []
allPileOrdering[ORDER_GLOBAL] = []
for(var i=0 ; i<nodes.length ; i++){
allPileOrdering[ORDER_DATA].push(i)
}
allPileOrdering[ORDER_GLOBAL] = calculateGlobalOrder(graph);
var menuX = MARGIN_LEFT;
// svg = d3.select("#pilesPlot")
// .append('svg')
// .attr("width", _courseWidth)
// .attr("height", 50)
// INIT PILES (each single matrix is a pile)
if (PRE_PILE) {
for (var i = 0; i < graph.clusters.length; i++)
piles.push(new Pile(pileIDCount++, scene, allPileOrdering[orderMenu.selectedIndex], _zoomFac));
// calculatePiles();
} else if (false) { // TV a pile is created for each matrix
for (var i = 0; i < Math.min(SHOW_MATRICES, graph.times.length) ; i++) {
var p = new Pile(pileIDCount++, scene, allPileOrdering[orderMenu.selectedIndex], _zoomFac);
piles.push(p);
}
} else { // TV a pile is created for each matrix
for (var i = 0; i < Math.min(SHOW_MATRICES, graph.times.length) ; i++) {
//for (var i = 0; i < graph.run_id.length; i++)
var p = new Pile(pileIDCount++, scene, allPileOrdering[orderMenu.selectedIndex], _zoomFac);
piles.push(p);
}
}
// INIT MATRICES
for (var t = 0 ; t < Math.min(SHOW_MATRICES, graph.times.length) ; t++) {
// Obtain pile for new matrix
var p = piles[t]
if(PRE_PILE){
for (var i = 0; i < graph.clusters.length; i++){
if(graph.clusters[i].indexOf(t) > -1){
p = piles[i];
break;
}
}
}
//TV console.log(graph.times[t].score);
//TV this is where the matrices from the data graph.times[t].matrix are loaded to the collection of piles: p = piles[t]
// Create matrix
var matrix = new Matrix(
t,
graph.times[t].run_id,
graph.times[t].matrix,
graph.times[t].score, //TV score added as an attribute of every Matrix
graph.times[t].iteration // TV iteration added as an attribute of every Matrix (prob not used)
)
//TV except from the collection of piles: p, it seems that the matrix object is also added in the local data array: matrices
matrices.push(matrix);
p.addMatrices([matrix]);
p.draw()
}
updateLayout(0, false);
// CREATE TIMELINE
timeline = new Timeline();
timeline.updateLayout();
timeline.updateNodeOrder(allPileOrdering[orderMenu.selectedIndex]);
if(_isLoadedSession)
finalizeLoadSession()
// create wait window
waitWindow = svgTimeline.append('g')
.attr('id', 'waitWindow')
.attr('transform', 'translate('+(_courseWidth/2 -200) + ',' +20 + ')')
waitWindow.append('rect')
.attr('x', 0).attr('y', 0)
.attr('width', 400)
.attr('height',100)
.style('fill', '#fff')
.style('stroke', '#000')
.style('opacity', .98);
waitWindow.append('text')
.attr('x', 100)
.attr('y', 40)
.attr('class', 'infotext')
.text('Please wait ...')
showWait(false)
//TV
this.consensusPile = new Pile(0, scene, allPileOrdering[orderMenu.selectedIndex], _zoomFac);
// RENDER
render()
savePilingHistory()
// selectNodes()
// calculatePrecisePiling()
// exportPileMeasures()
//TV
calculateConnectivity();
//TV
updateConnectivity(0);
}); // TV ENDOF d3.json(file)
} // TV ENDOF loadFile(file)
var highlightFrame
//TV variable for the grid
var gridFrame
var dotmesh
function highlightPile(pile){
highlightFrame.position.set(pile.x, pile.y, 0)
highlightFrame.visible = true
scene.add(highlightFrame)
}
function highlightNoPile(){
scene.remove(highlightFrame)
//TV TODO also set opacity to 1 for all timelineMatrix_id
d3.selectAll(".timelineMatrix")
//.transition()
.style("opacity", 1);
//.attr('opacity', 1)
}
function removeGridFrame(){
scene.remove(gridFrame)
render()
}
function removeDotMesh(){
scene.remove(dotmesh)
render()
}
function focusOn(nodes){
focusNodes = nodes
// update sizes
_matrixWidth = CELL_SIZE * focusNodes.length
_matrixWidthHalf = _matrixWidth/2
// _cols = Math.floor((_courseWidth- MARGIN_RIGHT) / (_matrixWidth + MATRIX_GAP_HORIZONTAL))
_cols = Math.floor((_courseWidth - MARGIN_LEFT - MARGIN_RIGHT) / (_matrixWidth + MATRIX_GAP_HORIZONTAL))-1
calculateDistanceMatrix()
// update highlight frame
scene.remove(highlightFrame)
highlightFrame = GLUtils.createRectFrame(_matrixWidth, _matrixWidth, 0x000000, 10)
scene.add(highlightFrame)
// redraw
for(var i=0 ; i<piles.length ; i++){
piles[i].updateFrame()
}
consensusPile.updateFrame()
redrawPiles(piles)
this.updateLayout(0, true)
render()
}
function calculateDistanceMatrix(){
dMat = []
var data = pileUtils.calculateDistance(graphMatrices, focusNodes)
dMat = data.distanceMatrix
pdMat = data.distanceMatrix
maxDistance = data.maxDistance;
pdMax = maxDistance // initialize
// pileDistanceColor.domain([0,pdMax])
// ADD SLIDER
if(slider)
slider.destroy()
slider = new Slider(svgTimeline, TIMELINE_HEIGHT, 0, maxDistance);
setPileSliderTick(0.25, graphMatrices)
setPileSliderTick(0.5, graphMatrices)
setPileSliderTick(0.75, graphMatrices)
}
function setPileSliderTick(frac, matrices){
var value = maxDistance * frac
var piling = pileUtils.calculateClusterPiling(maxDistance * frac, matrices, dMat)
var label = (maxDistance * frac).toFixed(2) + ' (' + (piling.length) + ')'
slider.setTick(label, maxDistance * frac)
}
function calculatePrecisePiling(){
var value = parseFloat($('#precisePilingValue').val())
calculatePiles(value)
slider.setSliderKnob(value)
}
function selectNodes(){
var value = $('#filteredNodes').val()
var desiredNodes = value.split(',')
for(var i=0 ; i<desiredNodes.length ; i++){
desiredNodes[i] = desiredNodes[i].trim()
}
var newNodes = []
for(var i=0 ; i<nodes.length ; i++){
for(var j=0 ; j<desiredNodes.length ; j++){
if(desiredNodes[j] == nodes[i].name)
newNodes.push(i)
}
}
focusOn(newNodes)
}
function showWait(b){
if(b){
svgTimeline.append(function () { return waitWindow[0][0] })
}else{
d3.select('#waitWindow').remove();
}
}
////////////////////////////////
/// PILING
var pilingAnimations = []
var interval
/* Starts all animations in pilingAnimations array.*/
function startAnimations(){
console.log('----> START ANIMATIONS')
clearInterval(interval)
interval = setInterval(function(){
for(var i=0 ; i<pilingAnimations.length ; i++){
pilingAnimations[i].step()
if(pilingAnimations[i].done)
pilingAnimations.splice(i,1)
}
if(pilingAnimations.length == 0){
clearInterval(interval)
interval = undefined
updateLayout()
pilingAnimations = []
savePilingHistory()
console.log('----> ANIMATIONS DONE')
}
render()
}, 500/FPS)
}
/** Piles a set of matrices onto a target pile
removes it from source pile, and
updates the layout.
If animated=true, a PilingAnimation is created and stored
in the pilingAnimations array. Animations are started by
calling startPilingAnimations()
*/
function pile(mats, targetPile, animate)
{
if(!animate) animate = false
if(animate){
pilingAnimations.push(new PilingAnimation(targetPile, mats))
}else{
var matricesToPile = mats.slice(0);
var insertIndex;
var pos;
var m;
var sourcePile, spi; // source-pile-index
var sourcePiles = []
for (var i = 0; i < matricesToPile.length; i++)
{
m = matricesToPile[i];
sourcePile = m.pile;
sourcePile.removeMatrices([m]);
if(sourcePile.size() == 0 && sourcePile != targetPile){
destroyPile(sourcePile)
}
}
targetPile.addMatrices(matricesToPile);
sortTime(targetPile)
redrawPiles(piles)
updateLayout(0, true)
timeline.updateLayout();
render()
}
}
/*Piles all matrices prior to the selected one, including the selected one.*/
function pileBackwards(p)
{
var i = piles.indexOf(p)
var mats = []
var num
if(p.size() == 1){
// console.log('pile matrices')
for(var j=i ; j>=0 ; j--){
if(j==0 || piles[j-1].size() > 1){
pile(mats, piles[j], $('#animateCheckBox').is(':checked'))
startAnimations()
return
}else{
mats.push.apply(mats, piles[j].getMatrices())
}
}
}else{
if(piles.indexOf(p) > 0){
pile(p.pileMatrices, piles[piles.indexOf(p)-1], $('#animateCheckBox').is(':checked'))
}
}
startAnimations()
}