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