| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 5 |
| 6 /** | 6 /** |
| 7 * @fileoverview Interactive visualizaiton of TimelineModel objects | 7 * @fileoverview Interactive visualizaiton of TimelineModel objects |
| 8 * based loosely on gantt charts. Each thread in the TimelineModel is given a | 8 * based loosely on gantt charts. Each thread in the TimelineModel is given a |
| 9 * set of TimelineTracks, one per subrow in the thread. The Timeline class | 9 * set of TimelineTracks, one per subrow in the thread. The Timeline class |
| 10 * acts as a controller, creating the individual tracks, while TimelineTracks | 10 * acts as a controller, creating the individual tracks, while TimelineTracks |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 if (this.model) { | 171 if (this.model) { |
| 172 throw Error('Cannot set model twice.'); | 172 throw Error('Cannot set model twice.'); |
| 173 } | 173 } |
| 174 this.model_ = model; | 174 this.model_ = model; |
| 175 | 175 |
| 176 // Create tracks. | 176 // Create tracks. |
| 177 this.tracks_.textContent = ''; | 177 this.tracks_.textContent = ''; |
| 178 var threads = model.getAllThreads(); | 178 var threads = model.getAllThreads(); |
| 179 for (var tI = 0; tI < threads.length; tI++) { | 179 for (var tI = 0; tI < threads.length; tI++) { |
| 180 var thread = threads[tI]; | 180 var thread = threads[tI]; |
| 181 for (var srI = 0; srI < thread.subRows.length; ++srI) { | 181 var track = new TimelineThreadTrack(); |
| 182 var track = document.createElement('div'); | 182 track.thread = thread; |
| 183 cr.ui.decorate(track, gpu.TimelineTrack); | 183 track.viewport = this.viewport_; |
| 184 track.viewport = this.viewport_; | 184 this.tracks_.appendChild(track); |
| 185 if (srI == 0) | 185 |
| 186 track.heading = thread.parent.pid + ': ' + thread.tid + ': '; | |
| 187 else | |
| 188 track.heading = ''; | |
| 189 track.slices = thread.subRows[srI]; | |
| 190 track.thread = thread; | |
| 191 this.tracks_.appendChild(track); | |
| 192 } | |
| 193 } | 186 } |
| 194 | 187 |
| 195 this.needsViewportReset_ = true; | 188 this.needsViewportReset_ = true; |
| 196 }, | 189 }, |
| 197 | 190 |
| 198 invalidate: function() { | 191 invalidate: function() { |
| 199 if (this.invalidatePending_) | 192 if (this.invalidatePending_) |
| 200 return; | 193 return; |
| 201 this.invalidatePending_ = true; | 194 this.invalidatePending_ = true; |
| 202 window.setTimeout(function() { | 195 window.setTimeout(function() { |
| 203 this.invalidatePending_ = false; | 196 this.invalidatePending_ = false; |
| 204 this.redrawAllTracks_(); | 197 this.redrawAllTracks_(); |
| 205 }.bind(this), 0); | 198 }.bind(this), 0); |
| 206 }, | 199 }, |
| 207 | 200 |
| 208 onResize: function() { | 201 onResize: function() { |
| 209 for (var i = 0; i < this.tracks_.children.length; ++i) { | 202 for (var i = 0; i < this.tracks_.children.length; ++i) { |
| 210 var track = this.tracks_.children[i]; | 203 var track = this.tracks_.children[i]; |
| 211 track.onResize(); | 204 track.onResize(); |
| 212 } | 205 } |
| 213 }, | 206 }, |
| 214 | 207 |
| 215 redrawAllTracks_: function() { | 208 redrawAllTracks_: function() { |
| 216 if (this.needsViewportReset_ && this.clientWidth != 0) { | 209 if (this.needsViewportReset_ && this.clientWidth != 0) { |
| 217 this.needsViewportReset_ = false; | 210 this.needsViewportReset_ = false; |
| 218 console.log('viewport was reset.'); | |
| 219 /* update viewport */ | 211 /* update viewport */ |
| 220 var rangeTimestamp = this.model_.maxTimestamp - | 212 var rangeTimestamp = this.model_.maxTimestamp - |
| 221 this.model_.minTimestamp; | 213 this.model_.minTimestamp; |
| 222 var w = this.tracks_.firstChild.getCanvasWidth(); | 214 var w = this.firstCanvas.width; |
| 215 console.log('viewport was reset with w=', w); |
| 223 var scaleX = w / rangeTimestamp; | 216 var scaleX = w / rangeTimestamp; |
| 224 var panX = -this.model_.minTimestamp; | 217 var panX = -this.model_.minTimestamp; |
| 225 this.viewport_.setPanAndScale(panX, scaleX); | 218 this.viewport_.setPanAndScale(panX, scaleX); |
| 226 } | 219 } |
| 227 for (var i = 0; i < this.tracks_.children.length; ++i) { | 220 for (var i = 0; i < this.tracks_.children.length; ++i) { |
| 228 this.tracks_.children[i].redraw(); | 221 this.tracks_.children[i].redraw(); |
| 229 } | 222 } |
| 230 }, | 223 }, |
| 231 | 224 |
| 232 updateChildViewports_: function() { | 225 updateChildViewports_: function() { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 ' w/s : Zoom in/out\n' + | 288 ' w/s : Zoom in/out\n' + |
| 296 ' a/d : Pan left/right\n' + | 289 ' a/d : Pan left/right\n' + |
| 297 ' e : Center on mouse'; | 290 ' e : Center on mouse'; |
| 298 }, | 291 }, |
| 299 | 292 |
| 300 get selection() { | 293 get selection() { |
| 301 return this.selection_; | 294 return this.selection_; |
| 302 }, | 295 }, |
| 303 | 296 |
| 304 get firstCanvas() { | 297 get firstCanvas() { |
| 305 if (this.tracks_.firstChild) | 298 return this.tracks_.firstChild ? |
| 306 return this.tracks_.firstChild.canvas; | 299 this.tracks_.firstChild.firstCanvas : undefined; |
| 307 }, | 300 }, |
| 308 | 301 |
| 309 showDragBox_: function() { | 302 showDragBox_: function() { |
| 310 this.dragBox_.hidden = false; | 303 this.dragBox_.hidden = false; |
| 311 }, | 304 }, |
| 312 | 305 |
| 313 hideDragBox_: function() { | 306 hideDragBox_: function() { |
| 314 this.dragBox_.hidden = true; | 307 this.dragBox_.hidden = true; |
| 315 }, | 308 }, |
| 316 | 309 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 function addHit(type, track, slice) { | 388 function addHit(type, track, slice) { |
| 396 selection.push({track: track, slice: slice}); | 389 selection.push({track: track, slice: slice}); |
| 397 } | 390 } |
| 398 for (i = 0; i < this.tracks_.children.length; ++i) { | 391 for (i = 0; i < this.tracks_.children.length; ++i) { |
| 399 var track = this.tracks_.children[i]; | 392 var track = this.tracks_.children[i]; |
| 400 | 393 |
| 401 // Only check tracks that insersect the rect. | 394 // Only check tracks that insersect the rect. |
| 402 var a = Math.max(loY, track.offsetTop); | 395 var a = Math.max(loY, track.offsetTop); |
| 403 var b = Math.min(hiY, track.offsetTop + track.offsetHeight); | 396 var b = Math.min(hiY, track.offsetTop + track.offsetHeight); |
| 404 if (a <= b) { | 397 if (a <= b) { |
| 405 track.pickRange(loWX, hiWX, addHit); | 398 track.pickRange(loWX, hiWX, loY, hiY, addHit); |
| 406 } | 399 } |
| 407 } | 400 } |
| 408 // Activate the new selection. | 401 // Activate the new selection. |
| 409 this.selection_ = selection; | 402 this.selection_ = selection; |
| 410 cr.dispatchSimpleEvent(this, 'selectionChange'); | 403 cr.dispatchSimpleEvent(this, 'selectionChange'); |
| 411 for (i = 0; i < this.selection_.length; ++i) { | 404 for (i = 0; i < this.selection_.length; ++i) { |
| 412 this.selection_[i].slice.selected = true; | 405 this.selection_[i].slice.selected = true; |
| 413 } | 406 } |
| 414 this.invalidate(); // Cause tracks to redraw. | 407 this.invalidate(); // Cause tracks to redraw. |
| 415 } | 408 } |
| 416 } | 409 } |
| 417 }; | 410 }; |
| 418 | 411 |
| 419 /** | 412 /** |
| 420 * The TimelineModel being viewed by the timeline | 413 * The TimelineModel being viewed by the timeline |
| 421 * @type {TimelineModel} | 414 * @type {TimelineModel} |
| 422 */ | 415 */ |
| 423 cr.defineProperty(Timeline, 'model', cr.PropertyKind.JS); | 416 cr.defineProperty(Timeline, 'model', cr.PropertyKind.JS); |
| 424 | 417 |
| 425 return { | 418 return { |
| 426 Timeline: Timeline | 419 Timeline: Timeline |
| 427 }; | 420 }; |
| 428 }); | 421 }); |
| OLD | NEW |