()
| 925 | } |
| 926 | |
| 927 | drawSelection() { |
| 928 | let ctx = this.canvas.getContext("2d"); |
| 929 | |
| 930 | // Draw the timeline image. |
| 931 | ctx.drawImage(this.buffer, 0, this.imageOffset); |
| 932 | |
| 933 | // Draw the current interval highlight. |
| 934 | let left; |
| 935 | let right; |
| 936 | if (this.selectionStart !== null && this.selectionEnd !== null) { |
| 937 | ctx.fillStyle = "rgba(0, 0, 0, 0.3)"; |
| 938 | left = Math.min(this.selectionStart, this.selectionEnd); |
| 939 | right = Math.max(this.selectionStart, this.selectionEnd); |
| 940 | let height = this.buffer.height - this.functionTimelineHeight; |
| 941 | ctx.fillRect(0, this.imageOffset, left, height); |
| 942 | ctx.fillRect(right, this.imageOffset, this.buffer.width - right, height); |
| 943 | } else { |
| 944 | left = 0; |
| 945 | right = this.buffer.width; |
| 946 | } |
| 947 | |
| 948 | // Draw the scale text. |
| 949 | let file = this.currentState.file; |
| 950 | ctx.fillStyle = "white"; |
| 951 | ctx.fillRect(0, 0, this.canvas.width, this.imageOffset); |
| 952 | if (file && file.ticks.length > 0) { |
| 953 | let firstTime = file.ticks[0].tm; |
| 954 | let lastTime = file.ticks[file.ticks.length - 1].tm; |
| 955 | |
| 956 | let leftTime = |
| 957 | firstTime + left / this.canvas.width * (lastTime - firstTime); |
| 958 | let rightTime = |
| 959 | firstTime + right / this.canvas.width * (lastTime - firstTime); |
| 960 | |
| 961 | let leftText = (leftTime / 1000000).toFixed(3) + "s"; |
| 962 | let rightText = (rightTime / 1000000).toFixed(3) + "s"; |
| 963 | |
| 964 | ctx.textBaseline = 'top'; |
| 965 | ctx.font = this.fontSize + "px Arial"; |
| 966 | ctx.fillStyle = "black"; |
| 967 | |
| 968 | let leftWidth = ctx.measureText(leftText).width; |
| 969 | let rightWidth = ctx.measureText(rightText).width; |
| 970 | |
| 971 | let leftStart = left - leftWidth / 2; |
| 972 | let rightStart = right - rightWidth / 2; |
| 973 | |
| 974 | if (leftStart < 0) leftStart = 0; |
| 975 | if (rightStart + rightWidth > this.canvas.width) { |
| 976 | rightStart = this.canvas.width - rightWidth; |
| 977 | } |
| 978 | if (leftStart + leftWidth > rightStart) { |
| 979 | if (leftStart > this.canvas.width - (rightStart - rightWidth)) { |
| 980 | rightStart = leftStart + leftWidth; |
| 981 | |
| 982 | } else { |
| 983 | leftStart = rightStart - leftWidth; |
| 984 | } |
no test coverage detected