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 Renders an array of slices into the provided div, | 7 * @fileoverview Renders an array of slices into the provided div, |
8 * using a child canvas element. Uses a FastRectRenderer to draw only | 8 * using a child canvas element. Uses a FastRectRenderer to draw only |
9 * the visible slices. | 9 * the visible slices. |
10 */ | 10 */ |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 86 |
87 decorate: function() { | 87 decorate: function() { |
88 this.className = 'timeline-thread-track'; | 88 this.className = 'timeline-thread-track'; |
89 }, | 89 }, |
90 | 90 |
91 set thread(thread) { | 91 set thread(thread) { |
92 this.thread_ = thread; | 92 this.thread_ = thread; |
93 this.updateChildTracks_(); | 93 this.updateChildTracks_(); |
94 }, | 94 }, |
95 | 95 |
| 96 /** |
| 97 * @return {string} A human-readable name for the track. |
| 98 */ |
| 99 get heading() { |
| 100 if (!this.thread_) |
| 101 return ''; |
| 102 var tname = this.thread_.name || this.thread_.tid; |
| 103 return this.thread_.parent.pid + ': ' + |
| 104 tname + ':'; |
| 105 }, |
| 106 |
| 107 set headingWidth(width) { |
| 108 for (var i = 0; i < this.tracks_.length; i++) |
| 109 this.tracks_[i].headingWidth = width; |
| 110 }, |
| 111 |
96 set viewport(v) { | 112 set viewport(v) { |
97 this.viewport_ = v; | 113 this.viewport_ = v; |
98 for (var i = 0; i < this.tracks_.length; i++) | 114 for (var i = 0; i < this.tracks_.length; i++) |
99 this.tracks_[i].viewport = v; | 115 this.tracks_[i].viewport = v; |
100 this.invalidate(); | 116 this.invalidate(); |
101 }, | 117 }, |
102 | 118 |
103 invalidate: function() { | 119 invalidate: function() { |
104 if (this.parentNode) | 120 if (this.parentNode) |
105 this.parentNode.invalidate(); | 121 this.parentNode.invalidate(); |
(...skipping 19 matching lines...) Expand all Loading... |
125 this.textContent = ''; | 141 this.textContent = ''; |
126 this.tracks_ = []; | 142 this.tracks_ = []; |
127 if (this.thread_) { | 143 if (this.thread_) { |
128 for (var srI = 0; srI < this.thread_.nonNestedSubRows.length; ++srI) { | 144 for (var srI = 0; srI < this.thread_.nonNestedSubRows.length; ++srI) { |
129 addTrack(this, this.thread_.nonNestedSubRows[srI]); | 145 addTrack(this, this.thread_.nonNestedSubRows[srI]); |
130 } | 146 } |
131 for (var srI = 0; srI < this.thread_.subRows.length; ++srI) { | 147 for (var srI = 0; srI < this.thread_.subRows.length; ++srI) { |
132 addTrack(this, this.thread_.subRows[srI]); | 148 addTrack(this, this.thread_.subRows[srI]); |
133 } | 149 } |
134 if (this.tracks_.length > 0) { | 150 if (this.tracks_.length > 0) { |
135 var tname = this.thread_.name || this.thread_.tid; | 151 this.tracks_[0].heading = this.heading; |
136 this.tracks_[0].heading = this.thread_.parent.pid + ': ' + | |
137 tname + ':'; | |
138 this.tracks_[0].tooltip = 'pid: ' + this.thread_.parent.pid + | 152 this.tracks_[0].tooltip = 'pid: ' + this.thread_.parent.pid + |
139 ', tid: ' + this.thread_.tid + | 153 ', tid: ' + this.thread_.tid + |
140 (this.thread_.name ? ', name: ' + this.thread_.name : ''); | 154 (this.thread_.name ? ', name: ' + this.thread_.name : ''); |
141 } | 155 } |
142 } | 156 } |
143 }, | 157 }, |
144 | 158 |
145 /** | 159 /** |
146 * Picks a slice, if any, at a given location. | 160 * Picks a slice, if any, at a given location. |
147 * @param {number} wX X location to search at, in worldspace. | 161 * @param {number} wX X location to search at, in worldspace. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 this.canvasContainer_ = document.createElement('div'); | 219 this.canvasContainer_ = document.createElement('div'); |
206 this.canvasContainer_.className = 'timeline-slice-track-canvas-container'; | 220 this.canvasContainer_.className = 'timeline-slice-track-canvas-container'; |
207 this.appendChild(this.canvasContainer_); | 221 this.appendChild(this.canvasContainer_); |
208 this.canvas_ = document.createElement('canvas'); | 222 this.canvas_ = document.createElement('canvas'); |
209 this.canvas_.className = 'timeline-slice-track-canvas'; | 223 this.canvas_.className = 'timeline-slice-track-canvas'; |
210 this.canvasContainer_.appendChild(this.canvas_); | 224 this.canvasContainer_.appendChild(this.canvas_); |
211 | 225 |
212 this.ctx_ = this.canvas_.getContext('2d'); | 226 this.ctx_ = this.canvas_.getContext('2d'); |
213 }, | 227 }, |
214 | 228 |
| 229 set headingWidth(width) { |
| 230 this.headingDiv_.style.width = width; |
| 231 }, |
| 232 |
| 233 get heading() { |
| 234 return this.headingDiv_.textContent; |
| 235 }, |
| 236 |
215 set heading(text) { | 237 set heading(text) { |
216 this.headingDiv_.textContent = text; | 238 this.headingDiv_.textContent = text; |
217 }, | 239 }, |
218 | 240 |
219 set tooltip(text) { | 241 set tooltip(text) { |
220 this.headingDiv_.title = text; | 242 this.headingDiv_.title = text; |
221 }, | 243 }, |
222 | 244 |
223 set slices(slices) { | 245 set slices(slices) { |
224 this.slices_ = slices; | 246 this.slices_ = slices; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 ctx.strokeStyle = 'rgb(0,0,0)'; | 350 ctx.strokeStyle = 'rgb(0,0,0)'; |
329 ctx.fillStyle = 'rgb(0,0,0)'; | 351 ctx.fillStyle = 'rgb(0,0,0)'; |
330 var quickDiscardThresshold = pixWidth * 20; // dont render until 20px wide | 352 var quickDiscardThresshold = pixWidth * 20; // dont render until 20px wide |
331 for (var i = 0; i < slices.length; ++i) { | 353 for (var i = 0; i < slices.length; ++i) { |
332 var slice = slices[i]; | 354 var slice = slices[i]; |
333 if (slice.duration > quickDiscardThresshold) { | 355 if (slice.duration > quickDiscardThresshold) { |
334 var title = slice.title; | 356 var title = slice.title; |
335 if (slice.didNotFinish) { | 357 if (slice.didNotFinish) { |
336 title += ' (Did Not Finish)'; | 358 title += ' (Did Not Finish)'; |
337 } | 359 } |
338 function labelWidth() { | 360 var labelWidth = quickMeasureText(ctx, title) + 2; |
339 return quickMeasureText(ctx, title) + 2; | 361 var labelWidthWorld = pixWidth * labelWidth; |
| 362 |
| 363 if (labelWidthWorld < slice.duration) { |
| 364 var cX = vp.xWorldToView(slice.start + 0.5 * slice.duration); |
| 365 ctx.fillText(title, cX, 2.5, labelWidthWorld); |
340 } | 366 } |
341 function labelWidthWorld() { | |
342 return pixWidth * labelWidth(); | |
343 } | |
344 var elided = false; | |
345 while (labelWidthWorld() > slice.duration) { | |
346 title = title.substring(0, title.length * 0.75); | |
347 elided = true; | |
348 } | |
349 if (elided && title.length > 3) | |
350 title = title.substring(0, title.length - 3) + '...'; | |
351 var cX = vp.xWorldToView(slice.start + 0.5 * slice.duration); | |
352 ctx.fillText(title, cX, 2.5, labelWidthWorld()); | |
353 } | 367 } |
354 } | 368 } |
355 }, | 369 }, |
356 | 370 |
357 /** | 371 /** |
358 * Picks a slice, if any, at a given location. | 372 * Picks a slice, if any, at a given location. |
359 * @param {number} wX X location to search at, in worldspace. | 373 * @param {number} wX X location to search at, in worldspace. |
360 * @param {number} wY Y location to search at, in offset space. | 374 * @param {number} wY Y location to search at, in offset space. |
361 * offset space. | 375 * offset space. |
362 * @param {function():*} onHitCallback Callback to call with the slice, | 376 * @param {function():*} onHitCallback Callback to call with the slice, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 var index = this.indexOfSlice_(slice); | 450 var index = this.indexOfSlice_(slice); |
437 if (index != undefined) { | 451 if (index != undefined) { |
438 if (index < this.slices_.length - 1) | 452 if (index < this.slices_.length - 1) |
439 index++; | 453 index++; |
440 else | 454 else |
441 index = undefined; | 455 index = undefined; |
442 } | 456 } |
443 return index != undefined ? this.slices_[index] : undefined; | 457 return index != undefined ? this.slices_[index] : undefined; |
444 }, | 458 }, |
445 | 459 |
446 /** | 460 /** |
447 * Return the previous slice, if any, before the given slice. | 461 * Return the previous slice, if any, before the given slice. |
448 * @param {slice} A slice. | 462 * @param {slice} A slice. |
449 * @return {slice} The previous slice, or undefined. | 463 * @return {slice} The previous slice, or undefined. |
450 */ | 464 */ |
451 pickPrevious: function(slice) { | 465 pickPrevious: function(slice) { |
452 var index = this.indexOfSlice_(slice); | 466 var index = this.indexOfSlice_(slice); |
453 if (index == 0) | 467 if (index == 0) |
454 return undefined; | 468 return undefined; |
455 else if ((index != undefined) && (index > 0)) | 469 else if ((index != undefined) && (index > 0)) |
456 index--; | 470 index--; |
457 return index != undefined ? this.slices_[index] : undefined; | 471 return index != undefined ? this.slices_[index] : undefined; |
458 }, | 472 } |
459 | 473 |
460 }; | 474 }; |
461 | 475 |
462 return { | 476 return { |
463 TimelineSliceTrack: TimelineSliceTrack, | 477 TimelineSliceTrack: TimelineSliceTrack, |
464 TimelineThreadTrack: TimelineThreadTrack | 478 TimelineThreadTrack: TimelineThreadTrack |
465 }; | 479 }; |
466 }); | 480 }); |
OLD | NEW |