diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2014-10-22 22:04:46 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2014-10-22 22:04:46 -0400 |
commit | bdff9572a03fea704c4ef2f3ff021634b7f31c7b (patch) | |
tree | 037dcc57fcc6b941478b1979f8806cbba26a6771 /coverage/htmlfiles/coverage_html.js | |
parent | 059b19d26dbc105340ffe4f150a1d2034956c3a3 (diff) | |
download | python-coveragepy-bdff9572a03fea704c4ef2f3ff021634b7f31c7b.tar.gz |
Filtering now computes coverage percentages properly.
Diffstat (limited to 'coverage/htmlfiles/coverage_html.js')
-rw-r--r-- | coverage/htmlfiles/coverage_html.js | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js index 6eb23fe..336b97b 100644 --- a/coverage/htmlfiles/coverage_html.js +++ b/coverage/htmlfiles/coverage_html.js @@ -116,9 +116,17 @@ coverage.wire_up_filter = function () { break; } - var sum = 0; + var sum = 0, numer = 0, denom = 0; $.each(cells.filter(':visible'), function () { - sum += parseInt(this.innerHTML, 10); + var ratio = $(this).data("ratio"); + if (ratio) { + var splitted = ratio.split(" "); + numer += parseInt(splitted[0], 10); + denom += parseInt(splitted[1], 10); + } + else { + sum += parseInt(this.innerHTML, 10); + } }); // Get footer cell element. @@ -126,8 +134,15 @@ coverage.wire_up_filter = function () { // Set value into dynamic footer cell element. if (cells[0].innerHTML.indexOf('%') > -1) { - // Value of "coverage" column is expressed as a percentage - footer_cell.text(parseInt((sum / show.length), 10) + '%'); + // Percentage columns use the numerator and denominator, + // and adapt to the number of decimal places. + var match = /\.([0-9]+)/.exec(cells[0].innerHTML); + var places = 0; + if (match) { + places = match[1].length; + } + var pct = numer * 100 / denom; + footer_cell.text(pct.toFixed(places) + '%'); } else { footer_cell.text(sum); |