Skip to content

Commit b174e5c

Browse files
committed
Match progress design
hide progress bar and use SVG to recreate the ring bar
1 parent 214cb82 commit b174e5c

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

lib/reporters/html.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ exports = module.exports = HTML;
3737

3838
var statsTemplate =
3939
'<ul id="mocha-stats">' +
40-
'<li class="progress-contain"><em>0</em>% <progress class="progress-element" max="100" value="0" /></li>' +
40+
'<li class="progress-contain"><progress class="progress-element" max="100" value="0"></progress><svg class="progress-ring"><circle class="ring-whole"/><circle class="ring-highlight" stroke-dasharray="0%,100%"/></svg><div class="progress-text"><em>0</em>%</div></li>' +
4141
'<li class="passes"><a href="javascript:void(0);">passes:</a> <em>0</em></li>' +
4242
'<li class="failures"><a href="javascript:void(0);">failures:</a> <em>0</em></li>' +
4343
'<li class="duration">duration: <em>0</em>s</li>' +
@@ -71,6 +71,7 @@ function HTML(runner, options) {
7171
var stack = [report];
7272
var progressText = items[0].getElementsByTagName('em')[0];
7373
var progressBar = items[0].getElementsByTagName('progress')[0];
74+
var progressRing = items[0].getElementsByClassName('ring-highlight')[0];
7475
var root = document.getElementById('mocha');
7576

7677
if (!root) {
@@ -228,6 +229,12 @@ function HTML(runner, options) {
228229
percent.toFixed(Math.min(Math.max(decmalPlaces, 0), 100))
229230
);
230231
}
232+
if (progressRing) {
233+
var radius = 19; // to do, figure out how to match with css
234+
var wholeArc = Math.PI * 2 * radius;
235+
var highlightArc = percent * (wholeArc / 100);
236+
progressRing.style['stroke-dasharray'] = `${highlightArc}px,${wholeArc}px`;
237+
}
231238

232239
// update stats
233240
var ms = new Date() - stats.start;

mocha.css

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,20 +334,47 @@ body {
334334
z-index: 1;
335335
}
336336

337-
#mocha-stats .progress {
337+
#mocha-stats .progress-contain {
338338
float: right;
339-
padding-top: 0;
340-
341-
/**
342-
* Set safe initial values, so mochas .progress does not inherit these
343-
* properties from Bootstrap .progress (which causes .progress height to
344-
* equal line height set in Bootstrap).
345-
*/
346-
height: auto;
347-
-webkit-box-shadow: none;
348-
-moz-box-shadow: none;
349-
box-shadow: none;
350-
background-color: initial;
339+
padding: 0;
340+
}
341+
342+
#mocha-stats .progress-element {
343+
visibility: hidden;
344+
width: 40px;
345+
height: 20px;
346+
position: absolute;
347+
top: 11px; /* padding */
348+
display: block;
349+
}
350+
351+
#mocha-stats .progress-text {
352+
text-align: center;
353+
position: absolute;
354+
width: 40px;
355+
display: block;
356+
top: 11px; /* padding */
357+
}
358+
359+
#mocha-stats .progress-ring {
360+
width: 40px;
361+
height: 40px;
362+
}
363+
364+
#mocha-stats .ring-whole, #mocha-stats .ring-highlight {
365+
cx: 20px; /* half of width */
366+
cy: 20px; /* half of height */
367+
r: 19px; /* radius - stroke */
368+
fill: var(--mocha-bg-color);
369+
stroke-width: 2px;
370+
}
371+
372+
#mocha-stats .ring-whole {
373+
stroke: var(--mocha-stats-color);
374+
}
375+
376+
#mocha-stats .ring-highlight {
377+
stroke: var(--mocha-stats-em-color);
351378
}
352379

353380
#mocha-stats em {

0 commit comments

Comments
 (0)