Skip to content

Commit ecd7ab8

Browse files
committed
Hide branches in functions list
1 parent 2b30faf commit ecd7ab8

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

gcovr-templates/html/functions_page.content.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{# -*- engine: jinja -*- #}
2-
<div class="functions-container">
2+
<div class="functions-container{% if not (info.branches.total > info.branches.excluded) %} no-branches{% endif %}">
33
<div class="functions-body">
44
<div class="functions-header">
55
{% set class_sortable = " sortable" if not info.static_report and function_list | length > 1 else "" %}
66
<div class="col-function{{class_sortable}}{% if class_sortable %} sorted-ascending{% endif %}" data-sort="name">Function</div>
77
<div class="col-calls{{class_sortable}}" data-sort="calls">Calls</div>
88
<div class="col-lines{{class_sortable}}" data-sort="lines">Lines</div>
9+
{% if info.branches.total > info.branches.excluded %}
10+
<div class="col-branches{{class_sortable}}" data-sort="branches">Branches</div>
11+
{% endif %}
912
{% if SHOW_CONDITION_COVERAGE %}
1013
<div class="col-conditions{{class_sortable}}" data-sort="conditions">Conditions</div>
1114
{% endif %}
@@ -39,6 +42,7 @@
3942
window.__functionsPageConfig = {
4043
singlePage: {{ "true" if info.single_page else "false" }},
4144
htmlFilename: "{{ html_filename }}",
45+
showBranches: {{ "true" if info.branches.total > info.branches.excluded else "false" }},
4246
showConditions: {{ "true" if SHOW_CONDITION_COVERAGE else "false" }}
4347
};
4448
</script>

gcovr-templates/html/functions_page.summary.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
<span class="stat-label">Lines:</span>
1010
<span class="stat-value {{info.lines.class}}">{{info.lines.coverage}}%</span>
1111
</div>
12+
{% if info.branches.coverage != '-' %}
1213
<div class="summary-stat">
1314
<span class="stat-label">Branches:</span>
1415
<span class="stat-value {{info.branches.class}}">{{info.branches.coverage}}%</span>
1516
</div>
17+
{% endif %}
1618
</div>

gcovr-templates/html/gcovr.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@
943943
var data = JSON.parse(dataEl.textContent);
944944
var container = document.querySelector('.functions-body');
945945
var loadingEl = document.getElementById('functions-loading');
946+
var showBranches = config.showBranches;
946947
var showConditions = config.showConditions;
947948
var singlePage = config.singlePage;
948949
var currentFile = config.htmlFilename || '';
@@ -1013,6 +1014,11 @@
10131014
// col-lines
10141015
row.appendChild(el('div', 'col-lines', entry.line_coverage + '%'));
10151016

1017+
// col-branches (optional)
1018+
if (showBranches) {
1019+
row.appendChild(el('div', 'col-branches', entry.branch_coverage + '%'));
1020+
}
1021+
10161022
// col-conditions (optional)
10171023
if (showConditions) {
10181024
row.appendChild(el('div', 'col-conditions', entry.condition_coverage + '%'));
@@ -1085,6 +1091,7 @@
10851091
case 'name': aVal = a.name; bVal = b.name; break;
10861092
case 'calls': aVal = a.excluded ? -1 : a.execution_count; bVal = b.excluded ? -1 : b.execution_count; break;
10871093
case 'lines': aVal = parseFloat(a.line_coverage) || 0; bVal = parseFloat(b.line_coverage) || 0; break;
1094+
case 'branches': aVal = parseFloat(a.branch_coverage) || 0; bVal = parseFloat(b.branch_coverage) || 0; break;
10881095
case 'conditions': aVal = parseFloat(a.condition_coverage) || 0; bVal = parseFloat(b.condition_coverage) || 0; break;
10891096
default: aVal = a.name; bVal = b.name;
10901097
}
@@ -2043,8 +2050,12 @@
20432050
} catch (e) {}
20442051

20452052
// Apply saved hidden columns
2053+
var fnList = document.querySelector('.source-functions-list');
20462054
for (var i = 0; i < hidden.length; i++) {
20472055
table.classList.add('hide-col-' + hidden[i]);
2056+
if (fnList) {
2057+
fnList.classList.add('hide-col-' + hidden[i]);
2058+
}
20482059
}
20492060

20502061
// Update button appearance to match state
@@ -2063,6 +2074,12 @@
20632074
var isHidden = table.classList.toggle(hideClass);
20642075
this.classList.toggle('show-col', !isHidden);
20652076

2077+
// Sync with function list sidebar
2078+
var fnList = document.querySelector('.source-functions-list');
2079+
if (fnList) {
2080+
fnList.classList.toggle(hideClass, isHidden);
2081+
}
2082+
20662083
// Save state
20672084
var current = [];
20682085
var allBtns = document.querySelectorAll('.col-toggle');

