Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make summary grid have multiple levels #893

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions asv/www/asv.css
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,38 @@ nav li.active span.navbar-brand:hover {

/* Summary page */

.benchmark-group > h1 {
text-align: center;
.benchmark-group h1, h2, h3, h4, h5, h6 {
margin: 5px 0;
}

.benchmark-group h2, h3, h4, h5, h6 {
background-color: #ddd;
}

.benchmark-group h1 {
font-weight: bold;
background-color: #ccc;
padding-left: 10px;
}

.benchmark-group h2 {
padding-left: 30px;
}

.benchmark-group h3 {
padding-left: 50px;
}

.benchmark-group h4 {
padding-left: 60px;
}

.benchmark-group h5 {
padding-left: 80px;
}

.benchmark-group h6 {
padding-left: 100px;
}

.benchmark-container {
Expand Down
124 changes: 106 additions & 18 deletions asv/www/summarygrid.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,47 @@
'use strict';

// Polyfill for Object.keys
if (!Object.keys) {
Object.keys = (function () {
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
dontEnums = [
'toString',
'toLocaleString',
'valueOf',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'constructor'
],
dontEnumsLength = dontEnums.length;

return function (obj) {
if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) throw new TypeError('Object.keys called on non-object');

var result = [];

for (var prop in obj) {
if (hasOwnProperty.call(obj, prop)) result.push(prop);
}

if (hasDontEnumBug) {
for (var i=0; i < dontEnumsLength; i++) {
if (hasOwnProperty.call(obj, dontEnums[i])) result.push(dontEnums[i]);
}
}
return result;
}
})()
}

function sort_alpha(a,b) {
return a.localeCompare(b);
}

$(document).ready(function() {
var summary_loaded = false;
var MAX_GRID_DEPTH = 3

/* Callback a function when an element comes in view */
function callback_in_view(element, func) {
Expand All @@ -18,19 +58,38 @@ $(document).ready(function() {
$(window).on('scroll', handler);
}

function get_benchmarks_by_groups() {
function get_benchmarks_tree() {
var master_json = $.asv.master_json;
var groups = {};
var groups_by_level = {};
var current_object;

$.each(master_json.benchmarks, function(bm_name, bm) {
var i = bm_name.indexOf('.');
var group = bm_name.slice(0, i);
var name = bm_name.slice(i + 1);
if (groups[group] === undefined) {
groups[group] = [];
current_object = groups_by_level;
for (var level = 0; level < MAX_GRID_DEPTH; level++) {
var i = bm_name.indexOf('.');
var nested = bm_name.slice(0, i);
bm_name = bm_name.slice(i + 1)
i = bm_name.indexOf('.');
if (i === -1) {
if (!Array.isArray(current_object[nested])) {
current_object[nested] = []
}
current_object[nested].push(bm_name);
break;
}
if (current_object[nested] === undefined) {
current_object[nested] = {};
if (level === MAX_GRID_DEPTH - 1) {
current_object[nested] = []
}
}
if (level === MAX_GRID_DEPTH - 1) {
current_object[nested].push(bm_name);
}
current_object = current_object[nested]
}
groups[group].push(bm_name);
});
return groups;
return groups_by_level;
}

function benchmark_container(bm) {
Expand Down Expand Up @@ -100,7 +159,35 @@ $(document).ready(function() {
});
return container;
}

function benchmarks_tree_to_html(current_object, parent_container, bm_name, level) {
if (Array.isArray(current_object)) {
$.each(Array.from(current_object).sort(sort_alpha), function (i, bm_suffix) {
var bm = $.asv.master_json.benchmarks[bm_name + '.' + bm_suffix];
if (bm !== undefined) {
parent_container.append(benchmark_container(bm));
}
})
}
else {
var sorted_keys = Object.keys(current_object).sort(sort_alpha);
$.each(sorted_keys, function(i, key) {
var new_bm_name = bm_name + '.' + key;
var nested_container = $('<div class="benchmark-group-nested"/>');
nested_container.append($('<h' + level + '>' + key + '</h' + level + '>'));

var next_object = current_object[key]
var inner = benchmarks_tree_to_html(
next_object,
nested_container,
new_bm_name,
level + 1
);
nested_container.append(inner);
parent_container.append(nested_container);
});
}
}
function make_summary() {
var summary_display = $('#summarygrid-display');
var master_json = $.asv.master_json;
Expand All @@ -109,17 +196,18 @@ $(document).ready(function() {
if (summary_loaded) {
return;
}
var tree = get_benchmarks_tree();
var sorted_keys = Object.keys(tree).sort(sort_alpha);
$.each(sorted_keys, function(i, key) {
if (tree.hasOwnProperty(key)) {
var group_container = $('<div class="benchmark-group"/>')
group_container.append($('<h1>' + key + '</h1>'));
benchmarks_tree_to_html(tree[key], group_container, key, 2)

$.each(get_benchmarks_by_groups(), function(group, benchmarks) {
var group_container = $('<div class="benchmark-group"/>')
group_container.append($('<h1>' + group + '</h1>'));
summary_display.append(group_container);
$.each(benchmarks, function(i, bm_name) {
var bm = $.asv.master_json.benchmarks[bm_name];
group_container.append(benchmark_container(bm));
});
summary_display.append(group_container);
}
});

summary_display.append(summary_container);
$(window).trigger('scroll');

Expand Down