forked from OskarElek/PolyGlot
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
1875 lines (1606 loc) · 70.3 KB
/
index.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>
<meta charset="utf-8">
<title>Polyglot</title>
<style>
html {
cursor: url("cursor 40x40.svg") 20 20, auto;
}
body {
margin: 0;
}
#data-selection{
height: 20px;
}
#tooltip {
position: fixed;
left: 0;
top: 0;
min-width: 100px;
text-align: center;
padding: 5px 12px;
font-family: Courier;
background: #c9c9c9;
display: none;
opacity: 0;
border: 1px solid black;
border-radius: 3px;
white-space: pre-line;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/fuzzysort.min.js"></script>
<script src="./chroma.js-master/chroma.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="x-shader/x-fragment" id="vertexshader-token">
attribute float alpha;
uniform float scale;
attribute float size;
varying vec3 gcolor;
varying float galpha;
varying float gsize;
void main() {
vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
gl_Position = projectionMatrix * mvPosition;
gl_PointSize = size * 5.0 * scale / length(mvPosition.xyz); // Adjust point size here!
gcolor = color;
galpha = alpha;
gsize = size;
}
</script>
<script type="x-shader/x-fragment" id="fragmentshader-token">
varying vec3 gcolor;
varying float galpha;
void main() {
// this is the part that clips the point into a circle
float distance = length(4.0 * gl_PointCoord - 2.0);
if (distance > 2.0) {
discard;
}
if (gcolor.x < 0.01 && gcolor.y < 0.01 && gcolor.z < 0.01) {
discard;
}
gl_FragColor = vec4(gcolor - distance / 40.0, galpha);
}
</script>
</head>
<body>
<div id="tooltip"></div>
<div id="container"></div>
<script type="module">
import * as THREE from './build/three.module.js';
import { GUI } from './jsm/libs/dat.gui.module.js';
import { OrbitControls } from './jsm/controls/OrbitControls.js';
// #######################################################
// COPY N PASTE FROM THE WEB
// #######################################################
var getFileBlob = function (url, cb) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.responseType = "blob";
xhr.addEventListener('load', function() {
cb(xhr.response);
});
xhr.send();
};
var blobToFile = function (blob, name) {
blob.lastModifiedDate = new Date();
blob.name = name;
return blob;
};
var getFileObject = function(filePathOrUrl, cb) {
var splitUrl = filePathOrUrl.split('/');
getFileBlob(filePathOrUrl, function (blob) {
cb(blobToFile(blob, splitUrl[splitUrl.length - 1]));
});
};
// #######################################################
// Get variable from URL, modified for quick access to music embedding
const urlParams = new URLSearchParams(window.location.search);
let ifMusic = urlParams.get('music') == 'true';
let dataDirectory = "data/global_1/";
let firstFile = true; // We want this to be false after loading the first file so that the points dont shift around
// ** Set of variables from deposit_reader.py, important for coordiante conversion **
let SCALING_FACTOR_SLIME = 10;
let GRID_MIN = [-115.75681, -101.80056, -126.10199]; // grid center - size / 2 given in metadata
let group
let container, stat;
let camera, scene, renderer;
let pointCloud;
let controls;
let gui;
let GUIparam;
let newAnnotationParam;
let origini = 0;
let originAttr = '';
let originX = 0;
let originY = 0;
let originZ = 0;
let raycaster, mouse = new THREE.Vector2(), INTERSECTED;
let raycasterMultiTokens = new THREE.Vector2();
let raycasterAnnotations = new THREE.Vector2();
let originalHEX;
var chooseAnchorController;
var zoomController;
var annotationOneDropdown;
var annotationTwoDropdown;
var annotationThreeDropdown;
var annotationFourDropdown;
var annotationFiveDropdown;
var anchorList = ["0: also_ADV", "918: right_NOUN"];
var searchAnchorList = ["0: also_ADV", "918: right_NOUN"];
var searchZoomList = ["0: also_ADV", "918: right_NOUN"];
var datasetList = ["data/global_1/", "data/global_2/", "data/music_demo/", "data/plankton/"];
//var datasetList = ["data/global_1/", "data/global_2/", "data/music_demo/", "data/Lautonomy_Data/"];
let traceDataDirectory = "data/global_1/"; // CONTROLS WHICH DATASET TO LOAD WITH!!
var dataTraceController;
// change initial dataset if music == true, modified for quick access to music embedding
if (ifMusic){
dataDirectory = datasetList[2];
traceDataDirectory = datasetList[2];
}
var chooseDatasetController;
var maxParticleCount = 1000;
let particleData = [];
let particles;
let particleConnectionWeight;
let particleHighDimConnectionWeight;
let particleColorMap;
let particleWeight;
let particlePositions;
let particleColor;
let particleOpacity;
let particleSize;
let allPoints;
let topEdgeWeight = -1;
let topNodeWeight = -1;
let topColorWeight = -1;
let nodeWeightThreshold = 0; // Use this to filter out low weight nodes
let connWeightThreshold = 0; // Use this to filter out low slime mold connection
let connWeightHighDimThreshold = 0;
let availableIds = {}; // List of IDs available, each entry is in format [id, info]
// ===================================
// =========VARIABLE FOR NEW THINGS===
// ===================================
// ===================================
let shiftPressed = false;
let shiftDim = true;
let displayMultiToken = false;
let alwaysAnchor = false;
let colorMode = "slime connect";
let filterPOS = "None";
// Allow linear intepolation between two colors based on distance
var closestRGB = chroma('#f2190a');
var farthestRGB = chroma('#293366');
var closestRGBColorMap = chroma('#f2190a');
var farthestRGBColorMap = chroma('#293366');
var closestRGBGrayscale = chroma('#FFFFFF');
var farthestRGBGrayscale = chroma('#000000');
var originRGB = chroma([224, 144, 154]);
var navigableRGB = chroma('#f7e968'); // color for anchor points
var zoomedPoint = chroma('#00ff22');
var zoomedTerm;
var originalRGB = [0, 0, 0, 0]; // Different from OriginRGB, this is used to store original color for highlighting
let posColorMap = { 'ADV': chroma('#5ddfe8'), 'NUM': chroma('#bfd474'),
'ADJ': chroma('#773ac2'), 'NOUN': chroma('#9cd63e'),
'VERB': chroma('#3e7bd6'), 'ADP': chroma('#8052bf'),
'AUX': chroma('#00399c'), 'PROPN': chroma('#d64d3e'),
'DET': chroma('#899400'), 'PUNCT': chroma('#940155'),
'PRON': chroma('#8a0d00'), 'CCONJ': chroma('#820133'),
'X': chroma('#006e0d'), 'PART': chroma('#734d00'),
'INTJ': chroma('#802700'), 'SYM': chroma('#ad00a8')};
var colorRatioPow = 0.5;
var opacityTuning = 0.4;
var navigationMode = false;
var grayScaleBool = false;
var numAnnotations = 0;
var annotationOn = -1; // equals -1 when no annotation mode is on and equals [1, 5] if a certain annotation mode is on
var showAnnotations = true;
var annotationOnePoints = [];
var annotationTwoPoints = [];
var annotationThreePoints = [];
var annotationFourPoints = [];
var annotationFivePoints = [];
var annotationOneColor = chroma("#1861b3");
var annotationTwoColor = chroma("#1861b3");
var annotationThreeColor = chroma("#1861b3");
var annotationFourColor = chroma("#1861b3");
var annotationFiveColor = chroma("#1861b3");
var annotationOneName = [''];
var annotationTwoName = [''];
var annotationThreeName = [''];
var annotationFourName = [''];
var annotationFiveName = [''];
var annotationOneNotes = [''];
var annotationTwoNotes = [''];
var annotationThreeNotes = [''];
var annotationFourNotes = [''];
var annotationFiveNotes = [''];
var yearsBool = false;
var years = {};
var full_years_arr;
var years_header;
var points_with_years = [];
var old_points_years = [0];
var currentYear = 1;
var timeScaler = 1000;
var minYear;
var maxYear;
var yearUI;
var resetSizesUI;
var docsBool = false;
var expand = false;
var docs = {};
var highDimMetricBool = false;
var colorMapBool = true;
var colorMapDropDown;
var subClassDropDown;
// actual calls
init();
animate();
function init(){
container = document.getElementById( 'container' );
raycaster = new THREE.Raycaster();
raycaster.params.Points.threshold = 0.7;
raycasterMultiTokens = new THREE.Raycaster();
raycasterMultiTokens.params.Points.threshold = 1.75;
raycasterAnnotations = new THREE.Raycaster();
raycasterMultiTokens.params.Points.threshold = 3.75;
// ALSO CHANGED THE POINTS THRESHOLD FOR BETTER POINT SELECTION WHEN ZOOMED IN
document.addEventListener('mousemove', onDocumentMouseMove, false);
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(45,
window.innerWidth/window.innerHeight, 5, 4000);
camera.position.z = 800;
camera.near = 5;
// CHANGED NEAR PARAM TO MAKE RAY CASTING SMOOTHER DURING ZOOM
// REQUIRED - For camera control
controls = new OrbitControls( camera, container );
//controls.minDistance = 0;
// REQUIRED - group to add everything in
group = new THREE.Group();
scene.add(group);
// REQUIRED - add meshes, add both point and edge (Should be reading data)
initializeData();
automaticLoadData(dataDirectory);
// REQUIRED
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
container.appendChild( renderer.domElement );
// REQUIRED - GUI Setup
gui = new GUI();
GUIparam = {
'selectData': dataDirectory,
'colorMode': "slime connect",
'filterPOS': "None",
'colorRatioPow': 0.5,
'nodeWeightThreshold': 0,
'particleConnectionWeight': 0,
'particleHighDimConnectionWeight': 0,
'opacityTuning': 0.4,
'shiftDim': true,
'displayMultiToken': false,
'alwaysAnchor': false,
'selectAnchor': "0: also_ADV",
'selectTraceDataset': traceDataDirectory,
'textField': "",
'zoomPoint':"",
'showAnnotations': true,
'grayScale': false,
'year': 2020.7,
'timeSize': 1,
'pointSize': 1
};
newAnnotationParam = {
'annotationName': 'Annotation Name',
'annotationColor': "#1861b3",
'annotationNotes': 'Annotation Notes',
'annotationStartSelect': false,
'annotationBrushSize': 1,
'annotationSearch': ""
};
if (dataDirectory === "data/plankton/") {
const axesHelper = new THREE.AxesHelper( 500 );
scene.add( axesHelper );
}
gui.add(GUIparam, 'selectData', datasetList).name('Dataset').onChange(function(){
if (dataDirectory === "data/global_1/" || (dataDirectory === "data/global_2/")) {
visualFolder.remove(subClassDropDown);
}
dataDirectory = GUIparam.selectData;
traceDataDirectory = dataDirectory;
scene.remove(scene.children[0]);
initializeData();
automaticLoadData(dataDirectory);
camera.position.z = 800;
camera.near = 5;
group = new THREE.Group();
scene.add(group);
if (dataDirectory === "data/plankton/") {
const axesHelper = new THREE.AxesHelper( 500 );
scene.add( axesHelper );
}
visualFolder.remove(colorMapDropDown);
colorModeList = ["slime connect", "part of speech"];
if (colorMapBool && (dataDirectory === "data/plankton/")) {
colorModeList.push("lat", "lon", "t", "s", "H1", "H2", "H3");
colorMapDropDown = visualFolder.add(GUIparam, 'colorMode', colorModeList).name('Color Mode').onChange(function(){
colorMode = GUIparam.colorMode;
if (colorMode !== ("slime connect" || "part of speech")) {
getFileObject(traceDataDirectory + 'color_map/' + colorMode +".csv", function (colorMapData) {
let reader = new FileReader();
reader.onload = (e) => {
const file = e.target.result;
var lines = file.split(/\r\n|\n/);
lines = lines.slice(0, lines.length - 1);
loadColorMap(lines);
}
var a = reader.readAsText(colorMapData);
});
}
updatePtsColor();
})
} else {
colorMapDropDown = visualFolder.add(GUIparam, 'colorMode', colorModeList).name('Color Mode').onChange(function(){
colorMode = GUIparam.colorMode;
updatePtsColor();
})
}
if (dataDirectory === "data/global_1/" || (dataDirectory === "data/global_2/")) {
subClassDropDown = visualFolder.add(GUIparam, 'filterPOS', filterPOSList).name('Pick Subclass').onChange(function(){
filterPOS = GUIparam.filterPOS;
updatePtsColor();
})
}
})
var colorModeList = ["slime connect", "part of speech"];
if (highDimMetricBool) {
colorModeList.push("high dimension");
}
const visualFolder = gui.addFolder('Visual Parameters')
var filterPOSList = ['None', 'NOUN+VERB+ADJ+ADV', 'ADV', 'NUM', 'ADJ', 'NOUN', 'VERB', 'ADP', 'AUX', 'PROPN',
'DET', 'PUNCT', 'PRON', 'CCONJ', 'X', 'PART', 'INTJ', 'SYM']
if (dataDirectory === "data/global_1/" || (dataDirectory === "data/global_2/")) {
subClassDropDown = visualFolder.add(GUIparam, 'filterPOS', filterPOSList).name('Pick Subclass').onChange(function(){
filterPOS = GUIparam.filterPOS;
updatePtsColor();
});
}
visualFolder.add(GUIparam, 'colorRatioPow', 0.05, 1, 0.005).name('Color Gradient').onChange(function(){
colorRatioPow = GUIparam.colorRatioPow;
updatePtsColor();
});
// gui.add(GUIparam, 'nodeWeightThreshold', 0, 1).name('Lowest Weight').onChange(function(){
// nodeWeightThreshold = GUIparam.nodeWeightThreshold;
// updatePtsColor();
// })
visualFolder.add(GUIparam, 'pointSize', 0.001, 1).name('Point Size').onChange(function(size){
for (let k = 0; k < maxParticleCount; k++)
particleSize[k] = size;
updatePtsColor();
});
gui.add(GUIparam, 'particleConnectionWeight', 0, 100000).name('Filter LD').onChange(function(){
connWeightThreshold = GUIparam.particleConnectionWeight;
updatePtsColor();
});
gui.add(GUIparam, 'particleHighDimConnectionWeight', 0, 100000).name('Filter HD').onChange(function(){
connWeightHighDimThreshold = GUIparam.particleHighDimConnectionWeight;
updatePtsColor();
});
visualFolder.add(GUIparam, 'opacityTuning', 0, 1).name('Opacity').onChange(function(){
opacityTuning = GUIparam.opacityTuning;
updatePtsColor();
});
visualFolder.add(GUIparam, 'shiftDim').name('Dim When Shift').onChange(function(){
shiftDim = GUIparam.shiftDim;
});
gui.add(GUIparam, 'displayMultiToken').name('Fuzzy Cursor').onChange(function(){
displayMultiToken = GUIparam.displayMultiToken;
});
// gui.add(GUIparam, 'alwaysAnchor').name('Keep Anchor Displayed').onChange(function(){
// alwaysAnchor = GUIparam.alwaysAnchor;
// updatePtsColor();
// })
gui.add(GUIparam, 'showAnnotations').name('ShowAnnotations').onChange(function(showAnnotationsBool){
showAnnotations = showAnnotationsBool;
updatePtsColor();
});
visualFolder.add(GUIparam, 'grayScale').name('grayScale').onChange(function(usergrayScaleBool){
grayScaleBool = usergrayScaleBool;
updatePtsColor();
});
if (colorMapBool && dataDirectory === "data/plankton/") {
colorModeList.push("lat", "lon", "t", "s", "H1", "H2", "H3");
colorMapDropDown = visualFolder.add(GUIparam, 'colorMode', colorModeList).name('Color Mode').onChange(function(){
colorMode = GUIparam.colorMode;
if (colorMode !== ("slime connect" || "part of speech")) {
getFileObject(traceDataDirectory + 'color_map/' + colorMode +".csv", function (colorMapData) {
let reader = new FileReader();
reader.onload = (e) => {
const file = e.target.result;
var lines = file.split(/\r\n|\n/);
lines = lines.slice(0, lines.length - 1);
loadColorMap(lines);
}
var a = reader.readAsText(colorMapData);
});
}
updatePtsColor();
})
} else {
colorMapDropDown = visualFolder.add(GUIparam, 'colorMode', colorModeList).name('Color Mode').onChange(function(){
colorMode = GUIparam.colorMode;
updatePtsColor();
})
}
window.addEventListener( 'resize', onWindowResize, false );
document.addEventListener('dblclick', onDocumentDoubleClick);
document.addEventListener('click', onDocumentClick);
document.addEventListener('keydown', onKeyDownEvent);
document.addEventListener('keyup', onKeyUpEvent);
}
function onWindowResize() {
const size = new THREE.Vector2()
renderer.getSize( size );
camera.aspect = size.x / size.y;
camera.updateProjectionMatrix();
renderer.setSize( size.x, size.y );
}
function onDocumentMouseMove(event) {
event.preventDefault();
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
}
function onDocumentClick(event) {
if (event.detail === 2) {
return;
}
event.preventDefault();
if (INTERSECTED) {
if (expand === true) {
var particle_pos = new THREE.Vector3(particlePositions[INTERSECTED*3],
particlePositions[INTERSECTED*3 + 1],
particlePositions[INTERSECTED*3 + 2]);
if (docsBool === true) {
var topDocs = docs[INTERSECTED];
}
var particle_text = particleData[INTERSECTED].name;
var particle_mesg = INTERSECTED.toString() + ": " + particle_text;
hideTooltip();
showTooltip(particle_pos, particle_mesg);
expand = false;
} else {
expand = true;
var particle_pos = new THREE.Vector3(particlePositions[INTERSECTED * 3],
particlePositions[INTERSECTED * 3 + 1],
particlePositions[INTERSECTED * 3 + 2]);
if (docsBool === true) {
var topDocs = docs[INTERSECTED];
var particle_text = particleData[INTERSECTED].name;
var particle_mesg = INTERSECTED.toString() + ": " + particle_text + '\n1. ' + topDocs[0]
+ '\n2. ' + topDocs[1] + '\n3. ' + topDocs[2] + '\n4. ' + topDocs[3] + '\n5. ' + topDocs[4];
hideTooltip();
showTooltip(particle_pos, particle_mesg);
} else {
var particle_text = particleData[INTERSECTED].name;
var particle_mesg = INTERSECTED.toString() + ": " + particle_text;
hideTooltip();
showTooltip(particle_pos, particle_mesg);
}
}
}
}
// Check if the point being clicked on can be navigated, if so, load the point
function onDocumentDoubleClick(event) {
if (event.detail === 1) {
return;
}
event.preventDefault();
if (INTERSECTED) {
if (availableIds[particleData[INTERSECTED].id]){ // Check if point is navigatable
originAttr = particleData[INTERSECTED].id;
getFileObject(dataDirectory + particleData[INTERSECTED].id.toString() +".txt",
function (anchorData) {
let reader = new FileReader();
reader.onload = (e) => {
const file = e.target.result;
var lines = file.split(/\r\n|\n/);
lines = lines.slice(0, lines.length - 1);
loadAnchor(lines);
var anchorName = particleData[INTERSECTED].id.toString() + ": " + particleData[INTERSECTED].name.toString();
anchorList.unshift(anchorName);
updateDropdown(chooseAnchorController, anchorList);
}
var a = reader.readAsText(anchorData);
});
if(highDimMetricBool) {
getFileObject(dataDirectory + 'sim_scores/' + particleData[INTERSECTED].id.toString() +".txt",
function (anchorData) {
let reader = new FileReader();
reader.onload = (e) => {
const file = e.target.result;
var lines = file.split(/\r\n|\n/);
lines = lines.slice(0, lines.length - 1);
loadHighDimAnchor(lines);
var anchorName = particleData[INTERSECTED].id.toString() + ": " + particleData[INTERSECTED].name.toString();
anchorList.unshift(anchorName);
updateDropdown(chooseAnchorController, anchorList);
}
var a = reader.readAsText(anchorData);
});
}
}
}
}
function onKeyDownEvent(event) {
if (event.keyCode == 16 && !shiftPressed){ // SHIFT key
shiftPressed = true;
updatePtsColor();
}
}
function onKeyUpEvent(event) {
if (event.keyCode == 16 && shiftPressed){ // SHIFT key
shiftPressed = false;
updatePtsColor();
}
}
function animate() {
pointCloud.geometry.attributes.position.needsUpdate = true;
pointCloud.geometry.attributes.color.needsUpdate = true;
pointCloud.geometry.attributes.alpha.needsUpdate = true;
pointCloud.geometry.attributes.size.needsUpdate = true;
requestAnimationFrame( animate );
render();
}
function render() {
const time = Date.now() * 0.001;
raycastMouse();
renderer.render( scene, camera );
}
function raycastMouse() {
var topDocs;
if (displayMultiToken) {
raycasterMultiTokens.setFromCamera( mouse, camera );
var intersectsMultiTokens = raycasterMultiTokens.intersectObject(pointCloud);
}
if (annotationOn !== -1) {
raycasterAnnotations.setFromCamera( mouse, camera );
var annotationIntersects = raycasterAnnotations.intersectObject(pointCloud);
}
raycaster.setFromCamera( mouse, camera );
var intersects = raycaster.intersectObject(pointCloud);
// if there is any point being intersected at the moment
if (intersects.length > 0){
var tobeINTERSECTED = null;
for (var i = 0; i < intersects.length; i++) {
// Test shift filtering and then test threshold
if (shiftPressed && availableIds[particleData[intersects[i].index].id]
|| !shiftPressed){
if (
(particleWeight[intersects[i].index] >= nodeWeightThreshold &&
particleConnectionWeight[intersects[i].index]>= connWeightThreshold &&
particleHighDimConnectionWeight[intersects[i].index] >= connWeightHighDimThreshold)
||
(availableIds[particleData[intersects[i].index].id] && alwaysAnchor)
){
tobeINTERSECTED = intersects[i].index;
break;
}
}
}
if ( tobeINTERSECTED && INTERSECTED != intersects[0].index ) {
particleColor[INTERSECTED * 3] = originalRGB[0];
particleColor[INTERSECTED * 3 + 1] = originalRGB[1];
particleColor[INTERSECTED * 3 + 2] = originalRGB[2];
particleOpacity[INTERSECTED] = originalRGB[3];
INTERSECTED = tobeINTERSECTED;
originalRGB = [particleColor[INTERSECTED * 3],
particleColor[INTERSECTED * 3 + 1],
particleColor[INTERSECTED * 3 + 2],
particleOpacity[INTERSECTED]];
particleColor[INTERSECTED * 3] = 1;
particleColor[INTERSECTED * 3 + 1] = 1;
particleColor[INTERSECTED * 3 + 2] = 1;
particleOpacity[INTERSECTED] = 1;
var particle_text = particleData[INTERSECTED].name;
var particle_pos = new THREE.Vector3(particlePositions[INTERSECTED*3],
particlePositions[INTERSECTED*3 + 1],
particlePositions[INTERSECTED*3 + 2]);
// A hacky solution to display multiple tokens
var particle_mesg = "";
if (displayMultiToken){
for (var i = 0; i < intersectsMultiTokens.length; i++) {
if (shiftPressed && availableIds[particleData[intersectsMultiTokens[i].index].id]
|| !shiftPressed){
if (particleWeight[intersectsMultiTokens[i].index] >= nodeWeightThreshold &&
particleConnectionWeight[intersectsMultiTokens[i].index]>= connWeightThreshold &&
particleHighDimConnectionWeight[intersectsMultiTokens[i].index] >= connWeightHighDimThreshold){
particle_mesg += "{" + particleData[intersectsMultiTokens[i].index].name + "}\n";
}
}
}
}
else {
particle_mesg = intersects[i].index.toString() + ": " + particle_text;
}
expand = false;
showTooltip(particle_pos, particle_mesg);
// Check if annotation mode is on and add points to respective annotation group
if (annotationOn !== -1) {
switch (annotationOn) {
case 1:
for (var i = 0; i < annotationIntersects.length; i++) {
particleColor[annotationIntersects[i].index * 3] = annotationOneColor.rgb()[0] / 255;
particleColor[annotationIntersects[i].index * 3 + 1] = annotationOneColor.rgb()[1] / 255;
particleColor[annotationIntersects[i].index * 3 + 2] = annotationOneColor.rgb()[2] / 255;
annotationOnePoints.push(annotationIntersects[i].index.toString() + ": " + particleData[annotationIntersects[i].index].name);
}
originalRGB = [particleColor[INTERSECTED * 3],
particleColor[INTERSECTED * 3 + 1],
particleColor[INTERSECTED * 3 + 2],
particleOpacity[INTERSECTED]];
break
case 2:
for (var i = 0; i < annotationIntersects.length; i++) {
particleColor[annotationIntersects[i].index * 3] = annotationTwoColor.rgb()[0] / 255;
particleColor[annotationIntersects[i].index * 3 + 1] = annotationTwoColor.rgb()[1] / 255;
particleColor[annotationIntersects[i].index * 3 + 2] = annotationTwoColor.rgb()[2] / 255;
annotationTwoPoints.push(annotationIntersects[i].index.toString() + ": " + particleData[annotationIntersects[i].index].name);
}
originalRGB = [particleColor[INTERSECTED * 3],
particleColor[INTERSECTED * 3 + 1],
particleColor[INTERSECTED * 3 + 2],
particleOpacity[INTERSECTED]];
break
case 3:
for (var i = 0; i < annotationIntersects.length; i++) {
particleColor[annotationIntersects[i].index * 3] = annotationThreeColor.rgb()[0] / 255;
particleColor[annotationIntersects[i].index * 3 + 1] = annotationThreeColor.rgb()[1] / 255;
particleColor[annotationIntersects[i].index * 3 + 2] = annotationThreeColor.rgb()[2] / 255;
annotationThreePoints.push(annotationIntersects[i].index.toString() + ": " + particleData[annotationIntersects[i].index].name);
}
originalRGB = [particleColor[INTERSECTED * 3],
particleColor[INTERSECTED * 3 + 1],
particleColor[INTERSECTED * 3 + 2],
particleOpacity[INTERSECTED]];
break
case 4:
for (var i = 0; i < annotationIntersects.length; i++) {
particleColor[annotationIntersects[i].index * 3] = annotationFourColor.rgb()[0] / 255;
particleColor[annotationIntersects[i].index * 3 + 1] = annotationFourColor.rgb()[1] / 255;
particleColor[annotationIntersects[i].index * 3 + 2] = annotationFourColor.rgb()[2] / 255;
annotationFourPoints.push(annotationIntersects[i].index.toString() + ": " + particleData[annotationIntersects[i].index].name);
}
originalRGB = [particleColor[INTERSECTED * 3],
particleColor[INTERSECTED * 3 + 1],
particleColor[INTERSECTED * 3 + 2],
particleOpacity[INTERSECTED]];
break
case 5:
for (var i = 0; i < annotationIntersects.length; i++) {
particleColor[annotationIntersects[i].index * 3] = annotationFiveColor.rgb()[0] / 255;
particleColor[annotationIntersects[i].index * 3 + 1] = annotationFiveColor.rgb()[1] / 255;
particleColor[annotationIntersects[i].index * 3 + 2] = annotationFiveColor.rgb()[2] / 255;
annotationFivePoints.push(annotationIntersects[i].index.toString() + ": " + particleData[annotationIntersects[i].index].name);
}
originalRGB = [particleColor[INTERSECTED * 3],
particleColor[INTERSECTED * 3 + 1],
particleColor[INTERSECTED * 3 + 2],
particleOpacity[INTERSECTED]];
break
default:
break
}
}
}
}
else{
if (INTERSECTED && annotationOn === -1){
particleColor[INTERSECTED * 3] = originalRGB[0];
particleColor[INTERSECTED * 3 + 1] = originalRGB[1];
particleColor[INTERSECTED * 3 + 2] = originalRGB[2];
particleOpacity[INTERSECTED] = originalRGB[3];
} else if (annotationOn !== -1) {
particleColor[INTERSECTED * 3] = annotationOneColor.rgb()[0] / 255;
particleColor[INTERSECTED * 3 + 1] = annotationOneColor.rgb()[1] / 255;
particleColor[INTERSECTED * 3 + 2] = annotationOneColor.rgb()[2] / 255;
}
INTERSECTED = null;
hideTooltip();
}
}
function showTooltip(objectPosition, text) {
var divElement = $("#tooltip");
divElement.css({
display: "block",
opacity: 0.0
});
var canvasHalfWidth = renderer.domElement.offsetWidth / 2;
var canvasHalfHeight = renderer.domElement.offsetHeight / 2;
var tooltipPosition = objectPosition.clone().project(camera);
tooltipPosition.x = (tooltipPosition.x * canvasHalfWidth) + canvasHalfWidth;
tooltipPosition.y = -(tooltipPosition.y * canvasHalfHeight) + canvasHalfHeight;
var tooltipWidth = divElement[0].offsetWidth;
var tooltipHeight = divElement[0].offsetHeight;
divElement.css({
left: `${tooltipPosition.x + tooltipWidth / 16 - tooltipWidth/2}px`,
top: `${tooltipPosition.y + tooltipHeight / 16 + 30}px`
});
divElement.text(text);
divElement.css({opacity: 0.7});
}
function hideTooltip() {
var divElement = $("#tooltip");
if (divElement) {
divElement.css({
display: "none"
});
}
divElement.text('');
}
// Initialize all the data structures
// This function is necessary because it creates all the data structures
function initializeData() {
loadFullData([]);
loadMetaMain([]);
loadAnchor([]);
if (highDimMetricBool) {
loadHighDimAnchor([]);
}
}
// This is the main data load function, calls three other load functions
function automaticLoadData(data_dir) {
// 1. Load full_data
getFileObject(data_dir + "meta-main.txt", function (metamain) {
let reader = new FileReader();
// Clear the scene
scene.remove(scene.children[0]);
group = new THREE.Group();
scene.add(group);
// ===================
reader.onload = (e) => {
const file = e.target.result;
var lines = file.split(/\r\n|\n/);
lines = lines.slice(0, lines.length - 1);
// Important initialization steps
originAttr = lines[0]/1;
// ===================
loadMetaMain(lines);
// 2. Load meta-main, this is embedded because it needs originAttr to be assigned
getFileObject(data_dir + "full_data", function (fulldata) {
let reader = new FileReader();
reader.onload = (e) => {
const file = e.target.result;
var lines = file.split(/\r\n|\n/);
lines = lines.slice(0, lines.length - 1);
loadFullData(lines);
// 3. Load years data
if (yearsBool) {
var req = new XMLHttpRequest();
req.onload = function () {
// change to num years
years_header = this.responseText.split(/\n/)[0].split(/,/);
full_years_arr = this.responseText.split(/\n/);
for (i = 1; i < full_years_arr.length; i++) {
var temp_row = full_years_arr[i].split(/,/);
var temp_key = temp_row[0];
var temp_scores = temp_row.slice(2);
years[temp_key] = temp_scores;
points_with_years.push(temp_key);
}
if (yearsBool) {
minYear = parseFloat(years_header[2]);
maxYear = parseFloat(years_header[years_header.length - 1]);
if (typeof yearUI !== 'undefined') {
gui.remove(yearUI)
}
yearUI = gui.add(GUIparam, 'year', minYear, maxYear).step(0.00001).onChange(function (val) {
var lwr_year = Math.floor(val);
var uppr_year = Math.ceil(val);
var fraction = val - Math.floor(val)
var year_index = lwr_year - minYear;
for (var word_index = 0; word_index < points_with_years.length; word_index++) {
if (uppr_year >= maxYear) {
var uppr_year_index = year_index
} else {
var uppr_year_index = year_index + 1
}
var lwr_year_imp = years[points_with_years[word_index]][year_index];
var uppr_year_imp = years[points_with_years[word_index]][uppr_year_index];
var imp = (1 - fraction) * lwr_year_imp + fraction * uppr_year_imp;
particleSize[points_with_years[word_index]] = imp;
}
});
var obj2 = {
resetSizes: function () {
for (let k = 0; k < maxParticleCount; k++) {
particleSize[k] = 1
}
}
};
if (typeof resetSizesUI !== 'undefined') {
gui.remove(resetSizesUI)
}
resetSizesUI = gui.add(obj2, 'resetSizes').name('resetSizes');
}
}
req.open("GET", dataDirectory + "years/if_idf_scores_fill_with_zeros.csv");
req.send();
}
// 4. Load years data
if (docsBool) {
var docReq = new XMLHttpRequest();
docReq.onload = function () {
// change to num years