1 // Copyright (C) 2013 Google Inc. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ui.popup.hide = function()
37 var popup = $('popup');
39 popup.parentNode.removeChild(popup);
40 document.removeEventListener('mousedown', ui.popup._handleMouseDown, false);
44 ui.popup.show = function(target, html)
46 var popup = $('popup');
48 popup = document.createElement('div');
50 document.body.appendChild(popup);
51 document.addEventListener('mousedown', ui.popup._handleMouseDown, false);
54 // Set html first so that we can get accurate size metrics on the popup.
55 popup.innerHTML = html;
57 var targetRect = target.getBoundingClientRect();
59 var x = Math.min(targetRect.left - 10, document.documentElement.clientWidth - popup.offsetWidth);
61 popup.style.left = x + window.pageXOffset + 'px';
63 var y = targetRect.top + targetRect.height;
64 if (y + popup.offsetHeight > document.documentElement.clientHeight)
65 y = targetRect.top - popup.offsetHeight;
67 popup.style.top = y + window.pageYOffset + 'px';
70 ui.popup._handleMouseDown = function(e) {
71 // Clear the open popup, unless the click was inside the popup.
72 var popup = $('popup');
73 if (popup && e.target != popup && !(popup.compareDocumentPosition(e.target) & 16))
79 ui.html.checkbox = function(queryParameter, label, isChecked, opt_extraJavaScript)
81 var js = opt_extraJavaScript || '';
82 return '<label style="padding-left: 2em">' +
83 '<input type="checkbox" onchange="g_history.toggleQueryParameter(\'' + queryParameter + '\');' + js + '" ' +
84 (isChecked ? 'checked' : '') + '>' + label +
88 ui.html.range = function(queryParameter, label, min, max, initialValue)
92 '<input type=range onchange="g_history.setQueryParameter(\'' + queryParameter + '\', this.value)" min=' + min + ' max=' + max + ' value=' + initialValue + '>' +
96 ui.html.select = function(label, queryParameter, options)
98 var html = '<label style="padding-left: 2em">' + label + ': ' +
99 '<select onchange="g_history.setQueryParameter(\'' + queryParameter + '\', this[this.selectedIndex].value)">';
101 for (var i = 0; i < options.length; i++) {
102 var value = options[i];
103 html += '<option value="' + value + '" ' +
104 (g_history.queryParameterValue(queryParameter) == value ? 'selected' : '') +
105 '>' + value + '</option>'
107 html += '</select></label> ';
111 ui.html.navbar = function(opt_extraHtml)
113 var html = '<div style="border-bottom:1px dashed">';
114 html = ui.html._dashboardLink('Overview', 'overview.html') +
115 ui.html._dashboardLink('Results', 'flakiness_dashboard.html') +
116 ui.html._dashboardLink('Times', 'treemap.html') +
117 ui.html._dashboardLink('Stats', 'aggregate_results.html') +
118 ui.html._dashboardLink('Stats Timeline', 'timeline_explorer.html');
121 html += opt_extraHtml;
123 if (!history.isTreeMap())
124 html += ui.html.checkbox('showAllRuns', 'Use all recorded runs', g_history.crossDashboardState.showAllRuns);
126 return html + '</div>';
129 // Returns the HTML for the select element to switch to different testTypes.
130 ui.html.testTypeSwitcher = function(opt_noBuilderMenu, opt_extraHtml, opt_includeNoneBuilder)
132 var html = ui.html.select('Test type', 'testType', builders.testTypes);
133 if (!opt_noBuilderMenu) {
134 var buildersForMenu = Object.keys(currentBuilders());
135 if (opt_includeNoneBuilder)
136 buildersForMenu.unshift('--------------');
137 html += ui.html.select('Builder', 'builder', buildersForMenu);
140 html += ui.html.select('Group', 'group', builders.groupNamesForTestType(g_history.crossDashboardState.testType));
143 html += opt_extraHtml;
144 return ui.html.navbar(html);
147 ui.html._loadDashboard = function(fileName)
149 var pathName = window.location.pathname;
150 pathName = pathName.substring(0, pathName.lastIndexOf('/') + 1);
151 window.location = pathName + fileName + window.location.hash;
154 ui.html._topLink = function(html, onClick, isSelected)
156 var cssText = isSelected ? 'font-weight: bold;' : 'color:blue;text-decoration:underline;cursor:pointer;';
157 cssText += 'margin: 0 5px;';
158 return '<span style="' + cssText + '" onclick="' + onClick + '">' + html + '</span>';
161 ui.html._dashboardLink = function(html, fileName)
163 var pathName = window.location.pathname;
164 var currentFileName = pathName.substring(pathName.lastIndexOf('/') + 1);
165 var isSelected = currentFileName == fileName;
166 var onClick = 'ui.html._loadDashboard(\'' + fileName + '\')';
167 return ui.html._topLink(html, onClick, isSelected);
170 ui.html._revisionLink = function(resultsKey, testResults, index)
172 var currentRevision = parseInt(testResults[resultsKey][index], 10);
173 var previousRevision = parseInt(testResults[resultsKey][index + 1], 10);
175 var isChrome = resultsKey == results.CHROME_REVISIONS;
176 var singleUrl = 'http://src.chromium.org/viewvc/' + (isChrome ? 'chrome' : 'blink') + '?view=rev&revision=' + currentRevision;
178 if (currentRevision == previousRevision)
179 return 'At <a href="' + singleUrl + '">r' + currentRevision + '</a>';
181 if (currentRevision - previousRevision == 1)
182 return '<a href="' + singleUrl + '">r' + currentRevision + '</a>';
184 var rangeUrl = 'http://build.chromium.org/f/chromium/perf/dashboard/ui/changelog' +
185 (isChrome ? '' : '_blink') + '.html?url=/trunk' + (isChrome ? '/src' : '') +
186 '&range=' + (previousRevision + 1) + ':' + currentRevision + '&mode=html';
187 return '<a href="' + rangeUrl + '">r' + (previousRevision + 1) + ' to r' + currentRevision + '</a>';
190 ui.html.chromiumRevisionLink = function(testResults, index)
192 return ui.html._revisionLink(results.CHROME_REVISIONS, testResults, index);
195 ui.html.blinkRevisionLink = function(testResults, index)
197 return ui.html._revisionLink(results.BLINK_REVISIONS, testResults, index);
201 ui.Errors = function() {
203 // Element to display the errors within.
204 this._containerElement = null;
207 ui.Errors.prototype = {
210 if (!this._containerElement) {
211 this._containerElement = document.createElement('H2');
212 this._containerElement.style.color = 'red';
213 this._containerElement.id = 'errors';
214 document.documentElement.insertBefore(this._containerElement, document.body);
217 this._containerElement.innerHTML = this._messages;
219 // Record a new error message.
220 addError: function(message)
222 this._messages += message + '<br>';
224 hasErrors: function()
226 return !!this._messages;