Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/network/NetworkTimelineColumn.js

Issue 2470273002: [Devtools] Fixed new timeline simplified bars popover hover (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * @unrestricted 5 * @unrestricted
6 */ 6 */
7 WebInspector.NetworkTimelineColumn = class extends WebInspector.VBox { 7 WebInspector.NetworkTimelineColumn = class extends WebInspector.VBox {
8 /** 8 /**
9 * @param {number} rowHeight 9 * @param {number} rowHeight
10 * @param {!WebInspector.NetworkTimeCalculator} calculator 10 * @param {!WebInspector.NetworkTimeCalculator} calculator
11 */ 11 */
12 constructor(rowHeight, calculator) { 12 constructor(rowHeight, calculator) {
13 // TODO(allada) Make this a shadowDOM when the NetworkTimelineColumn gets mo ved into NetworkLogViewColumns. 13 // TODO(allada) Make this a shadowDOM when the NetworkTimelineColumn gets mo ved into NetworkLogViewColumns.
14 super(false); 14 super(false);
15 this.registerRequiredCSS('network/networkTimelineColumn.css'); 15 this.registerRequiredCSS('network/networkTimelineColumn.css');
16 16
17 this._canvas = this.contentElement.createChild('canvas'); 17 this._canvas = this.contentElement.createChild('canvas');
18 this._canvas.tabIndex = 1; 18 this._canvas.tabIndex = 1;
19 this.setDefaultFocusedElement(this._canvas); 19 this.setDefaultFocusedElement(this._canvas);
20 this._canvasPosition = this._canvas.getBoundingClientRect(); 20 this._canvasPosition = this._canvas.getBoundingClientRect();
21 21
22 /** @const */ 22 /** @const */
23 this._leftPadding = 5; 23 this._leftPadding = 5;
24 /** @const */ 24 /** @const */
25 this._fontSize = 10; 25 this._fontSize = 10;
26 /** @const */
27 this._borderOffset = .5;
dgozman 2016/11/03 21:52:43 I'm not sure what the styleguide says, but I prefe
allada 2016/11/03 22:31:22 Done.
26 28
27 this._rightPadding = 0; 29 this._rightPadding = 0;
28 30
29 this._rowHeight = rowHeight; 31 this._rowHeight = rowHeight;
30 this._headerHeight = 0; 32 this._headerHeight = 0;
31 this._calculator = calculator; 33 this._calculator = calculator;
32 34
33 this._popoverHelper = new WebInspector.PopoverHelper(this.element); 35 this._popoverHelper = new WebInspector.PopoverHelper(this.element);
34 this._popoverHelper.initializeCallbacks(this._getPopoverAnchor.bind(this), t his._showPopover.bind(this)); 36 this._popoverHelper.initializeCallbacks(this._getPopoverAnchor.bind(this), t his._showPopover.bind(this));
35 this._popoverHelper.setTimeout(300, 300); 37 this._popoverHelper.setTimeout(300, 300);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 80 }
79 81
80 /** 82 /**
81 * @param {!Element} element 83 * @param {!Element} element
82 * @param {!Event} event 84 * @param {!Event} event
83 * @return {!AnchorBox|undefined} 85 * @return {!AnchorBox|undefined}
84 */ 86 */
85 _getPopoverAnchor(element, event) { 87 _getPopoverAnchor(element, event) {
86 if (!this._hoveredRequest) 88 if (!this._hoveredRequest)
87 return; 89 return;
88 90 var useTimingBars =
89 var range = WebInspector.RequestTimingView.calculateRequestTimeRanges(this._ hoveredRequest, 0) 91 !WebInspector.moduleSetting('networkColorCodeResourceTypes').get() && !t his._calculator.startAtZero;
90 .find(data => data.name === 'total'); 92 if (useTimingBars) {
91 var start = this._timeToPosition(range.start); 93 var range = WebInspector.RequestTimingView.calculateRequestTimeRanges(this ._hoveredRequest, 0)
92 var end = this._timeToPosition(range.end); 94 .find(data => data.name === 'total');
95 var start = this._timeToPosition(range.start);
96 var end = this._timeToPosition(range.end);
97 } else {
98 var range = this._getSimplifiedBarRange(this._hoveredRequest);
99 var start = range.start;
100 var end = range.end;
101 }
93 102
94 if (event.clientX < this._canvasPosition.left + start || event.clientX > thi s._canvasPosition.left + end) 103 if (event.clientX < this._canvasPosition.left + start || event.clientX > thi s._canvasPosition.left + end)
95 return; 104 return;
96 105
97 var rowIndex = this._requestData.findIndex(request => this._hoveredRequest = == request); 106 var rowIndex = this._requestData.findIndex(request => this._hoveredRequest = == request);
98 var barHeight = this._getBarHeight(range.name); 107 var barHeight = this._getBarHeight(range.name);
99 var y = this._headerHeight + (this._rowHeight * rowIndex - this._scrollTop) + ((this._rowHeight - barHeight) / 2); 108 var y = this._headerHeight + (this._rowHeight * rowIndex - this._scrollTop) + ((this._rowHeight - barHeight) / 2);
100 109
101 if (event.clientY < this._canvasPosition.top + y || event.clientY > this._ca nvasPosition.top + y + barHeight) 110 if (event.clientY < this._canvasPosition.top + y || event.clientY > this._ca nvasPosition.top + y + barHeight)
102 return; 111 return;
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 hsla[1] -= Math.min(hsla[1], 0.28); 388 hsla[1] -= Math.min(hsla[1], 0.28);
380 hsla[2] -= Math.min(hsla[2], 0.15); 389 hsla[2] -= Math.min(hsla[2], 0.15);
381 var gradient = context.createLinearGradient(0, 0, 0, this._getBarHeight()); 390 var gradient = context.createLinearGradient(0, 0, 0, this._getBarHeight());
382 gradient.addColorStop(0, color); 391 gradient.addColorStop(0, color);
383 gradient.addColorStop(1, /** @type {string} */ (parsedColor.asString(null))) ; 392 gradient.addColorStop(1, /** @type {string} */ (parsedColor.asString(null))) ;
384 this._colorsForResourceTypeCache.set(color, gradient); 393 this._colorsForResourceTypeCache.set(color, gradient);
385 return gradient; 394 return gradient;
386 } 395 }
387 396
388 /** 397 /**
398 * @param {!WebInspector.NetworkRequest} request
399 * @return {!{start: number, mid: number, end: number}}
400 */
401 _getSimplifiedBarRange(request) {
402 var drawWidth = this._offsetWidth - this._leftPadding;
403 var percentages = this._calculator.computeBarGraphPercentages(request);
404 return {
405 start: this._leftPadding + Math.floor((percentages.start / 100) * drawWidt h) + this._borderOffset,
406 mid: this._leftPadding + Math.floor((percentages.middle / 100) * drawWidth ) + this._borderOffset,
407 end: this._leftPadding + Math.floor((percentages.end / 100) * drawWidth) + this._borderOffset
408 };
409 }
410
411 /**
389 * @param {!CanvasRenderingContext2D} context 412 * @param {!CanvasRenderingContext2D} context
390 * @param {!WebInspector.NetworkRequest} request 413 * @param {!WebInspector.NetworkRequest} request
391 * @param {number} y 414 * @param {number} y
392 */ 415 */
393 _drawSimplifiedBars(context, request, y) { 416 _drawSimplifiedBars(context, request, y) {
394 /** @const */ 417 const borderWidth = 1;
dgozman 2016/11/03 21:52:43 Should this be 2 * this._borderOffset?
allada 2016/11/03 22:31:22 Done.
395 var borderWidth = 1;
396 418
397 context.save(); 419 context.save();
398 var percentages = this._calculator.computeBarGraphPercentages(request); 420 var ranges = this._getSimplifiedBarRange(request);
399 var drawWidth = this._offsetWidth - this._leftPadding;
400 var borderOffset = borderWidth % 2 === 0 ? 0 : .5;
401 var start = this._leftPadding + Math.floor((percentages.start / 100) * drawW idth) + borderOffset;
402 var mid = this._leftPadding + Math.floor((percentages.middle / 100) * drawWi dth) + borderOffset;
403 var end = this._leftPadding + Math.floor((percentages.end / 100) * drawWidth ) + borderOffset;
404 var height = this._getBarHeight(); 421 var height = this._getBarHeight();
405 y += Math.floor(this._rowHeight / 2 - height / 2 + borderWidth) - borderWidt h / 2; 422 y += Math.floor(this._rowHeight / 2 - height / 2 + borderWidth) - borderWidt h / 2;
406 423
407 context.translate(0, y); 424 context.translate(0, y);
408 context.fillStyle = this._colorForResourceType(context, request); 425 context.fillStyle = this._colorForResourceType(context, request);
409 context.strokeStyle = this._borderColorForResourceType(request); 426 context.strokeStyle = this._borderColorForResourceType(request);
410 context.lineWidth = borderWidth; 427 context.lineWidth = borderWidth;
411 428
412 context.beginPath(); 429 context.beginPath();
413 context.globalAlpha = .5; 430 context.globalAlpha = .5;
414 context.rect(start, 0, mid - start, height - borderWidth); 431 context.rect(ranges.start, 0, ranges.mid - ranges.start, height - borderWidt h);
415 context.fill(); 432 context.fill();
416 context.stroke(); 433 context.stroke();
417 434
418 var barWidth = Math.max(2, end - mid); 435 var barWidth = Math.max(2, ranges.end - ranges.mid);
419 context.beginPath(); 436 context.beginPath();
420 context.globalAlpha = 1; 437 context.globalAlpha = 1;
421 context.rect(mid, 0, barWidth, height - borderWidth); 438 context.rect(ranges.mid, 0, barWidth, height - borderWidth);
422 context.fill(); 439 context.fill();
423 context.stroke(); 440 context.stroke();
424 441
425 if (request === this._hoveredRequest) { 442 if (request === this._hoveredRequest) {
426 var labels = this._calculator.computeBarGraphLabels(request); 443 var labels = this._calculator.computeBarGraphLabels(request);
427 this._drawSimplifiedBarDetails(context, labels.left, labels.right, start, mid, mid + barWidth + borderOffset); 444 this._drawSimplifiedBarDetails(context, labels.left, labels.right, ranges. start, ranges.mid, ranges.mid + barWidth + this._borderOffset);
428 } 445 }
429 446
430 context.restore(); 447 context.restore();
431 } 448 }
432 449
433 /** 450 /**
434 * @param {!CanvasRenderingContext2D} context 451 * @param {!CanvasRenderingContext2D} context
435 * @param {string} leftText 452 * @param {string} leftText
436 * @param {string} rightText 453 * @param {string} rightText
437 * @param {number} startX 454 * @param {number} startX
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 font: 'hsl(8, 100%, 80%)', 583 font: 'hsl(8, 100%, 80%)',
567 media: 'hsl(272, 64%, 80%)', 584 media: 'hsl(272, 64%, 80%)',
568 image: 'hsl(272, 64%, 80%)', 585 image: 'hsl(272, 64%, 80%)',
569 script: 'hsl(31, 100%, 80%)', 586 script: 'hsl(31, 100%, 80%)',
570 stylesheet: 'hsl(90, 50%, 80%)', 587 stylesheet: 'hsl(90, 50%, 80%)',
571 texttrack: 'hsl(8, 100%, 80%)', 588 texttrack: 'hsl(8, 100%, 80%)',
572 websocket: 'hsl(0, 0%, 95%)', 589 websocket: 'hsl(0, 0%, 95%)',
573 xhr: 'hsl(53, 100%, 80%)', 590 xhr: 'hsl(53, 100%, 80%)',
574 other: 'hsl(0, 0%, 95%)' 591 other: 'hsl(0, 0%, 95%)'
575 }; 592 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698