gcovr-templates/html/source_page.content.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@
9090
<span class="source-function-col-name{{ sortable }}{% if sortable %} sorted-ascending{% endif %}" data-sort="name">Function</span>
9191
<span class="source-function-col-stat{{ sortable }}" data-sort="calls">Calls</span>
9292
<span class="source-function-col-stat{{ sortable }}" data-sort="lines">Lines</span>
93-
<span class="source-function-col-stat{{ sortable }}" data-sort="branches">Branches</span>
93+
{% if has_branches %}
94+
<span class="source-function-col-stat col-branches{{ sortable }}" data-sort="branches">Branches</span>
95+
{% endif %}
9496
<span class="source-function-col-stat{{ sortable }}" data-sort="blocks">Blocks</span>
9597
</div>
9698
{% for entry in function_list | sort(attribute='line') %}
@@ -108,9 +110,11 @@
108110
<span class="source-function-col-stat{% if entry.excluded %} excluded{% elif entry.line_coverage is defined and entry.line_coverage == 100.0 %} cov-high{% elif entry.line_coverage is defined and entry.line_coverage > 0 %} cov-med{% else %} cov-low{% endif %}">
109111
{%- if entry.excluded %}&ndash;{% elif entry.line_coverage is defined %}{{ entry.line_coverage | round(1) }}%{% else %}&ndash;{% endif -%}
110112
</span>
111-
<span class="source-function-col-stat{% if entry.excluded %} excluded{% elif entry.branch_coverage is defined and entry.branch_coverage != '-' %}{% if entry.branch_coverage == 100.0 %} cov-high{% elif entry.branch_coverage > 0 %} cov-med{% else %} cov-low{% endif %}{% endif %}">
113+
{% if has_branches %}
114+
<span class="source-function-col-stat col-branches{% if entry.excluded %} excluded{% elif entry.branch_coverage is defined and entry.branch_coverage != '-' %}{% if entry.branch_coverage == 100.0 %} cov-high{% elif entry.branch_coverage > 0 %} cov-med{% else %} cov-low{% endif %}{% endif %}">
112115
{%- if entry.excluded %}&ndash;{% elif entry.branch_coverage is defined and entry.branch_coverage != '-' %}{{ entry.branch_coverage | round(1) }}%{% else %}&ndash;{% endif -%}
113116
</span>
117+
{% endif %}
114118
<span class="source-function-col-stat{% if entry.excluded %} excluded{% elif blks is not none %}{% if blks == 100.0 %} cov-high{% elif blks > 0 %} cov-med{% else %} cov-low{% endif %}{% endif %}">
115119
{%- if entry.excluded %}&ndash;{% elif blks is not none %}{{ blks | round(1) }}%{% else %}&ndash;{% endif -%}
116120
</span>

gcovr-templates/html/style.css

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,10 @@ tr.source-line.nav-highlight > td {
16581658
overflow-y: auto;
16591659
}
16601660

1661+
.source-functions-list.hide-col-branch .col-branches {
1662+
display: none;
1663+
}
1664+
16611665
.source-function-header {
16621666
display: flex;
16631667
align-items: center;
@@ -2247,7 +2251,7 @@ tr.source-line.nav-highlight > td {
22472251

22482252
.functions-header {
22492253
display: grid;
2250-
grid-template-columns: 1fr 90px 70px{% if SHOW_CALLS %} 90px{% endif %};
2254+
grid-template-columns: 1fr 90px 70px 90px{% if SHOW_CALLS %} 90px{% endif %};
22512255
gap: 0;
22522256
padding: 0 16px;
22532257
background: var(--bg-tertiary);
@@ -2291,14 +2295,19 @@ tr.source-line.nav-highlight > td {
22912295

22922296
.function-row {
22932297
display: grid;
2294-
grid-template-columns: 1fr 90px 70px{% if SHOW_CALLS %} 90px{% endif %};
2298+
grid-template-columns: 1fr 90px 70px 90px{% if SHOW_CALLS %} 90px{% endif %};
22952299
gap: 0;
22962300
padding: 0 16px;
22972301
border-bottom: 1px solid var(--border-muted);
22982302
align-items: stretch;
22992303
transition: background var(--transition-fast);
23002304
}
23012305

2306+
.functions-container.no-branches .functions-header,
2307+
.functions-container.no-branches .function-row {
2308+
grid-template-columns: 1fr 90px 70px{% if SHOW_CALLS %} 90px{% endif %};
2309+
}
2310+
23022311
.function-row > div:not(:first-child) {
23032312
display: flex;
23042313
align-items: center;

0 commit comments

Comments
 (0)