rearrange the rows when switching perf platforms (bug 650710)

This commit is contained in:
Jeff Balogh 2011-05-04 11:56:53 -07:00
Родитель ac9601b5cc
Коммит 629b92b2dd
2 изменённых файлов: 19 добавлений и 10 удалений

Просмотреть файл

@ -44,7 +44,8 @@
</p>
{% endif %}
<div id="perf-results" data-platforms="{{ platforms|json }}">
<div id="perf-results" data-platforms="{{ platforms|json }}"
data-threshold="{{ settings.PERF_THRESHOLD }}">
<div id="perf-results-inner">
<table>
<thead>

Просмотреть файл

@ -13,8 +13,10 @@ function initPerf() {
"use strict";
var $perfResults = $('#perf-results'),
$rows = $perfResults.find('tbody tr').clone(),
platforms = JSON.parse($perfResults.attr('data-platforms')),
results = [];
results = [],
THRESHOLD = $perfResults.attr('data-threshold');
// We only show 10 at the beginning and toggle the rest here.
$('#perf-more a').click(function(e) {
@ -47,14 +49,21 @@ function initPerf() {
// Change numbers and bar graphs to the selected platform data.
function switchNumbers(selected) {
var platform = platforms[selected],
numbers = $.map(results, function(e) { return e[platform] || 0; }),
worst = Math.max.apply(null, numbers);
$perfResults.find('tbody tr').each(function(i, e) {
var $this = $(this),
num = results[i][platform] || 0;
$this.find('.slower b').text(num === 0 ? gettext('N/A') : num + '%');
$this.find('.bar').css('width', num / worst * 100 + '%');
numbers = _.map(results, function(e, i) { return [e[platform] || 0, i]; }),
$newTbody = $('<tbody>');
numbers.sort(function(a, b){ return b[0] - a[0]; });
var worst = numbers[0][0];
$.each(numbers, function(i, e) {
var num = e[0], index = e[1];
if (num > THRESHOLD) {
var $row = $rows.eq(index).clone();
$row.find('.slower b').text(num + '%');
$row.find('.bar').css('width', num / worst * 100 + '%');
$row.find('.rank b').text(i + 1);
$row.appendTo($newTbody);
}
});
$perfResults.find('tbody').replaceWith($newTbody);
showPlatforms(selected);
}
@ -70,5 +79,4 @@ function initPerf() {
}
}
// END global protection
})();