Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /** | 1 /** |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 this._canvas.addEventListener("mousemove", this._onMouseMove.bind(this), fal se); | 61 this._canvas.addEventListener("mousemove", this._onMouseMove.bind(this), fal se); |
| 62 this._canvas.addEventListener("mousewheel", this._onMouseWheel.bind(this), f alse); | 62 this._canvas.addEventListener("mousewheel", this._onMouseWheel.bind(this), f alse); |
| 63 this._canvas.addEventListener("click", this._onClick.bind(this), false); | 63 this._canvas.addEventListener("click", this._onClick.bind(this), false); |
| 64 WebInspector.installDragHandle(this._canvas, this._startCanvasDragging.bind( this), this._canvasDragging.bind(this), this._endCanvasDragging.bind(this), "mov e", null); | 64 WebInspector.installDragHandle(this._canvas, this._startCanvasDragging.bind( this), this._canvasDragging.bind(this), this._endCanvasDragging.bind(this), "mov e", null); |
| 65 | 65 |
| 66 this._vScrollElement = this.element.createChild("div", "flame-chart-v-scroll "); | 66 this._vScrollElement = this.element.createChild("div", "flame-chart-v-scroll "); |
| 67 this._vScrollContent = this._vScrollElement.createChild("div"); | 67 this._vScrollContent = this._vScrollElement.createChild("div"); |
| 68 this._vScrollElement.addEventListener("scroll", this.scheduleUpdate.bind(thi s), false); | 68 this._vScrollElement.addEventListener("scroll", this.scheduleUpdate.bind(thi s), false); |
| 69 | 69 |
| 70 this._entryInfo = this.element.createChild("div", "profile-entry-info"); | 70 this._entryInfo = this.element.createChild("div", "profile-entry-info"); |
| 71 this._markerHighlighElement = this.element.createChild("div", "flame-chart-m arker-highlight-element"); | |
| 71 this._highlightElement = this.element.createChild("div", "flame-chart-highli ght-element"); | 72 this._highlightElement = this.element.createChild("div", "flame-chart-highli ght-element"); |
| 72 this._selectedElement = this.element.createChild("div", "flame-chart-selecte d-element"); | 73 this._selectedElement = this.element.createChild("div", "flame-chart-selecte d-element"); |
| 73 | 74 |
| 74 this._dataProvider = dataProvider; | 75 this._dataProvider = dataProvider; |
| 75 | 76 |
| 76 this._windowLeft = 0.0; | 77 this._windowLeft = 0.0; |
| 77 this._windowRight = 1.0; | 78 this._windowRight = 1.0; |
| 78 this._windowWidth = 1.0; | 79 this._windowWidth = 1.0; |
| 79 this._timeWindowLeft = 0; | 80 this._timeWindowLeft = 0; |
| 80 this._timeWindowRight = Infinity; | 81 this._timeWindowRight = Infinity; |
| 81 this._barHeight = dataProvider.barHeight(); | 82 this._barHeight = dataProvider.barHeight(); |
| 82 this._barHeightDelta = this._isTopDown ? -this._barHeight : this._barHeight; | 83 this._barHeightDelta = this._isTopDown ? -this._barHeight : this._barHeight; |
| 83 this._minWidth = 1; | 84 this._minWidth = 1; |
| 84 this._paddingLeft = this._dataProvider.paddingLeft(); | 85 this._paddingLeft = this._dataProvider.paddingLeft(); |
| 85 this._markerPadding = 2; | 86 this._markerPadding = 2; |
| 86 this._markerRadius = this._barHeight / 2 - this._markerPadding; | 87 this._markerRadius = this._barHeight / 2 - this._markerPadding; |
| 88 this._highlightMarker = null; | |
| 87 this._highlightedEntryIndex = -1; | 89 this._highlightedEntryIndex = -1; |
| 88 this._selectedEntryIndex = -1; | 90 this._selectedEntryIndex = -1; |
| 89 this._textWidth = {}; | 91 this._textWidth = {}; |
| 90 } | 92 } |
| 91 | 93 |
| 92 WebInspector.FlameChart.DividersBarHeight = 20; | 94 WebInspector.FlameChart.DividersBarHeight = 20; |
| 93 | 95 |
| 94 /** | 96 /** |
| 95 * @interface | 97 * @interface |
| 96 */ | 98 */ |
| 97 WebInspector.FlameChartDataProvider = function() | 99 WebInspector.FlameChartDataProvider = function() |
| 98 { | 100 { |
| 99 } | 101 } |
| 100 | 102 |
| 101 /** @typedef {!{ | 103 /** @typedef {!{ |
| 102 entryLevels: (!Array.<number>|!Uint8Array), | 104 entryLevels: (!Array.<number>|!Uint8Array), |
| 103 entryTotalTimes: (!Array.<number>|!Float32Array), | 105 entryTotalTimes: (!Array.<number>|!Float32Array), |
| 104 entryStartTimes: (!Array.<number>|!Float64Array) | 106 entryStartTimes: (!Array.<number>|!Float64Array) |
| 105 }} | 107 }} |
| 106 */ | 108 */ |
| 107 WebInspector.FlameChart.TimelineData; | 109 WebInspector.FlameChart.TimelineData; |
| 108 | 110 |
| 111 /** | |
| 112 * @constructor | |
| 113 * @param {number} timestamp | |
| 114 * @param {string} title | |
| 115 * @param {string} color | |
| 116 */ | |
| 117 WebInspector.FlameChartDataProvider.Marker = function(timestamp, title, color) | |
| 118 { | |
| 119 this.timestamp = timestamp; | |
| 120 this.title = title; | |
| 121 this.color = color; | |
| 122 } | |
| 123 | |
| 109 WebInspector.FlameChartDataProvider.prototype = { | 124 WebInspector.FlameChartDataProvider.prototype = { |
| 110 /** | 125 /** |
| 111 * @return {number} | 126 * @return {number} |
| 112 */ | 127 */ |
| 113 barHeight: function() { }, | 128 barHeight: function() { }, |
| 114 | 129 |
| 115 /** | 130 /** |
| 116 * @param {number} startTime | 131 * @param {number} startTime |
| 117 * @param {number} endTime | 132 * @param {number} endTime |
| 118 * @return {?Array.<number>} | 133 * @return {?Array.<number>} |
| 119 */ | 134 */ |
| 120 dividerOffsets: function(startTime, endTime) { }, | 135 dividerOffsets: function(startTime, endTime) { }, |
| 121 | 136 |
| 122 /** | 137 /** |
| 138 * @param {number} startTime | |
| 139 * @param {number} endTime | |
| 140 * @return {?Array.<!WebInspector.FlameChartDataProvider.Marker>} | |
| 141 */ | |
| 142 timelineMarkers: function(startTime, endTime) { }, | |
| 143 | |
| 144 /** | |
| 123 * @return {number} | 145 * @return {number} |
| 124 */ | 146 */ |
| 125 minimumBoundary: function() { }, | 147 minimumBoundary: function() { }, |
| 126 | 148 |
| 127 /** | 149 /** |
| 128 * @return {number} | 150 * @return {number} |
| 129 */ | 151 */ |
| 130 totalTime: function() { }, | 152 totalTime: function() { }, |
| 131 | 153 |
| 132 /** | 154 /** |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 this._isDragging = false; | 470 this._isDragging = false; |
| 449 }, | 471 }, |
| 450 | 472 |
| 451 /** | 473 /** |
| 452 * @param {!Event} event | 474 * @param {!Event} event |
| 453 */ | 475 */ |
| 454 _onMouseMove: function(event) | 476 _onMouseMove: function(event) |
| 455 { | 477 { |
| 456 if (this._isDragging) | 478 if (this._isDragging) |
| 457 return; | 479 return; |
| 480 | |
| 481 var inDividersBar = event.offsetY < WebInspector.FlameChart.DividersBarH eight; | |
| 482 this._highlightMarker = inDividersBar ? this._markerAtPosition(event.off setX) : null; | |
| 483 this._updateMarkerHighlight(); | |
| 484 if (inDividersBar) | |
| 485 return; | |
| 486 | |
| 458 var entryIndex = this._coordinatesToEntryIndex(event.offsetX, event.offs etY); | 487 var entryIndex = this._coordinatesToEntryIndex(event.offsetX, event.offs etY); |
| 459 | 488 |
| 460 if (this._highlightedEntryIndex === entryIndex) | 489 if (this._highlightedEntryIndex === entryIndex) |
| 461 return; | 490 return; |
| 462 | 491 |
| 463 if (entryIndex === -1 || !this._dataProvider.canJumpToEntry(entryIndex)) | 492 if (entryIndex === -1 || !this._dataProvider.canJumpToEntry(entryIndex)) |
| 464 this._canvas.style.cursor = "default"; | 493 this._canvas.style.cursor = "default"; |
| 465 else | 494 else |
| 466 this._canvas.style.cursor = "pointer"; | 495 this._canvas.style.cursor = "pointer"; |
| 467 | 496 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 592 var entryIndex = entryIndexes[indexOnLevel]; | 621 var entryIndex = entryIndexes[indexOnLevel]; |
| 593 if (checkEntryHit.call(this, entryIndex)) | 622 if (checkEntryHit.call(this, entryIndex)) |
| 594 return entryIndex; | 623 return entryIndex; |
| 595 entryIndex = entryIndexes[indexOnLevel + 1]; | 624 entryIndex = entryIndexes[indexOnLevel + 1]; |
| 596 if (checkEntryHit.call(this, entryIndex)) | 625 if (checkEntryHit.call(this, entryIndex)) |
| 597 return entryIndex; | 626 return entryIndex; |
| 598 return -1; | 627 return -1; |
| 599 }, | 628 }, |
| 600 | 629 |
| 601 /** | 630 /** |
| 631 * @param {number} x | |
| 632 * @return {?WebInspector.FlameChartDataProvider.Marker} | |
| 633 */ | |
| 634 _markerAtPosition: function(x) | |
| 635 { | |
| 636 var markers = this._markers; | |
| 637 if (!markers) | |
| 638 return null; | |
| 639 var accurracyOffset = 1; | |
|
alph
2014/07/21 12:05:30
nit: accuracyOffsetPx
yurys
2014/07/21 13:49:47
Done.
| |
| 640 var time = this._cursorTime(x); | |
| 641 var leftTime = this._cursorTime(x - accurracyOffset); | |
| 642 var rightTime = this._cursorTime(x + accurracyOffset); | |
| 643 | |
| 644 function comparator(time, marker) | |
| 645 { | |
| 646 return time - marker.timestamp; | |
| 647 } | |
| 648 var left = markers.lowerBound(leftTime, comparator); | |
| 649 var right = markers.upperBound(rightTime, comparator); | |
| 650 var marker = null; | |
| 651 var distance = Infinity; | |
| 652 for (var i = left; i < right; i++) { | |
| 653 var nextMarker = markers[i]; | |
| 654 var nextDistance = nextMarker.timestamp - time; | |
|
alph
2014/07/21 12:05:30
abs?
yurys
2014/07/21 13:49:47
Done.
| |
| 655 if (nextDistance < distance) | |
| 656 marker = nextMarker; | |
|
alph
2014/07/21 12:05:30
distance = nextDistance
yurys
2014/07/21 13:49:47
Done.
| |
| 657 } | |
| 658 return marker; | |
| 659 }, | |
| 660 | |
| 661 /** | |
| 602 * @param {number} height | 662 * @param {number} height |
| 603 * @param {number} width | 663 * @param {number} width |
| 604 */ | 664 */ |
| 605 _draw: function(width, height) | 665 _draw: function(width, height) |
| 606 { | 666 { |
| 607 var timelineData = this._timelineData(); | 667 var timelineData = this._timelineData(); |
| 608 if (!timelineData) | 668 if (!timelineData) |
| 609 return; | 669 return; |
| 610 | 670 |
| 611 var context = this._canvas.getContext("2d"); | 671 var context = this._canvas.getContext("2d"); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 740 continue; | 800 continue; |
| 741 | 801 |
| 742 context.fillStyle = this._dataProvider.textColor(entryIndex); | 802 context.fillStyle = this._dataProvider.textColor(entryIndex); |
| 743 context.fillText(text, barX + textPadding, textBaseHeight - barLevel * this._barHeightDelta); | 803 context.fillText(text, barX + textPadding, textBaseHeight - barLevel * this._barHeightDelta); |
| 744 } | 804 } |
| 745 context.restore(); | 805 context.restore(); |
| 746 | 806 |
| 747 var offsets = this._dataProvider.dividerOffsets(this._calculator.minimum Boundary(), this._calculator.maximumBoundary()); | 807 var offsets = this._dataProvider.dividerOffsets(this._calculator.minimum Boundary(), this._calculator.maximumBoundary()); |
| 748 WebInspector.TimelineGrid.drawCanvasGrid(this._canvas, this._calculator, offsets); | 808 WebInspector.TimelineGrid.drawCanvasGrid(this._canvas, this._calculator, offsets); |
| 749 | 809 |
| 810 this._markers = this._dataProvider.timelineMarkers(this._calculator.mini mumBoundary(), this._calculator.maximumBoundary()); | |
| 811 if (this._markers) | |
| 812 WebInspector.TimelineGrid.drawTimelineMarkers(this._canvas, this._ca lculator, this._markers); | |
|
alph
2014/07/21 12:05:30
I'm a bit concerned that FlameChart uses TimelineG
yurys
2014/07/21 13:49:47
Done.
| |
| 813 | |
| 750 this._updateElementPosition(this._highlightElement, this._highlightedEnt ryIndex); | 814 this._updateElementPosition(this._highlightElement, this._highlightedEnt ryIndex); |
| 751 this._updateElementPosition(this._selectedElement, this._selectedEntryIn dex); | 815 this._updateElementPosition(this._selectedElement, this._selectedEntryIn dex); |
| 816 this._updateMarkerHighlight(); | |
| 817 }, | |
| 818 | |
| 819 _updateMarkerHighlight: function() | |
| 820 { | |
| 821 var element = this._markerHighlighElement; | |
| 822 if (element.parentElement) | |
| 823 element.remove(); | |
| 824 var marker = this._highlightMarker; | |
| 825 if (!marker) | |
| 826 return; | |
| 827 var barX = this._timeToPosition(marker.timestamp); | |
| 828 if (barX === this._canvas.width) | |
|
alph
2014/07/21 12:05:30
This comparison looks suspicious. Is it a kinda sp
yurys
2014/07/21 13:49:47
Removed.
| |
| 829 return; | |
| 830 element.title = marker.title; | |
| 831 var style = element.style; | |
| 832 style.left = barX + "px"; | |
| 833 style.backgroundColor = marker.color; | |
| 834 this.element.appendChild(element); | |
| 752 }, | 835 }, |
| 753 | 836 |
| 754 /** | 837 /** |
| 755 * @param {?WebInspector.FlameChart.TimelineData} timelineData | 838 * @param {?WebInspector.FlameChart.TimelineData} timelineData |
| 756 */ | 839 */ |
| 757 _processTimelineData: function(timelineData) | 840 _processTimelineData: function(timelineData) |
| 758 { | 841 { |
| 759 if (!timelineData) { | 842 if (!timelineData) { |
| 760 this._timelineLevels = null; | 843 this._timelineLevels = null; |
| 761 this._rawTimelineData = null; | 844 this._rawTimelineData = null; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 946 if (!this._timelineData()) | 1029 if (!this._timelineData()) |
| 947 return; | 1030 return; |
| 948 this._resetCanvas(); | 1031 this._resetCanvas(); |
| 949 this._updateBoundaries(); | 1032 this._updateBoundaries(); |
| 950 this._calculator._updateBoundaries(this); | 1033 this._calculator._updateBoundaries(this); |
| 951 this._draw(this._offsetWidth, this._offsetHeight); | 1034 this._draw(this._offsetWidth, this._offsetHeight); |
| 952 }, | 1035 }, |
| 953 | 1036 |
| 954 reset: function() | 1037 reset: function() |
| 955 { | 1038 { |
| 1039 this._highlightMarker = null; | |
| 956 this._highlightedEntryIndex = -1; | 1040 this._highlightedEntryIndex = -1; |
| 957 this._selectedEntryIndex = -1; | 1041 this._selectedEntryIndex = -1; |
| 958 this._textWidth = {}; | 1042 this._textWidth = {}; |
| 959 this.update(); | 1043 this.update(); |
| 960 }, | 1044 }, |
| 961 | 1045 |
| 962 __proto__: WebInspector.HBox.prototype | 1046 __proto__: WebInspector.HBox.prototype |
| 963 } | 1047 } |
| OLD | NEW |