-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathkeyboard_compare.js
2683 lines (2511 loc) · 105 KB
/
keyboard_compare.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
const params = new Proxy(new URLSearchParams(window.location.search), {
get: (searchParams, prop) => searchParams.get(prop),
});
var url_layout1 = params.layout1;
var url_layout2 = params.layout2;
var swidth = 1050;
var sheight = 172;
var outlinewidth = 510;
var x_left = 0;
var x_right = swidth-outlinewidth;
var w = 38;
var gap = 8;
var letter = "";
var x = 0;
var y = 0;
var dx;
var importside = 1;
var fontsize;
var per;
var max = 11.870939;
var red = 0;
var scroll_amount = 0;
var green = 128;
var mode = params.mode;
if (!mode){ mode = "ergo"}
var lang = "english";
if (params.lan) {
lang = params.lan;
}
var needs_update = {}
needs_update[1] = true;
needs_update[2] = true;
// function scroll(event){
// event.preventDefault();
// scroll_amount += event.deltaY/125;
// if (scroll_amount < 0){scroll_amount = 0;}
// generatePlots();
// }
var svg = d3.select("#svglayout").append("svg").attr("xmlns","http://www.w3.org/2000/svg").attr("width", swidth).attr("height", sheight);
var stats = d3.select("#svgstats").append("svg").attr("width", swidth).attr("height", 900)
// const el = document.querySelector("#svgstats");
// el.onwheel = scroll;
const word_list_url = 'word_list.json';
const dictionary_url = 'dictionary.json';
const effort_url = 'bigram_effort.json';
let words = {};
let dictionary = [];
let bigram_effort = {};
function fetchData(){
fetch(word_list_url)
.then(response => response.json())
.then(data => {
words = data; // Assign data to the global variable
console.log("fetchData");
dataloaded = true;
needs_update[1] = true;
needs_update[2] = true;
})
.catch(error => console.error('Error loading JSON file:', error));
}
function fetchDictionary(){
fetch(dictionary_url)
.then(response => response.json())
.then(data => {
if (data["dictionary"]){
dictionary = data["dictionary"]; // Assign data to the global variable
} else {
console.log("something went wrong with loading the dictionary");
}
console.log("fetchDictionary");
dictionaryloaded = true;
needs_update[1] = true;
needs_update[2] = true;
})
.catch(error => console.error('Error loading dictionary JSON file:', error));
}
async function loadAllData() {
try {
const [wordsData, dictionaryData, effortData] = await Promise.all([
fetch(word_list_url).then(response => response.json()),
fetch(dictionary_url).then(response => response.json()),
fetch(effort_url).then(response => response.json())
]);
// Assign the data to your global variables
words = wordsData;
dictionary = dictionaryData.dictionary || [];
bigram_effort = effortData;
console.log("All data loaded successfully!");
dataloaded = true;
dictionaryloaded = true;
effortloaded = true;
needs_update[1] = true;
needs_update[2] = true;
generateCoords();
// measureDictionary();
measureWords(1);
measureWords(2);
generateLayout();
generatePlots();
} catch (error) {
console.error('Error loading data:', error);
}
}
function selectLanguage(lan) {
document.getElementById("langDropDown").innerHTML = lan.charAt(0).toUpperCase() + lan.substr(1).toLowerCase();
lang = lan
// var queryParams = new URLSearchParams(window.location.search);
// queryParams.set("lan",lang)
// history.replaceState(null, null, "?"+queryParams.toString());
if (lan == "english"){
console.log("============ ENGLISH ============")
updateRcData(lan);
dictionaryloaded = true;
dataloaded = true;
needs_update[1] = true;
needs_update[2] = true;
loadAllData();
return;
}
var word_list = 'words-'+lan+'.json'; // words-german.json
console.log("============ "+lan.toUpperCase()+" ============")
fetch(word_list)
.then(response => response.json())
.then(data => {
words = data; // Assign data to the global variable
needs_update[1] = true;
needs_update[2] = true;
console.log("fetchData");
dataloaded = true;
updateRcData(lan);
setMode();
getDictionaryFromWords();
dictionaryloaded = true;
measureDictionary();
measureWords(1);
measureWords(2);
generateLayout();
generatePlots();
})
.catch(error => console.error('Error loading JSON file:', error));
}
makeDraggable(svg.node());
// col 0 1 2 3 4 5 6 7 8 9 10 11
var fingerAssignment = [
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10],
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10],
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10]
]
// var hand = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]
// char, row, col, freq, y, x, width, keyname
var rcdata = [
["q", 0, 1, 0.06607202, 0, 0, 1, 0],
["w", 0, 2, 2.775025, 0, 0, 1, 1],
["e", 0, 3, 11.870939, 0, 0, 1, 2],
["r", 0, 4, 4.988437, 0, 0, 1, 3],
["t", 0, 5, 9.547406, 0, 0, 1, 4],
["y", 0, 6, 1.7949564, 0, 0, 1, 5],
["u", 0, 7, 2.7419887, 0, 0, 1, 6],
["i", 0, 8, 6.177734, 0, 0, 1, 7],
["o", 0, 9, 7.6643543, 0, 0, 1, 8],
["p", 0, 10, 1.4425724, 0, 0, 1, 9],
["-", 0, 11, 0.2753001, 0, 0, 1, 10],
["a", 1, 1, 7.466138, 0, 0, 1, 11],
["s", 1, 2, 5.5720735, 0, 0, 1, 12],
["d", 1, 3, 4.2616453, 0, 0, 1, 13],
["f", 1, 4, 2.0482326, 0, 0, 1, 14],
["g", 1, 5, 2.2244246, 0, 0, 1, 15],
["h", 1, 6, 6.519106, 0, 0, 1, 16],
["j", 1, 7, 0.06607202, 0, 0, 1, 17],
["k", 1, 8, 1.0571523, 0, 0, 1, 18],
["l", 1, 9, 4.6030173, 0, 0, 1, 19],
[";", 1, 10, 0.4184561, 0, 0, 1, 20],
["'", 1, 11, 0.3523841, 0, 0, 1, 21],
["z", 2, 1, 0.04404801, 0, 0, 1, 22],
["x", 2, 2, 0.07708402, 0, 0, 1, 23],
["c", 2, 3, 1.8830525, 0, 0, 1, 24],
["v", 2, 4, 0.7488162, 0, 0, 1, 25],
["b", 2, 5, 1.5526924, 0, 0, 1, 26],
["n", 2, 6, 6.1446977, 0, 0, 1, 27],
["m", 2, 7, 1.5857284, 0, 0, 1, 28],
[",", 2, 8, 1.9601365, 0, 0, 1, 29],
[".", 2, 9, 0.48452812, 0, 0, 1, 30],
["/", 2, 10, 0.14315604, 0, 0, 1, 31],
["\\", 2, 0, 0, 0, 0, 1, 32],
["^", 3, 4, 0, 0, 0, 1, 33],
["tab", 0, 0, 0, 0, 0, 1],
["ctrl", 1, 0, 0, 0, 0, 1],
["enter", 2, 11, 0, 0, 0, 1],
["mod", 3, 5, 0, 0, 0, 1],
["back", 3, 6, 0, 0, 0, 1],
["space", 3, 7, 0, 0, 0, 1],
]
var rcdata2 = [
["q", 0, 1, 0.06607202, 0, 0, 1, 0],
["w", 0, 2, 2.775025, 0, 0, 1, 1],
["e", 0, 3, 11.870939, 0, 0, 1, 2],
["r", 0, 4, 4.988437, 0, 0, 1, 3],
["t", 0, 5, 9.547406, 0, 0, 1, 4],
["y", 0, 6, 1.7949564, 0, 0, 1, 5],
["u", 0, 7, 2.7419887, 0, 0, 1, 6],
["i", 0, 8, 6.177734, 0, 0, 1, 7],
["o", 0, 9, 7.6643543, 0, 0, 1, 8],
["p", 0, 10, 1.4425724, 0, 0, 1, 9],
["-", 0, 11, 0.2753001, 0, 0, 1, 10],
["a", 1, 1, 7.466138, 0, 0, 1, 11],
["s", 1, 2, 5.5720735, 0, 0, 1, 12],
["d", 1, 3, 4.2616453, 0, 0, 1, 13],
["f", 1, 4, 2.0482326, 0, 0, 1, 14],
["g", 1, 5, 2.2244246, 0, 0, 1, 15],
["h", 1, 6, 6.519106, 0, 0, 1, 16],
["j", 1, 7, 0.06607202, 0, 0, 1, 17],
["k", 1, 8, 1.0571523, 0, 0, 1, 18],
["l", 1, 9, 4.6030173, 0, 0, 1, 19],
[";", 1, 10, 0.4184561, 0, 0, 1, 20],
["'", 1, 11, 0.3523841, 0, 0, 1, 21],
["z", 2, 1, 0.04404801, 0, 0, 1, 22],
["x", 2, 2, 0.07708402, 0, 0, 1, 23],
["c", 2, 3, 1.8830525, 0, 0, 1, 24],
["v", 2, 4, 0.7488162, 0, 0, 1, 25],
["b", 2, 5, 1.5526924, 0, 0, 1, 26],
["n", 2, 6, 6.1446977, 0, 0, 1, 27],
["m", 2, 7, 1.5857284, 0, 0, 1, 28],
[",", 2, 8, 1.9601365, 0, 0, 1, 29],
[".", 2, 9, 0.48452812, 0, 0, 1, 30],
["/", 2, 10, 0.14315604, 0, 0, 1, 31],
["\\", 2, 0, 0, 0, 0, 1, 32],
["^", 3, 4, 0, 0, 0, 1, 33],
["tab", 0, 0, 0, 0, 0, 1],
["ctrl", 1, 0, 0, 0, 0, 1],
["enter", 2, 11, 0, 0, 0, 1],
["mod", 3, 5, 0, 0, 0, 1],
["back", 3, 6, 0, 0, 0, 1],
["space", 3, 7, 0, 0, 0, 1],
]
var effort = [
[
5, // column 0 tab
3, // column 1 q
2, // column 2 w
1, // column 3 e
2, // column 4 r
7, // column 5 t
7, // column 6 y
2, // column 7 u
1, // column 8 i
2, // column 9 o
3, // column 10 p
5, // column 11 [
],
[
5, // column 0 ctrl
1, // column 1 a
0, // column 2 s
0, // column 3 d
0, // column 4
5, // column 5
5, // column 6
0, // column 7
0, // column 8
0, // column 9
1, // column 10
5, // column 11
],
[
7, // column 0
3, // column 1
2, // column 2
2, // column 3
1, // column 4
8, // column 5
8, // column 6
1, // column 7
2, // column 8
2, // column 9
3, // column 10
7, // column 11
],
];
// var bigram_effort = {
// 2 : { // col1
// 1 : { // row1
// 3 : { // col2
// 0 : 1.0, // row2
// }
// }
// }
// };
// 0 1 2 3 4 5 6 7 8 9 10 11
// 0 q w e r t y u i o p -
// 1 a s d f g h j k l ; '
// 2 \ z x c v b n m , . /
function openPopup() {
for (var row = 0; row < 3; row++){
for (var col = 0; col < 12; col++){
var name = "textInput-" + row + "-" + col
document.getElementById(name).value = effort[row][col];
}
}
document.getElementById('popup').style.display = 'flex';
}
function openImportPopup() {
document.getElementById('importPopup').style.display = 'flex';
}
function openCorpusPopup() {
document.getElementById('corpusPopup').style.display = 'flex';
}
function containsOneCopyOfAllLetters(str) {
str = str.toUpperCase();
if (strCount(str,",")!=1) {return false;}
if (strCount(str,".")!=1) {return false;}
if (strCount(str,";")>1) {return false;}
if (strCount(str,"/")>1) {return false;}
if (strCount(str,"'")>1) {return false;}
if (strCount(str,"\\")>1) {return false;}
if (strCount(str,"-")>1) {return false;}
// Convert the string to uppercase
// Remove non-alphabetic characters
str = str.replace(/[^A-Z]/g, '');
// Check if the string has exactly one copy of each letter
const uniqueLetters = new Set(str);
return uniqueLetters.size === 26; //wlrdzqgubj-shnt,.aeoi'fmvc/;pxky
}
function deepCopy(arr) {
return arr.map(item => Array.isArray(item) ? deepCopy(item) : item);
}
function strCount(str,char) {
for(var count=-1,index=-2; index != -1; count++,index=str.indexOf(char,index+1) );
return count
}
function closeImportPopup() {
var importString = document.getElementById('importText').value;
importString = importString.replace(/\s+/g, '');
// if we import a string that is 30 characters long and doesn't contain - or ' then we add them in
// but then what if we add a 30 character string that does contain - or '. well then we should add something else in
if (importString.length == 0) {
document.getElementById('importPopup').style.display = 'none';
return
}
if (importString.length == 30){ // probably cmini
if (strCount(importString,"-")==0 && strCount(importString,"'")==0){
importString = importString.slice(0, 10) + "-" + importString.slice(10,20) + "'" + importString.slice(20) + "\\^";
} else if (strCount(importString,"-")==0 && strCount(importString,";")==0 ) {
importString = importString.slice(0, 10) + "-" + importString.slice(10,20) + ";" + importString.slice(20) + "\\^";
} else if (strCount(importString,"'")==0 && strCount(importString,";")==0 ) {
importString = importString.slice(0, 10) + ";" + importString.slice(10,20) + "'" + importString.slice(20) + "\\^";
} else if (strCount(importString,"'")==0 && strCount(importString,"/")==0 ) {
importString = importString.slice(0, 10) + "/" + importString.slice(10,20) + "'" + importString.slice(20) + "\\^";
} else if (strCount(importString,";")==0 && strCount(importString,"/")==0 ) {
importString = importString.slice(0, 10) + "/" + importString.slice(10,20) + ";" + importString.slice(20) + "\\^";
} else if (strCount(importString,";")==0 && strCount(importString,"'")==0 ) {
importString = importString.slice(0, 10) + ";" + importString.slice(10,20) + "'" + importString.slice(20) + "\\^";
} else if (strCount(importString,"/")==0 && strCount(importString,"-")==0 ) {
importString = importString.slice(0, 10) + "/" + importString.slice(10,20) + "-" + importString.slice(20) + "\\^";
} else {
importString = importString.slice(0, 10) + "+" + importString.slice(10,20) + "*" + importString.slice(20) + "\\^";
}
}
if (containsOneCopyOfAllLetters(importString)){ // fwhmzqouybjsnrtk-aeicxvpld/;,'.g\^
if ((mode == "iso" || mode == "ansi") && importString.length >= 33) {
document.getElementById('importMessage').innerText = "You can't have layouts with thumb letters on ISO/ANSI"
} else if (importString.length == 33 || importString.length == 34) {
if (importString.length == 33) {
importString = importString + "^"
}
needs_update[1] = true;
needs_update[2] = true;
importLayout(importString, importside);
// var queryParams = new URLSearchParams(window.location.search);
// queryParams.set("layout", exportLayout());
// queryParams.set("mode",mode)
// queryParams.set("lan",lang)
// history.replaceState(null, null, "?"+queryParams.toString());
generateCoords();
// measureDictionary();
measureWords(1);
measureWords(2);
generateLayout();
generatePlots();
document.getElementById('importPopup').style.display = 'none';
} else {
document.getElementById('importMessage').innerText = "Input string needs to be 30,32 or 33 characters"
// console.log(document.getElementById('importMessage'));
console.log("input string is length "+ importString.length + " " + importString);
}
} else {
document.getElementById('importMessage').innerText = "Imported layout should have only 1 of A-Z and . and , "
}
needs_update[1] = true;
needs_update[2] = true;
}
function closeCorpusPopup() {
var massive_string = document.getElementById('corpusText').value;
massive_string = massive_string.toLowerCase().replace(/\s+/g, ' ');
words = {};
if (massive_string.length == 0) {
document.getElementById('corpusPopup').style.display = 'none';
return;
}
if (massive_string.length < 1000) {
document.getElementById('corpusMessage').innerText = "You call that a corpus?";
return;
}
list = massive_string.split(" ")
var regex = /\d/;
list.forEach(element => {
// i don't know what to do with these at the moment. just replacing them for now
element = element.replace("ä","a")
element = element.replace("å","a")
element = element.replace("á","a")
element = element.replace("à","a")
element = element.replace("â","a")
element = element.replace("ö","o")
element = element.replace("ó","o")
element = element.replace("í","i")
element = element.replace("ü","u")
element = element.replace("é","e")
element = element.replace("è","e")
element = element.replace("ç","c")
element = element.replace("æ","ae")
element = element.replace("ß","ss")
element = element.replace("ğ","g")
if (regex.test(element)){
} else {
if (words[element]) {
words[element] += 1
} else {
words[element] = 1
}
}
});
dictionary = [];
count = 0;
for(var word in words) {
dictionary.push(word)
count += 1
}
// console.log(count);
document.getElementById('corpusPopup').style.display = 'none';
needs_update[1] = true;
needs_update[2] = true;
// measureDictionary();
measureWords(1);
measureWords(2);
generatePlots();
}
function closePopup() {
for (var row = 0; row < 3; row++){
for (var col = 0; col < 12; col++){
var name = "textInput-" + row + "-" + col
effort[row][col] = document.getElementById(name).value;
}
}
document.getElementById('popup').style.display = 'none';
needs_update[1] = true;
needs_update[2] = true;
measureWords(1);
measureWords(2);
generateLayout();
}
function copyEffortGridToClipboard() {
values = []
for (var row = 0; row < 3; row++){
for (var col = 0; col < 12; col++){
var name = "textInput-" + row + "-" + col
values.push(document.getElementById(name).value);
}
}
var str = values.join(",");
if (!navigator.clipboard) {
console.error("Clipboard API not supported");
return;
}
navigator.clipboard.writeText(str)
.then(
// console.log("copied!")
)
.catch(err => {
console.error("Failed to copy to clipboard contents:", err);
});
}
function pasteEffortGridFromClipboard() {
if (!navigator.clipboard) {
console.error("Clipboard API not supported");
return;
}
// Retrieve clipboard content
navigator.clipboard.readText()
.then(text => {
// console.log("Clipboard content:", text);
var numbersArray = text.split(",").map(Number);
if (numbersArray.length != 36) {
return
}
for (var row = 0; row < 3; row++){
for (var col = 0; col < 12; col++){
var name = "textInput-" + row + "-" + col
document.getElementById(name).value = numbersArray[row * 12 + col]
}
}
})
.catch(err => {
console.error("Failed to read clipboard contents:", err);
});
}
function getEffort(row, column){
if (effort[row]){
if (effort[row][column]){
return effort[row][column];
}
}
return 0;
}
var skip_toggle = false;
function skipToggle() {
skip_toggle = !skip_toggle
generatePlots();
}
var scissors_toggle = 0;
function scissorsToggle(v) {
scissors_toggle += v
if (scissors_toggle > 2){
scissors_toggle = 0
}
if (scissors_toggle < 0){
scissors_toggle = 2
}
generatePlots();
}
var lsb_toggle = 0;
function lsbToggle() {
lsb_toggle += 1
if (lsb_toggle > 1){
lsb_toggle = 0
}
generatePlots();
}
var sfb_toggle = 0;
function sfbToggle(v) {
sfb_toggle += v
if (sfb_toggle > 2){
sfb_toggle = 0
}
if (sfb_toggle < 0){
sfb_toggle = 2
}
generatePlots();
}
var trigram_toggle = true;
function trigramToggle() {
trigram_toggle = !trigram_toggle
generatePlots();
}
function showTooltip(evt, text) {
let tooltip = document.getElementById("tooltip");
tooltip.innerHTML = text;
tooltip.style.display = "block";
tooltip.style.left = evt.pageX + 10 + 'px';
tooltip.style.top = evt.pageY + 10 + 'px';
}
function hideTooltip() {
var tooltip = document.getElementById("tooltip");
tooltip.style.display = "none";
}
function setMode() {
if (dataloaded == false || dictionaryloaded == false || effortloaded == false) {return;}
console.log("setMode to "+mode);
if (mode == "ergo") {
activateErgo()
} else if (mode == "ansi") {
activateAnsi()
} else if (mode == "iso") {
activateIso()
}
generateCoords()
}
function setErgo() {
if (dataloaded == false || dictionaryloaded == false || effortloaded == false) {return;}
console.log("setErgo");
rcdata[32][1] = 2
rcdata[32][2] = 0
rcdata[32][6] = 1
rcdata[33][1] = 3
rcdata[33][2] = 4
rcdata[33][6] = 1
rcdata[34] = ["tab", 0, 0, 0, 0, 0, 1]
rcdata[35] = ["ctrl", 1, 0, 0, 0, 0, 1]
rcdata[36] = ["enter", 2, 11, 0, 0, 0, 1]
rcdata[37] = ["mod", 3, 5, 0, 0, 0, 1]
rcdata[38] = ["back", 3, 6, 0, 0, 0, 1]
rcdata[39] = ["space", 3, 7, 0, 0, 0, 1]
mode = "ergo"
fingerAssignment = [
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10],
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10],
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10]
]
// var queryParams = new URLSearchParams(window.location.search);
// queryParams.set("layout", exportLayout());
// queryParams.set("mode",mode)
// queryParams.set("lan",lang)
// history.replaceState(null, null, "?"+queryParams.toString());
generateCoords()
}
function activateErgo() {
if (dataloaded == false || dictionaryloaded == false || effortloaded == false) {return;}
console.log("activateErgo");
rcdata[32][1] = 2
rcdata[32][2] = 0
rcdata[32][6] = 1
rcdata[33][1] = 3
rcdata[33][2] = 4
rcdata[33][6] = 1
rcdata[34] = ["tab", 0, 0, 0, 0, 0, 1, 34]
rcdata[35] = ["ctrl", 1, 0, 0, 0, 0, 1, 35]
rcdata[36] = ["enter", 2, 11, 0, 0, 0, 1, 36]
rcdata[37] = ["mod", 3, 5, 0, 0, 0, 1, 37]
rcdata[38] = ["back", 3, 6, 0, 0, 0, 1, 38]
rcdata[39] = ["space", 3, 7, 0, 0, 0, 1, 39]
mode = "ergo"
fingerAssignment = [
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10],
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10],
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10]
]
// var queryParams = new URLSearchParams(window.location.search);
// queryParams.set("layout", exportLayout());
// queryParams.set("mode",mode)
// queryParams.set("lan",lang)
// history.replaceState(null, null, "?"+queryParams.toString());
needs_update[1] = true;
needs_update[2] = true;
generateCoords();
// measureDictionary();
measureWords(1);
measureWords(2);
generateLayout();
generatePlots();
}
function activateIso(anglemod) {
// console.log(rcdata)
if (dataloaded == false || dictionaryloaded == false || effortloaded == false) {return;}
hasshift = false
for(let i = 0; i < 34; i++){
if (rcdata[i][0] == "shift" || rcdata[i][0] == "^") {
hasshift = true
}
}
if (hasshift == true) {
rcdata[32][1] = 2
rcdata[32][2] = 0
rcdata[32][6] = 1
rcdata[33][1] = 2
rcdata[33][2] = -1
rcdata[33][6] = 1.25
rcdata[34] = ["tab", 0, 0, 0, 0, 0, 1.5, 34]
rcdata[35] = ["back", 0, 12, 0, 0, 0, 2.25, 35]
rcdata[36] = ["ctrl", 1, 0, 0, 0, 0, 1.75, 36]
rcdata[37] = ["enter", 1, 12, 0, 0, 0, 2, 37]
rcdata[38] = ["rshift", 2, 12, 0, 0, 0, 2.5, 38]
rcdata[39] = ["space", 3, 3, 0, 0, 0, 6.5, 39]
if (anglemod){
fingerAssignment = [ // angle mod
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10],
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10],
[1, 2, 3, 4, 4, 4, 7, 7, 8, 9, 10, 10, 10]
]
} else {
fingerAssignment = [
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10],
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10],
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10]
]
}
mode = "iso"
// var queryParams = new URLSearchParams(window.location.search);
// queryParams.set("layout", exportLayout());
// queryParams.set("mode",mode)
// queryParams.set("lan",lang)
// history.replaceState(null, null, "?"+queryParams.toString());
needs_update[1] = true;
needs_update[2] = true;
generateCoords();
// measureDictionary();
measureWords(1);
measureWords(2);
generateLayout();
generatePlots();
} else {
console.log("You can't have layouts with thumb letters on ISO/ANSI")
}
}
function activateAnsi() {
// console.log(rcdata)
if (dataloaded == false || dictionaryloaded == false || effortloaded == false) {return;}
hasshift = false
for(let i = 0; i < 34; i++){
if (rcdata[i][0] == "shift" || rcdata[i][0] == "^") {
hasshift = true
}
}
if (hasshift == true) {
// rcdata[32] = [rcdata[32][0], 0, 12, 0.2753001, 0, 0, 1, rcdata[32][7]]
// rcdata[33] = [rcdata[33][0], 2, -1, 0, 0, 0, 2.25, rcdata[33][7]]
rcdata[32][1] = 0
rcdata[32][2] = 12
rcdata[32][6] = 1
rcdata[33][1] = 2
rcdata[33][2] = -1
rcdata[33][6] = 2.25
rcdata[34] = ["tab", 0, 0, 0, 0, 0, 1.5, 34]
rcdata[35] = ["back", 0, 13, 0, 0, 0, 1.25, 35]
rcdata[36] = ["ctrl", 1, 0, 0, 0, 0, 1.75, 36]
rcdata[37] = ["enter", 1, 12, 0, 0, 0, 2, 37]
rcdata[38] = ["rshift", 2, 11, 0, 0, 0, 2.5, 38]
rcdata[39] = ["space", 3, 3, 0, 0, 0, 6.5, 39]
fingerAssignment = [
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10],
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10],
[1, 1, 2, 3, 4, 4, 7, 7, 8, 9, 10, 10, 10]
]
mode = "ansi"
// var queryParams = new URLSearchParams(window.location.search);
// queryParams.set("layout", exportLayout());
// queryParams.set("mode",mode)
// queryParams.set("lan",lang)
// history.replaceState(null, null, "?"+queryParams.toString());
needs_update[1] = true;
needs_update[2] = true;
generateCoords();
// measureDictionary();
measureWords(1);
measureWords(2);
generateLayout();
generatePlots();
} else {
console.log("You can't have layouts with thumb letters on ISO/ANSI")
}
}
function importLayouts(layout1, layout2) {
importLayout(layout1,1);
importLayout(layout2,2);
var queryParams = new URLSearchParams(window.location.search);
queryParams.set("layout1", exportLayout(1));
queryParams.set("layout2", exportLayout(2));
history.replaceState(null, null, "?"+queryParams.toString());
}
function importLayout(layout, side) {
var decodedString = decodeURIComponent(layout);
console.log("importing: "+decodedString)
layout = decodedString
if (side == 1){
for (let i = 0; i < 34; i++) { // qwertyuiop-asdfghjkl;'zxcvbnm,./\^ - 34
for (let j = 0; j < 34; j++) {
if (layout.charAt(i) == rcdata[j][0]) {
// console.log("swap "+layout.charAt(i)+" at " + i + " with position " + j)
// swap
indices = [0, 3, 7]
for (let id = 0; id < indices.length; id++){
var k = indices[id];
tmp = rcdata[i][k];
rcdata[i][k] = rcdata[j][k];
rcdata[j][k] = tmp;
}
}
}
}
for (let i = 0; i < 34; i++) {
if (rcdata[i][0] == "^") {
if (rcdata[i][1] == 3 && rcdata[i][2] == 4) {
// cool
} else {
rcdata[i][0] = "="
}
}
}
} else {
for (let i = 0; i < 34; i++) { // qwertyuiop-asdfghjkl;'zxcvbnm,./\^ - 34
for (let j = 0; j < 34; j++) {
if (layout.charAt(i) == rcdata2[j][0]) {
// console.log("swap "+layout.charAt(i)+" at " + i + " with position " + j)
// swap
indices = [0, 3, 7]
for (let id = 0; id < indices.length; id++){
var k = indices[id];
tmp = rcdata2[i][k];
rcdata2[i][k] = rcdata2[j][k];
rcdata2[j][k] = tmp;
}
}
}
}
for (let i = 0; i < 34; i++) {
if (rcdata2[i][0] == "^") {
if (rcdata2[i][1] == 3 && rcdata2[i][2] == 4) {
// cool
} else {
rcdata2[i][0] = "="
}
}
}
}
}
function exportLayout(side) {
var str = "";
if (side == 1){
for (let i = 0; i <= 33; i++) {
str += rcdata[i][0];
}
} else {
for (let i = 0; i <= 33; i++) {
str += rcdata2[i][0];
}
}
return str;
}
function getX(name, row, col) {
dx = 10;
if (mode == "iso") {
if (row == 0){
if (name === "tab") {
off = 0
} else {
off = w*0.5;
}
} else if (row == 1) {
if (name === "ctrl") {
off = 0;
} else {
off = w*0.75;
}
} else if (row >= 2) {
if (col == -1) {
return dx
} else {
if (name === "space") {
off = 0;
} else if (name == "rshift") {
off = w*0.25;
} else {
off = w*1.25;
}
}
}
return dx + off + col * w
} else if (mode == "ansi") {
if (row == 0){
if (name === "tab") {
off = 0
} else {
off = w*0.5;
}
} else if (row == 1){
if (name === "ctrl") {
off = 0;
} else {
off = w*0.75;
}
} else if (row >= 2){
if (col == -1) {
return dx
} else {
if (name === "space") {
off = 0;
} else {
off = w*1.25;
}
}
}
return dx + off + col * w
} else if (mode == "ergo") {
if (col > 5) {
dx = dx + 40;
}
return dx + col * w
}
}
function getY(name, row, col) {
return 10 + row * w
}
function getCol(letter, side) {
if (side == 1) {
for (let i = 0; i < rcdata.length; i++) {
if (rcdata[i][0] === letter) {
return rcdata[i][2];
}
}
}
if (side == 2) {
for (let i = 0; i < rcdata2.length; i++) {
if (rcdata2[i][0] === letter) {
return rcdata2[i][2];
}
}
}
return -1;
}
function getRow(letter, side) {
if (side == 1) {
for (let i = 0; i < rcdata.length; i++) {
if (rcdata[i][0] === letter) {
return rcdata[i][1];
}
}
}
if (side == 2) {
for (let i = 0; i < rcdata2.length; i++) {
if (rcdata2[i][0] === letter) {
return rcdata2[i][1];
}
}
}
return -1;
}
function getChar(row,col,side) {
if (side == 1) {
for (let i = 0; i < rcdata.length; i++) {
if (rcdata[i][1] == row && rcdata[i][2] == col) {
return rcdata[i][0];
}
}
}
if (side == 2) {
for (let i = 0; i < rcdata.length; i++) {
if (rcdata[i][1] == row && rcdata[i][2] == col) {
return rcdata[i][0];
}
}
}
return "!";
}
function getFinger(row, col) {