Skip to content

Commit 2540637

Browse files
Add option to hide incomplete comparisions
1 parent 9968f1d commit 2540637

3 files changed

Lines changed: 57 additions & 3 deletions

File tree

‎codespeed/static/js/comparison.js‎

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function getConfiguration() {
2929
ben: readCheckbox("input[name='benchmarks']:checked"),
3030
env: readCheckbox("input[name='environments']:checked"),
3131
hor: $("input[name='direction']").is(':checked'),
32+
com: $("input[name='common_only']").is(':checked'),
3233
bas: $("#baseline option:selected").val() || "none",
3334
chart: $("#chart_type option:selected").val()
3435
};
@@ -141,11 +142,28 @@ function updateGraphTitle(exes, enviros, bens, baseline, chart, chartTitles) {
141142
$title.text(chartTitles.join(' / '));
142143
}
143144

145+
// Keep only the benchmarks that have a result for every selected
146+
// executable/environment pair, so each bar group covers the same set.
147+
function filterCommonBenchmarks(bens, exes, enviros) {
148+
if (!compdata) { return bens; }
149+
return bens.filter(function(ben) {
150+
return exes.every(function(exe) {
151+
return enviros.every(function(env) {
152+
var val = compdata[exe] && compdata[exe][env]
153+
? compdata[exe][env][ben]
154+
: null;
155+
return val !== null && val !== undefined;
156+
});
157+
});
158+
});
159+
}
160+
144161
function refreshContent() {
145162
var conf = getConfiguration(),
146163
exes = conf.exe.split(","),
147164
bens = conf.ben.split(","),
148165
enviros = conf.env.split(","),
166+
hiddenCount = 0,
149167
msg = "";
150168

151169
$("#graph-title").html("");
@@ -159,7 +177,19 @@ function refreshContent() {
159177
} else if (enviros[0] === "") {
160178
$("#plotwrapper").html('<p class="warning">No environments selected</p>');
161179
return false;
162-
} else if (conf.chart === "relative bars" && conf.bas === "none") {
180+
}
181+
182+
if (conf.com) {
183+
var common = filterCommonBenchmarks(bens, exes, enviros);
184+
hiddenCount = bens.length - common.length;
185+
bens = common;
186+
if (bens.length === 0) {
187+
$("#plotwrapper").html('<p class="warning">No benchmark has results for every selected executable and environment</p>');
188+
return false;
189+
}
190+
}
191+
192+
if (conf.chart === "relative bars" && conf.bas === "none") {
163193
msg = '<p class="warning">For relative bar charts, you must select a baseline to normalize to.</p>';
164194
$("#plotwrapper").html(msg);
165195
return false;
@@ -183,6 +213,14 @@ function refreshContent() {
183213
}
184214
}
185215

216+
var hiddenMsg = "";
217+
if (hiddenCount > 0) {
218+
hiddenMsg = '<p class="warning">' + hiddenCount + ' benchmark' +
219+
(hiddenCount === 1 ? '' : 's') +
220+
' hidden because not every selected executable has a result for ' +
221+
(hiddenCount === 1 ? 'it' : 'them') + '.</p>';
222+
}
223+
186224
chartInstances.forEach(function(c) { c.destroy(); });
187225
chartInstances = [];
188226
$("#plotwrapper").fadeOut("fast", function() {
@@ -204,6 +242,8 @@ function refreshContent() {
204242
var t = renderComparisonPlot(plotid, unit, benchmarks, exes, enviros, conf.bas, conf.chart, conf.hor);
205243
chartTitles.push(t);
206244
}
245+
// Shown below the chart(s) so it does not push them down
246+
$("#plotwrapper").append(hiddenMsg);
207247
updateGraphTitle(exes, enviros, bens, conf.bas, conf.chart, chartTitles);
208248
});
209249
}
@@ -445,6 +485,7 @@ function init(defaults) {
445485
// Set default values
446486
$("#chart_type").val(defaults.chart_type);
447487
$("#direction").prop('checked', defaults.direction === "True");
488+
$("#common_only").prop('checked', defaults.common_only === "True");
448489

449490
/*
450491
var sel = $("input[name='executables']");
@@ -477,7 +518,7 @@ function init(defaults) {
477518
$("#benchmark .checkall, #benchmark .uncheckall").click(loadData);
478519

479520
// Re-render without re-fetching for other controls
480-
$("#chart_type, #baseline, #direction").change(refreshContent);
521+
$("#chart_type, #baseline, #direction, #common_only").change(refreshContent);
481522
$("input[name='environments']").change(function() {
482523
updateBaselineDropdown();
483524
refreshContent();
@@ -536,6 +577,9 @@ function init(defaults) {
536577
var exes = conf.exe ? conf.exe.split(",").filter(Boolean) : [];
537578
var enviros = readCheckbox("input[name='environments']:checked").split(",").filter(Boolean);
538579
var benchmarks = conf.ben ? conf.ben.split(",").filter(Boolean) : [];
580+
if (conf.com) {
581+
benchmarks = filterCommonBenchmarks(benchmarks, exes, enviros);
582+
}
539583

540584
// Header row: benchmark, then one column per exe@env
541585
var header = ["benchmark"];

‎codespeed/templates/codespeed/comparison.html‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
<label for="direction">Horizontal:</label>
7979
<input id="direction" type="checkbox" name="direction" value="horizontal"/>
8080
</span>
81+
<span class="options" title="Only show benchmarks that have a result for every selected executable and environment">
82+
<label for="common_only">Hide incomplete:</label>
83+
<input id="common_only" type="checkbox" name="common_only" value="common"/>
84+
</span>
8185
{% comment %}Bootstrap Icons "download" glyph (MIT, twbs/icons).{% endcomment %}
8286
<a id="exportcsv" href="#"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5"/><path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z"/></svg>Export CSV</a>
8387
{% include "codespeed/permalink.html" %}
@@ -99,6 +103,7 @@
99103
chart_type: "{{ selectedchart }}",
100104
baseline: "{{ selectedbaseline }}",
101105
direction: "{{ selecteddirection }}",
106+
common_only: "{{ selectedcommon }}",
102107
executables: [{% for e in checkedexecutables %}"{{ e }}",{% endfor %}],
103108
benchmarks: [{% for b in checkedbenchmarks %}{{ b.id }},{% endfor %}],
104109
environments: [{% for e in checkedenviros %}{{ e.id }},{% endfor %}],

‎codespeed/views.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,10 @@ def comparison(request):
476476
settings.CHART_ORIENTATION == 'horizontal'):
477477
selecteddirection = True
478478

479+
# Hide benchmarks that lack a result for any selected executable, so
480+
# every bar group covers the same set of benchmarks.
481+
selectedcommon = data.get('com') == 'true'
482+
479483
return render(request, 'codespeed/comparison.html', {
480484
'checkedexecutables': checkedexecutables,
481485
'checkedbenchmarks': checkedbenchmarks,
@@ -487,7 +491,8 @@ def comparison(request):
487491
'charts': charts,
488492
'selectedbaseline': selectedbaseline,
489493
'selectedchart': selectedchart,
490-
'selecteddirection': selecteddirection
494+
'selecteddirection': selecteddirection,
495+
'selectedcommon': selectedcommon,
491496
})
492497

493498
def get_setting(name, default = None):

0 commit comments

Comments
 (0)