Repository navigation
Expand file tree
/
Copy pathchanges.js
More file actions
169 lines (140 loc) · 5.35 KB
/
Copy pathchanges.js
File metadata and controls
169 lines (140 loc) · 5.35 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
var Changes = (function(window){
// Localize globals
var TIMELINE_URL = window.TIMELINE_URL, getLoadText = window.getLoadText;
var currentproject, changethres, trendthres, projectmatrix, revisionboxes = {};
function getConfiguration(revision) {
return {
tre: $("#trend option:selected").val(),
rev: revision || $("#revision option:selected").val(),
exe: $("input[name='executable']:checked").val(),
env: $("input[name='environment']:checked").val()
};
}
function permalinkToTimeline(benchmark, environment) {
window.location=window.TIMELINE_URL + "?ben=" + benchmark + "&env=" + environment;
}
//colors number based on a threshold
function getColorcode(change, theigh, tlow) {
if (change < tlow) { return "status-red"; }
else if (change > theigh) { return "status-green"; }
else { return "status-node"; }
}
function colorTable() {
//color two colums to the right starting with index = last-1
// Each because there is one table per units type
$(".tablesorter").each(function() {
// Find column index of the current change column (one before last)
var index = $(this).find("thead tr th").length - 2;
var lessisbetter = $(this).data("lessisbetter");
$(this).find(":not(thead) > tr").each(function() {
var change = $(this).data("change"),
trend = $(this).data("trend");
// Check whether less is better
if (lessisbetter === "False") {
change = -change;
trend = -trend;
}
//Color change column
$(this).children("td:eq("+index+")").addClass(getColorcode(-change, changethres, -changethres));
//Color trend column
$(this).children("td:eq("+(index+1)+")").addClass(getColorcode(-trend, trendthres, -trendthres));
});
});
}
function updateTable() {
colorTable();
$(".tablesorter > tbody")
//Add permalink events to table rows
.on("click", "tr", function() {
var environment = $("input[name='environment']:checked").val();
permalinkToTimeline($(this).children("td:eq(0)").text(), environment);
})
//Add hover effect to rows
.on("mouseenter mouseleave", "tr", function() {
$(this).toggleClass("highlight");
});
//Configure table as tablesorter
$(".tablesorter").tablesorter({widgets: ['zebra']});
// Set prev and next links
$("#previous").click(function() {
refreshContentRev(
$("#previous").data("revision"),
$("#previous").data("desc")
);
});
$("#next").click(function() {
refreshContentRev(
$("#next").data("revision"),
$("#next").data("desc")
);
});
}
function refreshContent() {
refreshContentTable($("#revision option:selected").val());
}
function refreshContentRev(revision, desc) {
if ($('#revision option[value='+revision+']').length == 0) {
$("#revision").append($("<option value='" + revision + "'>" + desc + "</option>"));
}
$("#revision").val(revision);
refreshContentTable(revision);
}
function refreshContentTable(revision) {
var h = $("#content").height();//get height for loading text
$("#contentwrap").fadeOut("fast", function() {
$(this).show();
$(this).html(getLoadText("Loading...", h));
$(this).load("table/", $.param(getConfiguration(revision)), function() { updateTable(); });
});
}
function changeRevisions() {
// This function repopulates the revision selectbox everytime a new
// executable is selected that corresponds to a different project.
var executable = $("input[name='executable']:checked").val(),
selected_project = projectmatrix[executable];
if (selected_project !== currentproject) {
$("#revision").html(revisionboxes[selected_project]);
currentproject = selected_project;
//Give visual cue that the select box has changed
var bgc = $("#revision").parent().parent().css("backgroundColor");
$("#revision").parent()
.animate({ backgroundColor: "#9DADC6" }, 200, function() {
// Animation complete.
$(this).animate({ backgroundColor: bgc }, 1500);
});
}
refreshContent();
}
function config(c) {
changethres = c.changethres;
trendthres = c.trendthres;
}
function init(defaults) {
currentproject = defaults.project;
projectmatrix = defaults.projectmatrix;
$.each(defaults.revisionlists, function(project, revs) {
var options = "";
$.each(revs, function(index, r) {
options += "<option value='" + r[1] + "'>" + r[0] + "</option>";
});
revisionboxes[project] = options;
});
$("#trend").val(defaults.trend);
$("#trend").change(refreshContent);
$("#executable" + defaults.executable).prop('checked', true);
$("input[name='executable']").change(changeRevisions);
$("#env" + defaults.environment).prop('checked', true);
$("input[name='environment']").change(refreshContent);
$("#revision").html(revisionboxes[defaults.project]);
$("#revision").val(defaults.revision);
$("#revision").change(refreshContent);
$("#permalink").click(function() {
window.location = "?" + $.param(getConfiguration());
});
refreshContent();
}
return {
init: init,
config: config
};
})(window);