-
Notifications
You must be signed in to change notification settings - Fork 4
/
spatial.js
1744 lines (1627 loc) · 79.2 KB
/
spatial.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
let backimage, cropimage;
let Minimap;
let SpatialBackground, SpatialMidground, SpatialForeground;
let SpatialCanvas;
let spatialsketch = (p) => {
let f = {
"fontName": "Arial",
"fontSize": 18
};
let fb = {
"fontName": "Arial",
"fontSize": 18
}; // the font used for general text writing applications. defined in setup
p.initConfig = (windowWidth, windowHeight) => {
p.textFont(f.fontName);
p.textSize(f.fontSize);
};
p.setup = () => {
SpatialCanvas = p.createCanvas(Math.floor(spatial_width), Math.floor(spatial_height));
document.getElementById('pj1').style.height = Math.floor(spatial_height)+'px';
document.getElementById('canvas_box').style.height = Math.floor(p.windowHeight * CANVAS_BOX_HEIGHT_PERCENTAGE)+'px';
SPATIAL = p;
p.initConfig(p.windowWidth, p.windowHeight);
Minimap = p.createGraphics(p.width/2, p.height/2, p.P2D);
SpatialBackground = p.createGraphics(Math.floor(spatial_width), Math.floor(spatial_height), p.P2D);
SpatialMidground = p.createGraphics(Math.floor(spatial_width), Math.floor(spatial_height), p.P2D);
SpatialForeground = p.createGraphics(Math.floor(spatial_width), Math.floor(spatial_height), p.P2D);
background_changed = true;
update_filter_colors();
SpatialCanvas.mouseOver(() => {
p.mouseIsOver_spatial = true;
});
SpatialCanvas.mouseOut(() => { p.mouseIsOver_spatial = false; });
SpatialCanvas.mousePressed(() => {
p.pressedX = p.mouseX;
p.pressedY = p.mouseY;
p.mouseIsPressed_spatial = true;
p.mouseDragX = p.mouseX;
p.mouseDragY = p.mouseY;
X = (p.mouseX-ground_x)*inv_ratio; Y = (p.mouseY-ground_y)*inv_ratio;
if( SHOW_LENS && CONTROL_STATE=="aoi" ){
find_lens(X, Y);
}else if( SHOW_NOTES && CONTROL_STATE=="notes" ){
find_note(p, X, Y);
if(selected_note == -1){
view_panel(4);
new_note(X+OFFSET_X, Y+OFFSET_Y);
}
}else{
find_lens(X, Y);
}
});
SpatialCanvas.mouseClicked(() => {
p.pressedX = p.mouseX; p.pressedY = p.mouseY;
X = (p.mouseX-ground_x)*inv_ratio; Y = (p.mouseY-ground_y)*inv_ratio;
if( SHOW_LENS && CONTROL_STATE=="aoi" ){
if(p.mouseIsDragged) {
p.mouseIsDragged = false;
return; //assumed this is to action on an active lens such as dragging to adjust size or panning
}
click_lens(X, Y);
}else if( SHOW_NOTES && CONTROL_STATE=="notes" ){
}
});
SpatialCanvas.mouseReleased(() => {
p.mouseIsPressed_spatial = false;
if( CONTROL_STATE == 'crop' ){
let x1 = (p.pressedX - ground_x) *inv_ratio + OFFSET_X;
let y1 = (p.pressedY - ground_y)*inv_ratio + OFFSET_Y;
let x2 = (p.mouseX- ground_x)*inv_ratio + OFFSET_X;
let y2 = (p.mouseY- ground_y)*inv_ratio + OFFSET_Y;
if( Math.abs(x1-x2) + Math.abs(y1 - y2) < 10 ){ // restrict to a lens extent if one was clicked
find_lens(x2, y2);
if(selected_lens == -1){ return; }
[x1, y1, x2, y2] = base_lenses[ selected_lens ].extent();
}
if( x1 > x2 ){ [x1, x2] = [x2, x1]; }
if( y1 > y2 ){ [y1, y2] = [y2, y1]; }
x1 = Math.floor(x1); y1 = Math.floor(y1); x2 = Math.ceil(x2); y2 = Math.ceil(y2);
crop_stack.push( [OFFSET_X, OFFSET_Y, WIDTH, HEIGHT, limit_select] );
OFFSET_X = x1; OFFSET_Y = y1; // cropping resets offsets
WIDTH = x2-x1; HEIGHT = y2-y1;
document.getElementById('OFFSET_X').value = OFFSET_X;
document.getElementById('OFFSET_Y').value = OFFSET_Y;
document.getElementById('WIDTH').value = WIDTH;
document.getElementById('HEIGHT').value = HEIGHT;
crop_resized = true;
limit_select = true;
if(HEIGHT / spatial_height > WIDTH / spatial_width){
pos_ratio = spatial_height/HEIGHT; // ratio to position data on canvas
inv_ratio = HEIGHT/spatial_height; // inverse ratio to record canvas position in data
height_adjust = 0;
width_adjust = spatial_width - (spatial_height/HEIGHT* spatial_width);
}else{
pos_ratio = spatial_width/WIDTH;
inv_ratio = WIDTH/spatial_width;
height_adjust = spatial_height - (spatial_width/WIDTH * spatial_height);
width_adjust = 0;
}
ground_x = Math.ceil((spatial_width - (WIDTH * pos_ratio))/2);
ground_y = Math.ceil((spatial_height - (HEIGHT * pos_ratio))/2);
data_resize();
control_state('aoi');
}
});
};
p.draw = () => {
try{
load_controls();
if( (image_url == "" && VALUED.length == 0 && lenses.length == 0 && base_notes.length == 0) || order_twis.length == 0){ // initial message
p.background(0,0,0);
p.stroke(grey(100));
p.noFill();
p.strokeWeight(0);
p.rect(0,0,p.width,p.height);
p.fill(white(100));
p.textFont(f.fontName);
p.textSize(f.fontSize);
p.textAlign( p.CENTER );
p.text("Spatial Canvas, shows the spatial arrangement\nof the data", p.width/2, p.height/2);
if(image_url == "")
image_changed=false;
}else{
p.do_draw();
}
if(HasVal){ do_matrix_overlay(p); }
if(TIMELINE_MOUSE){
if( TIME_DATA=='lens' || TIME_DATA=='data'||TIME_DATA=='all'||TIME_DATA=='group'){
if( selected_data != -1 && DATASETS[selected_data] != undefined){
let data = DATASETS[selected_data];
let twi_id = -1, tmin = 0, tmax = 0, fixs = null, jmin = -1, jmax = -1, twi = null;
if(selected_twi != -1 && data.tois[data.toi_id] != undefined && data.tois[data.toi_id].included) {
twi = data.tois[data.toi_id];
twi_id = twi.twi_id;
if(twi_id < base_twis.length && base_twis[twi_id].included && base_twis[twi_id].checked) ;
else twi_id = -1;
}
if(twi_id > 0) {
tmin = twi.tmin; tmax = twi.tmax;
}
else {
tmin = data.tmin; tmax = data.tmax;
}
fixs = data.fixs;
v = (TIMELINE.mouseX - 200)/(spatial_width-300)*(tmax-tmin) + tmin;
p.stroke( cy(90, data.group) );
p.strokeWeight(2);
if(twi_id > 0) {
for(let j=twi.j_min; j<twi.j_max-1; j++){
let jt = fixs[j].t;
if( jt > v && jt - v < TIMELINE_MOUSEOVER_WINDOW*1000 ){
p.line( fixs[j].x*pos_ratio+ground_x, fixs[j].y*pos_ratio+ground_y, fixs[j+1].x*pos_ratio+ground_x, fixs[j+1].y*pos_ratio+ground_y );
}else if( jt - v > TIMELINE_MOUSEOVER_WINDOW*1000 ){ j = twi.j_max;}
}
}
else {
for(let j=0; j<fixs.length-1; j++){
let jt = fixs[j].t;
if( jt > v && jt - v < TIMELINE_MOUSEOVER_WINDOW*1000 ){
p.line( fixs[j].x*pos_ratio+ground_x, fixs[j].y*pos_ratio+ground_y, fixs[j+1].x*pos_ratio+ground_x, fixs[j+1].y*pos_ratio+ground_y );
}else if( jt - v > TIMELINE_MOUSEOVER_WINDOW*1000 ){ j = fixs.length;}
}
}
}
}
}
}catch(error){ console.error(error); background_changed = true; }
if(p.mouseIsPressed_spatial && CONTROL_STATE == 'crop'){
p.fill(white(30));
p.stroke(white(30));
p.rect( p.pressedX, p.pressedY, p.mouseX - p.pressedX, p.mouseY - p.pressedY );
}
if(p.mouseIsOver_spatial){ // mouse
p.fill(white(30));
p.stroke(white(30));
p.strokeWeight(2);
p.ellipse(p.mouseX, p.mouseY, 12, 12);
}
};
p.do_draw = () => {
p.background(black(100));
// background draw functionality
if(image_url.length > 0){
if(image_changed){ // refresh the image content
image_changed=false; new_back_image=true;
backimage = p.loadImage(image_url);
cropimage = undefined; crop_resized = true;
if(loaded == false){limit_select = false;}
}
if(new_back_image && backimage.width > 1 && backimage.height > 1){ // update the scaling
backimage_empty = false; new_back_image = false;
if(loaded == false){
WIDTH = backimage.width; HEIGHT = backimage.height;
document.getElementById('WIDTH').value = WIDTH; document.getElementById('HEIGHT').value = HEIGHT;
OFFSET_X = 0; OFFSET_Y = 0;
document.getElementById('OFFSET_X').value = 0; document.getElementById('OFFSET_Y').value = 0;
if(HEIGHT / spatial_height > WIDTH / spatial_width){ // checking which relationship limits resize
pos_ratio = spatial_height/HEIGHT; // ratio to position data on canvas
inv_ratio = HEIGHT/spatial_height; // inverse ratio to record canvas position in data
height_adjust = 0;
width_adjust = spatial_width - (spatial_height/HEIGHT* spatial_width);
}else{pos_ratio = spatial_width/WIDTH;
inv_ratio = WIDTH/spatial_width;
height_adjust = spatial_height - (spatial_width/WIDTH * spatial_height);
width_adjust = 0 ;
}
ground_x = Math.ceil((spatial_width - (WIDTH * pos_ratio))/2);
ground_y = Math.ceil((spatial_height - (HEIGHT * pos_ratio))/2);
crop_stack = [ [OFFSET_X, OFFSET_Y, WIDTH, HEIGHT, limit_select] ];
}
background_changed = true;
data_resize();
}
}else if(image_changed){ image_changed = false; background_changed = true; }
if(background_changed){ // includes background fixation density maps
SpatialBackground.background(black(100));
background_changed = false; midground_changed = true;
if( backimage!= undefined && backimage.width*backimage.height>1 ){
backimage_empty = false;
if(backimage != undefined && limit_select == false){
try{ // attach background
cropimage = backimage.get(0, 0, backimage.width, backimage.height);
if(HEIGHT / spatial_height > WIDTH / spatial_width){
cropimage.resize( 0, spatial_height );
}else{cropimage.resize( spatial_width, 0);}
ground_x = Math.ceil((spatial_width - (WIDTH * pos_ratio))/2);
ground_y = Math.ceil((spatial_height - (HEIGHT * pos_ratio))/2);
SpatialBackground.image(cropimage, ground_x, ground_y); //, -OFFSET_X*(cropimage.width/spatial_width), -OFFSET_Y*(cropimage.height/spatial_height) );
SpatialBackground.fill( black(100*(1 - BACK_BRIGHT)) ); SpatialBackground.noStroke();
SpatialBackground.rect(ground_x,ground_y,spatial_width,spatial_height);
}catch (error) { console.error(error); }
}
if( limit_select && crop_resized ){
cropimage = undefined;
cropimage = backimage.get(OFFSET_X, OFFSET_Y, WIDTH, HEIGHT);
if(HEIGHT / spatial_height > WIDTH / spatial_width){
cropimage.resize( 0, spatial_height );
pos_ratio = spatial_height/HEIGHT; // ratio to position data on canvas
inv_ratio = HEIGHT/spatial_height; // inverse ratio to record canvas position in relation to data (e.g. for AOI drawing)
height_adjust = 0;
width_adjust = spatial_width - (spatial_height/HEIGHT* spatial_width);
}else{cropimage.resize( spatial_width, 0 );
pos_ratio = spatial_width/WIDTH;
inv_ratio = WIDTH/spatial_width;
height_adjust = spatial_height - (spatial_width/WIDTH * spatial_height);
width_adjust = 0 ;
}
ground_x = Math.ceil((spatial_width - (WIDTH * pos_ratio))/2);
ground_y = Math.ceil((spatial_height - (HEIGHT * pos_ratio))/2);
crop_resized = false;
}
if(cropimage != undefined){
try{ // attach background
SpatialBackground.image(cropimage, ground_x, ground_y); //, -OFFSET_X*(cropimage.width/spatial_width), -OFFSET_Y*(cropimage.height/spatial_height) );
SpatialBackground.fill( black(100*(1 - BACK_BRIGHT)) ); SpatialBackground.noStroke();
SpatialBackground.rect(ground_x,ground_y,p.width,p.height);
}catch (error) { console.error(error); }
}
} else {
if(HEIGHT / spatial_height >WIDTH / spatial_width){
pos_ratio = spatial_height/HEIGHT; // ratio to position data on canvas
inv_ratio = HEIGHT/spatial_height; // inverse ratio to record canvas position in data
height_adjust = 0;
width_adjust = spatial_width - (spatial_height/HEIGHT* spatial_width);
}else{pos_ratio = spatial_width/WIDTH;
inv_ratio = WIDTH/spatial_width;
height_adjust = spatial_height - (spatial_width/WIDTH * spatial_height);
width_adjust = 0 ;
}
ground_x = Math.ceil((spatial_width - (WIDTH * pos_ratio))/2);
ground_y = Math.ceil((spatial_height - (HEIGHT * pos_ratio))/2);
}
// fixation list draw loop
if(SHOW_FIX){draw_fixs(SpatialBackground);}
if(SHOW_TOPO){draw_topo(SpatialBackground);}
}
if(midground_changed){ // includes the saccades
midground_changed = false; foreground_changed = true;
SpatialMidground.background(black(100));
SpatialMidground.image(SpatialBackground, 0,0 );
if(SHOW_SACCADE){draw_sacs(SpatialMidground);}
}
if(foreground_changed || foreground_redraw){ // includes the foreground marks
SpatialForeground.background(black(100));
SpatialForeground.image(SpatialMidground, 0,0 );
// mask for lens outside cropped area (when cropped)
if(backimage_empty == false || limit_select ){
if(HEIGHT / spatial_height > WIDTH / spatial_width){
draw_mask( SpatialForeground, 0, 0, ground_x, spatial_height);
draw_mask( SpatialForeground, spatial_width - ground_x, 0, ground_x, spatial_height);
}else{
draw_mask( SpatialForeground, 0, 0, spatial_width, ground_y);
draw_mask( SpatialForeground, 0, spatial_height - ground_y, spatial_width, ground_y);
}
}
if(selected_data != -1 && selected_lens != -1 && DATASETS[selected_data] != undefined && DATASETS[selected_data].initialised && SHOW_FORE != "" ){
if( foreground_changed ){ compute_fore_list(); }
if( foreground_redraw ){
draw_fore(SpatialForeground);
}
}else{ foreground_changed = false; foreground_redraw = false; }
}
p.image(SpatialForeground, 0, 0);
//notes
if( SHOW_NOTES ){
p.stroke(white(100)); p.fill(white(100)); p.textFont(f);
draw_notes( p );
}
// lenses
if( SHOW_LENS ){
for(let i=0; i<order_lenses.length; i++){
let l = base_lenses[order_lenses[i]];
p.fill(l.col(20)); p.stroke(l.col(60)); p.strokeWeight(2);
if( building_lens_id==order_lenses[i] || selected_lens==order_lenses[i]){
p.fill(l.col(20)); p.stroke(l.col(75)); p.strokeWeight(5);
}
l.draw(p, building_lens_id==order_lenses[i],
selected_lens==order_lenses[i],
spatial_width, spatial_height);
}
}
};
p.keyPressed = () => {
if( CONTROL_STATE=="notes" ){
key_note( p.key );
return;
}
if(p.key=='s'){p.noLoop();}
if(p.key==p.DELETE ){
try{
delete_lens(selected_lens);
}catch(error){ console.error(error); }
}
};
p.mouseDragged = () => {
if(!p.mouseIsPressed_spatial || p.mouseX < 0 || p.mouseY < 0 || p.mouseX > p.width || p.mouseY > p.height) return;
p.mouseIsDragged = true;
let mouseDx = p.mouseX - p.mouseDragX;
let mouseDy = p.mouseY - p.mouseDragY;
if( SHOW_LENS && CONTROL_STATE=="aoi" ){
if ( selected_lens == -1 ){ return; }
min_id = selected_lens;
base_lenses[min_id].move( (p.mouseDragX-ground_x)*inv_ratio+ OFFSET_X, (p.mouseDragY-ground_y)*inv_ratio+ OFFSET_Y, mouseDx*inv_ratio, mouseDy*inv_ratio);
midground_changed = true;
timeline_changed = true;
matrix_changed = true;
SAC_FILTER_CHANGED = true;
}else if( SHOW_NOTES && CONTROL_STATE=="notes" ){
if( selected_note != -1){
base_notes[selected_note].X += mouseDx*inv_ratio;
base_notes[selected_note].Y += mouseDy*inv_ratio;
}
}
p.mouseDragX = p.mouseX; p.mouseDragY = p.mouseY;
};
p.mouseIsOver_spatial = false;
p.mouseIsPressed_spatial = false;
p.mouseIsDragged = false;
p.pressedX = 0;
p.pressedY = 0;
p.mouseDragX = 0;
p.mouseDragY = 0;
p.resizeElements = (width_changed, height_changed) => {
spatial_width = p.windowWidth * SPATIAL_CANVAS_WIDTH_PERCENTAGE;
spatial_height = p.windowHeight * SPATIAL_CANVAS_HEIGHT_PERCENTAGE;
if(width_changed) {
//update width
document.getElementById('pj1').style.width = Math.floor(spatial_width)+'px';
document.getElementById('canvas_box').style.width = Math.floor(p.windowWidth * SPATIAL_CANVAS_WIDTH_PERCENTAGE)+'px';
}
if(height_changed) {
//update height
document.getElementById('pj1').style.height = Math.floor(spatial_height)+'px';
document.getElementById('canvas_box').style.height = Math.floor(p.windowHeight * CANVAS_BOX_HEIGHT_PERCENTAGE)+'px';
}
p.resizeCanvas(Math.floor(spatial_width), Math.floor(spatial_height));
p.initConfig(p.windowWidth, p.windowHeight);
Minimap = p.createGraphics(p.width/2, p.height/2, p.P2D);
SpatialBackground = p.createGraphics(Math.floor(spatial_width), Math.floor(spatial_height), p.P2D);
SpatialMidground = p.createGraphics(Math.floor(spatial_width), Math.floor(spatial_height), p.P2D);
SpatialForeground = p.createGraphics(Math.floor(spatial_width), Math.floor(spatial_height), p.P2D);
image_changed = true;
loaded = true;
background_changed = true;
};
p.windowResized = () => {
p.resizeElements(true, true);
};
};
let draw_mask = (canvas, x, y, w, h) => {
canvas.fill(4); canvas.noStroke(); canvas.rect(x, y, w, h);
if(x !=0){canvas.stroke(200); canvas.strokeWeight(1); canvas.line(x, 0, x, h);canvas.line(w, 0, w, h);}
if(y !=0){canvas.stroke(200); canvas.strokeWeight(1); canvas.line(0, y, w, y);canvas.line(0, h, w, h);}
};
let draw_fixs_by_twi = (canvas, data, group, twi, fixs) => {
if( !USE_RELATIVE ){ longest_duration = twi.tmax-twi.tmin; }
let j = 0;
let max_val = twi.j_max - twi.j_min -1;
if(fixs.length == 0) {
return;
}
for(let j = twi.j_min, seq=0; j<twi.j_max && (fixs[j].t - twi.tmin)/longest_duration < TIME_ANIMATE; j++,seq++){
if(fixs[j] != undefined && (fixs[j].t - twi.tmin)/longest_duration < TIME_ANIMATE){
let size = Math.exp(FIX_SIZE);
if(FIXS_SATURATION && legval == -1 || legval == group-1) {
let val = 75.5*seq/max_val + 30.0; //interpolation of transparency (saliency) in desired alpha range (30.0, 105.5)
canvas.noStroke();
if(seq == 0)
canvas.fill( cy(105.5, 5));
else if(seq == max_val)
canvas.fill( cy(val, 14));
else
canvas.fill( cy(val, group));
}
else {
canvas.fill(cy(100*Math.exp(FIX_ALPHA), group)); canvas.noStroke();
}
canvas.ellipse(fixs[j].x * pos_ratio + ground_x, fixs[j].y * pos_ratio + ground_y,
size*Math.sqrt(fixs[j].dt), size*Math.sqrt(fixs[j].dt));
let textsize = 20 * (FIX_SIZE + 3) / 6 + 10; //interpolation of textsize in desired text size (10, 30) from FIX_SIZE in (-3, 3)
textsize -= 5;
}
}
}
let draw_fixs = (canvas) => {
try{
for(let i=0;i<VALUED.length;i++){
let v = VALUED[i];
if(DATASETS[v] == undefined || !DATASETS[v].included)
continue;
if(DAT_MODE == 1 && DATASETS[v].group != selected_grp)
continue;
else if(DAT_MODE == 2 && v != selected_data)
continue;
if(v>=0 && v<DATASETS.length && DATASETS[v].initialised && DATASETS[v].checked){
//filter by twi_mode
let data = DATASETS[v]; let fixs = data.fixs;
let group = DATASETS[v].group;
//filter fixations by TWI_MODE
if(TWI_MODE == 2 && selected_twi != -1 && data.tois[data.toi_id] != undefined && data.tois[data.toi_id].included) {
let twi_id = data.tois[data.toi_id].twi_id;
if(twi_id < base_twis.length && base_twis[twi_id].included && base_twis[twi_id].checked) {
draw_fixs_by_twi(canvas, data, group, data.tois[data.toi_id], fixs);
}
}else if(TWI_MODE == 1 && selected_twigroup != -1){
for(let c=0; c<data.tois.length; c++) {
let twi_id = data.tois[c].twi_id;
if(data.tois[c].included && twi_id < base_twis.length && base_twis[twi_id].group == selected_twigroup && base_twis[twi_id].included && base_twis[twi_id].checked ) {
draw_fixs_by_twi(canvas, data, group, data.tois[c], fixs);
}
}
}else if(TWI_MODE == 0){
for(let c=0; c<data.tois.length; c++) {
let twi_id = data.tois[c].twi_id;
if(data.tois[c].included && twi_id < base_twis.length && base_twis[twi_id].included && base_twis[twi_id].checked ) {
draw_fixs_by_twi(canvas, data, group, data.tois[c], fixs);
}
}
}
}
}
}catch (error) { console.error(error); background_changed = true; }
};
function compute_hit_any_aoi_rate_by_twi(HAAR, data, group, twi, fixs){
for(let j = twi.j_min; j<twi.j_max; j++){
if(fixs[j] != undefined){
if(fixs[j].firstlens > -1 && fixs[j].firstlens < lenses.length)
HAAR.hit++;
else
HAAR.off++;
}
}
}
function compute_hit_any_aoi_rate(){
//calculate aggregated HAAR
let HAAR = {"hit": 0, "off": 0, "haar": 0};
for(let i=0;i<VALUED.length;i++){
let v = VALUED[i];
if(v>=0 && v<DATASETS.length && DATASETS[v].initialised && DATASETS[v].checked && DATASETS[v].included){
//filter by twi_mode
let data = DATASETS[v]; let fixs = data.fixs;
let group = DATASETS[v].group;
//filter fixations by TWI_MODE
if(TWI_MODE == 2 && selected_twi != -1 && data.tois[data.toi_id] != undefined && data.tois[data.toi_id].included) {
let twi_id = data.tois[data.toi_id].twi_id;
if(twi_id < base_twis.length && base_twis[twi_id].included && base_twis[twi_id].checked) {
compute_hit_any_aoi_rate_by_twi(HAAR, data, group, data.tois[data.toi_id], fixs);
}
}else if(TWI_MODE == 1 && selected_twigroup != -1){
for(let c=0; c<data.tois.length; c++) {
let twi_id = data.tois[c].twi_id;
if(data.tois[c].included && twi_id < base_twis.length && base_twis[twi_id].group == selected_twigroup && base_twis[twi_id].included && base_twis[twi_id].checked ) {
compute_hit_any_aoi_rate_by_twi(HAAR, data, group, data.tois[c], fixs);
}
}
}else if(TWI_MODE == 0){
for(let c=0; c<data.tois.length; c++) {
let twi_id = data.tois[c].twi_id;
if(data.tois[c].included && twi_id < base_twis.length && base_twis[twi_id].included && base_twis[twi_id].checked ) {
compute_hit_any_aoi_rate_by_twi(HAAR, data, group, data.tois[c], fixs);
}
}
}
}
}
return HAAR;
}
let draw_pixel_poly = (canvas, point_vector) => {
canvas.beginShape();
for(let vertex=0; vertex<point_vector.length; vertex+=2){ canvas.vertex( Math.floor(point_vector[vertex]), Math.floor(point_vector[vertex+1]) ); }
canvas.endShape();
};
let draw_topo = (canvas) => {
let found_flag = false;
for(let v=0;v<VALUED.length;v++){
if(DATASETS[VALUED[v]] == undefined || !DATASETS[VALUED[v]].included)
continue;
if(DAT_MODE == 1 && DATASETS[VALUED[v]].group != selected_grp)
continue;
else if(DAT_MODE == 2 && VALUED[v] != selected_data)
continue;
for(let t=0;t<DATASETS[VALUED[v]].tois.length;t++){
if( DATASETS[ VALUED[v] ].tois[t] != undefined && DATASETS[ VALUED[v] ].tois[t].included &&
DATASETS[ VALUED[v] ].tois[t].update_topo ){
give_topography(VALUED[v], t);
found_flag = true;
}
}
}
if(update_topos || found_flag){ compute_topos(); }
try{
for(let V=0;V<GROUPS.length;V++){
let group = GROUPS[V].group;
if((DAT_MODE == 1 || DAT_MODE == 2) && group != selected_grp)
continue;
let values = GROUPS[V].values; let max_value = GROUPS[V].max_value;
let width = canvas.width; let height = canvas.height;
canvas.strokeWeight(1);
for(let l=0; l<levels.length; l++){
let v = levels[l]*max_value;
for(let i = 0; i < X_NUM- 1; i++ ){
for(let j = 0; j < Y_NUM - 1; j++){
tl = values[i][j]; tr = values[i][j+1];
bl = values[i+1][j]; br = values[i+1][j+1];
// need to divide the line drawing into cases
num = 0;
if(tl < v){ num += 1; }
if(tr < v){ num += 2; }
if(bl < v){ num += 4; }
if(br < v){ num += 8; }
// cases are now controlled by the num, with 0 or 15 being "all on one side"
ls = Math.min(1, Math.max(0, (v-tl)/(bl-tl) ));
rs = Math.min(1, Math.max(0, (v-tr)/(br-tr) ));
ts = Math.min(1, Math.max(0, (v-tl)/(tr-tl) ));
bs = Math.min(1, Math.max(0, (v-bl)/(br-bl) ));
canvas.stroke( cy( Math.sqrt(levels[l]) * 256, group) ); canvas.noFill();
if( num == 3 || num == 12){ // vertical line case
canvas.line( (i+ls)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+rs)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y);
}else if( num == 5 || num == 10){ // horizontal line case
canvas.line( (i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+ts)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+bs)*(HEIGHT*pos_ratio)/Y_NUM+ground_y);
}else if( num == 1 || num == 14){
canvas.line( (i+ls)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+ts)*(HEIGHT*pos_ratio)/Y_NUM+ground_y);
}else if( num == 2 || num == 13){
canvas.line( (i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+ts)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+rs)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y);
}else if( num == 4 || num == 11){
canvas.line( (i+ls)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+bs)*(HEIGHT*pos_ratio)/Y_NUM+ground_y);
}else if( num == 8 || num == 7){
canvas.line( (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+bs)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+rs)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y);
}else if( num == 9 || num == 6){ // weird double-diagonal case, pick the diagonal pairing that is shorter
if( ls + ts < bs + rs ){
canvas.line( (i+ls)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+ts)*(HEIGHT*pos_ratio)/Y_NUM+ground_y);
canvas.line( (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+bs)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+rs)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y);
}else{
canvas.line( (i+ls)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+bs)*(HEIGHT*pos_ratio)/Y_NUM+ground_y);
canvas.line( (i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+ts)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+rs)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y);
}
}
// fill step
if(max_value > 0)
canvas.fill( cy( 15, group) );
canvas.noStroke();
if( num == 0 ){ // entire square is above the layer
draw_pixel_poly(canvas, [(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y]);
}else if( num == 12 ){ // half segments
draw_pixel_poly(canvas, [(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+rs)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+ls)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y]);
}else if( num == 3 ){
draw_pixel_poly(canvas, [(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+rs)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+ls)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y]);
}else if( num == 10 ){
draw_pixel_poly(canvas, [(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+bs)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+ts)*(HEIGHT*pos_ratio)/Y_NUM+ground_y]);
}else if( num == 5 ){
draw_pixel_poly(canvas, [(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+bs)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+ts)*(HEIGHT*pos_ratio)/Y_NUM+ground_y]);
}else if( num == 1 ){ // three corner above segments
draw_pixel_poly(canvas, [(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+ts)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+ls)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y]);
}else if( num == 14 ){ // one corner above segments
draw_pixel_poly(canvas, [(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+ts)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+ls)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y ]);
}else if( num == 2 ){ // three corner above segments
draw_pixel_poly(canvas, [(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+ts)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+rs)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y ]);
}else if( num == 13 ){ // one corner above segments
draw_pixel_poly(canvas, [(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+ts)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+rs)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y ]);
}else if( num == 4 ){ // three corner above segments
draw_pixel_poly(canvas, [(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+bs)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+ls)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y ]);
}else if( num == 11 ){ // one corner above segments
draw_pixel_poly(canvas, [(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+bs)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+ls)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y ]);
}else if( num == 8 ){ // three corner above segments
draw_pixel_poly(canvas, [(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+bs)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+rs)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y ]);
}else if( num == 7 ){ // one corner above segments
draw_pixel_poly(canvas, [(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+bs)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+rs)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y ]);
}else if( num == 9 ){ // weird double-diagonal case, pick the diagonal pairing that is shorter
if( ls + ts < bs + rs ){ // two triangles case
draw_pixel_poly(canvas, [(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+bs)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+rs)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y ]);
draw_pixel_poly(canvas, [(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+ts)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+ls)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y ]);
}else{ // hexagon case
draw_pixel_poly(canvas, [
(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+rs)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+bs)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+ls)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+ts)*(HEIGHT*pos_ratio)/Y_NUM+ground_y ]);
}
}else if( num == 6 ){ // weird double-diagonal case, pick the diagonal pairing that is shorter
if( ls + ts < bs + rs ){ // hexagon case
draw_pixel_poly(canvas, [
(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+rs)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+ts)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+ls)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y,
(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+bs)*(HEIGHT*pos_ratio)/Y_NUM+ground_y ]);
}else{ // two triangles case
draw_pixel_poly(canvas, [(i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+bs)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+1)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+ls)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j)*(HEIGHT*pos_ratio)/Y_NUM+ground_y ]);
draw_pixel_poly(canvas, [(i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+ts)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y, (i+rs)*(WIDTH*pos_ratio)/X_NUM+ground_x, (j+1)*(HEIGHT*pos_ratio)/Y_NUM+ground_y ]);
}
}
}
}
}
}
}catch (error) { console.error(error); background_changed = true; }
};
coef_splat = [2,6,10,14,16,20];
coef_weight = [];
occ_type = [0, 0, 0]; occ_dir = [0,0,0,0,0,0,0,0,0];
let draw_saccade_by_twi = (canvas, sacs, data, group, toi, longest_duration, new_type, new_dir, coef_weight) => {
let max_val = toi.j_max - toi.j_min -1;
if( !USE_RELATIVE ){ longest_duration = toi.tmax-toi.tmin; }
for(let j = toi.j_min, seq = 0; j<toi.j_max-1 && (sacs[j].t2 - toi.tmin)/longest_duration < TIME_ANIMATE; j++, seq++){
if( sacs[j].filter ){
if(sacs[j].length < SHORT_LENGTH){ new_type[0] += 1;}
else if(sacs[j].glance){ new_type[2] += 1;}
else{ new_type[1] += 1; }
new_dir[ (Math.floor( (sacs[j].tan * 4) / Math.PI + 0.5) + 4) % 8 ] += 1;
for(let splat=0; splat<coef_splat.length; splat++){
if(coef_splat[splat] > 0){
canvas.noFill(); canvas.strokeWeight(coef_splat[splat]);
if(COLOUR_MODE == "group"){
if(SACC_SATURATION && legval == -1 || legval == group-1) {
canvas.strokeWeight(3);
let val = 25.5*seq/max_val + 3.0; //interpolation of transparency (saliency) in desired alpha range (3.0, 25.5)
canvas.stroke( cy(val, group));
}
else {
canvas.stroke(cy(coef_weight[splat], group));
}
}
else if(COLOUR_MODE == "direction"){ canvas.stroke(color_wheel(coef_weight[splat], sacs[j].tan)); }
else if(COLOUR_MODE == "type"){
if(sacs[j].length < SHORT_LENGTH){ canvas.stroke( sacc_short(coef_weight[splat]) );}
else if(sacs[j].glance){ canvas.stroke( sacc_glance(coef_weight[splat]) );}
else{ canvas.stroke( sacc_basic(coef_weight[splat]) ); }
}
canvas.beginShape();
for(let m=0;m<sacs[j].xs.length;m++){
canvas.vertex(sacs[j].xs[m] * pos_ratio + ground_x, sacs[j].ys[m] * pos_ratio + ground_y);
}
canvas.endShape();
}
}
}
}
if(SACC_SATURATION) {
if(data.fixs.length == 0) {
return;
}
let textsize = 20 * (FIX_SIZE + 3) / 6 + 10; //interpolation of textsize in desired text size (10, 30) from FIX_SIZE in (-3, 3)
// textsize -= 5;
for(let j = toi.j_min, seq=0; j<toi.j_max && (data.fixs[j].t - toi.tmin)/longest_duration < TIME_ANIMATE; j++,seq++){
if(data.fixs[j] != undefined && (data.fixs[j].t - toi.tmin)/longest_duration < TIME_ANIMATE){
if(FIXS_SATURATION && legval == -1 || legval == group-1) {
//draw text label
canvas.strokeWeight(0);
canvas.fill(black(100));
canvas.textSize(textsize);
if(max_val <= 10){
if(seq%2 == 0) {
canvas.text( num_format(seq, 2), data.fixs[j].x * pos_ratio + ground_x-7, data.fixs[j].y * pos_ratio + ground_y+7);
}
}
else if(seq%5 == 0 || seq+1 == toi.j_max)
canvas.text( num_format(seq, 2), data.fixs[j].x * pos_ratio + ground_x-7, data.fixs[j].y * pos_ratio + ground_y+7);
console.log("text size: "+textsize+", data.fixs_size: "+FIX_SIZE);
canvas.textSize(f.fontSize);
canvas.strokeWeight(1);
}
}
}
}
};
let draw_sacs = (canvas) => {
filter_saccades();
coef_weight = [];
for(let i=0; i<coef_splat.length; i++){ // compute splat weights from control parameters
coef_weight.push( Math.floor( Math.exp( SACC_BRIGHT - Math.exp(-SACC_BLUR)*(coef_splat[i]-2)**2 ) ) );
if(i>0){ coef_weight[i-1] -= coef_weight[i]; }
}
try{
new_type = [0, 0, 0]; new_dir = [0,0,0,0,0,0,0,0,0];
for(let i=0;i<VALUED.length;i++){
let v = VALUED[i];
if(DATASETS[v] == undefined || !DATASETS[v].included)
continue;
if(DAT_MODE == 1 && DATASETS[v].group != selected_grp)
continue;
else if(DAT_MODE == 2 && v != selected_data)
continue;
if(v>=0 && v<DATASETS.length && DATASETS[v].initialised && DATASETS[v].checked){
//filter by twi_mode
let data = DATASETS[v]; let sacs = data.sacs; let group = data.group;
//filter sacs by TWI_MODE
if(TWI_MODE == 2 && selected_twi != -1 && data.tois[data.toi_id] != undefined && data.tois[data.toi_id].included) {
let twi_id = data.tois[data.toi_id].twi_id;
if(twi_id < base_twis.length && base_twis[twi_id].included && base_twis[twi_id].checked) {
draw_saccade_by_twi(canvas, sacs, data, group, data.tois[data.toi_id], longest_duration, new_type, new_dir, coef_weight);
}
}else if(TWI_MODE == 1 && selected_twigroup != -1){
for(let c=0; c<data.tois.length; c++) {
let twi_id = data.tois[c].twi_id;
if(data.tois[c].included && twi_id < base_twis.length && base_twis[twi_id].group == selected_twigroup && base_twis[twi_id].included && base_twis[twi_id].checked ) {
draw_saccade_by_twi(canvas, sacs, data, group, data.tois[c], longest_duration, new_type, new_dir, coef_weight);
}
}
}else if(TWI_MODE == 0){
for(let c=0; c<data.tois.length; c++) {
let twi_id = data.tois[c].twi_id;
if(data.tois[c].included && twi_id < base_twis.length && base_twis[twi_id].included && base_twis[twi_id].checked ) {
draw_saccade_by_twi(canvas, sacs, data, group, data.tois[c], longest_duration, new_type, new_dir, coef_weight);
}
}
}
}
}
let diff=false;
for(let i=0;i<3;i++){diff |= (new_type[i]!=occ_type[i]); }
for(let i=0;i<7;i++){diff |= (new_dir[i]!=occ_dir[i]); }
if( diff ){ occ_type=new_type; occ_dir=new_dir; update_legend=true; }
}catch (error) { console.error(error); midground_changed = true; }
};
FORE_LIST = [];
let compute_fore_list = () => {
try{
foreground_changed = false;
let l = base_lenses[selected_lens];
let toi_list = [];
let fixs_list = [];
//aggregate based on DAT_MODE and TWI_MODE
if(DAT_MODE == 0) {
for(let d=0; d<VALUED.length; d++) {
let data = DATASETS[VALUED[ d ]];
let fixs = data.fixs;
if(TWI_MODE == 2 && selected_twi != -1 && data.tois[data.toi_id] != undefined && data.tois[data.toi_id].included) {
let twi_id = data.tois[data.toi_id].twi_id;
if(twi_id < base_twis.length && base_twis[twi_id].included && base_twis[twi_id].checked) {
toi_list.push(data.tois[data.toi_id]);
fixs_list.push(fixs);
}
}else if(TWI_MODE == 1 && selected_twigroup != -1){
for(let c=0; c<data.tois.length; c++) {
let twi_id = data.tois[c].twi_id;
if(data.tois[c].included && twi_id < base_twis.length && base_twis[twi_id].group == selected_twigroup && base_twis[twi_id].included && base_twis[twi_id].checked ) {
toi_list.push(data.tois[c]);
fixs_list.push(fixs);
}
}
}else if(TWI_MODE == 0){
for(let c=0; c<data.tois.length; c++) {
let twi_id = data.tois[c].twi_id;
if(data.tois[c].included && twi_id < base_twis.length && base_twis[twi_id].included && base_twis[twi_id].checked ) {
toi_list.push(data.tois[c]);
fixs_list.push(fixs);
}
}
}
}
}else if(DAT_MODE == 1 && ORDERGROUPID.indexOf(selected_grp) != -1){
for(let d=0; d<VALUED.length; d++) {
if(DATASETS[VALUED[d]].group == selected_grp){
let data = DATASETS[VALUED[d]];
let fixs = data.fixs;
if(TWI_MODE == 2 && selected_twi != -1 && data.tois[data.toi_id] != undefined && data.tois[data.toi_id].included) {
let twi_id = data.tois[data.toi_id].twi_id;
if(twi_id < base_twis.length && base_twis[twi_id].included && base_twis[twi_id].checked) {
toi_list.push(data.tois[data.toi_id]);
fixs_list.push(fixs);
}
}else if(TWI_MODE == 1 && selected_twigroup != -1){
for(let c=0; c<data.tois.length; c++) {
let twi_id = data.tois[c].twi_id;
if(data.tois[c].included && twi_id < base_twis.length && base_twis[twi_id].group == selected_twigroup && base_twis[twi_id].included && base_twis[twi_id].checked ) {
toi_list.push(data.tois[c]);
fixs_list.push(fixs);
}
}
}else if(TWI_MODE == 0){
for(let c=0; c<data.tois.length; c++) {
let twi_id = data.tois[c].twi_id;
if(data.tois[c].included && twi_id < base_twis.length && base_twis[twi_id].included && base_twis[twi_id].checked ) {
toi_list.push(data.tois[c]);
fixs_list.push(fixs);
}
}
}
}
}
}else if(DAT_MODE == 2 && VALUED.indexOf(selected_data) != -1 && DATASETS[selected_data] != undefined && lenses.length > 0) {
data = DATASETS[selected_data]; fixs = data.fixs;
if(TWI_MODE == 2 && selected_twi != -1 && data.tois[data.toi_id] != undefined && data.tois[data.toi_id].included) {
let twi_id = data.tois[data.toi_id].twi_id;
if(twi_id < base_twis.length && base_twis[twi_id].included && base_twis[twi_id].checked) {
toi_list.push(data.tois[data.toi_id]);
fixs_list.push(fixs);
}
}else if(TWI_MODE == 1 && selected_twigroup != -1){
for(let c=0; c<data.tois.length; c++) {
let twi_id = data.tois[c].twi_id;
if(data.tois[c].included && twi_id < base_twis.length && base_twis[twi_id].group == selected_twigroup && base_twis[twi_id].included && base_twis[twi_id].checked ) {
toi_list.push(data.tois[c]);
fixs_list.push(fixs);
}
}
}else if(TWI_MODE == 0){
for(let c=0; c<data.tois.length; c++) {
let twi_id = data.tois[c].twi_id;
if(data.tois[c].included && twi_id < base_twis.length && base_twis[twi_id].included && base_twis[twi_id].checked ) {
toi_list.push(data.tois[c]);
fixs_list.push(fixs);
}
}
}
}
for(let i = 0; i<fixs_list.length; i++) {
for(let j = 0; j<fixs_list[i].length; j++){ // compute interaction with the selected lens
fixs_list[i][j].in_selected = l.inside(fixs_list[i][j].x, fixs_list[i][j].y);
}
}
let lens_bins = 60; lens_vals = [];
let time_bins = 60; time_vals = [];
// find lens edges and build lens hist values list
for(let i=0;i<lens_bins;i++){
lens_vals.push(10); angle = SPATIAL.TWO_PI*((i+0.5)/lens_bins); step = 50;
for(let k=1;k<30;k++){ // step out to the edge
if( l.inside((l.centx + Math.cos(angle)*lens_vals[i]*inv_ratio)-OFFSET_X, (l.centy + Math.sin(angle)*lens_vals[i]*inv_ratio)-OFFSET_Y)){ lens_vals[i]+=step ; }else{ lens_vals[i]-=step; step /= 2; }
}
lens_vals[i] += 10;
}
// build time hist values list
for(let i=0;i<time_bins;i++){ time_vals.push(20); }
// construct relevance list with all three sets of locations
FORE_LIST = [];
for(let i = 0; i<fixs_list.length; i++){
for(let j = 0; j<fixs_list[i].length - 1; j++){
if( fixs_list[i][j].t > toi_list[i].tmin && fixs_list[i][j].t < toi_list[i].tmax){
before = j<fixs_list[i].length-1 && fixs_list[i][j+1].in_selected;
now = fixs_list[i][j].in_selected;
after = j>0 && fixs_list[i][j-1].in_selected;
if(!now && (before || after) ){
s = Math.exp(FORE_SIZE); if(USE_SIZE){ s *= Math.sqrt(fixs_list[i][j].dt)*0.04; }
lens_bin = Math.floor(lens_bins*(Math.PI+Math.atan2(l.centy-OFFSET_Y-fixs_list[i][j].y, l.centx-OFFSET_X-fixs_list[i][j].x))/SPATIAL.TWO_PI) % lens_bins;
angle = SPATIAL.TWO_PI*((lens_bin+0.5)/lens_bins);
time_bin = Math.floor( time_bins * (fixs_list[i][j].t -toi_list[i].tmin) / (toi_list[i].tmax - toi_list[i].tmin) ) % time_bins;
lens_vals[lens_bin] += 0.75*s;
time_vals[time_bin] += 0.75*s;
FORE_LIST.push({fix:fixs_list[i][j], before:before, after:after, size:s,
spatial_x:fixs_list[i][j].x * pos_ratio + ground_x, spatial_y:fixs_list[i][j].y * pos_ratio + ground_y,
lens_x: (l.centx-OFFSET_X) * pos_ratio + ground_x + lens_vals[lens_bin]*Math.cos(angle), lens_y: (l.centy-OFFSET_Y) * pos_ratio + ground_y + lens_vals[lens_bin]*Math.sin(angle),
time_x: (time_bin * (spatial_width-200))/time_bins + 100, time_y: spatial_height - time_vals[time_bin]
});
lens_vals[lens_bin] += 0.75*s;
time_vals[time_bin] += 0.75*s;
}
}
}
}
foreground_redraw = true;
}catch (error) { console.error(error); foreground_changed = true; }
};
SPLIT_STATE = [1.0, 0.0, 0.0]; STEPS = 20;
let draw_fore = (canvas) => {
foreground_redraw = false;
canvas.noStroke();
for(let j = 0; j<FORE_LIST.length; j++){