-
Notifications
You must be signed in to change notification settings - Fork 1
/
asv_ui.js
231 lines (201 loc) · 7.5 KB
/
asv_ui.js
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
'use strict';
$(document).ready(function() {
function make_panel(nav, heading) {
var panel = $('<div class="panel panel-default"/>');
nav.append(panel);
var panel_header = $(
'<div class="panel-heading">' + heading + '</div>');
panel.append(panel_header);
var panel_body = $('<div class="panel-body"/>');
panel.append(panel_body);
return panel_body;
}
function make_value_selector_panel(nav, heading, values, setup_callback) {
var panel_body = make_panel(nav, heading);
var vertical = false;
var buttons = $('<div class="btn-group" ' +
'data-toggle="buttons"/>');
panel_body.append(buttons);
$.each(values, function (idx, value) {
var button = $(
'<a class="btn btn-default btn-xs active" role="button"/>');
setup_callback(idx, value, button);
buttons.append(button);
});
return panel_body;
}
function reflow_value_selector_panels(no_timeout) {
$('.panel').each(function (i, panel_obj) {
var panel = $(panel_obj);
panel.find('.btn-group').each(function (i, buttons_obj) {
var buttons = $(buttons_obj);
var width = 0;
if (buttons.hasClass('reflow-done')) {
/* already processed */
return;
}
$.each(buttons.children(), function(idx, value) {
width += value.scrollWidth;
});
var max_width = panel_obj.clientWidth;
if (width >= max_width) {
buttons.addClass("btn-group-vertical");
buttons.css("width", "100%");
buttons.css("max-height", "20ex");
buttons.css("overflow-y", "auto");
}
else {
buttons.addClass("btn-group-justified");
}
/* The widths can be zero if the UI is not fully layouted yet,
so mark the adjustment complete only if this is not the case */
if (width > 0 && max_width > 0) {
buttons.addClass("reflow-done");
}
});
});
if (!no_timeout) {
/* Call again asynchronously, in case the UI was not fully layouted yet */
setTimeout(function() { $.asv.ui.reflow_value_selector_panels(true); }, 0);
}
}
function network_error(ajax, status, error) {
$("#error-message").text(
"Error fetching content. " +
"Perhaps web server has gone down.");
$("#error").modal('show');
}
function hover_graph(element, graph_url, benchmark_basename, parameter_idx, revisions) {
/* Show the summary graph as a popup */
var plot_div = $('<div/>');
plot_div.css('width', '11.8em');
plot_div.css('height', '7em');
plot_div.css('border', '2px solid black');
plot_div.css('background-color', 'white');
function update_plot() {
var markings = [];
if (revisions) {
$.each(revisions, function(i, revs) {
var rev_a = revs[0];
var rev_b = revs[1];
if (rev_a !== null) {
markings.push({ color: '#d00', lineWidth: 2, xaxis: { from: rev_a, to: rev_a }});
markings.push({ color: "rgba(255,0,0,0.1)", xaxis: { from: rev_a, to: rev_b }});
}
markings.push({ color: '#d00', lineWidth: 2, xaxis: { from: rev_b, to: rev_b }});
});
}
$.asv.load_graph_data(
graph_url
).done(function (data) {
var params = $.asv.main_json.benchmarks[benchmark_basename].params;
data = $.asv.filter_graph_data_idx(data, 0, parameter_idx, params);
var options = {
colors: ['#000'],
series: {
lines: {
show: true,
lineWidth: 2
},
shadowSize: 0
},
grid: {
borderWidth: 1,
margin: 0,
labelMargin: 0,
axisMargin: 0,
minBorderMargin: 0,
markings: markings,
},
xaxis: {
ticks: [],
},
yaxis: {
ticks: [],
min: 0
},
legend: {
show: false
}
};
var plot = $.plot(plot_div, [{data: data}], options);
}).fail(function () {
// TODO: Handle failure
});
return plot_div;
}
element.popover({
placement: 'left auto',
trigger: 'hover',
html: true,
delay: 50,
content: $('<div/>').append(plot_div)
});
element.on('show.bs.popover', update_plot);
}
function hover_summary_graph(element, benchmark_basename) {
/* Show the summary graph as a popup */
var plot_div = $('<div/>');
plot_div.css('width', '11.8em');
plot_div.css('height', '7em');
plot_div.css('border', '2px solid black');
plot_div.css('background-color', 'white');
function update_plot() {
var markings = [];
$.asv.load_graph_data(
'graphs/summary/' + benchmark_basename + '.json'
).done(function (data) {
var options = {
colors: $.asv.colors,
series: {
lines: {
show: true,
lineWidth: 2
},
shadowSize: 0
},
grid: {
borderWidth: 1,
margin: 0,
labelMargin: 0,
axisMargin: 0,
minBorderMargin: 0,
markings: markings,
},
xaxis: {
ticks: [],
},
yaxis: {
ticks: [],
min: 0
},
legend: {
show: false
}
};
var plot = $.plot(plot_div, [{data: data}], options);
}).fail(function () {
// TODO: Handle failure
});
return plot_div;
}
element.popover({
placement: 'left auto',
trigger: 'hover',
html: true,
delay: 50,
content: $('<div/>').append(plot_div)
});
element.on('show.bs.popover', update_plot);
}
/*
Set up $.asv.ui
*/
this.network_error = network_error;
this.make_panel = make_panel;
this.make_value_selector_panel = make_value_selector_panel;
this.reflow_value_selector_panels = reflow_value_selector_panels;
this.hover_graph = hover_graph;
this.hover_summary_graph = hover_summary_graph;
$.asv.ui = this;
});