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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
467 | 467 |
468 onResize: function() | 468 onResize: function() |
469 { | 469 { |
470 this._scheduleUpdate(); | 470 this._scheduleUpdate(); |
471 }, | 471 }, |
472 | 472 |
473 _scheduleUpdate: function() | 473 _scheduleUpdate: function() |
474 { | 474 { |
475 if (this._updateTimerId) | 475 if (this._updateTimerId) |
476 return; | 476 return; |
477 this._updateTimerId = setTimeout(this.update.bind(this), 10); | 477 this._updateTimerId = requestAnimationFrame(this.update.bind(this)); |
478 }, | 478 }, |
479 | 479 |
480 update: function() | 480 update: function() |
481 { | 481 { |
482 this._updateTimerId = 0; | 482 this._updateTimerId = 0; |
483 var timelineData = this._timelineData(); | 483 var timelineData = this._timelineData(); |
484 if (!timelineData) | 484 if (!timelineData) |
485 return; | 485 return; |
486 this._resetCanvas(this._overviewContainer.clientWidth, this._overviewCon tainer.clientHeight - WebInspector.FlameChart.DividersBarHeight); | 486 this._resetCanvas(this._overviewContainer.clientWidth, this._overviewCon tainer.clientHeight - WebInspector.FlameChart.DividersBarHeight); |
487 this._overviewCalculator._updateBoundaries(this); | 487 this._overviewCalculator._updateBoundaries(this); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 this._windowRight = 1.0; | 606 this._windowRight = 1.0; |
607 this._windowWidth = 1.0; | 607 this._windowWidth = 1.0; |
608 this._timeWindowLeft = 0; | 608 this._timeWindowLeft = 0; |
609 this._timeWindowRight = Infinity; | 609 this._timeWindowRight = Infinity; |
610 this._barHeight = dataProvider.barHeight(); | 610 this._barHeight = dataProvider.barHeight(); |
611 this._barHeightDelta = this._isTopDown ? -this._barHeight : this._barHeight; | 611 this._barHeightDelta = this._isTopDown ? -this._barHeight : this._barHeight; |
612 this._minWidth = 1; | 612 this._minWidth = 1; |
613 this._paddingLeft = 15; | 613 this._paddingLeft = 15; |
614 this._highlightedEntryIndex = -1; | 614 this._highlightedEntryIndex = -1; |
615 this._selectedEntryIndex = -1; | 615 this._selectedEntryIndex = -1; |
616 this._textWidth = {}; | |
616 } | 617 } |
617 | 618 |
618 WebInspector.FlameChart.MainPane.prototype = { | 619 WebInspector.FlameChart.MainPane.prototype = { |
619 /** | 620 /** |
620 * @return {?WebInspector.FlameChart.TimelineData} | 621 * @return {?WebInspector.FlameChart.TimelineData} |
621 */ | 622 */ |
622 _timelineData: function() | 623 _timelineData: function() |
623 { | 624 { |
624 return this._dataProvider.timelineData(); | 625 return this._dataProvider.timelineData(); |
625 }, | 626 }, |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
817 var timeToPixel = this._timeToPixel; | 818 var timeToPixel = this._timeToPixel; |
818 var pixelWindowLeft = this._pixelWindowLeft; | 819 var pixelWindowLeft = this._pixelWindowLeft; |
819 var paddingLeft = this._paddingLeft; | 820 var paddingLeft = this._paddingLeft; |
820 var minWidth = this._minWidth; | 821 var minWidth = this._minWidth; |
821 var entryTotalTimes = timelineData.entryTotalTimes; | 822 var entryTotalTimes = timelineData.entryTotalTimes; |
822 var entryOffsets = timelineData.entryOffsets; | 823 var entryOffsets = timelineData.entryOffsets; |
823 var entryLevels = timelineData.entryLevels; | 824 var entryLevels = timelineData.entryLevels; |
824 | 825 |
825 var titleIndexes = new Uint32Array(timelineData.entryTotalTimes); | 826 var titleIndexes = new Uint32Array(timelineData.entryTotalTimes); |
826 var lastTitleIndex = 0; | 827 var lastTitleIndex = 0; |
827 var dotsWidth = context.measureText("\u2026").width; | |
828 var textPadding = this._dataProvider.textPadding(); | 828 var textPadding = this._dataProvider.textPadding(); |
829 this._minTextWidth = context.measureText("\u2026").width + 2 * textPaddi ng; | 829 var dotsWidth = this._measureWidth(context, "\u2026"); |
830 this._minTextWidth = 2 * textPadding + dotsWidth; | |
830 var minTextWidth = this._minTextWidth; | 831 var minTextWidth = this._minTextWidth; |
831 | 832 |
832 var lastDrawOffset = new Int32Array(this._dataProvider.maxStackDepth()); | 833 var lastDrawOffset = new Int32Array(this._dataProvider.maxStackDepth()); |
833 for (var i = 0; i < lastDrawOffset.length; ++i) | 834 for (var i = 0; i < lastDrawOffset.length; ++i) |
834 lastDrawOffset[i] = -1; | 835 lastDrawOffset[i] = -1; |
835 | 836 |
836 var barX = 0; | 837 var barX = 0; |
837 var barY = 0; | 838 var barY = 0; |
838 var barWidth = 0; | 839 var barWidth = 0; |
839 var barRight = 0; | 840 var barRight = 0; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 barLevel = entryLevels[entryIndex]; | 913 barLevel = entryLevels[entryIndex]; |
913 barY = this._levelToHeight(barLevel); | 914 barY = this._levelToHeight(barLevel); |
914 context.rect(barX, barY, barWidth, this._barHeight); | 915 context.rect(barX, barY, barWidth, this._barHeight); |
915 if (barWidth > minTextWidth) | 916 if (barWidth > minTextWidth) |
916 titleIndexes[lastTitleIndex++] = entryIndex; | 917 titleIndexes[lastTitleIndex++] = entryIndex; |
917 } | 918 } |
918 context.fill(); | 919 context.fill(); |
919 } | 920 } |
920 | 921 |
921 context.textBaseline = "alphabetic"; | 922 context.textBaseline = "alphabetic"; |
922 context.fillStyle = "#333"; | |
923 this._dotsWidth = context.measureText("\u2026").width; | |
924 | 923 |
925 for (i = 0; i < lastTitleIndex; ++i) { | 924 for (i = 0; i < lastTitleIndex; ++i) { |
926 entryIndex = titleIndexes[i]; | 925 entryIndex = titleIndexes[i]; |
927 text = this._dataProvider.entryTitle(entryIndex); | 926 text = this._dataProvider.entryTitle(entryIndex); |
928 if (!text || !text.length) | 927 if (!text || !text.length) |
929 continue; | 928 continue; |
930 font = this._dataProvider.entryFont(entryIndex); | 929 font = this._dataProvider.entryFont(entryIndex); |
931 entryOffset = entryOffsets[entryIndex]; | 930 entryOffset = entryOffsets[entryIndex]; |
932 barX = this._offsetToPosition(entryOffset); | 931 barX = this._offsetToPosition(entryOffset); |
933 barRight = this._offsetToPosition(entryOffset + entryTotalTimes[entr yIndex]); | 932 barRight = this._offsetToPosition(entryOffset + entryTotalTimes[entr yIndex]); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
998 titleCell.textContent = entryInfo[i].title; | 997 titleCell.textContent = entryInfo[i].title; |
999 titleCell.className = "title"; | 998 titleCell.className = "title"; |
1000 var textCell = row.createChild("td"); | 999 var textCell = row.createChild("td"); |
1001 textCell.textContent = entryInfo[i].text; | 1000 textCell.textContent = entryInfo[i].text; |
1002 } | 1001 } |
1003 return infoTable; | 1002 return infoTable; |
1004 }, | 1003 }, |
1005 | 1004 |
1006 _prepareText: function(context, title, maxSize) | 1005 _prepareText: function(context, title, maxSize) |
1007 { | 1006 { |
1008 if (maxSize < this._dotsWidth) | 1007 var titleWidth = this._measureWidth(context, title); |
1009 return null; | |
1010 var titleWidth = context.measureText(title).width; | |
1011 if (maxSize > titleWidth) | 1008 if (maxSize > titleWidth) |
1012 return title; | 1009 return title; |
1013 maxSize -= this._dotsWidth; | 1010 maxSize -= this._measureWidth(context, "\u2026"); |
1014 var dotRegExp=/[\.\$]/g; | 1011 var dotRegExp=/[\.\$]/g; |
1015 var match = dotRegExp.exec(title); | 1012 var match = dotRegExp.exec(title); |
1016 if (!match) { | 1013 if (!match) { |
1017 var visiblePartSize = maxSize / titleWidth; | 1014 var visiblePartSize = maxSize / titleWidth; |
1018 var newTextLength = Math.floor(title.length * visiblePartSize) + 1; | 1015 var newTextLength = Math.floor(title.length * visiblePartSize) + 1; |
1019 var minTextLength = 4; | 1016 var minTextLength = 2; |
1020 if (newTextLength < minTextLength) | 1017 if (newTextLength < minTextLength) |
1021 return null; | 1018 return null; |
1022 var substring; | 1019 var substring; |
1023 do { | 1020 do { |
1024 --newTextLength; | 1021 --newTextLength; |
1025 substring = title.substring(0, newTextLength); | 1022 substring = title.substring(0, newTextLength); |
1026 } while (context.measureText(substring).width > maxSize); | 1023 } while (this._measureWidth(context, substring).width > maxSize); |
1027 return title.substring(0, newTextLength) + "\u2026"; | 1024 return title.substring(0, newTextLength) + "\u2026"; |
1028 } | 1025 } |
1029 while (match) { | 1026 while (match) { |
1030 var substring = title.substring(match.index + 1); | 1027 var substring = title.substring(match.index + 1); |
1031 var width = context.measureText(substring).width; | 1028 var width = this._measureWidth(context, substring).width; |
1032 if (maxSize > width) | 1029 if (maxSize > width) |
1033 return "\u2026" + substring; | 1030 return "\u2026" + substring; |
1034 match = dotRegExp.exec(title); | 1031 match = dotRegExp.exec(title); |
1035 } | 1032 } |
1036 var i = 0; | 1033 var i = 0; |
1037 do { | 1034 do { |
1038 ++i; | 1035 ++i; |
1039 } while (context.measureText(title.substring(0, i)).width < maxSize); | 1036 } while (this._measureWidth(context, title.substring(0, i)).width < maxS ize); |
1040 return title.substring(0, i - 1) + "\u2026"; | 1037 return title.substring(0, i - 1) + "\u2026"; |
1041 }, | 1038 }, |
1042 | 1039 |
1040 /** | |
1041 * @param {!CanvasRenderingContext2D} context | |
1042 * @param {string} text | |
1043 * @return {number} | |
1044 */ | |
1045 _measureWidth: function(context, text) | |
1046 { | |
1047 if (text.length > 20) | |
1048 return context.measureText(text).width; | |
1049 | |
1050 var width = this._textWidth[text]; | |
1051 if (!width) { | |
1052 width = context.measureText(text).width; | |
1053 this._textWidth[text] = width; | |
1054 } | |
1055 return width; | |
1056 }, | |
1057 | |
1043 _updateBoundaries: function() | 1058 _updateBoundaries: function() |
1044 { | 1059 { |
1045 this._totalTime = this._dataProvider.totalTime(); | 1060 this._totalTime = this._dataProvider.totalTime(); |
1046 this._zeroTime = this._dataProvider.zeroTime(); | 1061 this._zeroTime = this._dataProvider.zeroTime(); |
1047 if (this._timeBasedWindow) { | 1062 if (this._timeBasedWindow) { |
1048 if (this._timeWindowRight !== Infinity) { | 1063 if (this._timeWindowRight !== Infinity) { |
1049 this._windowLeft = (this._timeWindowLeft - this._zeroTime) / thi s._totalTime; | 1064 this._windowLeft = (this._timeWindowLeft - this._zeroTime) / thi s._totalTime; |
1050 this._windowRight = (this._timeWindowRight - this._zeroTime) / t his._totalTime; | 1065 this._windowRight = (this._timeWindowRight - this._zeroTime) / t his._totalTime; |
1051 this._windowWidth = this._windowRight - this._windowLeft; | 1066 this._windowWidth = this._windowRight - this._windowLeft; |
1052 } else { | 1067 } else { |
1053 this._windowLeft = 0; | 1068 this._windowLeft = 0; |
1054 this._windowRight = 1; | 1069 this._windowRight = 1; |
1055 this._windowWidth = 1; | 1070 this._windowWidth = 1; |
1056 } | 1071 } |
1057 } else { | 1072 } else { |
1058 this._timeWindowLeft = this._windowLeft * this._totalTime; | 1073 this._timeWindowLeft = this._windowLeft * this._totalTime; |
1059 this._timeWindowRight = this._windowRight * this._totalTime; | 1074 this._timeWindowRight = this._windowRight * this._totalTime; |
1060 } | 1075 } |
1061 | 1076 |
1062 this._pixelWindowWidth = this.element.clientWidth - this._paddingLeft; | 1077 this._pixelWindowWidth = this._offsetWidth - this._paddingLeft; |
1063 this._totalPixels = Math.floor(this._pixelWindowWidth / this._windowWidt h); | 1078 this._totalPixels = Math.floor(this._pixelWindowWidth / this._windowWidt h); |
1064 this._pixelWindowLeft = Math.floor(this._totalPixels * this._windowLeft) ; | 1079 this._pixelWindowLeft = Math.floor(this._totalPixels * this._windowLeft) ; |
1065 this._pixelWindowRight = Math.floor(this._totalPixels * this._windowRigh t); | 1080 this._pixelWindowRight = Math.floor(this._totalPixels * this._windowRigh t); |
1066 | 1081 |
1067 this._timeToPixel = this._totalPixels / this._totalTime; | 1082 this._timeToPixel = this._totalPixels / this._totalTime; |
1068 this._pixelToTime = this._totalTime / this._totalPixels; | 1083 this._pixelToTime = this._totalTime / this._totalPixels; |
1069 this._paddingLeftTime = this._paddingLeft / this._timeToPixel; | 1084 this._paddingLeftTime = this._paddingLeft / this._timeToPixel; |
1070 }, | 1085 }, |
1071 | 1086 |
1072 onResize: function() | 1087 onResize: function() |
1073 { | 1088 { |
1089 this._offsetWidth = this.element.offsetWidth; | |
aandrey
2014/03/06 12:26:23
FYI, seems like this also can be delayed until the
| |
1090 this._offsetHeight = this.element.offsetHeight; | |
1074 this._scheduleUpdate(); | 1091 this._scheduleUpdate(); |
1075 }, | 1092 }, |
1076 | 1093 |
1077 _scheduleUpdate: function() | 1094 _scheduleUpdate: function() |
1078 { | 1095 { |
1079 if (this._updateTimerId) | 1096 if (this._updateTimerId) |
1080 return; | 1097 return; |
1081 this._updateTimerId = setTimeout(this.update.bind(this), 10); | 1098 this._updateTimerId = requestAnimationFrame(this.update.bind(this)); |
1082 }, | 1099 }, |
1083 | 1100 |
1084 update: function() | 1101 update: function() |
1085 { | 1102 { |
1086 this._updateTimerId = 0; | 1103 this._updateTimerId = 0; |
1087 if (!this._timelineData()) { | 1104 if (!this._timelineData()) { |
1088 this._timelineGrid.hideDividers(); | 1105 this._timelineGrid.hideDividers(); |
1089 return; | 1106 return; |
1090 } | 1107 } |
1091 this._updateBoundaries(); | 1108 this._updateBoundaries(); |
1092 if (this._timelineData().entryLevels.length) | 1109 if (this._timelineData().entryLevels.length) |
1093 this._timelineGrid.showDividers(); | 1110 this._timelineGrid.showDividers(); |
1094 else | 1111 else |
1095 this._timelineGrid.hideDividers(); | 1112 this._timelineGrid.hideDividers(); |
1096 this.draw(this.element.clientWidth, this.element.clientHeight); | 1113 this.draw(this._offsetWidth, this._offsetHeight); |
1097 this._calculator._updateBoundaries(this); | 1114 this._calculator._updateBoundaries(this); |
1098 this._timelineGrid.element.style.width = this.element.clientWidth; | 1115 this._timelineGrid.element.style.width = this._offsetWidth; |
1099 var offsets = this._dataProvider.dividerOffsets(this._calculator.minimum Boundary(), this._calculator.maximumBoundary()); | 1116 var offsets = this._dataProvider.dividerOffsets(this._calculator.minimum Boundary(), this._calculator.maximumBoundary()); |
1100 this._timelineGrid.updateDividers(this._calculator, offsets, true); | 1117 this._timelineGrid.updateDividers(this._calculator, offsets, true); |
1101 }, | 1118 }, |
1102 | 1119 |
1103 reset: function() | 1120 reset: function() |
1104 { | 1121 { |
1105 this._highlightedEntryIndex = -1; | 1122 this._highlightedEntryIndex = -1; |
1106 this._selectedEntryIndex = -1; | 1123 this._selectedEntryIndex = -1; |
1124 this._textWidth = {}; | |
1107 this.update(); | 1125 this.update(); |
1108 }, | 1126 }, |
1109 | 1127 |
1110 __proto__: WebInspector.View.prototype | 1128 __proto__: WebInspector.View.prototype |
1111 } | 1129 } |
OLD | NEW |