Skip to content

Commit

Permalink
src: apply sort function proposal with slight modifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrej.ille committed Sep 26, 2024
1 parent 13f0c51 commit 9dc1261
Showing 1 changed file with 29 additions and 73 deletions.
102 changes: 29 additions & 73 deletions src/cov/cov-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,14 @@ static void cover_print_hierarchy_header(FILE *f, const char *table_id)
{
fprintf(f, "<table id=\"%s\" style=\"width:75%%;margin-left:" MARGIN_LEFT ";margin-right:auto;\"> \n"
" <tr style=\"height:40px\">\n"
" <th class=\"cbg\" onclick=\"sortTable(0, &quot;%s&quot;, false)\" style=\"width:30%%\">Instance</th>\n"
" <th class=\"cbg\" onclick=\"sortTable(1, &quot;%s&quot;, true)\" style=\"width:8%%\">Statement</th>\n"
" <th class=\"cbg\" onclick=\"sortTable(2, &quot;%s&quot;, true)\" style=\"width:8%%\">Branch</th>\n"
" <th class=\"cbg\" onclick=\"sortTable(3, &quot;%s&quot;, true)\" style=\"width:8%%\">Toggle</th>\n"
" <th class=\"cbg\" onclick=\"sortTable(4, &quot;%s&quot;, true)\" style=\"width:8%%\">Expression</th>\n"
" <th class=\"cbg\" onclick=\"sortTable(5, &quot;%s&quot;, true)\" style=\"width:8%%\">FSM state</th>\n"
" <th class=\"cbg\" onclick=\"sortTable(6, &quot;%s&quot;, true)\" style=\"width:8%%\">Functional</th>\n"
" <th class=\"cbg\" onclick=\"sortTable(7, &quot;%s&quot;, true)\" style=\"width:8%%\">Average</th>\n"
" <th class=\"cbg\" onclick=\"sortTable(0, &quot;%s&quot;)\" style=\"width:30%%\">Instance</th>\n"
" <th class=\"cbg\" onclick=\"sortTable(1, &quot;%s&quot;)\" style=\"width:8%%\">Statement</th>\n"
" <th class=\"cbg\" onclick=\"sortTable(2, &quot;%s&quot;)\" style=\"width:8%%\">Branch</th>\n"
" <th class=\"cbg\" onclick=\"sortTable(3, &quot;%s&quot;)\" style=\"width:8%%\">Toggle</th>\n"
" <th class=\"cbg\" onclick=\"sortTable(4, &quot;%s&quot;)\" style=\"width:8%%\">Expression</th>\n"
" <th class=\"cbg\" onclick=\"sortTable(5, &quot;%s&quot;)\" style=\"width:8%%\">FSM state</th>\n"
" <th class=\"cbg\" onclick=\"sortTable(6, &quot;%s&quot;)\" style=\"width:8%%\">Functional</th>\n"
" <th class=\"cbg\" onclick=\"sortTable(7, &quot;%s&quot;)\" style=\"width:8%%\">Average</th>\n"
" </tr>\n", table_id, table_id, table_id, table_id, table_id, table_id, table_id, table_id, table_id);
}

Expand Down Expand Up @@ -1032,72 +1032,28 @@ static void cover_print_hierarchy_guts(FILE *f, cover_report_ctx_t *ctx)
" function GetExclude(excludeCmd) {\n"
" navigator.clipboard.writeText(excludeCmd);\n"
" }\n"
" function sortTable(n, tableId, is_number) {\n"
" var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;\n"
" table = document.getElementById(tableId);\n"
" switching = true;\n"
" // Set the sorting direction to ascending:\n"
" dir = \"asc\";\n"
" /* Make a loop that will continue until\n"
" no switching has been done: */\n"
" while (switching) {\n"
" // Start by saying: no switching is done:\n"
" switching = false;\n"
" rows = table.rows;\n"
" /* Loop through all table rows (except the\n"
" first, which contains table headers): */\n"
" for (i = 1; i < (rows.length - 1); i++) {\n"
" // Start by saying there should be no switching:\n"
" shouldSwitch = false;\n"
" /* Get the two elements you want to compare,\n"
" one from current row and one from the next: */\n"
" if (is_number === true) {"
" x = rows[i].getElementsByTagName(\"TD\")[n];\n"
" y = rows[i + 1].getElementsByTagName(\"TD\")[n];\n"
" x = parseInt(x.innerHTML.split(\"%%\")[0]);\n"
" y = parseInt(y.innerHTML.split(\"%%\")[0]);\n"
" if (isNaN(x)) {\n"
" x = 0;\n"
" }\n"
" if (isNaN(y)) {\n"
" y = 0;\n"
" }\n"
" } else {\n"
" x = rows[i].getElementsByTagName(\"TD\")[n].innerHTML.toLowerCase();\n"
" y = rows[i + 1].getElementsByTagName(\"TD\")[n].innerHTML.toLowerCase();\n"
" }\n"
" /* Check if the two rows should switch place,\n"
" based on the direction, asc or desc: */\n"
" if (dir == \"asc\") {\n"
" if (x > y) {\n"
" // If so, mark as a switch and break the loop:\n"
" shouldSwitch = true;\n"
" break;\n"
" }\n"
" } else if (dir == \"desc\") {\n"
" if (x < y) {\n"
" // If so, mark as a switch and break the loop:\n"
" shouldSwitch = true;\n"
" break;\n"
" }\n"
" }\n"
" }\n"
" if (shouldSwitch) {\n"
" /* If a switch has been marked, make the switch\n"
" and mark that a switch has been done: */\n"
" rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);\n"
" switching = true;\n"
" // Each time a switch is done, increase this count by 1:\n"
" switchcount ++;\n"
" } else {\n"
" /* If no switching has been done AND the direction is \"asc\",\n"
" set the direction to \"desc\" and run the while loop again. */\n"
" if (switchcount == 0 && dir == \"asc\") {\n"
" dir = \"desc\";\n"
" switching = true;\n"
" }\n"
" }\n"
" function getCellValue (tr, n) {\n"
" v = tr.getElementsByTagName(\"TD\")[n];\n"
" v = parseInt(v.innerHTML.split(\"%%\")[0]);\n"
" if (isNaN(v)) {\n"
" v = tr.getElementsByTagName(\"TD\")[n].innerHTML.toLowerCase();\n"
" }\n"
" return v;\n"
" }\n"
" function sortTable(n, tableId) {\n"
" const table = document.getElementById(tableId);\n"
" const rows = Array.from(table.querySelectorAll('tr:nth-child(n+2)'));\n"
" rows.sort((a, b) => {\n"
" const left = getCellValue(this.ascending ? a : b, n);\n"
" const right = getCellValue(this.ascending ? b : a, n);\n"
" if (!isNaN(left) && !isNaN(right)) {\n"
" return left - right;\n"
" } else {\n"
" return left.localeCompare(right);\n"
" }\n"
" });\n"
" rows.forEach(tr => table.appendChild(tr));\n"
" this.ascending = !this.ascending;\n"
" }\n"
" document.getElementById(\"defaultOpen\").click();\n"
"</script>\n");
Expand Down

0 comments on commit 9dc1261

Please sign in to comment.