-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgviz-menu.js
2744 lines (2350 loc) · 111 KB
/
cgviz-menu.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
/*
cgviz-menu
Html menu handling
# Author: Malek Cellier
#
# Email: [email protected]
# Created: 2020-02-02
*/
class CgVizMenu {
/**
* Hierarchy
* menu: left hand side menu. main
* panel: right hand side menu with colorbar etc
* modal: file loading
* info: renderer info
*/
constructor() {
this.cgviz = null; // reference to the cgviz instance
this._directory = null;
this.setup();
//this.AddToolTips(); // Has to be the last one called
}
setup() {
this.createMenu();
this.createPanel();
this.createModal();
this.createCanvas();
}
createMenu() {
/**
* The menu has a container which in turn has:
* the main menu
* head
* body
* the menu control
*/
// The menu container
let menu = _el('div', 'menu-container', ['hidden']);
// The main menu
let menu_main = _el('div', 'menu-main', ['hidden']);
// The main menus's head
menu_main.appendChild(this._createMenu_Head());
// The main menu's body
menu_main.appendChild(this._createMenu_Body());
// The menu control
let menu_ctrl = _el('div', 'menu-control');
menu_ctrl.appendChild(this.createSvg('show_hide')); // The svg logo
menu_ctrl.addEventListener('click', () => this._eventShowHideMainMenu());
// Append children to the menu container
menu.appendChild(menu_main);
menu.appendChild(menu_ctrl);
// Append the menu container to the body
document.body.appendChild(menu);
}
_createMenu_Head() {
/**
* The menu head has 2 parts:
* the logo
* the tabs selector
*/
let head_container = _el('div', 'menu-main-head-container');
head_container.appendChild(this.__createMenu_MainHead());
head_container.appendChild(this.__createMenu_MainHeadTabs());
return head_container;
}
__createMenu_MainHead() {
let head = _el('div', 'menu-main-head');
// Head left contains the LOGO and Titles
let head_left = _el('div', 'menu-main-head-left');
head.appendChild(head_left);
// Head right contains the icons for bug report, share, info
let head_right = _el('div', 'menu-main-head-right');
head.appendChild(head_right);
// HEad LEFT
// The cgviz logo with 2 circles
let logo = _el('div', 'menu-main-head-logo-svg');
logo.appendChild(this.createSvg('cgviz'));
head_left.appendChild(logo);
// The title and subtitle
let title = _el('div', 'menu-main-head-logo');
title.innerText = 'cg-viz';
let subtitle = _el('div', 'menu-main-head-logo-subtitle');
subtitle.appendChild(document.createTextNode('lite'));
title.appendChild(subtitle);
head_left.append(title);
// HEAD RIGHT
// Create a new issue in GitLab
let bug = _el('div', '', ['top-icon']);
bug.appendChild(this.createSvg('bug'));
bug.addEventListener('click', () => { window.open('http://rnd-gitlab-eu.gmail.com/ransystem-eu/cg-viz-lite/issues/new', '_blank'); });
addTooltip(bug, 'bottom', 'File an issue in the gitlab');
head_right.appendChild(bug);
// Open the Wiki in Gitlab
let info = _el('div', '', ['top-icon']);
info.appendChild(this.createSvg('info'));
info.addEventListener('click', () => { window.open('http://rnd-gitlab-eu.gmail.com/ransystem-eu/cg-viz-lite/wikis/home', '_blank'); });
addTooltip(info, 'left', 'Wiki access');
head_right.appendChild(info);
// Take a screenshot of the screen
let share = _el('div', '', ['top-icon']);
share.appendChild(this.createSvg('share'));
share.addEventListener('click', () => this._eventCaptureScreen());
head_right.appendChild(share);
return head;
}
__createMenu_MainHeadTabs() {
/**
* One tab per menu category:
* scenarios
* filters
* interactions
* settings
*/
let head_tabs = _el('div', 'menu-main-head-tabs');
let tab_scenario = _el('div', 'tab-Scenarios', ['tab', 'current-tab']);
tab_scenario.appendChild(this.createSvg('scenarios'));
tab_scenario.addEventListener('click', (evt) => this._eventTabSelection(evt));
head_tabs.appendChild(tab_scenario);
let tab_filter = _el('div', 'tab-Filters', ['tab']);
tab_filter.appendChild(this.createSvg('filters'));
tab_filter.addEventListener('click', (evt) => this._eventTabSelection(evt));
head_tabs.appendChild(tab_filter);
let tab_interaction = _el('div', 'tab-Interactions', ['tab']);
tab_interaction.appendChild(this.createSvg('interactions'));
tab_interaction.addEventListener('click', (evt) => this._eventTabSelection(evt));
head_tabs.appendChild(tab_interaction);
let tab_setting = _el('div', 'tab-Settings', ['tab']);
tab_setting.appendChild(this.createSvg('settings'));
tab_setting.addEventListener('click', (evt) => this._eventTabSelection(evt));
head_tabs.appendChild(tab_setting);
return head_tabs;
}
_createMenu_Body() {
/**
* The menu body contains as many divs as there are categories:
* scenarios
* filters
* interactions
* settings
* Only one of them is visible at any time
*/
let main_body = _el('div', 'menu-main-body');
main_body.appendChild(this.__createMenu_Scenarios());
main_body.appendChild(this.__createMenuFilters());
main_body.appendChild(this.__createMenuInteractions());
main_body.appendChild(this.__createMenuSettings());
return main_body;
}
__createMenu_Scenarios() {
let scenarios = _el('div', 'Scenarios', ['container-tab-content', 'visible']);
let title = _el('div', '', ['menu-title']);
title.innerText = 'Scenarios';
scenarios.appendChild(title);
// A visiual separator
scenarios.appendChild(_el('hr', '', ['title-body-separator']));
// A container for the scenario data
scenarios.appendChild(_el('div', 'div-scenarios'));
// A button to laod a scenario
let btn = _el('div', '', ['div-button', 'scenario']);
btn.appendChild(this.createSvg('add'));
let txt = _el('p', '', ['menu-text']);
txt.innerText = 'Add Scenario';
btn.addEventListener('click', () => this._eventShowModal());
btn.appendChild(txt)
scenarios.appendChild(btn);
return scenarios;
}
__populateMenuScenariosContent() {
/**
* The scenarios div contains:
* A Header with the name of the scenario, under which
* a smaller header for each category: obj, pov, rays, kpis
* a box for elements of each category
*
* Example:
* HongKong:
* Object
* {list of obj files}
* Point of View
* {list of simple boxes with eye and color}
* Traces
* {2 levels: tx level and then rx level}
* Kpis
* {...}
*/
console.group('Populate scenarios content');
console.time('Populate scenarios content');
let div = _get('#div-scenarios');
// The ID of the scenario is contained in this.cgviz.data.selected
// in case the ID already exists, it is removed and built anew
let div_scenario = _get('#' + this.cgviz.data.selected);
if (div_scenario !== null) {
div.removeChild(div_scenario);
}
// 1) THE HEADER
div_scenario = this.HeaderMenu(this.cgviz.data.selected, 'scenario-header', '', false, true);
// attach en event to the click on the expand element
div_scenario.getElementsByClassName('expand')[0].addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
div.appendChild(div_scenario);
// 2) THE CONTENT
let sce_content = _el('div', '', ['scenario-content', 'hidden']);
div.appendChild(sce_content);
// 2.1) The universe
console.info(' universe');
// 2.1.1) the header
let obj_header = this.HeaderMenu('Universe', 'obj-header');
obj_header.querySelector('.eye').addEventListener('click', (evt) => this._eventToggleEntireUniverse(evt));
sce_content.appendChild(obj_header);
// 2.1.2 the content
let obj_content = this.__populateUniverseContent();
if (obj_content !== undefined) {
sce_content.appendChild(obj_content);
obj_header.getElementsByClassName('expand')[0].addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
}
// 2.2) The Point of Views
console.info(' point of views');
// 2.2.1) the header
let pov_header = this.HeaderMenu('PoV', 'pov-header');
pov_header.querySelector('.eye').addEventListener('click', (evt) => this._eventToggleAllPovs(evt));
sce_content.appendChild(pov_header);
// 2.2.2) the content
//let pov_content = _el('div', '', ['pov-content', 'hidden']);
let pov_content = this.__populatePovContent();
if (pov_content !== undefined) {
sce_content.appendChild(pov_content);
pov_header.getElementsByClassName('expand')[0].addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
}
// TODO: general module to group the boxes by 50s for ex
// 2.3) The traces:
console.info(' traces');
// 2.3.1) the header
let trace_header = this.HeaderMenu('Traces', 'trace-header');
trace_header.querySelector('.eye').addEventListener('click', (evt) => this._eventToggleAllRays(evt));
sce_content.appendChild(trace_header);
// 2.3.2) the content
let trace_content = this.__populateTraceContent();
if (trace_content !== undefined) {
sce_content.appendChild(trace_content);
trace_header.getElementsByClassName('expand')[0].addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
}
// 2.4) The kpis
console.info(' kpis');
// 2.4.1) the header
let kpis_header = this.HeaderMenu('Kpis', 'kpis-header', '', false, false, false);
sce_content.appendChild(kpis_header);
// 2.4.2) the content
let kpis_content = this.__populateKpisContent();
if (kpis_content !== undefined) {
sce_content.appendChild(kpis_content);
kpis_header.getElementsByClassName('expand')[0].addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
}
console.groupEnd('Populate scenarios content');
console.timeEnd('Populate scenarios content');
}
__populateUniverseContent() {
/**
* The Universe is a list of .obj files with show/hide option
*/
let qcmUniverse = this.cgviz.data.scenarios[this.cgviz.data.selected].qcmUniverse;
let objects = Object.keys(qcmUniverse.objs);
if (objects.length === 0) {
console.warn('no universe objects found');
return;
}
let obj_content = _el('div', '', ['obj-content', 'hidden']);
// Add the .obj files
for (let i=0; i<objects.length; i++) {
let submenu = this.HeaderSubMenu(objects[i]);
submenu.querySelector('.eye').addEventListener('click', (evt) => this._eventToggleUniverse(evt));
obj_content.appendChild(submenu);
}
// Add a ground plane
let submenu = this.HeaderSubMenu('ground plane');
submenu.querySelector('.eye').addEventListener('click', (evt) => this._eventToggleGroundPlane(evt));
obj_content.appendChild(submenu);
return obj_content;
}
__populatePovContent() {
/**
* The point of view are:
* - grouped by name
* - represented by small boxes the size of up to 4 digits, for the POV ID
* TODO: general module to group the boxes by 50s for ex
*/
// pov_content is the div
// TODO: change the key
let qcmPov = this.cgviz.data.scenarios[this.cgviz.data.selected].qcmPov;
let pov_types = Object.keys(qcmPov);
if (pov_types.length === 0) {
console.log('No data in qcmPov');
return;
}
let pov_content = _el('div', '', ['pov-content', 'hidden']);
let pov_type;
for (let i=0; i<pov_types.length; i++) {
pov_type = pov_types[i];
let submenu = this.HeaderSubMenu(pov_type, '', true);
pov_content.appendChild(submenu);
// show/hide all the pov of this type in the scene
submenu.querySelector('.eye').addEventListener('click', (evt) => this._eventTogglePovs(evt));
// show/hide the submenu content i.e. the list of povs
submenu.querySelector('.expand').addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
// The povs are shown in sub-menu-content
let submenu_content = _el('div', '', ['sub-menu-content', 'hidden']);
let pov_ids = Object.keys(qcmPov[pov_type]).sort();
// we had a spcial character to symbolize mast toggle
let item = _el('div', '', ['sub-menu-content-pov']);
submenu_content.appendChild(item);
let span = _el('span');
span.innerText = 'M';
item.appendChild(span);
item.addEventListener('click', (evt) => this._eventTogglePovTypeMast(evt));
// Now the actual povs
for (let j=0; j<pov_ids.length; j++) {
let item = _el('div', '', ['sub-menu-content-pov']);
submenu_content.appendChild(item);
let span = _el('span');
span.innerText = pov_ids[j];
item.appendChild(span);
//item.addEventListener('click', (evt) => {evt.target.classList.toggle('clicked');});
item.addEventListener('click', (evt) => this._eventTogglePov(evt));
}
pov_content.appendChild(submenu_content);
}
return pov_content;
}
__populateTraceContent() {
// The Traces are:
// - grouped by Tx name, then by Rx name
// - represented by small boxes the size of up to 4 digits, for the Rx ID
let qcmTrace = this.cgviz.data.scenarios[this.cgviz.data.selected].qcmTrace;
let tx_ids = Object.keys(qcmTrace).sort();
if (tx_ids.length === 0) {
console.log('No data in qcmTrace');
return;
}
let trace_content = _el('div', '', ['trace-content', 'hidden']);
let tx_id;
for (let i=0; i<tx_ids.length; i++) {
tx_id = tx_ids[i];
let submenu = this.HeaderSubMenu(tx_id, '', true);
trace_content.appendChild(submenu);
// show/hide all the traces from this txpovid in the scene
submenu.querySelector('.eye').addEventListener('click', (evt) => this._eventToggleAllRaysFromPovId(evt));
// show/hide the submenu content i.e. the list of traces
submenu.querySelector('.expand').addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
// The traces are shown in sub-menu-content
let submenu_content = _el('div', '', ['sub-menu-content', 'hidden']);
let rx_ids = Object.keys(qcmTrace[tx_id]).sort();
for (let j=0; j<rx_ids.length; j++) {
let item = _el('div', '', ['sub-menu-content-trace']);
submenu_content.appendChild(item);
let span = _el('span');
span.innerText = rx_ids[j];
item.appendChild(span);
//item.addEventListener('click', (evt) => {evt.target.classList.toggle('clicked');});
//item.addEventListener('click', (evt) => this._eventToggleTrace(evt));
item.addEventListener('click', (evt) => this._eventToggleRaysBetweenPovs(evt));
}
trace_content.appendChild(submenu_content);
}
return trace_content;
}
__populateKpisContent() {
let qcmKpis = this.cgviz.data.scenarios[this.cgviz.data.selected].qcmKpis;
let tx_ids = Object.keys(qcmKpis).sort();
if (tx_ids.length === 0) {
console.log('No data in qcmTrace');
return;
}
let kpis_content = _el('div', '', ['kpis-content', 'hidden']);
let kpiList = qcmKpis.nfo.KPIS;
for (let i=0; i<kpiList.length; i++) {
let submenu = this.HeaderSubMenu(kpiList[i], '', true, false);
kpis_content.appendChild(submenu);
// show/hide the submenu content
submenu.querySelector('.expand').addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
let submenu_content = _el('div', '', ['sub-menu-content', 'vertical', 'hidden']);
// some other loop to add the elements:
// Header TX content:
// - Best (of all TX), Worst (of all TX), Mean (of all TX), Sum (of all TX), IDs (1, 2, ...)
// - highlight IDs => if best or worst is chosen, then use other colors: 1 color per tx and change the luminosity with intensity
// - AA selection
// Header RX:
// - AA selection?
// Header position
// - x, y, z?
// Header configuration
// - tile shape
// - tile size
// - color scheme
let subsubmenus = ['tx', 'rx', 'position', 'customization'];
for (let i=0; i<subsubmenus.length; i++) {
let ssm = this.HeaderSubSubMenu(subsubmenus[i], '');
ssm.querySelector('.dots').addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
submenu_content.appendChild(ssm);
// Add the TX part
if (subsubmenus[i] === 'tx') {
let subsubmenu_content = _el('div', '', ['subsub-menu-content', 'hidden']);
let tx_options = ['Coverage', 'Acoverage', 'Best', 'Worst', 'Mean', 'Sum'];
let tx_ids = qcmKpis.nfo.TXPOVIDS;
let tx_all = [...tx_options, ...tx_ids]
// loop on the elements
for (let j=0; j<tx_all.length; j++) {
//let item = _el('div', '', ['subsub-menu-content-kpi']);
let item = _el('div', '', ['sub-menu-content-pov']);
if (tx_options.includes(tx_all[j])) {
item.classList.add('option');
if (tx_all[j].includes('overage')) {
item.classList.add('large');
}
} else {
// HACK to add a 0 in front of the name
tx_all[j] = '0' + tx_all[j];
}
subsubmenu_content.appendChild(item);
let span = _el('span');
span.innerText = tx_all[j];
item.appendChild(span);
item.addEventListener('click', (evt) => this._eventToggleHeatmap(evt))
}
submenu_content.appendChild(subsubmenu_content);
}
}
kpis_content.appendChild(submenu_content);
}
return kpis_content;
}
HeaderMenu(id_, className, innerText, grab, bin, eye) {
/**
* Header for Menu, used for example in:
* - the scenario level (the actual simulation name)
* - the categories below it, qcmpov, qcmobj, qcmtrace, qcmkpis
* It has:
* - an id_
* - a class: div-scenario
* It contains:
* - a grab icon: move scenario up/down to reorganize
* - an eye icon: click and everything is HIDDEN in the view
* - a name bar: name of the scenario (same as folder where data was loaded from)
* - a bin icon: click and the scenario is deleted, along with all the related data and meshes
* - an expand icon: click and it shows the categories under (obj, pov, trace, kpis)
*/
if (innerText === '') {
innerText = undefined;
}
innerText = innerText || id_;
grab = grab || false;
bin = bin || false;
if (eye === undefined) {
eye = true;
}
let div = _el('div', id_, [className]);
if (grab === true) {
let grab = _el('div', '', ['header-svg', 'weak']);
grab.appendChild(this.createSvg('grab'));
div.appendChild(grab);
}
if (eye === true) {
let eye_ = _el('div', '', ['header-svg', 'eye']);
eye_.appendChild(this.createSvg('eye_open'));
div.appendChild(eye_);
}
let name = _el('div', '', ['header-text']);
name.innerText = innerText;
div.appendChild(name);
if (bin === true) {
let bin = _el('div', '', ['header-svg', 'delete']);
bin.appendChild(this.createSvg('delete'));
div.appendChild(bin);
}
let expand = _el('div', '', ['header-svg', 'expand']);
expand.appendChild(this.createSvg('down'));
div.appendChild(expand);
return div;
}
HeaderSubMenu(innerText, id_, expand, eye) {
/**
* A simpler Header
* Contains a title and an eye
*/
if (expand === undefined) {
expand = true;
}
if (eye === undefined) {
eye = true;
}
if (id_ === '') {
id_ = null;
}
let div = _el('div', id_, ['sub-menu']);
if (eye === true) {
let eye = _el('div', '', ['header-svg', 'eye']);
eye.appendChild(this.createSvg('eye_open'));
div.appendChild(eye);
}
let name = _el('div', '', ['header-text']);
name.innerText = innerText;
div.appendChild(name);
if (expand == true) {
let expand = _el('div', '', ['header-svg', 'expand']);
expand.appendChild(this.createSvg('down'));
div.appendChild(expand);
}
return div;
}
HeaderSubSubMenu(innerText, id_) {
let div = _el('div', id_, ['subsub-menu']);
let name = _el('span', '', ['header-text']);
name.innerText = innerText;
div.appendChild(name);
let dots = _el('div', '', ['header-svg', 'dots']);
dots.appendChild(this.createSvg('dots'));
div.appendChild(dots);
return div;
}
HeaderSwitch(innerText, id_, default_on) {
if (id_ === '') {
id_ = null;
}
if (default_on === undefined) {
default_on = true;
}
let div = _el('div', id_, ['sub-menu', 'switch']);
let name = _el('div', '', ['header-text']);
name.innerText = innerText;
div.appendChild(name);
let svg = this.createSvg('switch-off');
if (default_on) {
svg = this.createSvg('switch-on');
}
let icon =_el('div', '', ['switch-svg']);
icon.appendChild(svg);
div.appendChild(icon);
return div;
}
HeaderRadioButton(optionsList, defaultOption, id_) {
// optionsList is an array of strings
if (id_ === '') {
id_ = null;
}
let div = _el('div', id_, ['sub-menu', 'radio']);
for (let i=0; i<optionsList.length; i++) {
let option = _el('div', '', ['header-text']);
option.innerText = optionsList[i];
if (optionsList[i] === defaultOption) {
option.classList.add('active');
}
div.appendChild(option);
}
return div;
}
__createMenuFilters() {
/**
* Filters
* allow users to filter data from the heatmap
*/
let filters = _el('div', 'Filters', ['container-tab-content']);
let title = _el('div', '', ['menu-title']);
title.innerText = 'Filters';
filters.appendChild(title);
// A visiual separator
filters.appendChild(_el('hr', '', ['title-body-separator']));
return filters;
}
__createMenuInteractions() {
/**
* Interactions
* Allow users to toggle helpers tools like:
* - show GPS coordinates unders the mouse (per tile)
* - show tooltip with selectable list of KPIs
*/
let interactions = _el('div', 'Interactions', ['container-tab-content']);
let title = _el('div', '', ['menu-title']);
title.innerText = 'Interactions';
interactions.appendChild(title);
// A visiual separator
interactions.appendChild(_el('hr', '', ['title-body-separator']));
// A container for the interaction data
let div_interactions = _el('div', 'div-interactions');
interactions.appendChild(div_interactions);
// 1) Tooltips
// The header
let tooltip_header = this.HeaderMenu('Tooltips', 'scenario-header', '', false, false, false);
tooltip_header.getElementsByClassName('expand')[0].addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
interactions.appendChild(tooltip_header);
// The content
let tooltip_content = _el('div', '', ['obj-content', 'hidden']);
// 1.1) Visibility
let tooltip_visible = this.HeaderSwitch('Visible', '', false);
tooltip_visible.querySelector('.switch-svg').addEventListener('click', (evt) => this._eventToggleTooltip(evt));
tooltip_content.appendChild(tooltip_visible);
// 1.2) Coordinates
let tooltip_coord = this.HeaderSwitch('Coordinates', '', false);
tooltip_coord.querySelector('.switch-svg').addEventListener('click', (evt) => this._eventToggleTooltip(evt));
tooltip_content.appendChild(tooltip_coord);
// 1.3) Pov ID
let tooltip_povid = this.HeaderSwitch('PoV ID', '', false);
tooltip_povid.querySelector('.switch-svg').addEventListener('click', (evt) => this._eventToggleTooltip(evt));
tooltip_content.appendChild(tooltip_povid);
// 1.4) KPIs => TODO: allow user to select which KPIs => offer a list
let tooltip_kpis = this.HeaderSwitch('KPIs', '', false);
tooltip_kpis.querySelector('.switch-svg').addEventListener('click', (evt) => this._eventToggleTooltip(evt));
tooltip_content.appendChild(tooltip_kpis);
interactions.appendChild(tooltip_content);
return interactions;
}
__createMenuSettings() {
/**
* Settings
* Allow users to change the same settings as dat.gui allowed
* - background color
* - helpers
* - show info
*/
let settings = _el('div', 'Settings', ['container-tab-content']);
let title = _el('div', '', ['menu-title']);
title.innerText = 'Settings';
settings.appendChild(title);
// A visiual separator
settings.appendChild(_el('hr', '', ['title-body-separator']));
// A container for the settings data
let div_settings = _el('div', 'div-settings');
settings.appendChild(div_settings);
// 1) General
// Header
let general_header = this.HeaderMenu('General', 'scenario-header', '', false, false, false);
general_header.getElementsByClassName('expand')[0].addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
settings.appendChild(general_header);
// Content
let general_content = _el('div', '', ['obj-content', 'hidden']);;
settings.appendChild(general_content);
//let general_content = this.HeaderSubMenu('Background');
let general_view = this.HeaderMenu('View', 'obj-header', '', false, false, false);
general_view.querySelector('.expand').addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
general_content.appendChild(general_view);
let view_content = _el('div', '', ['sub-menu-content', 'hidden'], true);
general_content.appendChild(view_content);
// Change view TODO: change this to a radio button with options Current, XY, YZ, ZX
//let view_xyz = this.HeaderSwitch('XY View');
//let view_xyz = this.HeaderRadioButton(['D', 'XY', 'YZ', 'ZX'], 'D');
//view_xyz.addEventListener('click', (evt) => this._eventToggleXYZView(evt));
let options = ['Dft', 'XY ', 'YZ', 'ZX'];
for (let i=0; i<options.length; i++) {
let item = _el('div', '', ['sub-menu-content-pov', 'hidden']);
if (options[i] === 'Dft') {
item.classList.add('clicked');
}
view_content.appendChild(item);
let span = _el('span');
span.innerText = options[i];
item.appendChild(span);
item.addEventListener('click', (evt) => this._eventToggleXYZView(evt));
}
//view_content.appendChild(view_xyz);
// 1 1/2) Labels
// Header
let labels_header = this.HeaderMenu('Labels', 'scenario-header', '', false, false, false);
labels_header.getElementsByClassName('expand')[0].addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
settings.appendChild(labels_header);
// Content
let labels_content = _el('div', '', ['obj-content', 'hidden']);
let labels_povs = this.HeaderMenu('Point of views', 'obj-header', '', false, false, false);
labels_povs.querySelector('.expand').addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
labels_content.appendChild(labels_povs);
let labels_pov_content = _el('div', '', ['sub-menu-content', 'column', 'hidden'], true);
labels_content.appendChild(labels_pov_content);
let povs_visible = this.HeaderSwitch('Visible', '', false);
povs_visible.querySelector('.switch-svg').addEventListener('click', (evt) => this._eventTogglePovLabels(evt));
labels_pov_content.appendChild(povs_visible);
let povs_detailed = this.HeaderSwitch('Detailed', '', false);
povs_detailed.querySelector('.switch-svg').addEventListener('click', (evt) => this._eventTogglePovLabels(evt));
labels_pov_content.appendChild(povs_detailed);
settings.appendChild(labels_content);
// 2) Helpers
// Header
let helpers_header = this.HeaderMenu('Helpers', 'scenario-header', '', false, false, false);
helpers_header.getElementsByClassName('expand')[0].addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
settings.appendChild(helpers_header);
// Content (Axes and Grid)
let helpers_content = _el('div', '', ['obj-content', 'hidden']);
// 2.1) The axes: show/hide, use arrows, size
let helpers_axes = this.HeaderMenu('Axes', 'obj-header', '', false, false, false);
helpers_axes.querySelector('.expand').addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
helpers_content.appendChild(helpers_axes);
let axes_content = _el('div', '', ['sub-menu-content', 'column', 'hidden'], true);
helpers_content.appendChild(axes_content);
let axes_visible = this.HeaderSwitch('Visible');
axes_visible.querySelector('.switch-svg').addEventListener('click', (evt) => this._eventToggleAxes(evt));
axes_content.appendChild(axes_visible);
let axes_arrows = this.HeaderSwitch('Use arrows');
axes_arrows.querySelector('.switch-svg').addEventListener('click', (evt) => this._eventToggleAxesArrows(evt));
axes_content.appendChild(axes_arrows);
//axes_content.appendChild(this.HeaderSwitch('Size'));
// 2.2) the grid: show/hide, size, divisions
let helpers_grid = this.HeaderMenu('Grid', 'obj-header', '', false, false, false);
helpers_grid.querySelector('.expand').addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
helpers_content.appendChild(helpers_grid);
let grid_content = _el('div', '', ['sub-menu-content', 'column', 'hidden'], true);
helpers_content.appendChild(grid_content);
// Visibility
let grid_visible = this.HeaderSwitch('Visible');
grid_visible.querySelector('.switch-svg').addEventListener('click', (evt) => this._eventToggleGrid(evt));
grid_content.appendChild(grid_visible);
// Fit the grid to the scene
let grid_fittoscene = this.HeaderSwitch('Fit to scene', '', false);
grid_fittoscene.querySelector('.switch-svg').addEventListener('click', (evt) => this._eventToggleFitGridToScene(evt));
grid_content.appendChild(grid_fittoscene);
// 2.3) the controls: center
let helpers_controls = this.HeaderMenu('Controls', 'obj-header', '', false, false, false);
helpers_controls.querySelector('.expand').addEventListener('click', (evt) => this._eventToggleNextSibling(evt));
helpers_content.appendChild(helpers_controls);
let controls_content = _el('div', '', ['sub-menu-content', 'column', 'hidden'], true);
helpers_content.appendChild(controls_content);
let controls_centered = this.HeaderSwitch('Center on scene', '', false);
controls_centered.querySelector('.switch-svg').addEventListener('click', (evt) => this._eventToggleCenteredControls(evt));
controls_content.appendChild(controls_centered);
settings.appendChild(helpers_content);
return settings;
}
createPanel() {
/**
* The Panel has a container which in turn has:
* the info icon
* => provides desciption about the current scene
* => should be updated each time a new scenario is selected
* the dual screen icon
* => splits the screen in 2
* => one scenario per screen
* the legend icon
* => shows as many sublegends as are used in the main view
*/
let panel = _el('div', 'panel');
let info = _el('div', 'panel-info', ['panel-icon']);
info.addEventListener('click', (evt) => this._eventToggleInfo(evt));
let svg_info = this.createSvg('info');
svg_info.setAttribute('height', '22px');
svg_info.setAttribute('width', '22px');
info.appendChild(svg_info);
panel.appendChild(info);
let dual = _el('div', 'panel-dual', ['panel-icon']);
let svg_dual = this.createSvg('dual');
svg_dual.setAttribute('height', '20px');
svg_dual.setAttribute('width', '20px');
dual.appendChild(svg_dual);
panel.appendChild(dual);
let threed = _el('div', 'panel-3d-toggle', ['panel-icon']);
let svg_threed = this.createSvg('cube-3d');
svg_threed.setAttribute('height', '20px');
svg_threed.setAttribute('width', '20px');
threed.appendChild(svg_threed);
panel.appendChild(threed);
let legend = _el('div', 'panel-legend', ['panel-icon']);
let svg_legend = this.createSvg('legend');
svg_legend.setAttribute('height', '22px');
svg_legend.setAttribute('width', '22px');
legend.appendChild(svg_legend);
legend.addEventListener('click', (evt) => {
evt.target.classList.toggle('clicked');
evt.target.querySelector('#legend-container').classList.toggle('hidden');
});
legend.appendChild(this.createLegend());
panel.appendChild(legend);
document.body.appendChild(panel);
}
createLegend() {
/**
* There are several categories of legend depending on the kpis:
* - rays
* - kpis of the heatmap
*/
let container = _el('div', 'legend-container', ['hidden']);
let head = _el('div', 'legend-head');
head.innerText = 'Legends';
container.appendChild(head);
let body = _el('div', 'legend-body');
// For each colormap, a title and a legendset. A loop here is in order :-)
//let title = _el('div','', ['title']);
//title.innerText = 'Body';
//body.appendChild(title);
//let clr_map = this._createLegendSet();
/*
let clr_map = _el('div', '', ['clrmap']);
//clr_map.appendChild(this._SvgColormap());
clr_map.appendChild(this._logoColorBox());
*/
//body.appendChild(clr_map);
container.appendChild(body);
return container;
}
_addLegendSet(scenarioName, kpiName, n_colors, scheme) {
/**
* REPLACES _createLegendSet
* NOTE: should be renamed to DiscreteColorBar
* Adds a legend set to the legend menu, depending on:
* - the scenario name
* - the kpi name
* - the number of colors
* - the color scheme
* - the range of the values (of the kpi)
*
* Note: the id of the Tx does not impact the legend set
*/
let units = {
Nr: '#',
Delay: 'ns',
Doppler: 'ns',
P: 'dB',
Kfactor: 'dB',
Rank: '#',
AoA0: 'deg',
EoA0: 'deg',
AoA1: 'deg',
EoA1: 'deg'
};
let container = document.querySelector('#legend-body');
// The id of the div is a combination of the scenario name and the kpi name
let name = scenarioName + '__' + kpiName;
// The container for the header and the body (which contains all the colors of the color map (aka discrete colorbar))
let clrmap = _el('div', name, ['clrmap']);
// HEAD
// The head should include:
// > An arrow that changes from right to bottom
// > A label for the kpi name
// > A settings wheel to open a submenu with:
// - the colorscheme: possibly with dropdown with the actual colors
// - the number of colors: up to 20 depending on the colorscheme
// - the order of colors: reverse or note
// - the range to be displayed. This is contained within [min, max]
// Create the set of colors using the n_colors, scheme and name of the kpi
let clrmap_head = _el('div', '', ['clrmap-head']);
// The text
let cmh_text = _el('div', '', ['clrmap-head-text']);
clrmap_head.appendChild(cmh_text);
cmh_text.innerText = `${kpiName} [${units[kpiName]}]`;
cmh_text.addEventListener('click', (evt) => {
evt.stopPropagation();
evt.target.parentNode.nextSibling.classList.toggle('hidden');
});
// The settings icons inside a div
let cmh_icons = _el('div', '', ['clrmap-head-icons']);
clrmap_head.appendChild(cmh_icons);
let cmh_settings = _el('div', '', ['header-svg']);
cmh_icons.appendChild(cmh_settings);
let svg_settings = this.createSvg('settings');
svg_settings.setAttribute('width', '18px');
svg_settings.setAttribute('height', '18px');
cmh_settings.appendChild(svg_settings);
cmh_settings.addEventListener('click', (evt) => {
evt.stopPropagation(); // to make sure the parent is not catching the click
// Popup a modal with color settings
// Note that those should be saved somewhere (init with Spectral and 10 for ex)
// then read and modified
// needs to be scenario/KPI specific
let settings = this.createLegendSettingsPopUp();
settings.style.display = 'block';
document.body.appendChild(settings);
});
// The expand icon, dots
/*
let cmh_dots = _el('div', '', ['header-svg', 'dots']);
cmh_icons.appendChild(cmh_dots);
cmh_dots.appendChild(this.createSvg('dots'));
*/