-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtableCompare.html
More file actions
786 lines (725 loc) · 25.9 KB
/
tableCompare.html
File metadata and controls
786 lines (725 loc) · 25.9 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>(Tab Separated) Table Comparing Tool</title>
<style>
.match-cell {
background-color: #d4edda !important; /* green */
cursor: pointer;
}
.type-mismatch-cell {
background-color: #fff3cd !important; /* yellow */
cursor: pointer;
}
.mismatch-cell {
background-color: #f8d7da !important; /* red */
cursor: pointer;
}
.sticky-header {
position: sticky;
top: 0;
background: #f9fafb;
z-index: 2;
}
.sticky-col {
position: sticky;
left: 0;
background: #f9fafb;
z-index: 1;
}
.coordinate-header {
font-weight: bold;
background: #e5e7eb;
text-align: center;
}
.comparison-table-wrapper {
max-height: 500px;
max-width: 100vw;
overflow: auto;
border: 1px solid #d1d5db;
border-radius: 0.5rem;
background: d1d5db;
}
.comparison-table {
border-collapse: collapse;
min-width: 800px;
}
.comparison-table th, .comparison-table td {
border: 1px solid #d1d5db;
padding: 0.5rem;
min-width: 80px;
max-width: 200px;
overflow-x: auto;
font-family: monospace;
font-size: 0.95rem;
}
/* Details table styles */
.details-table th, .details-table td {
border: 1px solid #d1d5db;
padding: 0.5rem;
font-family: monospace;
font-size: 0.95rem;
background: #f9fafb;
}
.details-table th {
background: #e5e7eb;
font-weight: bold;
}
/* === General Layout === */
body {
padding: 2rem;
background-color: #f3f4f6;
font-family: system-ui, sans-serif;
font-size: 16px;
color: #222;
}
.max-w-7xl {
max-width: 80rem;
margin-left: auto;
margin-right: auto;
}
h1 {
font-size: 2rem;
font-weight: bold;
margin-bottom: 1.5rem;
}
h2 {
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 1rem;
}
/* === Spacing Utilities === */
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mr-4 { margin-right: 1rem; }
.p-2 { padding: 0.5rem; }
.p-4 { padding: 1rem; }
.p-8 { padding: 2rem; }
.rounded { border-radius: 0.375rem; }
.rounded-lg { border-radius: 0.5rem; }
.block { display: block; }
.w-full { width: 100%; }
.flex { display: flex; }
.flex-1 { flex: 1 1 0%; }
.flex-col { flex-direction: column; }
.flex-row { flex-direction: row; }
.flex-wrap { flex-wrap: wrap; }
.gap-4 { gap: 1rem; }
.items-center { align-items: center; }
.font-bold { font-weight: bold; }
.font-semibold { font-weight: 600; }
.font-mono { font-family: monospace; }
.text-base { font-size: 1rem; }
.text-xl { font-size: 1.25rem; }
.text-3xl { font-size: 2rem; }
.text-green-700 { color: #047857; }
.text-red-700 { color: #b91c1c; }
.text-yellow-700 { color: #b45309; }
.text-white { color: #fff; }
.bg-gray-100 { background-color: #f3f4f6; }
.bg-gray-50 { background-color: #f9fafb; }
.bg-blue-500 { background-color: #3b82f6; }
.bg-blue-600 { background-color: #2563eb; }
.border { border: 1px solid #d1d5db; }
.border-gray-200 { border-color: #e5e7eb; }
/* === Responsive Design === */
@media (min-width: 640px) {
.sm\:flex-row { flex-direction: row; }
}
/* === Form Elements === */
textarea, select, input[type="text"], input[type="number"] {
border: 1px solid #d1d5db;
border-radius: 0.375rem;
padding: 0.5rem;
width: 100%;
box-sizing: border-box;
background: #fff;
color: #222;
margin-bottom: 0.5rem;
}
label {
margin-bottom: 0.5rem;
font-weight: 500;
}
select {
width: auto;
min-width: 120px;
}
/* === Button Styles === */
button {
padding: 0.5rem 1rem;
background-color: #3b82f6;
color: #fff;
border: none;
border-radius: 0.375rem;
font-size: 1rem;
font-weight: 500;
cursor: pointer;
transition: background 0.2s;
}
button:hover {
background-color: #2563eb;
}
/* === Table Styles === */
.comparison-table-wrapper {
max-height: 500px;
max-width: 100vw;
overflow: auto;
border: 1px solid #d1d5db;
border-radius: 0.5rem;
background: #d1d5db;
}
.comparison-table {
border-collapse: collapse;
min-width: 800px;
width: 100%;
}
.comparison-table th, .comparison-table td {
border: 1px solid #d1d5db;
padding: 0.5rem;
min-width: 80px;
max-width: 200px;
overflow-x: auto;
font-family: monospace;
font-size: 0.95rem;
background: #fff;
}
.details-table {
border-collapse: collapse;
width: 100%;
}
.details-table th, .details-table td {
border: 1px solid #d1d5db;
padding: 0.5rem;
font-family: monospace;
font-size: 0.95rem;
background: #f9fafb;
}
.details-table th {
background: #e5e7eb;
font-weight: bold;
}
/* === Table Header/Sticky Styles === */
.sticky-header {
position: sticky;
top: 0;
background: #f9fafb;
z-index: 2;
}
.sticky-col {
position: sticky;
left: 0;
background: #f9fafb;
z-index: 1;
}
.coordinate-header {
font-weight: bold;
background: #e5e7eb;
text-align: center;
}
/* === Cell Highlighting === */
.match-cell {
background-color: #d4edda !important; /* green */
cursor: pointer;
}
.type-mismatch-cell {
background-color: #fff3cd !important; /* yellow */
cursor: pointer;
}
.mismatch-cell {
background-color: #f8d7da !important; /* red */
cursor: pointer;
}
/* === Utility Classes for Hidden === */
.hidden {
display: none !important;
}
/* === Miscellaneous === */
i {
color: #888;
}
del {background-color: silver;}
ins {background-color: yellow;}
/* New: file input style */
.file-upload-label {
display: inline-block;
margin-bottom: 0.25rem;
font-size: 0.95rem;
color: #2563eb;
cursor: pointer;
}
.file-upload-input {
display: block;
margin-bottom: 0.5rem;
}
</style>
</head>
<body class="p-8 bg-gray-100">
<div class="max-w-7xl mx-auto">
<h1 class="text-3xl font-bold mb-6">(Tab Separated) Table Comparing Tool</h1>
<div class="mb-6 space-y-4">
<div class="flex gap-4 flex-col sm:flex-row">
<div class="flex-1">
<label class="block mb-2" for="tsvA">Table<u>1</u> Left:</label>
<input type="file" id="fileA" class="file-upload-input" />
<textarea id="tsvA" rows="8" class="block w-full p-2 border rounded font-mono text-base" placeholder="Paste Table Left here"></textarea>
</div>
<div class="flex-1">
<label class="block mb-2" for="tsvB">Table<u>2</u> Right:</label>
<input type="file" id="fileB" class="file-upload-input" />
<textarea id="tsvB" rows="8" class="block w-full p-2 border rounded font-mono text-base" placeholder="Paste Table Right here"></textarea>
</div>
</div>
<div class="flex flex-wrap gap-4 items-center">
<!-- Improved tolerance input -->
<div class="flex items-center gap-2">
<label for="tolerance" class="mr-2 font-semibold">T<u>o</u>lerance:</label>
<div class="flex items-center">
<input type="number" id="tolerance" class="border rounded p-1" style="width:80px;" value="0" min="0" step="any" />
</div>
</div>
<div>
<label for="numberMode" class="mr-2 font-semibold">Number Cell Displa<u>y</u>:</label>
<select id="numberMode" class="border rounded p-1">
<option value="a-b">Left - Right</option>
<option value="a-b-div-b">(Left - Right) / Right</option>
<option value="b-a-div-a">(Right - Left) / Left</option>
<option value="a-vs-b"> L̶e̶f̶t̶ Right</del></option>
</select>
</div>
<!-- New filter dropdown -->
<div>
<label for="filterMode" class="mr-2 font-semibold">Filte<u>r</u>:</label>
<select id="filterMode" class="border rounded p-1">
<option value="all">Show All</option>
<option value="mismatch">Show Only Mismatch</option>
<option value="number-mismatch">Show Only Number Mismatch</option>
</select>
</div>
<div hidden>
<label for="textMode" class="mr-2 font-semibold">Text Cell Display:</label>
<select id="textMode" class="border rounded p-1">
<option value="a-vs-b">L̶e̶f̶t̶ Right</option>
<option value="a">Left</option>
<option value="b">Right</option>
</select>
</div>
<div hidden>
<label for="typeMismatchMode" class="mr-2 font-semibold">Type Mismatch Display:</label>
<select id="typeMismatchMode" class="border rounded p-1">
<option value="a-vs-b">L̶e̶f̶t̶ Right</option>
<option value="type-mismatch">Type mismatch</option>
<option value="a">Left</option>
<option value="b">Right</option>
</select>
</div>
<button id="compareBtn" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
Compare (Ctrl+Enter)
</button>
</div>
</div>
<div id="result" class="hidden">
<h2 class="text-xl font-semibold mb-4">Comparison Results</h2>
<div id="summary" class="mb-4 p-4 bg-gray-50 rounded border border-gray-200 text-base"></div>
<div id="detailsTableWrapper" class="mb-4 hidden">
<table class="details-table w-full">
<thead>
<tr>
<th>Address</th>
<th>Table Left</th>
<th>Table Right</th>
<th>Comparison</th>
<th>Difference</th>
</tr>
</thead>
<tbody id="detailsTableBody"></tbody>
</table>
</div>
<div class="comparison-table-wrapper">
<table class="comparison-table" id="comparisonTable">
<!-- Table will be generated here -->
</table>
</div>
</div>
</div>
<script>
// initialize textbox
document.getElementById('tsvA').value = 'Year\tBalance\tReturn\n1\t100\tNot Given\n2\t104\t4';
document.getElementById('tsvB').value = 'Year\tBalance\tReturn rate\n1\t100\tNot Given\n2\t105\t5%\n3\t107.1\t2%';
// Set initial focus to textarea when page loads
document.getElementById("tsvA").focus();
document.getElementById("tsvA").select();
// File upload handlers
function handleFileInput(fileInputId, textareaId) {
const fileInput = document.getElementById(fileInputId);
const textarea = document.getElementById(textareaId);
fileInput.addEventListener('change', function(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
textarea.value = e.target.result;
};
reader.readAsText(file);
});
}
handleFileInput('fileA', 'tsvA');
handleFileInput('fileB', 'tsvB');
// Utility function to parse TSV (simple, does not handle quoted commas)
function parseTSV(tsv) {
return tsv
.split('\n')
.map(row => row.split('\t').map(cell => cell.trim()));
}
// Convert column index to Excel-like column letters (A, B, ..., Z, AA, AB, ...)
function colIndexToLetters(index) {
let letters = '';
index += 1; // 1-based
while (index > 0) {
let rem = (index - 1) % 26;
letters = String.fromCharCode(65 + rem) + letters;
index = Math.floor((index - 1) / 26);
}
return letters;
}
function parseFloatOrPercent(str){
if (str === '-')
return 0
if (str.charAt(str.length - 1) === '%')
return parseFloat(+str.slice(0, -1)) / 100
if (str.charAt(0) === '(' && str.charAt(str.length - 1) === ')')
return parseFloat(+str.slice(1, -1).replace(/(?<=\d),(?=\d{3}\b)/g, ''));
return parseFloat(+str.replace(/(?<=\d),(?=\d{3}\b)/g, ''))
}
function formatPercent(val) {
if (val === 'NA') return 'NA';
return (parseFloatOrPrecent(val) * 100).toFixed(2) + '%';
}
function compareCells(cellA, cellB, textMode, numberMode, typeMismatchMode) {
const numA = (cellA !== '')? parseFloatOrPercent(cellA) : 0;
const numB = (cellB !== '')? parseFloatOrPercent(cellB) : 0;
const isNumA = !isNaN(numA) && cellA !== '';
const isNumB = !isNaN(numB) && cellB !== '';
var tolerance = parseFloatOrPercent(document.getElementById('tolerance').value) || 0;
if (cellA === '' && cellB === '') {
return { result: '', className: 'match-cell', type: 'empty', match: true, diff: '', cmpLabel: 'empty match', displayA: cellA, displayB: cellB };
}
if (isNumA && isNumB) {
let result, diff, cmpLabel;
var isWithinTolerance = (Math.abs(numA - numB) <= tolerance)
switch (numberMode) {
case 'a-b':
diff = (numA - numB).toFixed(2);
result = diff;
cmpLabel = (isWithinTolerance) ? 'number match' : 'number mismatch';
break;
case 'a-b-div-b':
if (numB === 0) {
diff = (numA === 0)? '0.00%': 'NA';
} else {
diff = (100*(numA - numB) / numB).toFixed(2) + '%';
}
result = diff;
cmpLabel = (isWithinTolerance) ? 'number match' : 'number mismatch';
break;
case 'b-a-div-a':
if (numA === 0) {
diff = (numB === 0)? '0.00%': 'NA';
} else {
diff = (100*(numB - numA) / numA).toFixed(2) + '%';
}
result = diff;
cmpLabel = (isWithinTolerance) ? 'number match' : 'number mismatch';
break;
case 'a-vs-b':
diff = (cellA === cellB)? cellA: `<del>${cellA}</del> <ins>${cellB}</ins>`;
result = diff;
cmpLabel = (isWithinTolerance) ? 'number match' : 'number mismatch';
break;
default:
diff = (numA - numB).toFixed(2);
result = diff;
cmpLabel = (isWithinTolerance) ? 'number match' : 'number mismatch';
}
return {
result,
className: (isWithinTolerance) ? 'match-cell' : 'mismatch-cell',
type: 'number',
match: (isWithinTolerance),
diff,
cmpLabel,
displayA: cellA,
displayB: cellB
};
} else if (isNumA !== isNumB) {
// Type mismatch
let result;
switch (typeMismatchMode) {
case 'type-mismatch':
result = 'Type mismatch';
break;
case 'a':
result = cellA;
break;
case 'b':
result = cellB;
break;
case 'a-vs-b':
result = (cellA === cellB)? cellA: `<del>${cellA}</del> <ins>${cellB}</ins>`;
break;
default:
result = (cellA === cellB)? cellA: `<del>${cellA}</del> <ins>${cellB}</ins>`;
}
return {
result: result,
className: 'type-mismatch-cell',
type: 'type-mismatch',
match: false,
diff: '',
cmpLabel: 'type mismatch',
displayA: cellA,
displayB: cellB
};
} else {
// Both are text
let result, cmpLabel;
switch (textMode) {
case 'a':
result = cellA;
break;
case 'b':
result = cellB;
break;
case 'a-vs-b':
result = (cellA === cellB)? cellA: `<del>${cellA}</del> <ins>${cellB}</ins>`;
break;
default:
result = (cellA === cellB)? cellA: `<del>${cellA}</del> <ins>${cellB}</ins>`;
}
cmpLabel = (cellA === cellB) ? 'text match' : 'text mismatch';
return {
result,
className: (cellA === cellB) ? 'match-cell' : 'mismatch-cell',
type: 'text',
match: cellA === cellB,
diff: '',
cmpLabel,
displayA: cellA,
displayB: cellB
};
}
}
function displayResults2D(rowsA, rowsB) {
const resultDiv = document.getElementById('result');
const table = document.getElementById('comparisonTable');
const summaryDiv = document.getElementById('summary');
const textMode = document.getElementById('textMode').value;
const numberMode = document.getElementById('numberMode').value;
const typeMismatchMode = document.getElementById('typeMismatchMode').value;
const filterMode = document.getElementById('filterMode').value; // NEW
resultDiv.classList.remove('hidden');
const maxRows = Math.max(rowsA.length, rowsB.length);
const maxCols = Math.max(
...[rowsA, rowsB].map(rows => rows.reduce((max, row) => Math.max(max, row.length), 0))
);
// Summary counters
let minError = 0, maxError = 0, numMatch = 0, numMismatch = 0, textMatch = 0, textMismatch = 0, typeMismatch = 0;
// Build table header
let thead = '<thead><tr>';
thead += '<th class="sticky-header coordinate-header"></th>'; // Top-left corner
for (let col = 0; col < maxCols; col++) {
thead += `<th class="sticky-header coordinate-header">${colIndexToLetters(col)}</th>`;
}
thead += '</tr></thead>';
const cmpMatrix = [];
for (let row = 0; row < maxRows; row++) {
cmpMatrix[row] = [];
for (let col = 0; col < maxCols; col++) {
const cellA = (rowsA[row] && rowsA[row][col]) ? rowsA[row][col] : '';
const cellB = (rowsB[row] && rowsB[row][col]) ? rowsB[row][col] : '';
cmpMatrix[row][col] = compareCells(cellA, cellB, textMode, numberMode, typeMismatchMode);
// Count for summary
const cmp = cmpMatrix[row][col];
if (cmp.type === 'number') {
if (cmp.match) numMatch++;
else {
numMismatch++;
var valdiff = parseFloatOrPercent(cmp.diff);
if (valdiff < minError) minError = valdiff;
if (valdiff > maxError) maxError = valdiff;
}
} else if (cmp.type === 'text') {
if (cmp.match) textMatch++;
else textMismatch++;
} else if (cmp.type === 'type-mismatch') {
typeMismatch++;
}
}
}
// Build table body
let tbody = '<tbody>';
for (let row = 0; row < maxRows; row++) {
// Determine if this row should be shown based on filterMode
let showRow = true;
if (filterMode === 'mismatch') {
showRow = cmpMatrix[row].some(cmp => !cmp.match);
} else if (filterMode === 'number-mismatch') {
showRow = cmpMatrix[row].some(cmp => cmp.type === 'number' && !cmp.match);
}
if (filterMode === 'all' || showRow) {
tbody += '<tr>';
tbody += `<th class="sticky-col coordinate-header">${row + 1}</th>`;
for (let col = 0; col < maxCols; col++) {
const cmp = cmpMatrix[row][col];
tbody += `<td class="${cmp.className}"
data-row="${row}" data-col="${col}"
data-tsv-a="${encodeURIComponent(cmp.displayA)}"
data-tsv-b="${encodeURIComponent(cmp.displayB)}"
data-cmp-label="${cmp.cmpLabel}"
data-diff="${cmp.diff}"
onclick="showCellDetail(event, ${row}, ${col})"
>${cmp.result}</td>`;
}
tbody += '</tr>';
}
}
tbody += '</tbody>';
table.innerHTML = thead + tbody;
// Show summary
minError = (numberMode === 'a-b-div-b' || numberMode === 'b-a-div-a') ? (minError * 100).toFixed(2) + '%' : minError.toFixed(2);
maxError = (numberMode === 'a-b-div-b' || numberMode === 'b-a-div-a') ? (maxError * 100).toFixed(2) + '%' : maxError.toFixed(2);
summaryDiv.innerHTML = `
<span class="mr-4"><span class="font-semibold text-black-700">Error range:</span> ${minError} ~ ${maxError}</span>
<span class="mr-4"><span class="font-semibold text-green-700">Number match:</span> ${numMatch}</span>
<span class="mr-4"><span class="font-semibold text-red-700">Number mismatch:</span> ${numMismatch}</span>
<span class="mr-4"><span class="font-semibold text-green-700">Text match:</span> ${textMatch}</span>
<span class="mr-4"><span class="font-semibold text-red-700">Text mismatch:</span> ${textMismatch}</span>
<span class="mr-4"><span class="font-semibold text-yellow-700">Type mismatch:</span> ${typeMismatch}</span>
`;
// Hide details table on new compare
document.getElementById('detailsTableWrapper').classList.add('hidden');
document.getElementById('detailsTableBody').innerHTML = '';
// Scroll to bottom of page
setTimeout(() => {
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
}, 100);
}
function compareTSVs() {
const tsvA = document.getElementById('tsvA').value;
const tsvB = document.getElementById('tsvB').value;
if (!tsvA.trim() || !tsvB.trim()) {
alert('Contents cannot be empty');
return;
}
const rowsA = parseTSV(tsvA);
const rowsB = parseTSV(tsvB);
displayResults2D(rowsA, rowsB);
}
document.getElementById('compareBtn').addEventListener('click', compareTSVs);
document.getElementById('textMode').addEventListener('change', compareTSVs);
document.getElementById('numberMode').addEventListener('change', compareTSVs);
document.getElementById('typeMismatchMode').addEventListener('change', compareTSVs);
document.getElementById('filterMode').addEventListener('change', function() {
// Re-run comparison if results are visible
const resultDiv = document.getElementById('result');
if (!resultDiv.classList.contains('hidden')) {
compareTSVs();
}
});
// Show details in table below summary
function showCellDetail(event, row, col) {
event.stopPropagation();
const td = event.currentTarget;
const cellA = decodeURIComponent(td.getAttribute('data-tsv-a') || '');
const cellB = decodeURIComponent(td.getAttribute('data-tsv-b') || '');
const cmpLabel = td.getAttribute('data-cmp-label') || '';
const diff = td.getAttribute('data-diff') || '';
const colLetter = colIndexToLetters(col);
const rowNum = row + 1;
const address = `${colLetter}${rowNum}`;
const detailsTableWrapper = document.getElementById('detailsTableWrapper');
const detailsTableBody = document.getElementById('detailsTableBody');
// Only show one row at a time (replace)
detailsTableBody.innerHTML = `
<tr>
<td>${address}</td>
<td>${cellA === '' ? '<i>(empty)</i>' : escapeHtml(cellA)}</td>
<td>${cellB === '' ? '<i>(empty)</i>' : escapeHtml(cellB)}</td>
<td>${cmpLabel}</td>
<td>${diff}</td>
</tr>
`;
detailsTableWrapper.classList.remove('hidden');
}
// Escape HTML for safe display
function escapeHtml(text) {
return text.replace(/[&<>"']/g, function(m) {
return ({
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
})[m];
});
}
// Expose for inline onclick
window.showCellDetail = showCellDetail;
// ===== Keyboard Shortcuts =====
document.addEventListener('keydown', function(event) {
// Ctrl+Enter or Cmd+Enter: Compare (works from anywhere, including textareas)
if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') {
event.preventDefault();
compareTSVs();
return;
}
// Alt shortcuts
if (event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey) {
const key = event.key.toLowerCase();
switch(key) {
case 'o':
event.preventDefault();
const toleranceInput = document.getElementById('tolerance');
toleranceInput.focus();
toleranceInput.select();
break;
case '1':
document.getElementById('tsvA').focus();
document.getElementById('tsvA').select();
break;
case '2':
document.getElementById('tsvB').focus();
document.getElementById('tsvB').select();
break;
case 'y':
// Cycle through number mode options
const numberMode = document.getElementById('numberMode');
const options = ['a-b', 'a-b-div-b', 'b-a-div-a', 'a-vs-b'];
const currentIndex = options.indexOf(numberMode.value);
const nextIndex = (currentIndex + 1) % options.length;
numberMode.value = options[nextIndex];
numberMode.dispatchEvent(new Event('change'));
break;
case 'r':
// Cycle through filter options
const filterMode = document.getElementById('filterMode');
const filterOptions = ['all', 'mismatch', 'number-mismatch'];
const currentFilterIndex = filterOptions.indexOf(filterMode.value);
const nextFilterIndex = (currentFilterIndex + 1) % filterOptions.length;
filterMode.value = filterOptions[nextFilterIndex];
filterMode.dispatchEvent(new Event('change'));
// Re-run comparison if results are visible
const resultDiv = document.getElementById('result');
if (!resultDiv.classList.contains('hidden')) {
compareTSVs();
}
break;
}
}
});
</script>
</body>
</html>