-
Notifications
You must be signed in to change notification settings - Fork 1
/
graphdisplay.js
1427 lines (1276 loc) · 50.1 KB
/
graphdisplay.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
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
$(document).ready(function() {
/* The state of the parameters in the sidebar. Dictionary mapping
strings to arrays containing the "enabled" configurations. */
var state = null;
/* The name of the current benchmark being displayed. */
var current_benchmark = null;
/* An array of graphs being displayed. */
var graphs = [];
var orig_graphs = [];
/* An array of commit revisions being displayed */
var current_revisions = [];
/* True when log scaling is enabled. */
var log_scale = false;
/* True when zooming in on the y-axis. */
var zoom_y_axis = false;
/* True when log scaling is enabled. */
var reference_scale = false;
/* True when selecting a reference point */
var select_reference = false;
/* The reference value */
var reference = 1.0;
/* Whether to show the legend */
var show_legend = true;
/* Is even commit spacing being used? */
var even_spacing = false;
var even_spacing_revisions = [];
/* Is date scale being used ? */
var date_scale = false;
var date_to_revision = {};
/* A little div to handle tooltip placement on the graph */
var tooltip = null;
/* X-axis coordinate axis in the data set; always 0 for
non-parameterized tests where revision and date are the only potential x-axis */
var x_coordinate_axis = 0;
var x_coordinate_is_category = false;
/* List of lists of value combinations to plot (apart from x-axis)
in parameterized tests. */
var benchmark_param_selection = [[null]];
/* Highlighted revisions */
var highlighted_revisions = null;
/* Whether benchmark graph display was set up */
var benchmark_graph_display_ready = false;
/* UTILITY FUNCTIONS */
function arr_remove_from(a, x) {
var out = [];
$.each(a, function(i, val) {
if (x !== val) {
out.push(val);
}
});
return out;
}
function obj_copy(obj) {
var newobj = {};
$.each(obj, function(key, val) {
newobj[key] = val;
});
return newobj;
}
function obj_length(obj) {
var i = 0;
for (var x in obj)
++i;
return i;
}
function obj_get_first_key(data) {
for (var prop in data)
return prop;
}
function no_data(ajax, status, error) {
$("#error-message").text(
"No data for this combination of filters. ");
$("#error").modal('show');
}
function get_x_from_revision(rev) {
if (date_scale) {
return $.asv.main_json.revision_to_date[rev];
} else {
return rev;
}
}
function get_commit_hash(x) {
// Return the commit hash in the current graph located at position x
if (date_scale) {
x = date_to_revision[x];
}
return $.asv.get_commit_hash(x);
}
function display_benchmark(bm_name, state_selection, highlight_revisions) {
setup_benchmark_graph_display();
$('#graph-display').show();
$('#summarygrid-display').hide();
$('#regressions-display').hide();
$('.tooltip').remove();
if (reference_scale) {
reference_scale = false;
$('#reference').removeClass('active');
reference = 1.0;
}
current_benchmark = bm_name;
highlighted_revisions = highlight_revisions;
$("#title").text(bm_name);
setup_benchmark_params(state_selection);
replace_graphs();
}
function setup_benchmark_graph_display() {
if (benchmark_graph_display_ready) {
return;
}
benchmark_graph_display_ready = true;
/* When the window resizes, redraw the graphs */
$(window).on('resize', function() {
update_graphs();
});
var nav = $("#graphdisplay-navigation");
/* Make the static tooltips look correct */
$('[data-toggle="tooltip"]').tooltip({container: 'body'});
/* Add insertion point for benchmark parameters */
var state_params_nav = $("<div id='graphdisplay-state-params'/>");
nav.append(state_params_nav);
/* Add insertion point for benchmark parameters */
var bench_params_nav = $("<div id='graphdisplay-navigation-params'/>");
nav.append(bench_params_nav);
/* Benchmark panel */
var panel_body = $.asv.ui.make_panel(nav, 'benchmark');
var tree = $('<ul class="nav nav-list" style="padding-left: 0px"/>');
var cursor = [];
var stack = [tree];
/* Sort keys for tree construction */
var benchmark_keys = Object.keys($.asv.main_json.benchmarks);
benchmark_keys.sort();
/* Build tree */
$.each(benchmark_keys, function(i, bm_name) {
var bm = $.asv.main_json.benchmarks[bm_name];
var parts = bm_name.split('.');
var i = 0;
var j;
for (; i < cursor.length; ++i) {
if (cursor[i] !== parts[i]) {
break;
}
}
for (j = cursor.length - 1; j >= i; --j) {
stack.pop();
cursor.pop();
}
for (j = i; j < parts.length - 1; ++j) {
var top = $(
'<li class="dropdown">' +
'<label class="nav-header"><b class="caret-right"/> ' + parts[j] +
'</label><ul class="nav nav-list tree" style="display: none;"/></li>');
stack[stack.length - 1].append(top);
stack.push($(top.children()[1]));
cursor.push(parts[j]);
$(top.children()[0]).on('click', function () {
$(this).parent().children('ul.tree').toggle(150);
var caret = $(this).children('b');
if (caret.attr('class') == 'caret') {
caret.removeClass().addClass("caret-right");
} else {
caret.removeClass().addClass("caret");
}
});
}
var name = bm.pretty_name || parts[parts.length - 1];
var top = $('<li><a href="#' + bm_name + '">' + name + '</li>');
stack[stack.length - 1].append(top);
top.tooltip({
title: bm.code,
html: true,
placement: 'right',
container: 'body',
animation: 'false'
});
});
panel_body.append(tree);
$('#log-scale').on('click', function(evt) {
log_scale = !evt.target.classList.contains("active");
reference_scale = false;
zoom_y_axis = false;
$('#reference').removeClass('active');
$('#zoom-y-axis').removeClass('active');
reference = 1.0;
update_state_url({'y-axis-scale': log_scale ? ['log']: []});
});
$('#zoom-y-axis').on('click', function(evt) {
zoom_y_axis = !evt.target.classList.contains("active");
reference_scale = false;
log_scale = false;
$('#reference').removeClass('active');
$('#log-scale').removeClass('active');
reference = 1.0;
update_state_url({'y-axis-scale': zoom_y_axis ? ['zoom'] : []});
});
$('#reference').on('click', function(evt) {
reference_scale = !evt.target.classList.contains("active");
log_scale = false;
zoom_y_axis = false;
$('#log-scale').removeClass('active');
$('#zoom-y-axis').removeClass('active');
if (!reference_scale) {
reference = 1.0;
update_graphs();
} else {
$('#reference').popover({
content: 'Select a reference point',
placement: 'top',
container: 'body'});
$('#reference').popover('show');
reference = 1.0;
select_reference = true;
}
});
$('#even-spacing').on('click', function(evt) {
even_spacing = !evt.target.classList.contains("active");
date_scale = false;
$('#date-scale').removeClass('active');
update_state_url({'x-axis-scale': even_spacing ? ['even'] : []});
});
$('#date-scale').on('click', function(evt) {
date_scale = !evt.target.classList.contains("active");
even_spacing = false;
$('#even-spacing').removeClass('active');
update_state_url({'x-axis-scale': date_scale ? ['date'] : []});
});
$('#show-legend').on('click', function(evt) {
show_legend = !show_legend;
update_state_url({'show-legend': show_legend ? [] : [false]});
});
tooltip = $("<div></div>");
tooltip.appendTo("body");
/* The tooltip on a point shows the exact timing and the
commit hash */
function showTooltip(x, y, contents) {
tooltip
.css({
position: "absolute",
display: "none",
top: y - 4,
left: x - 2,
width: 4,
height: 4
})
.fadeIn(0)
.tooltip({
title: contents,
html: true,
placement: 'top',
container: 'body',
animation: false
})
.tooltip('show');
}
var previous_hover = null;
$("#main-graph").on("plothover", function (event, pos, item) {
if (item) {
if (previous_hover != item.datapoint) {
previous_hover = item.datapoint;
var y = item.datapoint[1];
var commit_hash = get_commit_hash(item.datapoint[0]);
if (commit_hash) {
var unit = $.asv.main_json.benchmarks[current_benchmark].unit;
showTooltip(
item.pageX, item.pageY,
$.asv.pretty_unit(y, unit) + " @ " + commit_hash);
}
}
} else {
tooltip.tooltip("destroy");
}
});
/* Clicking on a point should display the particular commit
hash in another tab. */
var previous_click;
var previous_hash;
$("#main-graph").on("plotclick", function (event, pos, item) {
if (item) {
if (previous_click != item.datapoint) {
previous_click = item.datapoint;
if (select_reference) {
$('#reference').popover('destroy');
select_reference = false;
reference = item.datapoint[1];
update_graphs();
} else {
var commit_hash = get_commit_hash(item.datapoint[0]);
if (previous_hash !== commit_hash) {
previous_hash = commit_hash;
window.open(
$.asv.main_json.show_commit_url + previous_hash,
'_blank');
}
}
}
}
});
}
function setup_benchmark_params(state_selection) {
if (!current_benchmark) {
x_coordinate_axis = 0;
x_coordinate_is_category = false;
benchmark_param_selection = [[null]];
return
}
/*
Generic parameter selections
*/
var index = $.asv.main_json;
if (!state || state_selection !== null) {
/*
Setup the default configuration on first load,
or when state selector is present
*/
state = {};
state.machine = index.params.machine;
$.each(index.params, function(param, values) {
state[param] = values;
if (values.length > 1 && param !== 'machine') {
if (param == 'branch') {
state[param] = [values[0]];
}
}
});
}
if (state_selection !== null) {
/* Select a specific generic parameter state */
$.each(index.params, function(param, values) {
if (state_selection[param]) {
state[param] = state_selection[param];
}
});
}
/*
Benchmark-specific parameter selections
*/
var params = index.benchmarks[current_benchmark].params;
var param_names = index.benchmarks[current_benchmark].param_names;
/* Default plot: time series */
x_coordinate_axis = 0;
if (state_selection['x-axis'] !== undefined &&
state_selection['x-axis'] != "commit") {
for (var k = 0; k < params.length; ++k) {
if (state_selection['x-axis'] == param_names[k]) {
x_coordinate_axis = k + 1;
break;
}
}
}
/* Default plot: up to 8 lines */
benchmark_param_selection = [[null]];
if (params.length >= 1) {
var count = 1;
var max_curves = 8;
for (var k = 0; k < params.length; ++k) {
var param_name = param_names[k]
var param_values = params[k]
var item = [];
if (state_selection['p-'+param_name] !== undefined) {
for (var j = 0; j < param_values.length; ++j) {
if (state_selection['p-'+param_name].includes(param_values[j])) {
item.push(j);
}
}
} else {
for (var j = 0; j < param_values.length && (j+1)*count <= max_curves; ++j) {
item.push(j);
}
}
count = count * item.length;
benchmark_param_selection.push(item);
}
}
check_x_coordinate_axis();
replace_params_ui();
replace_benchmark_params_ui();
}
function update_state_url(params) {
var info = $.asv.parse_hash_string(window.location.hash);
$.each($.asv.main_json.params, function(param, values) {
if (values.length > 1) {
if (state[param].length != values.length || param == 'branch') {
info.params[param] = state[param];
}
else if (info.params[param]) {
delete info.params[param];
}
}
});
$.each(params || {}, function(key, value) {
info.params[key] = value;
});
window.location.hash = $.asv.format_hash_string(info);
}
function replace_params_ui() {
var index = $.asv.main_json;
var nav = $('#graphdisplay-state-params');
nav.empty();
/* Machine selection */
$.asv.ui.make_value_selector_panel(nav, 'machine', index.params.machine, function(i, machine, button) {
button.text(machine);
if (index.params.machine.length > 1) {
button.on('click', function(evt) {
if (!evt.target.classList.contains("active")) {
state.machine.push(machine);
} else {
state.machine = arr_remove_from(
state.machine, machine);
}
update_state_url();
});
}
if ($.inArray(machine, state.machine) == -1) {
button.removeClass('active');
}
/* Create tooltips for each machine */
var details = [];
$.each(index.machines[machine], function(key, val) {
details.push(key + ': ' + val);
});
details = details.join('<br/>');
button.tooltip({
title: details,
html: true,
placement: 'right',
container: 'body',
animation: false
});
});
/* Generic parameter selectors */
$.each(index.params, function(param, values) {
if (values.length > 1 && param != 'machine') {
$.asv.ui.make_value_selector_panel(nav, param, values, function(i, value, button) {
var value_display;
if (value === null)
value_display = '[none]';
else if (!value)
value_display = '[default]';
else
value_display = value;
button.text(value_display);
if ($.inArray(value, state[param]) == -1) {
button.removeClass('active');
}
if (values.length > 1) {
button.on('click', function(evt) {
if (!evt.target.classList.contains("active")) {
state[param].push(value);
} else {
state[param] = arr_remove_from(
state[param], value);
}
update_state_url();
});
}
});
}
});
}
function replace_benchmark_params_ui() {
var params = $.asv.main_json.benchmarks[current_benchmark].params;
var param_names = $.asv.main_json.benchmarks[current_benchmark].param_names;
/* Parameter selection UI */
var nav = $('#graphdisplay-navigation-params');
nav.empty();
if (params.length == 0) {
/* Simple time series: no need for parameter selection UI */
$.asv.ui.reflow_value_selector_panels();
return;
}
/* x-axis selector */
{
var axes = [];
for (var axis = 0; axis < params.length + 1; ++axis) {
axes.push(axis);
}
$.asv.ui.make_value_selector_panel(nav, "x-axis", axes, function (idx, axis, button) {
var text;
if (axis == 0) {
text = "commit";
} else {
text = param_names[axis - 1];
}
if (x_coordinate_axis != axis) {
button.removeClass('active');
}
button.text(text);
button.on('click', function (evt) {
$(evt.target).siblings().removeClass('active');
x_coordinate_axis = axis;
update_state_url({'x-axis': [text]});
});
});
}
/* Revision/commit value selector */
if (x_coordinate_axis != 0) {
/* Generate list of all revisions */
var revisions = current_revisions.slice();
revisions.sort();
revisions.push(null);
revisions.reverse();
/* Add buttons */
$.asv.ui.make_value_selector_panel(nav, "commit", revisions, function(idx, rev, button) {
if (rev === null) {
button.text("last");
} else {
var date_fmt = new Date($.asv.main_json.revision_to_date[rev]);
button.text($.asv.get_commit_hash(rev)
+ " "
+ date_fmt.toUTCString());
}
if ($.inArray(rev, benchmark_param_selection[0]) == -1) {
button.removeClass('active');
}
button.on('click', function(evt) {
var idx = $.inArray(rev, benchmark_param_selection[0]);
if (!evt.target.classList.contains("active")) {
if (idx == -1) {
benchmark_param_selection[0].push(rev);
benchmark_param_selection[0].sort();
}
} else {
if (idx != -1) {
benchmark_param_selection[0].splice(idx, 1);
}
}
replace_graphs();
update_graphs();
});
});
}
/* Parameters axes value selector */
$.each(params, function(param_idx, values) {
var axis = param_idx + 1;
if (axis == x_coordinate_axis) {
return;
}
name = param_names[param_idx];
/* Add benchmark parameter selector */
$.asv.ui.make_value_selector_panel(nav, name, values, function(value_idx, value, button) {
var value_display;
value_display = '' + $.asv.convert_benchmark_param_value(value);
button.text(value_display);
if ($.inArray(value_idx, benchmark_param_selection[axis]) == -1) {
button.removeClass('active');
}
button.on('click', function(evt) {
var new_selection = [];
var old_selection = benchmark_param_selection[param_idx+1];
if (!evt.target.classList.contains("active")) {
for (var k = 0; k < params[param_idx].length; ++k) {
if ($.inArray(k, old_selection) != -1 || k == value_idx) {
new_selection.push(k);
}
}
} else {
for (var k = 0; k < params[param_idx].length; ++k) {
if ($.inArray(k, old_selection) != -1 && k != value_idx) {
new_selection.push(k);
}
}
}
benchmark_param_selection[param_idx+1] = new_selection;
var new_selection_params = {};
new_selection_params['p-'+param_names[param_idx]] = new_selection.map(function(k) {
return params[param_idx][k];
});
update_state_url(new_selection_params);
});
});
});
$.asv.ui.reflow_value_selector_panels();
}
/* Check if x-axis is a category axis */
function check_x_coordinate_axis() {
if (!current_benchmark) {
return;
}
var params = $.asv.main_json.benchmarks[current_benchmark].params;
x_coordinate_is_category = false;
if (x_coordinate_axis != 0) {
for (var j = 0; j < params[x_coordinate_axis-1].length; ++j) {
var value = $.asv.convert_benchmark_param_value(params[x_coordinate_axis-1][j]);
if (typeof value != "number") {
x_coordinate_is_category = true;
break;
}
}
}
}
function replace_graphs() {
/* Given the settings in the sidebar, generate a list of the
graphs we need to load. */
function collect_graphs(current_benchmark, state, param_selection) {
/* Given a specific group of parameters, generate the legend
label to display for that line. Differences is an object of
parameters that have different values across all graphs. */
function graph_label(state, differences) {
var ignore = {
'os': null,
'cpu': null,
'arch': null,
'ram': null
};
var parts = [];
$.each(state, function(key, value) {
if (!ignore.hasOwnProperty(key) &&
differences.hasOwnProperty(key)) {
if (value === null) {
// missing key, skip
} else if (value) {
parts.push(key + "-" + value);
} else {
parts.push(key);
}
}
});
parts.sort();
return parts.join('; ');
}
/* For a given parameter matrix, generate all permutations. */
function permutations(matrix) {
if (obj_length(matrix) === 0) {
return [{}];
}
matrix = obj_copy(matrix);
var key = obj_get_first_key(matrix);
var entry = matrix[key];
delete matrix[key];
var results = [];
$.each(permutations(matrix), function(i, result) {
result = obj_copy(result);
if (entry.length) {
$.each(entry, function(i, value) {
result[key] = value;
results.push(obj_copy(result));
});
} else {
result[key] = null;
results.push(obj_copy(result));
}
});
results.sort();
return results;
}
/* For all of the selected graphs, find out which parameters
have different values across them. We don't want to show
parameters that are the same across all graphs in the
legend labels, as that information is not really
necessary. */
function find_different_properties(graphs) {
var different = {};
var last_values = obj_copy(graphs[0]);
$.each(graphs, function(i, graph) {
$.each(graph, function(key, val) {
if (last_values[key] != val) {
different[key] = true;
}
});
});
return different;
}
if (current_benchmark) {
/* For the current set of enabled parameters, generate a
list of all the permutations we need to load. */
var state_permutations = $.grep($.asv.main_json.graph_param_list, function (params) {
var ok = true;
$.each(state, function (key, values) {
if ($.inArray(params[key], values) == -1) {
ok = false;
}
});
return ok;
});
/* Find where the parameters are different. */
var different = find_different_properties(state_permutations);
/* For parameterized tests: names of benchmark parameters */
var params = $.asv.main_json.benchmarks[current_benchmark].params;
var param_names = $.asv.main_json.benchmarks[current_benchmark].param_names;
/* Selected permutations of benchmark parameters, omitting x-axis */
var selection = obj_copy(param_selection);
selection[x_coordinate_axis] = [null]; /* value not referenced, set to null */
var param_permutations = permutations(selection);
/* Generate a main list of URLs and legend labels for
the graphs. */
var all = [];
$.each(state_permutations, function (i, perm) {
var graph_contents = [];
$.each(param_permutations, function(k, param_perm) {
/* For each state value, there can be several
benchmark parameter sets to plot */
var labels = obj_copy(perm);
for (var axis = 0; axis < params.length + 1; ++axis) {
if (axis != x_coordinate_axis) {
if (axis == 0) {
/* Add time/commit value to the labels */
var timestamp = param_perm[axis];
different["commit"] = true;
if (timestamp === null) {
labels["commit"] = "last";
}
else {
labels["commit"] = ""+$.asv.get_commit_hash(timestamp);
}
}
else if (params[axis-1].length > 1) {
/* Add parameter value to the labels */
if (param_perm[axis] === null) {
/* Empty permutation */
return;
}
different[param_names[axis-1]] = true;
labels[param_names[axis-1]] = "" + $.asv.convert_benchmark_param_value(params[axis-1][param_perm[axis]]);
}
}
}
graph_contents.push([param_perm,
graph_label(labels, different)]);
});
all.push([$.asv.graph_to_path(current_benchmark, perm),
graph_contents]);
});
return all;
} else {
return [];
}
}
/* Before loading graphs, remove any that are currently
active. */
graphs = [];
orig_graphs = [];
var to_load = collect_graphs(current_benchmark, state, benchmark_param_selection);
var failures = 0;
var count = 1;
if (to_load.length === 0) {
$('#main-graph').html("<div style='display: flex;" +
"justify-content: center;" +
" align-items: center; height: 100%;'>" +
"<p style='font-size: 2rem;'>No graphs to load.</p>" +
"</div>")
return
}
current_revisions = [];
$.each(to_load, function(i, item) {
$.asv.load_graph_data(
item[0]
).done(function (data) {
$.each(data, function(i, point) {
if (current_revisions.indexOf(point[0]) === -1) {
current_revisions.push(point[0]);
}
});
$.each(item[1], function(j, graph_content) {
var series;
series = $.asv.filter_graph_data(data,
x_coordinate_axis,
graph_content[0],
$.asv.main_json.benchmarks[current_benchmark].params);
orig_graphs.push({
data: series,
label: graph_content[1],
bars: { order: count, },
});
count += 1;
});
graphs = orig_graphs;
update_graphs();
}).fail(function () {
failures += 1;
if (failures == to_load.length) {
/* If we don't get any results, we check that the
webserver is still live by loading a file we know
we have. If that fails, too, then the webserver
is probably down. */
$.ajax({
url: "swallow.ico",
dataType: "text",
cache: false
}).done(function (index) {
update_graphs();
no_data();
}).fail(function () {
$.asv.ui.network_error();
});
}
});
});
}
/* Handle log scaling the plot */
function handle_y_scale(options) {
if (!graphs.length)
return;
/* Find the minimum and maximum values */
var min = Infinity;
var max = -Infinity;
var left = options.xaxis.min || 0;
var right = options.xaxis.max || Infinity;
$.each(graphs, function(i, graph) {
var data = graph.data;
var j = 0;
if (!x_coordinate_is_category) {
for (; j < data.length; ++j) {
var x = data[j][0];
if (x >= left) {
break;
}
}
}
for (; j < data.length; ++j) {
if (!x_coordinate_is_category) {
var x = data[j][0];
if (x >= right) {
break;
}
}
var p = data[j][1];
if (p !== null && (!log_scale || p > 0)) {
if (p < min) {
min = p;
}
if (p > max) {
max = p;
}
}
}
});
if (!isFinite(min) || !isFinite(max)) {
min = max = 1;
}
min /= reference;
max /= reference;
options.yaxis.min = min;
options.yaxis.max = max;
if (log_scale || reference_scale) {
min = Math.floor(Math.log(min) / Math.LN10);
max = Math.ceil(Math.log(max) / Math.LN10);
if (min == max) {
--min;
}
else if (reference_scale) {
// Don't allow the reference level to be at graph top/bottom,
// as this can look strange.
if (min == 0) {
--min;
}
if (max == 0) {
++max;
}
}
var ticks = [];
for (var x = min; x <= max; ++x) {
ticks.push(Math.pow(10, x) * reference);
}
options.yaxis.ticks = ticks;
options.yaxis.transform = function(v) {
if (v <= 0) {
return null;
} else {
return Math.log(v / reference) / Math.LN10;
}
};
/* inverseTransform is required for plothover to work */
options.yaxis.inverseTransform = function (v) {
return Math.pow(10.0, v);
};
options.yaxis.tickDecimals = 3;
options.yaxis.tickFormatter = function (v, axis) {
return "10" + (
Math.round(
Math.log(v / reference) / Math.LN10)).toString().sup();
};
options.yaxis.min = Math.pow(10, min) * reference;
options.yaxis.max = Math.pow(10, max) * reference;
if (!reference_scale) {
options.yaxis.axisLabel = $.asv.main_json.benchmarks[current_benchmark].unit;
}
}
else {
var unit = $.asv.main_json.benchmarks[current_benchmark].unit;
var unit_list = null;
if (unit == "seconds") {
unit_list = $.asv.time_units;
}
else if (unit == "bytes") {
unit_list = $.asv.mem_units;
}
if (unit_list !== null) {
if (!zoom_y_axis) {
options.yaxis.min = 0.0;
options.yaxis.max = max * 1.3;