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 Network.NetworkWaterfallColumn = class extends UI.VBox { | 4 Network.NetworkWaterfallColumn = class extends UI.VBox { |
5 /** | 5 /** |
6 * @param {number} rowHeight | 6 * @param {number} rowHeight |
7 * @param {!Network.NetworkTimeCalculator} calculator | 7 * @param {!Network.NetworkTimeCalculator} calculator |
8 */ | 8 */ |
9 constructor(rowHeight, calculator) { | 9 constructor(rowHeight, calculator) { |
10 // TODO(allada) Make this a shadowDOM when the NetworkWaterfallColumn gets m
oved into NetworkLogViewColumns. | 10 // TODO(allada) Make this a shadowDOM when the NetworkWaterfallColumn gets m
oved into NetworkLogViewColumns. |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 context.beginPath(); | 468 context.beginPath(); |
469 context.fillStyle = fillColor; | 469 context.fillStyle = fillColor; |
470 context.rect(ranges.mid, 0, barWidth, height - borderWidth); | 470 context.rect(ranges.mid, 0, barWidth, height - borderWidth); |
471 context.fill(); | 471 context.fill(); |
472 context.stroke(); | 472 context.stroke(); |
473 | 473 |
474 /** @type {?{left: string, right: string, tooltip: (string|undefined)}} */ | 474 /** @type {?{left: string, right: string, tooltip: (string|undefined)}} */ |
475 var labels = null; | 475 var labels = null; |
476 if (node.hovered()) { | 476 if (node.hovered()) { |
477 labels = this._calculator.computeBarGraphLabels(request); | 477 labels = this._calculator.computeBarGraphLabels(request); |
478 this._drawSimplifiedBarDetails( | 478 // TODO(allada) This will be inlined in an immidate next patch. |
479 context, labels.left, labels.right, ranges.start, ranges.mid, ranges.m
id + barWidth + borderOffset, y); | 479 var leftText = labels.left; |
| 480 var rightText = labels.right; |
| 481 var startX = ranges.start; |
| 482 var midX = ranges.mid; |
| 483 var endX = ranges.mid + barWidth + borderOffset; |
| 484 var currentY = y; |
| 485 |
| 486 var barDotLineLength = 10; |
| 487 context.save(); |
| 488 var leftLabelWidth = context.measureText(leftText).width; |
| 489 var rightLabelWidth = context.measureText(rightText).width; |
| 490 context.fillStyle = UI.themeSupport.patchColor('#888', UI.ThemeSupport.Col
orUsage.Foreground); |
| 491 context.strokeStyle = UI.themeSupport.patchColor('#888', UI.ThemeSupport.C
olorUsage.Foreground); |
| 492 if (leftLabelWidth < midX - startX) { |
| 493 var midBarX = startX + (midX - startX) / 2 - leftLabelWidth / 2; |
| 494 this._textLayers.push({text: leftText, x: midBarX, y: currentY + this._f
ontSize}); |
| 495 } else if (barDotLineLength + leftLabelWidth + this._leftPadding < startX)
{ |
| 496 this._textLayers.push( |
| 497 {text: leftText, x: startX - leftLabelWidth - barDotLineLength - 1,
y: currentY + this._fontSize}); |
| 498 context.beginPath(); |
| 499 context.arc(startX, Math.floor(height / 2), 2, 0, 2 * Math.PI); |
| 500 context.fill(); |
| 501 context.beginPath(); |
| 502 context.lineWidth = 1; |
| 503 context.moveTo(startX - barDotLineLength, Math.floor(height / 2)); |
| 504 context.lineTo(startX, Math.floor(height / 2)); |
| 505 context.stroke(); |
| 506 } |
| 507 |
| 508 if (rightLabelWidth < endX - midX) { |
| 509 var midBarX = midX + (endX - midX) / 2 - rightLabelWidth / 2; |
| 510 this._textLayers.push({text: rightText, x: midBarX, y: currentY + this._
fontSize}); |
| 511 } else if (endX + barDotLineLength + rightLabelWidth < this._offsetWidth -
this._leftPadding) { |
| 512 this._textLayers.push({text: rightText, x: endX + barDotLineLength + 1,
y: currentY + this._fontSize}); |
| 513 context.beginPath(); |
| 514 context.arc(endX, Math.floor(height / 2), 2, 0, 2 * Math.PI); |
| 515 context.fill(); |
| 516 context.beginPath(); |
| 517 context.lineWidth = 1; |
| 518 context.moveTo(endX, Math.floor(height / 2)); |
| 519 context.lineTo(endX + barDotLineLength, Math.floor(height / 2)); |
| 520 context.stroke(); |
| 521 } |
| 522 context.restore(); |
480 } | 523 } |
481 | 524 |
482 if (!this._calculator.startAtZero) { | 525 if (!this._calculator.startAtZero) { |
483 var queueingRange = Network.RequestTimingView.calculateRequestTimeRanges(r
equest, 0) | 526 var queueingRange = Network.RequestTimingView.calculateRequestTimeRanges(r
equest, 0) |
484 .find(data => data.name === Network.RequestTimeRan
geNames.Total); | 527 .find(data => data.name === Network.RequestTimeRan
geNames.Total); |
485 var leftLabelWidth = labels ? context.measureText(labels.left).width : 0; | 528 var leftLabelWidth = labels ? context.measureText(labels.left).width : 0; |
486 var leftTextPlacedInBar = leftLabelWidth < ranges.mid - ranges.start; | 529 var leftTextPlacedInBar = leftLabelWidth < ranges.mid - ranges.start; |
487 const wiskerTextPadding = 13; | 530 const wiskerTextPadding = 13; |
488 var textOffset = (labels && !leftTextPlacedInBar) ? leftLabelWidth + wiske
rTextPadding : 0; | 531 var textOffset = (labels && !leftTextPlacedInBar) ? leftLabelWidth + wiske
rTextPadding : 0; |
489 var queueingStart = this._timeToPosition(queueingRange.start); | 532 var queueingStart = this._timeToPosition(queueingRange.start); |
490 if (ranges.start - textOffset > queueingStart) { | 533 if (ranges.start - textOffset > queueingStart) { |
491 context.beginPath(); | 534 context.beginPath(); |
492 context.globalAlpha = 1; | 535 context.globalAlpha = 1; |
493 context.strokeStyle = UI.themeSupport.patchColor('#a5a5a5', UI.ThemeSupp
ort.ColorUsage.Foreground); | 536 context.strokeStyle = UI.themeSupport.patchColor('#a5a5a5', UI.ThemeSupp
ort.ColorUsage.Foreground); |
494 context.moveTo(queueingStart, Math.floor(height / 2)); | 537 context.moveTo(queueingStart, Math.floor(height / 2)); |
495 context.lineTo(ranges.start - textOffset, Math.floor(height / 2)); | 538 context.lineTo(ranges.start - textOffset, Math.floor(height / 2)); |
496 | 539 |
497 const wiskerHeight = height / 2; | 540 const wiskerHeight = height / 2; |
498 context.moveTo(queueingStart + borderOffset, wiskerHeight / 2); | 541 context.moveTo(queueingStart + borderOffset, wiskerHeight / 2); |
499 context.lineTo(queueingStart + borderOffset, height - wiskerHeight / 2 -
1); | 542 context.lineTo(queueingStart + borderOffset, height - wiskerHeight / 2 -
1); |
500 context.stroke(); | 543 context.stroke(); |
501 } | 544 } |
502 } | 545 } |
503 | 546 |
504 context.restore(); | 547 context.restore(); |
505 } | 548 } |
506 | 549 |
507 /** | 550 /** |
508 * @param {!CanvasRenderingContext2D} context | 551 * @param {!CanvasRenderingContext2D} context |
509 * @param {string} leftText | |
510 * @param {string} rightText | |
511 * @param {number} startX | |
512 * @param {number} midX | |
513 * @param {number} endX | |
514 * @param {number} currentY | |
515 */ | |
516 _drawSimplifiedBarDetails(context, leftText, rightText, startX, midX, endX, cu
rrentY) { | |
517 /** @const */ | |
518 var barDotLineLength = 10; | |
519 | |
520 context.save(); | |
521 var height = this._getBarHeight(); | |
522 var leftLabelWidth = context.measureText(leftText).width; | |
523 var rightLabelWidth = context.measureText(rightText).width; | |
524 context.fillStyle = UI.themeSupport.patchColor('#888', UI.ThemeSupport.Color
Usage.Foreground); | |
525 context.strokeStyle = UI.themeSupport.patchColor('#888', UI.ThemeSupport.Col
orUsage.Foreground); | |
526 if (leftLabelWidth < midX - startX) { | |
527 var midBarX = startX + (midX - startX) / 2 - leftLabelWidth / 2; | |
528 this._textLayers.push({text: leftText, x: midBarX, y: currentY + this._fon
tSize}); | |
529 } else if (barDotLineLength + leftLabelWidth + this._leftPadding < startX) { | |
530 this._textLayers.push( | |
531 {text: leftText, x: startX - leftLabelWidth - barDotLineLength - 1, y:
currentY + this._fontSize}); | |
532 context.beginPath(); | |
533 context.arc(startX, Math.floor(height / 2), 2, 0, 2 * Math.PI); | |
534 context.fill(); | |
535 context.beginPath(); | |
536 context.lineWidth = 1; | |
537 context.moveTo(startX - barDotLineLength, Math.floor(height / 2)); | |
538 context.lineTo(startX, Math.floor(height / 2)); | |
539 context.stroke(); | |
540 } | |
541 | |
542 if (rightLabelWidth < endX - midX) { | |
543 var midBarX = midX + (endX - midX) / 2 - rightLabelWidth / 2; | |
544 this._textLayers.push({text: rightText, x: midBarX, y: currentY + this._fo
ntSize}); | |
545 } else if (endX + barDotLineLength + rightLabelWidth < this._offsetWidth - t
his._leftPadding) { | |
546 this._textLayers.push({text: rightText, x: endX + barDotLineLength + 1, y:
currentY + this._fontSize}); | |
547 context.beginPath(); | |
548 context.arc(endX, Math.floor(height / 2), 2, 0, 2 * Math.PI); | |
549 context.fill(); | |
550 context.beginPath(); | |
551 context.lineWidth = 1; | |
552 context.moveTo(endX, Math.floor(height / 2)); | |
553 context.lineTo(endX + barDotLineLength, Math.floor(height / 2)); | |
554 context.stroke(); | |
555 } | |
556 context.restore(); | |
557 } | |
558 | |
559 /** | |
560 * @param {!CanvasRenderingContext2D} context | |
561 * @param {!Network.NetworkNode} node | 552 * @param {!Network.NetworkNode} node |
562 * @param {number} y | 553 * @param {number} y |
563 */ | 554 */ |
564 _drawTimingBars(context, node, y) { | 555 _drawTimingBars(context, node, y) { |
565 var request = node.request(); | 556 var request = node.request(); |
566 if (!request) | 557 if (!request) |
567 return; | 558 return; |
568 context.save(); | 559 context.save(); |
569 var ranges = Network.RequestTimingView.calculateRequestTimeRanges(request, 0
); | 560 var ranges = Network.RequestTimingView.calculateRequestTimeRanges(request, 0
); |
570 for (var range of ranges) { | 561 for (var range of ranges) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 script: 'hsl(31, 100%, 80%)', | 638 script: 'hsl(31, 100%, 80%)', |
648 stylesheet: 'hsl(272, 64%, 80%)', | 639 stylesheet: 'hsl(272, 64%, 80%)', |
649 texttrack: 'hsl(8, 100%, 80%)', | 640 texttrack: 'hsl(8, 100%, 80%)', |
650 websocket: 'hsl(0, 0%, 95%)', | 641 websocket: 'hsl(0, 0%, 95%)', |
651 xhr: 'hsl(53, 100%, 80%)', | 642 xhr: 'hsl(53, 100%, 80%)', |
652 other: 'hsl(0, 0%, 95%)' | 643 other: 'hsl(0, 0%, 95%)' |
653 }; | 644 }; |
654 | 645 |
655 /** @typedef {!{x: number, y: number, text: string}} */ | 646 /** @typedef {!{x: number, y: number, text: string}} */ |
656 Network.NetworkWaterfallColumn._TextLayer; | 647 Network.NetworkWaterfallColumn._TextLayer; |
OLD | NEW |