| OLD | NEW |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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 Coverage.CoverageListView = class extends UI.VBox { | 5 Coverage.CoverageListView = class extends UI.VBox { |
| 6 constructor() { | 6 constructor() { |
| 7 super(true); | 7 super(true); |
| 8 this.registerRequiredCSS('coverage/coverageListView.css'); | 8 this.registerRequiredCSS('coverage/coverageListView.css'); |
| 9 var columns = [ | 9 var columns = [ |
| 10 {id: 'url', title: Common.UIString('URL'), width: '300px', fixedWidth: fal
se, sortable: true}, { | 10 {id: 'url', title: Common.UIString('URL'), width: '300px', fixedWidth: fal
se, sortable: true}, { |
| 11 id: 'size', | 11 id: 'size', |
| 12 title: Common.UIString('Total Bytes'), | 12 title: Common.UIString('Total Bytes'), |
| 13 width: '60px', | 13 width: '60px', |
| 14 fixedWidth: true, | 14 fixedWidth: true, |
| 15 sortable: true, | 15 sortable: true, |
| 16 align: DataGrid.DataGrid.Align.Right | 16 align: DataGrid.DataGrid.Align.Right |
| 17 }, | 17 }, |
| 18 { | 18 {id: 'type', title: Common.UIString('Type'), width: '30px', fixedWidth: tr
ue, sortable: true}, { |
| 19 id: 'unusedSize', | 19 id: 'unusedSize', |
| 20 title: Common.UIString('Unused Bytes'), | 20 title: Common.UIString('Unused Bytes'), |
| 21 width: '60px', | 21 width: '60px', |
| 22 fixedWidth: true, | 22 fixedWidth: true, |
| 23 sortable: true, | 23 sortable: true, |
| 24 align: DataGrid.DataGrid.Align.Right, | 24 align: DataGrid.DataGrid.Align.Right, |
| 25 sort: DataGrid.DataGrid.Order.Descending | 25 sort: DataGrid.DataGrid.Order.Descending |
| 26 }, | 26 }, |
| 27 {id: 'bars', title: '', width: '500px', fixedWidth: false, sortable: false
} | 27 {id: 'bars', title: '', width: '500px', fixedWidth: false, sortable: false
} |
| 28 ]; | 28 ]; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 _sortingChanged() { | 85 _sortingChanged() { |
| 86 var columnId = this._dataGrid.sortColumnId(); | 86 var columnId = this._dataGrid.sortColumnId(); |
| 87 if (!columnId) | 87 if (!columnId) |
| 88 return; | 88 return; |
| 89 var sortFunction; | 89 var sortFunction; |
| 90 switch (columnId) { | 90 switch (columnId) { |
| 91 case 'url': | 91 case 'url': |
| 92 sortFunction = compareURL; | 92 sortFunction = compareURL; |
| 93 break; | 93 break; |
| 94 case 'type': |
| 95 sortFunction = compareNumericField.bind(null, 'type'); |
| 96 break; |
| 94 case 'size': | 97 case 'size': |
| 95 sortFunction = compareNumericField.bind(null, 'size'); | 98 sortFunction = compareNumericField.bind(null, 'size'); |
| 96 break; | 99 break; |
| 97 case 'unusedSize': | 100 case 'unusedSize': |
| 98 sortFunction = compareNumericField.bind(null, 'unusedSize'); | 101 sortFunction = compareNumericField.bind(null, 'unusedSize'); |
| 99 break; | 102 break; |
| 100 default: | 103 default: |
| 101 console.assert(false, 'Unknown sort field: ' + columnId); | 104 console.assert(false, 'Unknown sort field: ' + columnId); |
| 102 return; | 105 return; |
| 103 } | 106 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 122 * @param {!DataGrid.DataGridNode} b | 125 * @param {!DataGrid.DataGridNode} b |
| 123 * @return {number} | 126 * @return {number} |
| 124 */ | 127 */ |
| 125 function compareNumericField(fieldName, a, b) { | 128 function compareNumericField(fieldName, a, b) { |
| 126 var nodeA = /** @type {!Coverage.CoverageListView.GridNode} */ (a); | 129 var nodeA = /** @type {!Coverage.CoverageListView.GridNode} */ (a); |
| 127 var nodeB = /** @type {!Coverage.CoverageListView.GridNode} */ (b); | 130 var nodeB = /** @type {!Coverage.CoverageListView.GridNode} */ (b); |
| 128 | 131 |
| 129 return nodeA._coverageInfo[fieldName] - nodeB._coverageInfo[fieldName]; | 132 return nodeA._coverageInfo[fieldName] - nodeB._coverageInfo[fieldName]; |
| 130 } | 133 } |
| 131 } | 134 } |
| 135 |
| 136 /** |
| 137 * @param {!Coverage.CoverageType} type |
| 138 */ |
| 139 static _typeToString(type) { |
| 140 var types = []; |
| 141 if (type & Coverage.CoverageType.CSS) |
| 142 types.push(Common.UIString('CSS')); |
| 143 if (type & Coverage.CoverageType.JavaScript) |
| 144 types.push(Common.UIString('JS')); |
| 145 return types.join('+'); |
| 146 } |
| 132 }; | 147 }; |
| 133 | 148 |
| 134 Coverage.CoverageListView.GridNode = class extends DataGrid.SortableDataGridNode
{ | 149 Coverage.CoverageListView.GridNode = class extends DataGrid.SortableDataGridNode
{ |
| 135 /** | 150 /** |
| 136 * @param {!Coverage.CoverageInfo} coverageInfo | 151 * @param {!Coverage.CoverageInfo} coverageInfo |
| 137 * @param {number} maxSize | 152 * @param {number} maxSize |
| 138 */ | 153 */ |
| 139 constructor(coverageInfo, maxSize) { | 154 constructor(coverageInfo, maxSize) { |
| 140 super(); | 155 super(); |
| 141 this._coverageInfo = coverageInfo; | 156 this._coverageInfo = coverageInfo; |
| 142 this._maxSize = maxSize; | 157 this._maxSize = maxSize; |
| 143 } | 158 } |
| 144 | 159 |
| 145 /** | 160 /** |
| 146 * @override | 161 * @override |
| 147 * @param {string} columnId | 162 * @param {string} columnId |
| 148 * @return {!Element} | 163 * @return {!Element} |
| 149 */ | 164 */ |
| 150 createCell(columnId) { | 165 createCell(columnId) { |
| 151 var cell = this.createTD(columnId); | 166 var cell = this.createTD(columnId); |
| 152 switch (columnId) { | 167 switch (columnId) { |
| 153 case 'url': | 168 case 'url': |
| 154 cell.textContent = this._coverageInfo.url; | 169 cell.textContent = this._coverageInfo.url; |
| 170 cell.title = this._coverageInfo.url; |
| 171 break; |
| 172 case 'type': |
| 173 cell.textContent = Coverage.CoverageListView._typeToString(this._coverag
eInfo.type); |
| 155 break; | 174 break; |
| 156 case 'size': | 175 case 'size': |
| 157 cell.classList.add('numeric-column'); | 176 cell.classList.add('numeric-column'); |
| 158 cell.textContent = this._coverageInfo.size; | 177 cell.textContent = this._coverageInfo.size; |
| 159 break; | 178 break; |
| 160 case 'unusedSize': | 179 case 'unusedSize': |
| 161 cell.classList.add('numeric-column'); | 180 cell.classList.add('numeric-column'); |
| 162 cell.textContent = this._coverageInfo.unusedSize; | 181 cell.textContent = this._coverageInfo.unusedSize; |
| 163 break; | 182 break; |
| 164 case 'bars': | 183 case 'bars': |
| 165 var barContainer = cell.createChild('div', 'bar-container'); | 184 var barContainer = cell.createChild('div', 'bar-container'); |
| 166 var unusedSizeBar = barContainer.createChild('div', 'bar bar-unused-size
'); | 185 var unusedSizeBar = barContainer.createChild('div', 'bar bar-unused-size
'); |
| 167 unusedSizeBar.style.width = Math.ceil(100 * this._coverageInfo.unusedSiz
e / this._maxSize) + '%'; | 186 unusedSizeBar.style.width = Math.ceil(100 * this._coverageInfo.unusedSiz
e / this._maxSize) + '%'; |
| 168 var usedSizeBar = barContainer.createChild('div', 'bar bar-used-size'); | 187 var usedSizeBar = barContainer.createChild('div', 'bar bar-used-size'); |
| 169 usedSizeBar.style.width = Math.ceil(100 * this._coverageInfo.usedSize /
this._maxSize) + '%'; | 188 usedSizeBar.style.width = Math.ceil(100 * this._coverageInfo.usedSize /
this._maxSize) + '%'; |
| 170 var sizeBar = barContainer.createChild('div', 'bar bar-slack-size'); | 189 var sizeBar = barContainer.createChild('div', 'bar bar-slack-size'); |
| 171 var slackSize = this._coverageInfo.size - this._coverageInfo.unusedSize
- this._coverageInfo.usedSize; | 190 var slackSize = this._coverageInfo.size - this._coverageInfo.unusedSize
- this._coverageInfo.usedSize; |
| 172 sizeBar.style.width = Math.ceil(100 * slackSize / this._maxSize) + '%'; | 191 sizeBar.style.width = Math.ceil(100 * slackSize / this._maxSize) + '%'; |
| 173 } | 192 } |
| 174 return cell; | 193 return cell; |
| 175 } | 194 } |
| 176 }; | 195 }; |
| OLD | NEW |