diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2019-12-14 06:14:16 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2019-12-14 06:14:16 -0500 |
commit | bde31306de4ff2b6e4945683e5deb821c85984e8 (patch) | |
tree | ab06e18d6d59adf0e383b5f9c2113ed01f10c0b6 /doc/sample_html/coverage_html.js | |
parent | b92a84c8e5ec9eca615bd5a481b491f6865072a9 (diff) | |
download | python-coveragepy-git-bde31306de4ff2b6e4945683e5deb821c85984e8.tar.gz |
Sample html report for 5.0coverage-5.0
Diffstat (limited to 'doc/sample_html/coverage_html.js')
-rw-r--r-- | doc/sample_html/coverage_html.js | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/doc/sample_html/coverage_html.js b/doc/sample_html/coverage_html.js index 84b5a7e0..22152333 100644 --- a/doc/sample_html/coverage_html.js +++ b/doc/sample_html/coverage_html.js @@ -169,22 +169,13 @@ coverage.wire_up_filter = function () { // Loaded on index.html coverage.index_ready = function ($) { - // Look for a cookie containing previous sort settings: + // Look for a localStorage item containing previous sort settings: var sort_list = []; - var cookie_name = "COVERAGE_INDEX_SORT"; - var i; + var storage_name = "COVERAGE_INDEX_SORT"; + var stored_list = localStorage.getItem(storage_name); - // This almost makes it worth installing the jQuery cookie plugin: - if (document.cookie.indexOf(cookie_name) > -1) { - var cookies = document.cookie.split(";"); - for (i = 0; i < cookies.length; i++) { - var parts = cookies[i].split("="); - - if ($.trim(parts[0]) === cookie_name && parts[1]) { - sort_list = eval("[[" + parts[1] + "]]"); - break; - } - } + if (stored_list) { + sort_list = JSON.parse('[[' + stored_list + ']]'); } // Create a new widget which exists only to save and restore @@ -231,7 +222,7 @@ coverage.index_ready = function ($) { // Watch for page unload events so we can save the final sort settings: $(window).unload(function () { - document.cookie = cookie_name + "=" + sort_list.toString() + "; path=/"; + localStorage.setItem(storage_name, sort_list.toString()) }); }; @@ -240,7 +231,7 @@ coverage.index_ready = function ($) { coverage.pyfile_ready = function ($) { // If we're directed to a particular line number, highlight the line. var frag = location.hash; - if (frag.length > 2 && frag[1] === 'n') { + if (frag.length > 2 && frag[1] === 't') { $(frag).addClass('highlight'); coverage.set_sel(parseInt(frag.substr(2), 10)); } @@ -265,21 +256,22 @@ coverage.pyfile_ready = function ($) { coverage.init_scroll_markers(); - // Rebuild scroll markers after window high changing - $(window).resize(coverage.resize_scroll_markers); + // Rebuild scroll markers when the window height changes. + $(window).resize(coverage.build_scroll_markers); }; coverage.toggle_lines = function (btn, cls) { btn = $(btn); - var hide = "hide_"+cls; - if (btn.hasClass(hide)) { - $("#source ."+cls).removeClass(hide); - btn.removeClass(hide); + var show = "show_"+cls; + if (btn.hasClass(show)) { + $("#source ." + cls).removeClass(show); + btn.removeClass(show); } else { - $("#source ."+cls).addClass(hide); - btn.addClass(hide); + $("#source ." + cls).addClass(show); + btn.addClass(show); } + coverage.build_scroll_markers(); }; // Return the nth line div. @@ -292,11 +284,6 @@ coverage.num_elt = function (n) { return $("#n" + n); }; -// Return the container of all the code. -coverage.code_container = function () { - return $(".linenos"); -}; - // Set the selection. b and e are line numbers. coverage.set_sel = function (b, e) { // The first line selected. @@ -315,9 +302,17 @@ coverage.to_first_chunk = function () { coverage.to_next_chunk(); }; -coverage.is_transparent = function (color) { - // Different browsers return different colors for "none". - return color === "transparent" || color === "rgba(0, 0, 0, 0)"; +// Return a string indicating what kind of chunk this line belongs to, +// or null if not a chunk. +coverage.chunk_indicator = function (line_elt) { + var klass = line_elt.attr('class'); + if (klass) { + var m = klass.match(/\bshow_\w+\b/); + if (m) { + return m[0]; + } + } + return null; }; coverage.to_next_chunk = function () { @@ -325,14 +320,14 @@ coverage.to_next_chunk = function () { // Find the start of the next colored chunk. var probe = c.sel_end; - var color, probe_line; + var chunk_indicator, probe_line; while (true) { probe_line = c.line_elt(probe); if (probe_line.length === 0) { return; } - color = probe_line.css("background-color"); - if (!c.is_transparent(color)) { + chunk_indicator = c.chunk_indicator(probe_line); + if (chunk_indicator) { break; } probe++; @@ -342,11 +337,11 @@ coverage.to_next_chunk = function () { var begin = probe; // Find the end of this chunk. - var next_color = color; - while (next_color === color) { + var next_indicator = chunk_indicator; + while (next_indicator === chunk_indicator) { probe++; probe_line = c.line_elt(probe); - next_color = probe_line.css("background-color"); + next_indicator = c.chunk_indicator(probe_line); } c.set_sel(begin, probe); c.show_selection(); @@ -361,25 +356,25 @@ coverage.to_prev_chunk = function () { if (probe_line.length === 0) { return; } - var color = probe_line.css("background-color"); - while (probe > 0 && c.is_transparent(color)) { + var chunk_indicator = c.chunk_indicator(probe_line); + while (probe > 0 && !chunk_indicator) { probe--; probe_line = c.line_elt(probe); if (probe_line.length === 0) { return; } - color = probe_line.css("background-color"); + chunk_indicator = c.chunk_indicator(probe_line); } // There's a prev chunk, `probe` points to its last line. var end = probe+1; // Find the beginning of this chunk. - var prev_color = color; - while (prev_color === color) { + var prev_indicator = chunk_indicator; + while (prev_indicator === chunk_indicator) { probe--; probe_line = c.line_elt(probe); - prev_color = probe_line.css("background-color"); + prev_indicator = c.chunk_indicator(probe_line); } c.set_sel(probe+1, end); c.show_selection(); @@ -451,29 +446,29 @@ coverage.select_line_or_chunk = function (lineno) { if (probe_line.length === 0) { return; } - var the_color = probe_line.css("background-color"); - if (!c.is_transparent(the_color)) { + var the_indicator = c.chunk_indicator(probe_line); + if (the_indicator) { // The line is in a highlighted chunk. // Search backward for the first line. var probe = lineno; - var color = the_color; - while (probe > 0 && color === the_color) { + var indicator = the_indicator; + while (probe > 0 && indicator === the_indicator) { probe--; probe_line = c.line_elt(probe); if (probe_line.length === 0) { break; } - color = probe_line.css("background-color"); + indicator = c.chunk_indicator(probe_line); } var begin = probe + 1; // Search forward for the last line. probe = lineno; - color = the_color; - while (color === the_color) { + indicator = the_indicator; + while (indicator === the_indicator) { probe++; probe_line = c.line_elt(probe); - color = probe_line.css("background-color"); + indicator = c.chunk_indicator(probe_line); } coverage.set_sel(begin, probe); @@ -487,7 +482,7 @@ coverage.show_selection = function () { var c = coverage; // Highlight the lines in the chunk - c.code_container().find(".highlight").removeClass("highlight"); + $(".linenos .highlight").removeClass("highlight"); for (var probe = c.sel_begin; probe > 0 && probe < c.sel_end; probe++) { c.num_elt(probe).addClass("highlight"); } @@ -517,21 +512,21 @@ coverage.finish_scrolling = function () { coverage.init_scroll_markers = function () { var c = coverage; // Init some variables - c.lines_len = $('td.text p').length; + c.lines_len = $('#source p').length; c.body_h = $('body').height(); c.header_h = $('div#header').height(); - c.missed_lines = $('td.text p.mis, td.text p.par'); // Build html - c.resize_scroll_markers(); + c.build_scroll_markers(); }; -coverage.resize_scroll_markers = function () { +coverage.build_scroll_markers = function () { var c = coverage, min_line_height = 3, max_line_height = 10, visible_window_h = $(window).height(); + c.lines_to_mark = $('#source').find('p.show_run, p.show_mis, p.show_exc, p.show_exc, p.show_par'); $('#scroll_marker').remove(); // Don't build markers if the window has no scroll bar. if (c.body_h <= visible_window_h) { @@ -555,11 +550,16 @@ coverage.resize_scroll_markers = function () { var previous_line = -99, last_mark, - last_top; + last_top, + offsets = {}; - c.missed_lines.each(function () { - var line_top = Math.round($(this).offset().top * marker_scale), - id_name = $(this).attr('id'), + // Calculate line offsets outside loop to prevent relayouts + c.lines_to_mark.each(function() { + offsets[this.id] = $(this).offset().top; + }); + c.lines_to_mark.each(function () { + var id_name = $(this).attr('id'), + line_top = Math.round(offsets[id_name] * marker_scale), line_number = parseInt(id_name.substring(1, id_name.length)); if (line_number === previous_line + 1) { |