Abhishek Arya | 39a7832 | 2018-05-17 02:40:53 | [diff] [blame] | 1 | {% if table_entry_type == "Component" %} |
| 2 | <p> |
| 3 |  Filter: <input type="text" id="filter" size="30" /> (e.g. "crypto,VR") |
| 4 | </p> |
| 5 | {% endif %} |
Yuke Liao | ea228d0 | 2018-01-05 19:10:33 | [diff] [blame] | 6 | <table> |
Abhishek Arya | 865fffd | 2018-05-08 22:16:01 | [diff] [blame] | 7 | <thead> |
| 8 | <tr> |
| 9 | <th class="column-entry-bold">{{ table_entry_type }}</th> |
Abhishek Arya | a88e7cd4 | 2019-04-25 22:36:06 | [diff] [blame] | 10 | <th class="column-entry-bold" onclick="sortTable(SORT_COLUMN.LINE)" title= |
Abhishek Arya | 865fffd | 2018-05-08 22:16:01 | [diff] [blame] | 11 | "Line coverage is the percentage of code lines which have been executed at least once. Only executable lines within function bodies are considered to be code lines."> |
Abhishek Arya | a88e7cd4 | 2019-04-25 22:36:06 | [diff] [blame] | 12 | Line Coverage |
| 13 | </th> |
| 14 | <th class="column-entry-bold" onclick="sortTable(SORT_COLUMN.FUNCTION)" title= |
Abhishek Arya | 865fffd | 2018-05-08 22:16:01 | [diff] [blame] | 15 | "Function coverage is the percentage of functions which have been executed at least once. A function is considered to be executed if any of its instantiations are executed."> |
Abhishek Arya | a88e7cd4 | 2019-04-25 22:36:06 | [diff] [blame] | 16 | Function Coverage |
| 17 | </th> |
| 18 | <th class="column-entry-bold" onclick="sortTable(SORT_COLUMN.REGION)" title= |
Abhishek Arya | 865fffd | 2018-05-08 22:16:01 | [diff] [blame] | 19 | "Region coverage is the percentage of code regions which have been executed at least once. A code region may span multiple lines (e.g in a large function body with no control flow). However, it's also possible for a single line to contain multiple code regions (e.g in 'return x || y && z')."> |
Abhishek Arya | a88e7cd4 | 2019-04-25 22:36:06 | [diff] [blame] | 20 | Region Coverage |
| 21 | </th> |
Abhishek Arya | 865fffd | 2018-05-08 22:16:01 | [diff] [blame] | 22 | </tr> |
| 23 | </thead> |
| 24 | <tbody> |
Yuke Liao | ea228d0 | 2018-01-05 19:10:33 | [diff] [blame] | 25 | {% for entry in entries %} |
Abhishek Arya | 865fffd | 2018-05-08 22:16:01 | [diff] [blame] | 26 | <tr class="light-row"> |
| 27 | <td> |
| 28 | {% if entry["is_dir"] == True %} |
| 29 | <pre><a href='{{ entry["href"] }}'>{{ entry["name"] }}/</a></pre> |
| 30 | {% else %} |
| 31 | <pre><a href='{{ entry["href"] }}'>{{ entry["name"] }}</a></pre> |
| 32 | {% endif %} |
| 33 | </td> |
| 34 | {% for feature in ("lines", "functions", "regions") %} |
| 35 | <td class='column-entry-{{ entry[feature]["color_class"] }}'> |
| 36 | <pre>{{ entry[feature]["percentage"] }}% ({{ entry[feature]["covered"] }}/{{ entry[feature]["total"] }})</pre> |
| 37 | </td> |
| 38 | {% endfor %} |
| 39 | </tr> |
Yuke Liao | ea228d0 | 2018-01-05 19:10:33 | [diff] [blame] | 40 | {% endfor %} |
Abhishek Arya | 865fffd | 2018-05-08 22:16:01 | [diff] [blame] | 41 | </tbody> |
Abhishek Arya | efbe1df | 2018-05-14 20:19:48 | [diff] [blame] | 42 | {% if total_entry %} |
| 43 | <tfoot> |
| 44 | <tr class="light-row-bold"> |
| 45 | <td> |
| 46 | <pre>Totals</pre> |
| 47 | </td> |
| 48 | {% for feature in ("lines", "functions", "regions") %} |
| 49 | <td class='column-entry-{{ total_entry[feature]["color_class"] }}'> |
| 50 | <pre>{{ total_entry[feature]["percentage"] }}% ({{ total_entry[feature]["covered"] }}/{{ total_entry[feature]["total"] }})</pre> |
| 51 | </td> |
| 52 | {% endfor %} |
| 53 | </tr> |
| 54 | </tfoot> |
| 55 | {% endif %} |
Abhishek Arya | 39a7832 | 2018-05-17 02:40:53 | [diff] [blame] | 56 | </table> |
Abhishek Arya | a88e7cd4 | 2019-04-25 22:36:06 | [diff] [blame] | 57 | |
Abhishek Arya | 39a7832 | 2018-05-17 02:40:53 | [diff] [blame] | 58 | <script> |
Abhishek Arya | a88e7cd4 | 2019-04-25 22:36:06 | [diff] [blame] | 59 | const SORT_COLUMN = { |
| 60 | LINE: 2, |
| 61 | FUNCTION: 3, |
| 62 | REGION: 4, |
| 63 | } |
| 64 | |
| 65 | const SORT_TYPES = { |
| 66 | UNSET: -1, |
| 67 | PERCENT: 0, |
| 68 | AGGREGATE: 1, |
| 69 | } |
| 70 | |
| 71 | var SORT_ORDER = { |
| 72 | [SORT_COLUMN.LINE]: [SORT_TYPES.UNSET], |
| 73 | [SORT_COLUMN.FUNCTION]: [SORT_TYPES.UNSET], |
| 74 | [SORT_COLUMN.REGION]: [SORT_TYPES.UNSET], |
| 75 | } |
| 76 | |
| 77 | function sortTable(columnNumber) { |
| 78 | SORT_ORDER[columnNumber] = ++SORT_ORDER[columnNumber] % 2; |
| 79 | |
| 80 | let columnSortOrder = SORT_ORDER[columnNumber]; |
| 81 | let tbody = document.getElementsByTagName("tbody")[0]; |
| 82 | |
| 83 | [].slice.call(tbody.rows).sort(function(a, b) { |
| 84 | let aColumn = a.cells[columnNumber-1].textContent; |
| 85 | let bColumn = b.cells[columnNumber-1].textContent; |
| 86 | |
| 87 | let aColumnCompare, bColumnCompare; |
| 88 | if (columnSortOrder == SORT_TYPES.PERCENT) { |
| 89 | aColumnCompare = parseFloat(/([0-9.]+)%/.exec(aColumn)[1]); |
| 90 | bColumnCompare = parseFloat(/([0-9.]+)%/.exec(bColumn)[1]); |
| 91 | } else { |
| 92 | aColumnCompare = parseInt(/\/(\d+)/.exec(aColumn)[1]); |
| 93 | bColumnCompare = parseInt(/\/(\d+)/.exec(bColumn)[1]); |
| 94 | } |
| 95 | |
| 96 | return ( |
| 97 | aColumnCompare < bColumnCompare ? -1: |
| 98 | aColumnCompare > bColumnCompare ? 1 : 0); |
| 99 | }).forEach(function(value, index) { |
| 100 | tbody.appendChild(value); |
| 101 | }); |
| 102 | } |
| 103 | |
| 104 | {% if table_entry_type == "Component" %} |
Abhishek Arya | 39a7832 | 2018-05-17 02:40:53 | [diff] [blame] | 105 | function filterInputChanged() { |
| 106 | let filter = document.getElementById("filter"); |
| 107 | let filterString = filter.value; |
| 108 | |
| 109 | // Update query paramater in URL. |
| 110 | let queryParams = new URLSearchParams(window.location.search); |
| 111 | queryParams.set('filter', filterString); |
| 112 | let newPath = window.location.pathname; |
| 113 | if (filterString) |
| 114 | newPath += '?' + queryParams.toString(); |
| 115 | history.pushState(null, '', newPath); |
| 116 | |
| 117 | filterRowsIfNeeded(); |
| 118 | } |
| 119 | |
| 120 | function filterRowsIfNeeded() { |
| 121 | let queryParams = new URLSearchParams(window.location.search); |
Abhishek Arya | 559a729 | 2018-05-17 23:06:59 | [diff] [blame] | 122 | let filterString = queryParams.get('filter') || ""; |
| 123 | let filterValuesLower = filterString.toLowerCase().split(','); |
Abhishek Arya | 39a7832 | 2018-05-17 02:40:53 | [diff] [blame] | 124 | let tbody = document.getElementsByTagName("tbody")[0]; |
| 125 | let rows = tbody.getElementsByTagName("tr"); |
| 126 | for (let row of rows) { |
| 127 | let td = row.getElementsByTagName("td"); |
| 128 | let tdContent = row.innerText.toLowerCase(); |
| 129 | |
| 130 | // |match| should be true on empty search (show everything). |
Abhishek Arya | 559a729 | 2018-05-17 23:06:59 | [diff] [blame] | 131 | let match = !filterValuesLower; |
| 132 | for (let filterValueLower of filterValuesLower) { |
| 133 | if (tdContent.includes(filterValueLower)) { |
Abhishek Arya | 39a7832 | 2018-05-17 02:40:53 | [diff] [blame] | 134 | match = true; |
| 135 | break |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | if (match && row.style.display == 'none') |
| 140 | row.style.display = 'table-row'; |
| 141 | else if (!match) |
| 142 | row.style.display = 'none'; |
| 143 | } |
| 144 | |
| 145 | // Update filter value in input box (for cases when filter is provided |
| 146 | // as part of page load URL). |
| 147 | let filter = document.getElementById("filter"); |
Abhishek Arya | 559a729 | 2018-05-17 23:06:59 | [diff] [blame] | 148 | if (filter.value != filterString) |
Abhishek Arya | 39a7832 | 2018-05-17 02:40:53 | [diff] [blame] | 149 | filter.value = filterString; |
| 150 | } |
| 151 | |
| 152 | window.onload = filterRowsIfNeeded; |
| 153 | |
| 154 | var filter = document.getElementById("filter"); |
| 155 | filter.onchange = filter.onkeyup = filterInputChanged; |
Abhishek Arya | 39a7832 | 2018-05-17 02:40:53 | [diff] [blame] | 156 | {% endif %} |
Abhishek Arya | a88e7cd4 | 2019-04-25 22:36:06 | [diff] [blame] | 157 | </script> |