Repository navigation
Expand file tree
/
Copy pathcomparison.js
More file actions
365 lines (326 loc) · 13.5 KB
/
Copy pathcomparison.js
File metadata and controls
365 lines (326 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
var Comparison = (function(window){
// Localize globals
var readCheckbox = window.readCheckbox, getLoadText = window.getLoadText;
var compdata, bench_units, dataCache = {}, chartInstances = [];
Chart.Tooltip.positioners.cursor = function(_items, eventPosition) {
return {x: eventPosition.x, y: eventPosition.y};
};
var COLORS = [
'#4e79a7', '#f28e2b', '#e15759', '#76b7b2',
'#59a14f', '#edc948', '#b07aa1', '#ff9da7',
'#9c755f', '#bab0ac'
];
function getColor(i) { return COLORS[i % COLORS.length]; }
function getConfiguration() {
return {
exe: readCheckbox("input[name='executables']:checked"),
ben: readCheckbox("input[name='benchmarks']:checked"),
env: readCheckbox("input[name='environments']:checked"),
hor: $("input[name='direction']").is(':checked'),
bas: $("#baseline option:selected").val(),
chart: $("#chart_type option:selected").val()
};
}
function refreshContent() {
var conf = getConfiguration(),
exes = conf.exe.split(","),
bens = conf.ben.split(","),
enviros = conf.env.split(","),
msg = "";
var h = $("#plotwrapper").height();//get height for error message
if (exes[0] === "") {
$("#plotwrapper").html('<p class="warning">No executables selected</p>');
return false;
} else if (bens[0] === "") {
$("#plotwrapper").html('<p class="warning">No benchmarks selected</p>');
return false;
} else if (enviros[0] === "") {
$("#plotwrapper").html('<p class="warning">No environments selected</p>');
return false;
} else if (conf.chart === "relative bars" && conf.bas === "none") {
msg = '<p class="warning">For relative bar charts, you must select a baseline to normalize to.</p>';
$("#plotwrapper").html(msg);
return false;
} else if (conf.chart === "stacked bars" && conf.bas !== "none") {
msg = '<p class="warning">Normalized stacked bars actually represent the weighted arithmetic sum, useful to spot which individual benchmarks take up the most time. Choosing different weightings from the "Normalization" menu will change the totals relative to one another. For the correct way to calculate total bars, the geometric mean must be used (see <a href="http://portal.acm.org/citation.cfm?id=5666.5673 " title="How not to lie with statistics: the correct way to summarize benchmark results">paper</a>)</p>';
}
chartInstances.forEach(function(c) { c.destroy(); });
chartInstances = [];
$("#plotwrapper").fadeOut("fast", function() {
$(this).html(msg).show();
var plotcounter = 1;
for (var unit in bench_units) {
var benchmarks = [];
for (var ben in bens) {
if ($.inArray(parseInt(bens[ben]), bench_units[unit][0]) !== -1) {
benchmarks.push(bens[ben]);
}
}
if (benchmarks.length === 0) { continue; }
var plotid = "plot" + plotcounter;
$("#plotwrapper").append('<div class="compplot-wrap"><canvas id="' + plotid + '"></canvas></div>');
plotcounter++;
renderComparisonPlot(plotid, unit, benchmarks, exes, enviros, conf.bas, conf.chart, conf.hor);
}
});
}
function savedata(cacheKey, data) {
if (data.error !== "None") {
var h = $("#content").height();//get height for error message
$("#plotwrapper").html(getLoadText(data.error, h));
return 1;
}
delete data.error;
dataCache[cacheKey] = data;
compdata = data;
refreshContent();
}
function updateBaselineDropdown() {
var $baseline = $("#baseline");
var current = $baseline.val();
$baseline.find("option:not([value='none'])").remove();
$("input[name='executables']:checked").each(function() {
var key = $(this).val();
var name = $(this).next('label').text().trim();
$baseline.append($('<option>').val(key).text(name));
});
if ($baseline.find("option[value='" + current + "']").length) {
$baseline.val(current);
} else {
$baseline.val('none');
}
}
function loadData() {
var conf = getConfiguration();
if (!conf.exe || !conf.ben) {
// Nothing to fetch: clear any previous chart and show the warning
chartInstances.forEach(function(c) { c.destroy(); });
chartInstances = [];
refreshContent();
return;
}
var cacheKey = conf.exe + "|" + conf.ben;
if (dataCache[cacheKey]) {
compdata = dataCache[cacheKey];
refreshContent();
return;
}
var h = $("#content").height();
$("#plotwrapper").html(getLoadText("Loading...", h));
$.getJSON("json/", {exe: conf.exe, ben: conf.ben}, function(data) {
savedata(cacheKey, data);
});
}
function renderComparisonPlot(plotid, unit, benchmarks, exes, enviros, baseline, chart, horizontal) {
var baselineLabel = baseline !== "none" ? $("label[for='exe_" + baseline + "']").text().trim() : "";
var title;
if (baseline === "none") {
title = (chart === "stacked bars" ? "Cumulative " : "") + unit;
} else if (chart === "stacked bars") {
title = "Cumulative " + unit + " normalized to " + baselineLabel;
} else if (chart === "relative bars") {
title = unit + " ratio to " + baselineLabel;
} else {
title = unit + " normalized to " + baselineLabel;
}
var valueAxisLabel = baseline === "none"
? bench_units[unit][2] + bench_units[unit][1]
: (chart === "relative bars" ? "← worse | better →" : "Ratio " + bench_units[unit][1]);
var datasets = [];
var labels = [];
var colorIdx = 0;
if (chart === "normal bars" || chart === "relative bars") {
// Labels = benchmark names
for (var b = 0; b < benchmarks.length; b++) {
labels.push($("label[for='benchmark_" + benchmarks[b] + "']").text().trim());
}
for (var i = 0; i < exes.length; i++) {
for (var j = 0; j < enviros.length; j++) {
var exeLabel = $("label[for='exe_" + exes[i] + "']").text().trim();
if (chart === "relative bars" && exes[i] === baseline) { continue; }
var data = [];
for (var b = 0; b < benchmarks.length; b++) {
var val = compdata[exes[i]] && compdata[exes[i]][enviros[j]]
? compdata[exes[i]][enviros[j]][benchmarks[b]]
: null;
if (val !== null && baseline !== "none") {
var baseval = compdata[baseline] && compdata[baseline][enviros[j]]
? compdata[baseline][enviros[j]][benchmarks[b]]
: null;
val = (baseval === null || baseval === 0) ? null : val / baseval;
}
data.push(val);
}
var color = getColor(colorIdx++);
datasets.push({
label: exeLabel + (enviros.length > 1 ? " @ " + $("label[for='env_" + enviros[j] + "']").text().trim() : ""),
data: data,
backgroundColor: color,
borderColor: color,
borderWidth: 1
});
}
}
} else if (chart === "stacked bars") {
// Labels = exe@env names
for (var i = 0; i < exes.length; i++) {
for (var j = 0; j < enviros.length; j++) {
var exeLabel = $("label[for='exe_" + exes[i] + "']").text().trim();
labels.push(exeLabel + (enviros.length > 1 ? " @ " + $("label[for='env_" + enviros[j] + "']").text().trim() : ""));
}
}
for (var b = 0; b < benchmarks.length; b++) {
var benchLabel = $("label[for='benchmark_" + benchmarks[b] + "']").text().trim();
var data = [];
for (var i = 0; i < exes.length; i++) {
for (var j = 0; j < enviros.length; j++) {
var val = compdata[exes[i]] && compdata[exes[i]][enviros[j]]
? compdata[exes[i]][enviros[j]][benchmarks[b]]
: null;
if (val !== null && baseline !== "none") {
var baseval = compdata[baseline] && compdata[baseline][enviros[j]]
? compdata[baseline][enviros[j]][benchmarks[b]]
: null;
val = (baseval === null || baseval === 0) ? null : val / baseval;
}
data.push(val);
}
}
var color = getColor(colorIdx++);
datasets.push({label: benchLabel, data: data, backgroundColor: color, borderColor: color, borderWidth: 1});
}
}
if (datasets.length === 0) { return; }
// Size the container
var wrapWidth = $("#plotwrapper").width();
var h = horizontal
? Math.min(2000, Math.max(300, labels.length * datasets.length * 22 + 100))
: 400;
var wrap = $("#" + plotid).parent();
wrap.css({width: wrapWidth, height: h, marginBottom: '20px'});
var isStacked = chart === "stacked bars";
var indexAxis = horizontal ? 'y' : 'x';
var valueAxis = horizontal ? 'x' : 'y';
var FONT_SIZE = 13;
var scaleValue = {
stacked: isStacked,
title: {display: true, text: valueAxisLabel, font: {size: FONT_SIZE}},
ticks: {font: {size: FONT_SIZE}},
min: (chart === "relative bars") ? undefined : 0
};
var scaleIndex = {
stacked: isStacked,
ticks: {autoSkip: false, font: {size: FONT_SIZE}}
};
var ctx = document.getElementById(plotid);
var instance = new Chart(ctx, {
type: 'bar',
data: {labels: labels, datasets: datasets},
options: {
indexAxis: indexAxis,
animation: false,
responsive: true,
maintainAspectRatio: false,
plugins: {
title: {display: true, text: title, font: {size: 15}},
tooltip: {position: 'cursor'},
legend: {
position: 'right',
align: 'start',
labels: {
font: {size: FONT_SIZE},
boxWidth: 20,
boxHeight: FONT_SIZE,
padding: 8
}
}
},
scales: {
[valueAxis]: scaleValue,
[indexAxis]: scaleIndex
}
}
});
chartInstances.push(instance);
}
function init(defaults) {
bench_units = defaults.bench_units;
// Set default values
$("#chart_type").val(defaults.chart_type);
$("#direction").prop('checked', defaults.direction === "True");
var sel = $("input[name='executables']");
$.each(defaults.executables, function(i, exe) {
sel.filter("[value='" + exe + "']").prop('checked', true);
});
sel = $("input[name='environments']");
$.each(defaults.environments, function(i, env) {
sel.filter("[value='" + env + "']").prop('checked', true);
});
// Populate baseline dropdown from initially-checked executables
updateBaselineDropdown();
$("#baseline").val(defaults.baseline);
// Exe changes: rebuild baseline dropdown + re-fetch
$("input[name='executables']").change(function() {
updateBaselineDropdown();
loadData();
});
$("#executable .checkall, #executable .uncheckall").click(function() {
updateBaselineDropdown();
loadData();
});
// Benchmark changes: re-fetch only
$("input[name='benchmarks']").change(loadData);
$("#benchmark .checkall, #benchmark .uncheckall").click(loadData);
// Re-render without re-fetching for other controls
$("#chart_type, #baseline, #direction, input[name='environments']").change(refreshContent);
$.ajaxSetup ({
cache: false
});
loadData();
$("#permalink").click(function() {
window.location = "?" + $.param(getConfiguration());
});
$("#exportcsv").click(function(e) {
e.preventDefault();
if (!compdata) { return; }
var conf = getConfiguration();
var exes = conf.exe ? conf.exe.split(",").filter(Boolean) : [];
var enviros = readCheckbox("input[name='environments']:checked").split(",").filter(Boolean);
var benchmarks = conf.ben ? conf.ben.split(",").filter(Boolean) : [];
// Header row: benchmark, then one column per exe@env
var header = ["benchmark"];
for (var i = 0; i < exes.length; i++) {
for (var j = 0; j < enviros.length; j++) {
var exeLabel = $("label[for='exe_" + exes[i] + "']").text().trim();
var envLabel = $("label[for='env_" + enviros[j] + "']").text().trim();
header.push(enviros.length > 1 ? exeLabel + "@" + envLabel : exeLabel);
}
}
var rows = [header];
for (var b = 0; b < benchmarks.length; b++) {
var benchLabel = $("label[for='benchmark_" + benchmarks[b] + "']").text().trim();
var row = [benchLabel];
for (var i = 0; i < exes.length; i++) {
for (var j = 0; j < enviros.length; j++) {
var val = compdata[exes[i]] && compdata[exes[i]][enviros[j]]
? compdata[exes[i]][enviros[j]][benchmarks[b]]
: "";
row.push(val === null || val === undefined ? "" : val);
}
}
rows.push(row);
}
var csv = rows.map(function(r) { return r.join(","); }).join("\n");
var blob = new Blob([csv], {type: "text/csv"});
var url = URL.createObjectURL(blob);
var a = document.createElement("a");
a.href = url;
a.download = "comparison.csv";
a.click();
URL.revokeObjectURL(url);
});
}
return {
init: init
};
})(window);