summaryrefslogtreecommitdiff
path: root/doc/sample_html/coverage_html.js
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-09-20 10:31:52 -0400
committerNed Batchelder <ned@nedbatchelder.com>2015-09-20 10:31:52 -0400
commita6f8fd26ab1c019dba1bad590c5170a79d575f36 (patch)
tree249184e8a8555b1b7d4fc633d0d6f0a88360128e /doc/sample_html/coverage_html.js
parent4c5e40148d75ed04b1c0b6cbe099d9c1327cff48 (diff)
downloadpython-coveragepy-a6f8fd26ab1c019dba1bad590c5170a79d575f36.tar.gz
Latest sample HTML report
Diffstat (limited to 'doc/sample_html/coverage_html.js')
-rw-r--r--doc/sample_html/coverage_html.js142
1 files changed, 139 insertions, 3 deletions
diff --git a/doc/sample_html/coverage_html.js b/doc/sample_html/coverage_html.js
index b24006d..bd6a875 100644
--- a/doc/sample_html/coverage_html.js
+++ b/doc/sample_html/coverage_html.js
@@ -1,10 +1,13 @@
+// Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+// For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+
// Coverage.py HTML report browser code.
/*jslint browser: true, sloppy: true, vars: true, plusplus: true, maxerr: 50, indent: 4 */
/*global coverage: true, document, window, $ */
coverage = {};
-// Find all the elements with shortkey_* class, and use them to assign a shotrtcut key.
+// Find all the elements with shortkey_* class, and use them to assign a shortcut key.
coverage.assign_shortkeys = function () {
$("*[class*='shortkey_']").each(function (i, e) {
$.each($(e).attr("class").split(" "), function (i, c) {
@@ -35,6 +38,137 @@ coverage.wire_up_help_panel = function () {
});
};
+// Create the events for the filter box.
+coverage.wire_up_filter = function () {
+ // Cache elements.
+ var table = $("table.index");
+ var table_rows = table.find("tbody tr");
+ var table_row_names = table_rows.find("td.name a");
+ var no_rows = $("#no_rows");
+
+ // Create a duplicate table footer that we can modify with dynamic summed values.
+ var table_footer = $("table.index tfoot tr");
+ var table_dynamic_footer = table_footer.clone();
+ table_dynamic_footer.attr('class', 'total_dynamic hidden');
+ table_footer.after(table_dynamic_footer);
+
+ // Observe filter keyevents.
+ $("#filter").on("keyup change", $.debounce(150, function (event) {
+ var filter_value = $(this).val();
+
+ if (filter_value === "") {
+ // Filter box is empty, remove all filtering.
+ table_rows.removeClass("hidden");
+
+ // Show standard footer, hide dynamic footer.
+ table_footer.removeClass("hidden");
+ table_dynamic_footer.addClass("hidden");
+
+ // Hide placeholder, show table.
+ if (no_rows.length > 0) {
+ no_rows.hide();
+ }
+ table.show();
+
+ }
+ else {
+ // Filter table items by value.
+ var hide = $([]);
+ var show = $([]);
+
+ // Compile elements to hide / show.
+ $.each(table_row_names, function () {
+ var element = $(this).parents("tr");
+
+ if ($(this).text().indexOf(filter_value) === -1) {
+ // hide
+ hide = hide.add(element);
+ }
+ else {
+ // show
+ show = show.add(element);
+ }
+ });
+
+ // Perform DOM manipulation.
+ hide.addClass("hidden");
+ show.removeClass("hidden");
+
+ // Show placeholder if no rows will be displayed.
+ if (no_rows.length > 0) {
+ if (show.length === 0) {
+ // Show placeholder, hide table.
+ no_rows.show();
+ table.hide();
+ }
+ else {
+ // Hide placeholder, show table.
+ no_rows.hide();
+ table.show();
+ }
+ }
+
+ // Manage dynamic header:
+ if (hide.length > 0) {
+ // Calculate new dynamic sum values based on visible rows.
+ for (var column = 2; column < 20; column++) {
+ // Calculate summed value.
+ var cells = table_rows.find('td:nth-child(' + column + ')');
+ if (!cells.length) {
+ // No more columns...!
+ break;
+ }
+
+ var sum = 0, numer = 0, denom = 0;
+ $.each(cells.filter(':visible'), function () {
+ 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.
+ var footer_cell = table_dynamic_footer.find('td:nth-child(' + column + ')');
+
+ // Set value into dynamic footer cell element.
+ if (cells[0].innerHTML.indexOf('%') > -1) {
+ // 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);
+ }
+ }
+
+ // Hide standard footer, show dynamic footer.
+ table_footer.addClass("hidden");
+ table_dynamic_footer.removeClass("hidden");
+ }
+ else {
+ // Show standard footer, hide dynamic footer.
+ table_footer.removeClass("hidden");
+ table_dynamic_footer.addClass("hidden");
+ }
+ }
+ }));
+
+ // Trigger change event on setup, to force filter on page refresh
+ // (filter value may still be present).
+ $("#filter").trigger("change");
+};
+
// Loaded on index.html
coverage.index_ready = function ($) {
// Look for a cookie containing previous sort settings:
@@ -95,6 +229,7 @@ coverage.index_ready = function ($) {
coverage.assign_shortkeys();
coverage.wire_up_help_panel();
+ coverage.wire_up_filter();
// Watch for page unload events so we can save the final sort settings:
$(window).unload(function () {
@@ -187,12 +322,13 @@ coverage.to_next_chunk = function () {
// Find the start of the next colored chunk.
var probe = c.sel_end;
+ var color, probe_line;
while (true) {
- var probe_line = c.line_elt(probe);
+ probe_line = c.line_elt(probe);
if (probe_line.length === 0) {
return;
}
- var color = probe_line.css("background-color");
+ color = probe_line.css("background-color");
if (!c.is_transparent(color)) {
break;
}