Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /* Counter accessor for Name Node. */ | 5 /* Counter accessor for Name Node. */ |
| 6 function getCounterNameFromCounterNode(node) { | 6 function getCounterNameFromCounterNode(node) { |
| 7 return node.childNodes[1]; | 7 return node.childNodes[1]; |
| 8 } | 8 } |
| 9 | 9 |
| 10 /* Counter accessor for Value Node. */ | 10 /* Counter accessor for Value Node. */ |
| 11 function getCounterValueFromCounterNode(node) { | 11 function getCounterValueFromCounterNode(node) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 35 /* Timer accessor for Average Time Node. */ | 35 /* Timer accessor for Average Time Node. */ |
| 36 function getTimerAvgTimeFromTimerNode(node) { | 36 function getTimerAvgTimeFromTimerNode(node) { |
| 37 return node.childNodes[7]; | 37 return node.childNodes[7]; |
| 38 } | 38 } |
| 39 | 39 |
| 40 /* Do the filter work. Hide all nodes matching node.*/ | 40 /* Do the filter work. Hide all nodes matching node.*/ |
| 41 function filterMatching(text, nodelist, functionToGetNameNode) { | 41 function filterMatching(text, nodelist, functionToGetNameNode) { |
| 42 var showAll = text.length == 0; | 42 var showAll = text.length == 0; |
| 43 for (var i = 0, node; node = nodelist[i]; i++) { | 43 for (var i = 0, node; node = nodelist[i]; i++) { |
| 44 var name = functionToGetNameNode(node).innerHTML.toLowerCase(); | 44 var name = functionToGetNameNode(node).innerHTML.toLowerCase(); |
| 45 if (showAll || name.indexOf(text) >= 0) { | 45 if (showAll || name.indexOf(text) >= 0) { |
|
Dan Beam
2012/04/05 22:24:13
nit: no curlies
Tyler Breisacher (Chromium)
2012/04/05 22:39:13
Done.
| |
| 46 node.style.display = "table-row"; | 46 node.style.display = 'table-row'; |
| 47 } else { | 47 } else { |
| 48 node.style.display = "none"; | 48 node.style.display = 'none'; |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 /* Hides or shows counters based on the user's current filter selection. */ | 53 /* Hides or shows counters based on the user's current filter selection. */ |
| 54 function doFilter() { | 54 function doFilter() { |
| 55 var filter = document.getElementById("filter"); | 55 var filter = document.getElementById('filter'); |
| 56 var text = filter.value.toLowerCase(); | 56 var text = filter.value.toLowerCase(); |
| 57 var nodes = document.getElementsByName("counter"); | 57 var nodes = document.getElementsByName('counter'); |
| 58 filterMatching(text, nodes, getCounterNameFromCounterNode); | 58 filterMatching(text, nodes, getCounterNameFromCounterNode); |
| 59 var nodes = document.getElementsByName("timer"); | 59 var nodes = document.getElementsByName('timer'); |
| 60 filterMatching(text, nodes, getTimerNameFromTimerNode); | 60 filterMatching(text, nodes, getTimerNameFromTimerNode); |
| 61 } | 61 } |
| 62 | 62 |
| 63 /* Colors the counters based on increasing or decreasing value. */ | 63 /* Colors the counters based on increasing or decreasing value. */ |
| 64 function doColor() { | 64 function doColor() { |
| 65 var nodes = document.getElementsByName("counter"); | 65 var nodes = document.getElementsByName('counter'); |
| 66 for (var i = 0, node; node = nodes[i]; i++) { | 66 for (var i = 0, node; node = nodes[i]; i++) { |
| 67 var child = getCounterDeltaFromCounterNode(node); | 67 var child = getCounterDeltaFromCounterNode(node); |
| 68 var delta = child.innerHTML; | 68 var delta = child.innerHTML; |
| 69 if (delta > 0) { | 69 if (delta > 0) { |
|
Dan Beam
2012/04/05 22:24:13
nor here
Tyler Breisacher (Chromium)
2012/04/05 22:39:13
Done.
| |
| 70 child.style.color = "Green"; | 70 child.style.color = 'Green'; |
| 71 } else if (delta == 0) { | 71 } else if (delta == 0) { |
| 72 child.style.color = "Black"; | 72 child.style.color = 'Black'; |
| 73 } else { | 73 } else { |
| 74 child.style.color = "Red"; | 74 child.style.color = 'Red'; |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 /* Counters with no values are null. Remove them. */ | 79 /* Counters with no values are null. Remove them. */ |
| 80 function removeNullValues() { | 80 function removeNullValues() { |
| 81 var nodes = document.getElementsByName("counter"); | 81 var nodes = document.getElementsByName('counter'); |
| 82 for (var i = nodes.length - 1; i >= 0; i--) { | 82 for (var i = nodes.length - 1; i >= 0; i--) { |
| 83 var node = nodes[i]; | 83 var node = nodes[i]; |
| 84 var value = getCounterValueFromCounterNode(node).innerHTML; | 84 var value = getCounterValueFromCounterNode(node).innerHTML; |
| 85 if (value == "null") { | 85 if (value == 'null') { |
|
Dan Beam
2012/04/05 22:24:13
:^( == 'null', nor here
Tyler Breisacher (Chromium)
2012/04/05 22:39:13
Done.
| |
| 86 node.parentNode.removeChild(node); | 86 node.parentNode.removeChild(node); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 var nodes = document.getElementsByName("timer"); | 89 var nodes = document.getElementsByName('timer'); |
| 90 for (var i = 0, node; node = nodes[i]; i++) { | 90 for (var i = 0, node; node = nodes[i]; i++) { |
| 91 var value_node = getTimerValueFromTimerNode(node); | 91 var value_node = getTimerValueFromTimerNode(node); |
| 92 if (value_node.innerHTML == "null") { | 92 if (value_node.innerHTML == 'null') { |
|
Dan Beam
2012/04/05 22:24:13
:_( == 'null', nor here
Tyler Breisacher (Chromium)
2012/04/05 22:39:13
Done.
| |
| 93 value_node.innerHTML = ""; | 93 value_node.innerHTML = ''; |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 /* Compute the average time for timers */ | 98 /* Compute the average time for timers */ |
| 99 function computeTimes() { | 99 function computeTimes() { |
| 100 var nodes = document.getElementsByName("timer"); | 100 var nodes = document.getElementsByName('timer'); |
| 101 for (var i = 0, node; node = nodes[i]; i++) { | 101 for (var i = 0, node; node = nodes[i]; i++) { |
| 102 var count = getTimerValueFromTimerNode(node).innerHTML; | 102 var count = getTimerValueFromTimerNode(node).innerHTML; |
| 103 if (count.length > 0) { | 103 if (count.length > 0) { |
| 104 var time = getTimerTimeFromTimerNode(node).innerHTML; | 104 var time = getTimerTimeFromTimerNode(node).innerHTML; |
| 105 var avg = getTimerAvgTimeFromTimerNode(node); | 105 var avg = getTimerAvgTimeFromTimerNode(node); |
| 106 avg.innerHTML = Math.round(time / count * 100) / 100; | 106 avg.innerHTML = Math.round(time / count * 100) / 100; |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 /* All the work we do onload. */ | 111 /* All the work we do onload. */ |
| 112 function onLoadWork() { | 112 function onLoadWork() { |
| 113 // This is the javascript code that processes the template: | 113 // This is the javascript code that processes the template: |
| 114 var input = new JsEvalContext(templateData); | 114 var input = new JsEvalContext(templateData); |
| 115 var output = document.getElementById('t'); | 115 var output = document.getElementById('t'); |
| 116 jstProcess(input, output); | 116 jstProcess(input, output); |
| 117 | 117 |
| 118 // Add handlers to dynamically created HTML elements. | 118 // Add handlers to dynamically created HTML elements. |
| 119 var elements = document.getElementsByName("string-sort"); | 119 var elements = document.getElementsByName('string-sort'); |
| 120 for (var i = 0; i < elements.length; ++i) | 120 for (var i = 0; i < elements.length; ++i) |
| 121 elements[i].onclick = function () { sort_table("string"); }; | 121 elements[i].onclick = function() { sort_table('string'); }; |
| 122 | 122 |
| 123 elements = document.getElementsByName("number-sort"); | 123 elements = document.getElementsByName('number-sort'); |
| 124 for (i = 0; i < elements.length; ++i) | 124 for (i = 0; i < elements.length; ++i) |
| 125 elements[i].onclick = function () { sort_table("number"); }; | 125 elements[i].onclick = function() { sort_table('number'); }; |
| 126 | 126 |
| 127 doColor(); | 127 doColor(); |
| 128 removeNullValues(); | 128 removeNullValues(); |
| 129 computeTimes(); | 129 computeTimes(); |
| 130 document.getElementById("filter").focus(); | 130 document.getElementById('filter').focus(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 // The function should only be used as the event handler | 133 // The function should only be used as the event handler |
| 134 // on a table cell element. To use it, put it in a <td> element: | 134 // on a table cell element. To use it, put it in a <td> element: |
| 135 // <td onclick="sort('string')" ...> | 135 // <td onclick="sort('string')" ...> |
| 136 // | 136 // |
| 137 // The function sorts rows after the row with onclick event handler. | 137 // The function sorts rows after the row with onclick event handler. |
| 138 // | 138 // |
| 139 // type: the data type, 'string', 'number' | 139 // type: the data type, 'string', 'number' |
| 140 function sort_table(type){ | 140 function sort_table(type) { |
| 141 var cell = event.target; | 141 var cell = event.target; |
| 142 var cnum = cell.cellIndex; | 142 var cnum = cell.cellIndex; |
| 143 | 143 |
| 144 var row = cell.parentNode; | 144 var row = cell.parentNode; |
| 145 var start_index = row.rowIndex + 1; | 145 var start_index = row.rowIndex + 1; |
| 146 | 146 |
| 147 var tbody = row.parentNode; | 147 var tbody = row.parentNode; |
| 148 var table = tbody.parentNode; | 148 var table = tbody.parentNode; |
| 149 | 149 |
| 150 var rows = new Array(); | 150 var rows = new Array(); |
| 151 | 151 |
| 152 var indexes = new Array(); | 152 var indexes = new Array(); |
| 153 // skip the first row | 153 // skip the first row |
| 154 for (var i = start_index; i < table.rows.length; i++) | 154 for (var i = start_index; i < table.rows.length; i++) |
| 155 rows.push(table.rows[i]); | 155 rows.push(table.rows[i]); |
| 156 | 156 |
| 157 // a, b are strings | 157 // a, b are strings |
| 158 function compare_strings(a,b) { | 158 function compare_strings(a, b) { |
| 159 if (a == b) return 0; | 159 if (a == b) return 0; |
| 160 if (a < b) return -1; | 160 if (a < b) return -1; |
| 161 return 1; | 161 return 1; |
| 162 } | 162 } |
| 163 | 163 |
| 164 // a, b are numbers | 164 // a, b are numbers |
| 165 function compare_numbers(a,b) { | 165 function compare_numbers(a, b) { |
| 166 var x = isNaN(a) ? 0 : a; | 166 var x = isNaN(a) ? 0 : a; |
| 167 var y = isNaN(b) ? 0 : b; | 167 var y = isNaN(b) ? 0 : b; |
| 168 return x - y; | 168 return x - y; |
| 169 } | 169 } |
| 170 | 170 |
| 171 var sort_func = undefined; | 171 var sort_func = undefined; |
|
Dan Beam
2012/04/05 22:24:13
remove "= undefined"
Tyler Breisacher (Chromium)
2012/04/05 22:39:13
Done.
| |
| 172 if (type === 'string') { | 172 if (type === 'string') { |
| 173 sort_func = function(a, b) { | 173 sort_func = function(a, b) { |
| 174 var x = a.cells[cnum].innerText; | 174 var x = a.cells[cnum].innerText; |
| 175 var y = b.cells[cnum].innerText; | 175 var y = b.cells[cnum].innerText; |
| 176 return compare_strings(x, y); | 176 return compare_strings(x, y); |
| 177 } ; | 177 }; |
| 178 | 178 |
| 179 } else if (type === 'number') { | 179 } else if (type === 'number') { |
| 180 sort_func = function(a, b) { | 180 sort_func = function(a, b) { |
| 181 var x = parseFloat(a.cells[cnum].innerText); | 181 var x = parseFloat(a.cells[cnum].innerText); |
| 182 var y = parseFloat(b.cells[cnum].innerText); | 182 var y = parseFloat(b.cells[cnum].innerText); |
| 183 return compare_numbers(x, y); | 183 return compare_numbers(x, y); |
| 184 } | 184 } |
|
Dan Beam
2012/04/05 22:24:13
nit: ;
Tyler Breisacher (Chromium)
2012/04/05 22:39:13
Done.
| |
| 185 } | 185 } |
| 186 | 186 |
| 187 rows.sort(sort_func); | 187 rows.sort(sort_func); |
| 188 | 188 |
| 189 // change tables | 189 // change tables |
| 190 if (cell._reverse) { | 190 if (cell._reverse) { |
| 191 for (var i = rows.length - 1; i >= 0; i--) | 191 for (var i = rows.length - 1; i >= 0; i--) |
| 192 tbody.appendChild(rows[i]); | 192 tbody.appendChild(rows[i]); |
| 193 cell._reverse = false; | 193 cell._reverse = false; |
| 194 } else { | 194 } else { |
| 195 for (var i = 0; i < rows.length; i++) | 195 for (var i = 0; i < rows.length; i++) |
| 196 tbody.appendChild(rows[i]); | 196 tbody.appendChild(rows[i]); |
| 197 cell._reverse = true; | 197 cell._reverse = true; |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 document.addEventListener('DOMContentLoaded', onLoadWork); | 201 document.addEventListener('DOMContentLoaded', onLoadWork); |
|
Dan Beam
2012/04/05 22:24:13
nit: no \n
Tyler Breisacher (Chromium)
2012/04/05 22:39:13
Done.
| |
| 202 | 202 |
| OLD | NEW |