Skip to content

Commit d7ce0c7

Browse files
committed
Calculate and show difference statistics
1 parent bdc5e66 commit d7ce0c7

File tree

2 files changed

+77
-7
lines changed

2 files changed

+77
-7
lines changed

app.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const select_from = document.getElementById('select_from');
22
const select_to = document.getElementById('select_to');
33
const div_diff = document.getElementById('div_diff');
4+
const stats = document.getElementById('stats');
45

56
const added_types = document.getElementById('added_types');
67
const added_functions = document.getElementById('added_functions');
@@ -314,8 +315,29 @@ function set_visible_ty_fn(main, ty, fn, where) {
314315
}
315316
}
316317

318+
function set_td_text(tr, index, object) {
319+
tr.children[index].replaceChild(
320+
document.createTextNode(Object.keys(object).length.toString()),
321+
tr.children[index].lastChild
322+
)
323+
}
324+
325+
function fill_stats(diff) {
326+
const tbody = stats.children[1];
327+
const ty = tbody.children[0];
328+
const fn = tbody.children[1];
329+
330+
set_td_text(ty, 1, diff.added.types);
331+
set_td_text(fn, 1, diff.added.functions);
332+
set_td_text(ty, 2, diff.removed.types);
333+
set_td_text(fn, 2, diff.removed.functions);
334+
set_td_text(ty, 3, diff.changed.types);
335+
set_td_text(fn, 3, diff.changed.functions);
336+
}
337+
317338
function load_diff() {
318339
div_diff.style.display = 'none';
340+
319341
let from_idx = Number(select_from.value);
320342
let to_idx = Number(select_to.value);
321343
if (used_diff == collapsed_diff) {
@@ -363,6 +385,7 @@ function load_diff() {
363385
set_visible_ty_fn(removed_div, removed_types_div, removed_functions_div, diff.removed);
364386
set_visible_ty_fn(changed_div, changed_types_div, changed_functions_div, diff.changed);
365387

388+
fill_stats(diff);
366389
div_diff.style.display = '';
367390
}
368391

index.html

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,36 @@
5353
.diff li {
5454
margin: 0.1em 0;
5555
}
56-
label {
56+
.info {
5757
border-bottom: 1px dashed #000;
58+
}
59+
td, th, td {
60+
border: 1px solid #ccc;
61+
padding: 0.5em;
62+
text-align: center;
63+
}
64+
th a {
65+
color: #fff;
66+
}
67+
th[scope="row"] {
68+
text-align: right;
69+
}
70+
tr:nth-child(even) {
71+
background-color: #eee;
72+
}
73+
thead {
74+
background-color: #777;
75+
color: #fff;
76+
}
77+
th[scope="row"] {
78+
background-color: #ddf;
79+
}
80+
table {
81+
border-collapse: collapse;
82+
border: 1px solid #ccc;
83+
letter-spacing: 1px;
84+
font-family: sans-serif;
85+
font-size: .8rem;
5886
}
5987
</style>
6088
</head>
@@ -78,12 +106,31 @@ <h1>Type Language Differ</h1>
78106
<p>To begin, select from which layer up to which layer you would like to
79107
see the changes.</p>
80108

81-
<select id="select_from" onchange="change_select_to()"></select>
82-
<select id="select_to" onchange="change_select_from()"></select>
83-
<input type="checkbox" id="merge-layers" name="merge-layers" onchange="change_used_diff(event)" checked>
84-
<label
85-
title="Telegram sometimes publishes updates to a layer without increasing the layer number. By default (checked), only the most recent version of a layer is shown, but you can uncheck this to show all the known revisions of a layer."
86-
for="merge-layers">Show only the most recent version for a layer (?)</label>
109+
<p>Calculate diff
110+
<label for="select_from">from</label> <select id="select_from" onchange="change_select_to()"></select>
111+
<label for="select_to">to</label> <select id="select_to" onchange="change_select_from()"></select>
112+
<br>
113+
<input type="checkbox" id="merge-layers" name="merge-layers" onchange="change_used_diff(event)" checked>
114+
<label
115+
class="info"
116+
title="Telegram sometimes publishes updates to a layer without increasing the layer number. By default (checked), only the most recent version of a layer is shown, but you can uncheck this to show all the known revisions of a layer."
117+
for="merge-layers">Show only the most recent version for a layer (?)</label>
118+
</p>
119+
120+
<h2>Difference Statistics</h2>
121+
<table id="stats">
122+
<thead>
123+
<tr>
124+
<th scope="col">Kind</th>
125+
<th scope="col"><a href="#added_div">Added</a></th>
126+
<th scope="col"><a href="#removed_div">Removed</a></th>
127+
<th scope="col"><a href="#changed_div">Changed</a></th></tr>
128+
</thead>
129+
<tbody>
130+
<tr><th scope="row">Types</th><td>0</td><td>0</td><td>0</td></tr>
131+
<tr><th scope="row">Functions</th><td>0</td><td>0</td><td>0</td></tr>
132+
</tbody>
133+
</table>
87134
</div>
88135
<div id="div_diff" class="diff">
89136
<div id="added_div" class="added">

0 commit comments

Comments
 (0)