Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.VBox} | 7 * @extends {WebInspector.VBox} |
| 8 * @param {number} rowHeight | 8 * @param {number} rowHeight |
| 9 * @param {!WebInspector.NetworkTimeCalculator} calculator | 9 * @param {!WebInspector.NetworkTimeCalculator} calculator |
| 10 */ | 10 */ |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 var availableWidth = this._offsetWidth - this._leftPadding; | 282 var availableWidth = this._offsetWidth - this._leftPadding; |
| 283 var timeToPixel = availableWidth / (this._endTime - this._startTime); | 283 var timeToPixel = availableWidth / (this._endTime - this._startTime); |
| 284 return Math.floor(this._leftPadding + (time - this._startTime) * timeToP ixel); | 284 return Math.floor(this._leftPadding + (time - this._startTime) * timeToP ixel); |
| 285 }, | 285 }, |
| 286 | 286 |
| 287 _draw: function() | 287 _draw: function() |
| 288 { | 288 { |
| 289 var useTimingBars = !WebInspector.moduleSetting("networkColorCodeResourc eTypes").get() && !this._calculator.startAtZero; | 289 var useTimingBars = !WebInspector.moduleSetting("networkColorCodeResourc eTypes").get() && !this._calculator.startAtZero; |
| 290 var requests = this._requestData; | 290 var requests = this._requestData; |
| 291 var context = this._canvas.getContext("2d"); | 291 var context = this._canvas.getContext("2d"); |
| 292 this._calculator.setDisplayWindow(this._offsetWidth); | |
|
caseq
2016/10/31 21:59:45
This could probably go next to where we actually c
allada
2016/10/31 23:35:25
Done.
| |
| 292 context.save(); | 293 context.save(); |
| 293 context.scale(window.devicePixelRatio, window.devicePixelRatio); | 294 context.scale(window.devicePixelRatio, window.devicePixelRatio); |
| 294 context.save(); | |
| 295 context.translate(0, this._headerHeight); | 295 context.translate(0, this._headerHeight); |
| 296 context.rect(0, 0, this._offsetWidth, this._offsetHeight); | 296 context.rect(0, 0, this._offsetWidth, this._offsetHeight); |
| 297 context.clip(); | 297 context.clip(); |
| 298 var firstRequestIndex = Math.floor(this._scrollTop / this._rowHeight); | 298 var firstRequestIndex = Math.floor(this._scrollTop / this._rowHeight); |
| 299 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / this._rowHeight)); | 299 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / this._rowHeight)); |
| 300 for (var i = firstRequestIndex; i < lastRequestIndex; i++) { | 300 for (var i = firstRequestIndex; i < lastRequestIndex; i++) { |
| 301 var rowOffset = this._rowHeight * i; | 301 var rowOffset = this._rowHeight * i; |
| 302 var request = requests[i]; | 302 var request = requests[i]; |
| 303 this._decorateRow(context, request, i, rowOffset - this._scrollTop); | 303 this._decorateRow(context, request, i, rowOffset - this._scrollTop); |
| 304 if (useTimingBars) | 304 if (useTimingBars) |
| 305 this._drawTimingBars(context, request, rowOffset - this._scrollT op); | 305 this._drawTimingBars(context, request, rowOffset - this._scrollT op); |
| 306 else | 306 else |
| 307 this._drawSimplifiedBars(context, request, rowOffset - this._scr ollTop); | 307 this._drawSimplifiedBars(context, request, rowOffset - this._scr ollTop); |
| 308 } | 308 } |
| 309 this._drawEventDividers(context); | 309 this._drawEventDividers(context); |
| 310 context.restore(); | 310 context.restore(); |
| 311 // This is outside of the save/restore above because it must draw in hea der. | 311 |
| 312 this._drawDividers(context); | 312 WebInspector.TimelineGrid.drawCanvasGrid(context, this._calculator, this ._fontSize, 75); |
|
caseq
2016/10/31 21:59:45
Extract a constant for 75?
allada
2016/10/31 23:35:25
Done.
| |
| 313 context.restore(); | |
| 314 }, | 313 }, |
| 315 | 314 |
| 316 /** | 315 /** |
| 317 * @param {!CanvasRenderingContext2D} context | 316 * @param {!CanvasRenderingContext2D} context |
| 318 */ | 317 */ |
| 319 _drawEventDividers: function(context) | 318 _drawEventDividers: function(context) |
| 320 { | 319 { |
| 321 context.save(); | 320 context.save(); |
| 322 context.lineWidth = 1; | 321 context.lineWidth = 1; |
| 323 for (var color of this._eventDividers.keys()) { | 322 for (var color of this._eventDividers.keys()) { |
| 324 context.strokeStyle = color; | 323 context.strokeStyle = color; |
| 325 for (var time of this._eventDividers.get(color)) { | 324 for (var time of this._eventDividers.get(color)) { |
| 326 context.beginPath(); | 325 context.beginPath(); |
| 327 var x = this._timeToPosition(time); | 326 var x = this._timeToPosition(time); |
| 328 context.moveTo(x, 0); | 327 context.moveTo(x, 0); |
| 329 context.lineTo(x, this._offsetHeight); | 328 context.lineTo(x, this._offsetHeight); |
| 330 } | 329 } |
| 331 context.stroke(); | 330 context.stroke(); |
| 332 } | 331 } |
| 333 context.restore(); | 332 context.restore(); |
| 334 }, | 333 }, |
| 335 | 334 |
| 336 /** | 335 /** |
| 337 * @param {!CanvasRenderingContext2D} context | |
| 338 */ | |
| 339 _drawDividers: function(context) | |
| 340 { | |
| 341 context.save(); | |
| 342 /** @const */ | |
| 343 var minGridSlicePx = 64; // minimal distance between grid lines. | |
| 344 | |
| 345 var drawableWidth = this._offsetWidth - this._leftPadding; | |
| 346 var timelineDuration = this._timelineDuration(); | |
| 347 var dividersCount = drawableWidth / minGridSlicePx; | |
| 348 var gridSliceTime = timelineDuration / dividersCount; | |
| 349 var pixelsPerTime = drawableWidth / timelineDuration; | |
| 350 | |
| 351 // Align gridSliceTime to a nearest round value. | |
| 352 // We allow spans that fit into the formula: span = (1|2|5)x10^n, | |
| 353 // e.g.: ... .1 .2 .5 1 2 5 10 20 50 ... | |
| 354 // After a span has been chosen make grid lines at multiples of the span . | |
| 355 | |
| 356 var logGridSliceTime = Math.ceil(Math.log(gridSliceTime) / Math.LN10); | |
| 357 gridSliceTime = Math.pow(10, logGridSliceTime); | |
| 358 if (gridSliceTime * pixelsPerTime >= 5 * minGridSlicePx) | |
| 359 gridSliceTime = gridSliceTime / 5; | |
| 360 if (gridSliceTime * pixelsPerTime >= 2 * minGridSlicePx) | |
| 361 gridSliceTime = gridSliceTime / 2; | |
| 362 | |
| 363 context.lineWidth = 1; | |
| 364 context.strokeStyle = "rgba(0, 0, 0, .1)"; | |
| 365 context.font = this._fontSize + "px sans-serif"; | |
| 366 context.fillStyle = "#444"; | |
| 367 gridSliceTime = gridSliceTime; | |
| 368 for (var position = gridSliceTime * pixelsPerTime; position < drawableWi dth; position += gridSliceTime * pixelsPerTime) { | |
| 369 // Added .5 because canvas drawing points are between pixels. | |
| 370 var drawPosition = Math.floor(position) + this._leftPadding + .5; | |
| 371 context.beginPath(); | |
| 372 context.moveTo(drawPosition, 0); | |
| 373 context.lineTo(drawPosition, this._offsetHeight); | |
| 374 context.stroke(); | |
| 375 if (position <= gridSliceTime * pixelsPerTime) | |
| 376 continue; | |
| 377 var textData = Number.secondsToString(position / pixelsPerTime); | |
| 378 context.fillText(textData, drawPosition - context.measureText(textDa ta).width - 2, Math.floor(this._headerHeight - this._fontSize / 2)); | |
| 379 } | |
| 380 context.restore(); | |
| 381 }, | |
| 382 | |
| 383 /** | |
| 384 * @return {number} | 336 * @return {number} |
| 385 */ | 337 */ |
| 386 _timelineDuration: function() | 338 _timelineDuration: function() |
| 387 { | 339 { |
| 388 return this._calculator.maximumBoundary() - this._calculator.minimumBoun dary(); | 340 return this._calculator.maximumBoundary() - this._calculator.minimumBoun dary(); |
| 389 }, | 341 }, |
| 390 | 342 |
| 391 /** | 343 /** |
| 392 * @param {!WebInspector.RequestTimeRangeNames=} type | 344 * @param {!WebInspector.RequestTimeRangeNames=} type |
| 393 * @return {number} | 345 * @return {number} |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 color = this._rowNavigationRequestColor; | 563 color = this._rowNavigationRequestColor; |
| 612 | 564 |
| 613 context.fillStyle = color; | 565 context.fillStyle = color; |
| 614 context.rect(0, y, this._offsetWidth, this._rowHeight); | 566 context.rect(0, y, this._offsetWidth, this._rowHeight); |
| 615 context.fill(); | 567 context.fill(); |
| 616 context.restore(); | 568 context.restore(); |
| 617 }, | 569 }, |
| 618 | 570 |
| 619 __proto__: WebInspector.VBox.prototype | 571 __proto__: WebInspector.VBox.prototype |
| 620 }; | 572 }; |
| OLD | NEW |