Skip to content

Commit 43af712

Browse files
authored
frontend: Display number of hits on each line, fixes #188 (#193)
1 parent ed1f3f1 commit 43af712

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

frontend/src/base.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ <h2>
6767
<td>
6868
<pre class="language-{{ language }}"><code>{{ line }}</code></pre>
6969
</td>
70+
<td>
71+
{{#hits}}
72+
<span class="{{ hits.unit }}" title="That line is hit {{ coverage }} times.">{{ hits.nb }} {{ hits.unit }}</span>
73+
{{/hits}}
74+
</td>
7075
</tr>
7176
{{/lines}}
7277
</tbody>

frontend/src/index.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,32 @@ async function showFile(file, revision) {
153153
lines: source.split("\n").map((line, nb) => {
154154
const coverage = file.coverage[nb];
155155
let cssClass = "";
156-
if (coverage && coverage !== -1) {
156+
let hits = null;
157+
if (coverage !== undefined && coverage >= 0) {
157158
cssClass = coverage > 0 ? "covered" : "uncovered";
159+
160+
// Build a nicer coverage string for counts
161+
if (coverage >= 1000000) {
162+
hits = {
163+
nb: parseInt(coverage / 1000000),
164+
unit: "M"
165+
};
166+
} else if (coverage >= 1000) {
167+
hits = {
168+
nb: parseInt(coverage / 1000),
169+
unit: "k"
170+
};
171+
} else if (coverage > 0) {
172+
hits = {
173+
nb: coverage,
174+
unit: ""
175+
};
176+
}
158177
}
159178
return {
160179
nb,
180+
hits,
181+
coverage,
161182
line: line || " ",
162183
covered: cssClass
163184
};

frontend/src/style.scss

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ $samp_size: 20px;
289289

290290
td {
291291
font-size: 0.9em;
292+
background: $no_data_color;
292293
}
293294

294295
pre {
@@ -299,6 +300,7 @@ $samp_size: 20px;
299300
background: $no_data_color;
300301
}
301302

303+
// Line number
302304
td:first-child {
303305
color: grey;
304306
font-size: 1em;
@@ -309,6 +311,28 @@ $samp_size: 20px;
309311
padding: 0 2px;
310312
}
311313

314+
// Line coverage stats
315+
td:last-child {
316+
padding-right: 3px;
317+
text-align: right;
318+
319+
span {
320+
padding: 2px;
321+
color: white;
322+
font-size: 0.9em;
323+
font-weight: bold;
324+
border-radius: 3px;
325+
background: #363636;
326+
327+
&.k {
328+
background: #209cee;
329+
}
330+
&.M {
331+
background: #3273dc;
332+
}
333+
}
334+
}
335+
312336
&.covered {
313337
td {
314338
background: darken($covered_color, 10%);

0 commit comments

Comments
 (0)