Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following disclaimer |
| 12 | * in the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * * Neither the name of Google Inc. nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived from |
| 16 | * this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Tim van der Lippe | bb76917 | 2020-02-12 15:32:44 | [diff] [blame] | 31 | import * as Common from '../common/common.js'; |
| 32 | import * as Host from '../host/host.js'; |
Jack Franklin | 1be909c | 2020-03-04 08:57:41 | [diff] [blame] | 33 | import * as Platform from '../platform/platform.js'; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 34 | import * as Root from '../root/root.js'; |
Paul Lewis | ead4575 | 2020-06-23 09:51:36 | [diff] [blame] | 35 | import * as SDK from '../sdk/sdk.js'; // eslint-disable-line no-unused-vars |
Paul Lewis | ca569a5 | 2020-09-09 16:11:51 | [diff] [blame] | 36 | import * as ThemeSupport from '../theme_support/theme_support.js'; |
Tim van der Lippe | dfbb48f | 2020-11-19 14:49:15 | [diff] [blame] | 37 | import * as TimelineModel from '../timeline_model/timeline_model.js'; // eslint-disable-line no-unused-vars |
Tim van der Lippe | bb76917 | 2020-02-12 15:32:44 | [diff] [blame] | 38 | import * as UI from '../ui/ui.js'; |
| 39 | |
Paul Lewis | 2cfa94e | 2020-01-13 10:30:15 | [diff] [blame] | 40 | import {ChartViewport, ChartViewportDelegate} from './ChartViewport.js'; // eslint-disable-line no-unused-vars |
| 41 | import {Calculator, TimelineGrid} from './TimelineGrid.js'; // eslint-disable-line no-unused-vars |
| 42 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 43 | /** |
| 44 | * @interface |
| 45 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 46 | export class FlameChartDelegate { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 47 | /** |
| 48 | * @param {number} startTime |
| 49 | * @param {number} endTime |
| 50 | * @param {boolean} animate |
| 51 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 52 | windowChanged(startTime, endTime, animate) { |
| 53 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * @param {number} startTime |
| 57 | * @param {number} endTime |
| 58 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 59 | updateRangeSelection(startTime, endTime) { |
| 60 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 61 | |
| 62 | /** |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 63 | * @param {!FlameChart} flameChart |
Tim van der Lippe | 8ef250c | 2020-02-20 16:29:25 | [diff] [blame] | 64 | * @param {?Group} group |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 65 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 66 | updateSelectedGroup(flameChart, group) { |
| 67 | } |
| 68 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 69 | |
| 70 | /** |
Paul Lewis | 2cfa94e | 2020-01-13 10:30:15 | [diff] [blame] | 71 | * @implements {Calculator} |
| 72 | * @implements {ChartViewportDelegate} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 73 | */ |
Tim van der Lippe | bb76917 | 2020-02-12 15:32:44 | [diff] [blame] | 74 | export class FlameChart extends UI.Widget.VBox { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 75 | /** |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 76 | * @param {!FlameChartDataProvider} dataProvider |
| 77 | * @param {!FlameChartDelegate} flameChartDelegate |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 78 | * @param {!Common.Settings.Setting<?>=} groupExpansionSetting |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 79 | */ |
| 80 | constructor(dataProvider, flameChartDelegate, groupExpansionSetting) { |
| 81 | super(true); |
Jack Franklin | 71519f8 | 2020-11-03 12:08:59 | [diff] [blame] | 82 | this.registerRequiredCSS('perf_ui/flameChart.css', {enableLegacyPatching: true}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 83 | this.contentElement.classList.add('flame-chart-main-pane'); |
| 84 | this._groupExpansionSetting = groupExpansionSetting; |
| 85 | this._groupExpansionState = groupExpansionSetting && groupExpansionSetting.get() || {}; |
| 86 | this._flameChartDelegate = flameChartDelegate; |
| 87 | |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 88 | this._useWebGL = Root.Runtime.experiments.isEnabled('timelineWebGL'); |
Paul Lewis | 2cfa94e | 2020-01-13 10:30:15 | [diff] [blame] | 89 | this._chartViewport = new ChartViewport(this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 90 | this._chartViewport.show(this.contentElement); |
| 91 | |
| 92 | this._dataProvider = dataProvider; |
| 93 | |
Paul Lewis | 49b1682 | 2020-02-21 14:22:03 | [diff] [blame] | 94 | this._candyStripeCanvas = /** @type {!HTMLCanvasElement} */ (document.createElement('canvas')); |
| 95 | this._createCandyStripePattern(); |
| 96 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 97 | this._viewportElement = this._chartViewport.viewportElement; |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 98 | if (this._useWebGL) { |
| 99 | this._canvasGL = /** @type {!HTMLCanvasElement} */ (this._viewportElement.createChild('canvas', 'fill')); |
| 100 | this._initWebGL(); |
| 101 | } |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 102 | /** @type {!HTMLCanvasElement} */ |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 103 | this._canvas = /** @type {!HTMLCanvasElement} */ (this._viewportElement.createChild('canvas', 'fill')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 104 | |
Joel Einbinder | 83fc76e | 2018-06-11 23:19:47 | [diff] [blame] | 105 | this._canvas.tabIndex = 0; |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 106 | UI.ARIAUtils.setAccessibleName(this._canvas, ls`Flame Chart`); |
| 107 | UI.ARIAUtils.markAsTree(this._canvas); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 108 | this.setDefaultFocusedElement(this._canvas); |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 109 | this._canvas.classList.add('flame-chart-canvas'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 110 | this._canvas.addEventListener('mousemove', this._onMouseMove.bind(this), false); |
| 111 | this._canvas.addEventListener('mouseout', this._onMouseOut.bind(this), false); |
| 112 | this._canvas.addEventListener('click', this._onClick.bind(this), false); |
| 113 | this._canvas.addEventListener('keydown', this._onKeyDown.bind(this), false); |
| 114 | |
| 115 | this._entryInfo = this._viewportElement.createChild('div', 'flame-chart-entry-info'); |
| 116 | this._markerHighlighElement = this._viewportElement.createChild('div', 'flame-chart-marker-highlight-element'); |
| 117 | this._highlightElement = this._viewportElement.createChild('div', 'flame-chart-highlight-element'); |
| 118 | this._selectedElement = this._viewportElement.createChild('div', 'flame-chart-selected-element'); |
Michael Liao | 712bbc2 | 2019-10-15 19:21:51 | [diff] [blame] | 119 | this._canvas.addEventListener('focus', () => { |
| 120 | this._selectedElement.classList.remove('flame-chart-unfocused-selected-element'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 121 | this.dispatchEventToListeners(Events.CanvasFocused); |
Michael Liao | 712bbc2 | 2019-10-15 19:21:51 | [diff] [blame] | 122 | }, false); |
| 123 | this._canvas.addEventListener('blur', () => { |
| 124 | this._selectedElement.classList.add('flame-chart-unfocused-selected-element'); |
| 125 | }, false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 126 | |
Tim van der Lippe | bb76917 | 2020-02-12 15:32:44 | [diff] [blame] | 127 | UI.UIUtils.installDragHandle( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 128 | this._viewportElement, this._startDragging.bind(this), this._dragging.bind(this), this._endDragging.bind(this), |
| 129 | null); |
| 130 | |
| 131 | this._rulerEnabled = true; |
| 132 | this._rangeSelectionStart = 0; |
| 133 | this._rangeSelectionEnd = 0; |
| 134 | this._barHeight = 17; |
| 135 | this._textBaseline = 5; |
| 136 | this._textPadding = 5; |
| 137 | this._markerRadius = 6; |
| 138 | this._chartViewport.setWindowTimes( |
| 139 | dataProvider.minimumBoundary(), dataProvider.minimumBoundary() + dataProvider.totalTime()); |
| 140 | |
| 141 | /** @const */ |
| 142 | this._headerLeftPadding = 6; |
| 143 | /** @const */ |
| 144 | this._arrowSide = 8; |
| 145 | /** @const */ |
| 146 | this._expansionArrowIndent = this._headerLeftPadding + this._arrowSide / 2; |
| 147 | /** @const */ |
| 148 | this._headerLabelXPadding = 3; |
| 149 | /** @const */ |
| 150 | this._headerLabelYPadding = 2; |
| 151 | |
| 152 | this._highlightedMarkerIndex = -1; |
| 153 | this._highlightedEntryIndex = -1; |
| 154 | this._selectedEntryIndex = -1; |
| 155 | this._rawTimelineDataLength = 0; |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 156 | /** @type {!Map<string, !Map<string,number>>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 157 | this._textWidth = new Map(); |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 158 | /** @type {!Map<number, !{x: number, width: number}>} */ |
| 159 | this._markerPositions = new Map(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 160 | |
| 161 | this._lastMouseOffsetX = 0; |
| 162 | this._selectedGroup = -1; |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 163 | |
| 164 | // Keyboard focused group is used to navigate groups irrespective of whether they are selectable or not |
| 165 | this._keyboardFocusedGroup = -1; |
| 166 | |
Paul Lewis | ca569a5 | 2020-09-09 16:11:51 | [diff] [blame] | 167 | this._selectedGroupBackroundColor = ThemeSupport.ThemeSupport.instance().patchColorText( |
| 168 | Colors.SelectedGroupBackground, ThemeSupport.ThemeSupport.ColorUsage.Background); |
| 169 | this._selectedGroupBorderColor = ThemeSupport.ThemeSupport.instance().patchColorText( |
| 170 | Colors.SelectedGroupBorder, ThemeSupport.ThemeSupport.ColorUsage.Background); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 171 | |
| 172 | /** @type {number} */ |
| 173 | this._offsetWidth; |
| 174 | |
| 175 | /** @type {number} */ |
| 176 | this._offsetHeight; |
| 177 | |
| 178 | /** @type {!HTMLCanvasElement} */ |
| 179 | this._canvasGL; |
| 180 | |
| 181 | /** @type {number} */ |
| 182 | this._dragStartX; |
| 183 | |
| 184 | /** @type {number} */ |
| 185 | this._dragStartY; |
| 186 | |
| 187 | /** @type {number} */ |
| 188 | this._lastMouseOffsetX; |
| 189 | |
| 190 | /** @type {number} */ |
| 191 | this._lastMouseOffsetY; |
| 192 | |
| 193 | /** @type {number} */ |
| 194 | this._minimumBoundary; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /** |
| 198 | * @override |
| 199 | */ |
| 200 | willHide() { |
| 201 | this.hideHighlight(); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * @param {number} value |
| 206 | */ |
| 207 | setBarHeight(value) { |
| 208 | this._barHeight = value; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * @param {number} value |
| 213 | */ |
| 214 | setTextBaseline(value) { |
| 215 | this._textBaseline = value; |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * @param {number} value |
| 220 | */ |
| 221 | setTextPadding(value) { |
| 222 | this._textPadding = value; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * @param {boolean} enable |
| 227 | */ |
| 228 | enableRuler(enable) { |
| 229 | this._rulerEnabled = enable; |
| 230 | } |
| 231 | |
| 232 | alwaysShowVerticalScroll() { |
| 233 | this._chartViewport.alwaysShowVerticalScroll(); |
| 234 | } |
| 235 | |
| 236 | disableRangeSelection() { |
| 237 | this._chartViewport.disableRangeSelection(); |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * @param {number} entryIndex |
| 242 | */ |
| 243 | highlightEntry(entryIndex) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 244 | if (this._highlightedEntryIndex === entryIndex) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 245 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 246 | } |
| 247 | if (!this._dataProvider.entryColor(entryIndex)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 248 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 249 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 250 | this._highlightedEntryIndex = entryIndex; |
| 251 | this._updateElementPosition(this._highlightElement, this._highlightedEntryIndex); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 252 | this.dispatchEventToListeners(Events.EntryHighlighted, entryIndex); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | hideHighlight() { |
| 256 | this._entryInfo.removeChildren(); |
| 257 | this._highlightedEntryIndex = -1; |
| 258 | this._updateElementPosition(this._highlightElement, this._highlightedEntryIndex); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 259 | this.dispatchEventToListeners(Events.EntryHighlighted, -1); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 260 | } |
| 261 | |
Paul Lewis | 49b1682 | 2020-02-21 14:22:03 | [diff] [blame] | 262 | _createCandyStripePattern() { |
| 263 | // Set the candy stripe pattern to 17px so it repeats well. |
| 264 | const size = 17; |
| 265 | this._candyStripeCanvas.width = size; |
| 266 | this._candyStripeCanvas.height = size; |
| 267 | |
| 268 | const ctx = this._candyStripeCanvas.getContext('2d'); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 269 | if (!ctx) { |
| 270 | return; |
| 271 | } |
Paul Lewis | 49b1682 | 2020-02-21 14:22:03 | [diff] [blame] | 272 | |
| 273 | // Rotate the stripe by 45deg to the right. |
| 274 | ctx.translate(size * 0.5, size * 0.5); |
| 275 | ctx.rotate(Math.PI * 0.25); |
| 276 | ctx.translate(-size * 0.5, -size * 0.5); |
| 277 | |
| 278 | ctx.fillStyle = 'rgba(255, 0, 0, 0.4)'; |
| 279 | for (let x = -size; x < size * 2; x += 3) { |
| 280 | ctx.fillRect(x, -size, 1, size * 3); |
| 281 | } |
| 282 | } |
| 283 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 284 | _resetCanvas() { |
| 285 | const ratio = window.devicePixelRatio; |
| 286 | const width = Math.round(this._offsetWidth * ratio); |
| 287 | const height = Math.round(this._offsetHeight * ratio); |
| 288 | this._canvas.width = width; |
| 289 | this._canvas.height = height; |
| 290 | this._canvas.style.width = `${width / ratio}px`; |
| 291 | this._canvas.style.height = `${height / ratio}px`; |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 292 | if (this._useWebGL) { |
| 293 | this._canvasGL.width = width; |
| 294 | this._canvasGL.height = height; |
| 295 | this._canvasGL.style.width = `${width / ratio}px`; |
| 296 | this._canvasGL.style.height = `${height / ratio}px`; |
| 297 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /** |
| 301 | * @override |
| 302 | * @param {number} startTime |
| 303 | * @param {number} endTime |
| 304 | * @param {boolean} animate |
| 305 | */ |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 306 | windowChanged(startTime, endTime, animate) { |
| 307 | this._flameChartDelegate.windowChanged(startTime, endTime, animate); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /** |
| 311 | * @override |
| 312 | * @param {number} startTime |
| 313 | * @param {number} endTime |
| 314 | */ |
| 315 | updateRangeSelection(startTime, endTime) { |
| 316 | this._flameChartDelegate.updateRangeSelection(startTime, endTime); |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * @override |
| 321 | * @param {number} width |
| 322 | * @param {number} height |
| 323 | */ |
| 324 | setSize(width, height) { |
| 325 | this._offsetWidth = width; |
| 326 | this._offsetHeight = height; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * @param {!MouseEvent} event |
| 331 | */ |
| 332 | _startDragging(event) { |
| 333 | this.hideHighlight(); |
| 334 | this._maxDragOffset = 0; |
| 335 | this._dragStartX = event.pageX; |
| 336 | this._dragStartY = event.pageY; |
| 337 | return true; |
| 338 | } |
| 339 | |
| 340 | /** |
| 341 | * @param {!MouseEvent} event |
| 342 | */ |
| 343 | _dragging(event) { |
| 344 | const dx = event.pageX - this._dragStartX; |
| 345 | const dy = event.pageY - this._dragStartY; |
| 346 | this._maxDragOffset = Math.max(this._maxDragOffset, Math.sqrt(dx * dx + dy * dy)); |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * @param {!MouseEvent} event |
| 351 | */ |
| 352 | _endDragging(event) { |
| 353 | this._updateHighlight(); |
| 354 | } |
| 355 | |
| 356 | /** |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 357 | * @return {?TimelineData} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 358 | */ |
| 359 | _timelineData() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 360 | if (!this._dataProvider) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 361 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 362 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 363 | const timelineData = this._dataProvider.timelineData(); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 364 | if (timelineData !== this._rawTimelineData || |
| 365 | (timelineData && timelineData.entryStartTimes.length !== this._rawTimelineDataLength)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 366 | this._processTimelineData(timelineData); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 367 | } |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 368 | return this._rawTimelineData || null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /** |
| 372 | * @param {number} entryIndex |
| 373 | */ |
| 374 | _revealEntry(entryIndex) { |
| 375 | const timelineData = this._timelineData(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 376 | if (!timelineData) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 377 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 378 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 379 | const timeLeft = this._chartViewport.windowLeftTime(); |
| 380 | const timeRight = this._chartViewport.windowRightTime(); |
| 381 | const entryStartTime = timelineData.entryStartTimes[entryIndex]; |
| 382 | const entryTotalTime = timelineData.entryTotalTimes[entryIndex]; |
| 383 | const entryEndTime = entryStartTime + entryTotalTime; |
| 384 | let minEntryTimeWindow = Math.min(entryTotalTime, timeRight - timeLeft); |
| 385 | |
| 386 | const level = timelineData.entryLevels[entryIndex]; |
| 387 | this._chartViewport.setScrollOffset(this._levelToOffset(level), this._levelHeight(level)); |
| 388 | |
| 389 | const minVisibleWidthPx = 30; |
| 390 | const futurePixelToTime = (timeRight - timeLeft) / this._offsetWidth; |
| 391 | minEntryTimeWindow = Math.max(minEntryTimeWindow, futurePixelToTime * minVisibleWidthPx); |
| 392 | if (timeLeft > entryEndTime) { |
| 393 | const delta = timeLeft - entryEndTime + minEntryTimeWindow; |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 394 | this.windowChanged(timeLeft - delta, timeRight - delta, /* animate */ true); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 395 | } else if (timeRight < entryStartTime) { |
| 396 | const delta = entryStartTime - timeRight + minEntryTimeWindow; |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 397 | this.windowChanged(timeLeft + delta, timeRight + delta, /* animate */ true); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * @param {number} startTime |
| 403 | * @param {number} endTime |
| 404 | * @param {boolean=} animate |
| 405 | */ |
| 406 | setWindowTimes(startTime, endTime, animate) { |
| 407 | this._chartViewport.setWindowTimes(startTime, endTime, animate); |
| 408 | this._updateHighlight(); |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * @param {!Event} event |
| 413 | */ |
| 414 | _onMouseMove(event) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 415 | const mouseEvent = /** @type {!MouseEvent} */ (event); |
| 416 | this._lastMouseOffsetX = mouseEvent.offsetX; |
| 417 | this._lastMouseOffsetY = mouseEvent.offsetY; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 418 | if (!this._enabled()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 419 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 420 | } |
| 421 | if (this._chartViewport.isDragging()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 422 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 423 | } |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 424 | if (this._coordinatesToGroupIndex(mouseEvent.offsetX, mouseEvent.offsetY, true /* headerOnly */) >= 0) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 425 | this.hideHighlight(); |
| 426 | this._viewportElement.style.cursor = 'pointer'; |
| 427 | return; |
| 428 | } |
| 429 | this._updateHighlight(); |
| 430 | } |
| 431 | |
| 432 | _updateHighlight() { |
Alexei Filippov | 8ee6638 | 2018-11-30 01:53:56 | [diff] [blame] | 433 | const entryIndex = this._coordinatesToEntryIndex(this._lastMouseOffsetX, this._lastMouseOffsetY); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 434 | if (entryIndex === -1) { |
| 435 | this.hideHighlight(); |
| 436 | const group = |
| 437 | this._coordinatesToGroupIndex(this._lastMouseOffsetX, this._lastMouseOffsetY, false /* headerOnly */); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 438 | if (group >= 0 && this._rawTimelineData && this._rawTimelineData.groups && |
| 439 | this._rawTimelineData.groups[group].selectable) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 440 | this._viewportElement.style.cursor = 'pointer'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 441 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 442 | this._viewportElement.style.cursor = 'default'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 443 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 444 | return; |
| 445 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 446 | if (this._chartViewport.isDragging()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 447 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 448 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 449 | this._updatePopover(entryIndex); |
| 450 | this._viewportElement.style.cursor = this._dataProvider.canJumpToEntry(entryIndex) ? 'pointer' : 'default'; |
| 451 | this.highlightEntry(entryIndex); |
| 452 | } |
| 453 | |
| 454 | _onMouseOut() { |
| 455 | this._lastMouseOffsetX = -1; |
| 456 | this._lastMouseOffsetY = -1; |
| 457 | this.hideHighlight(); |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * @param {number} entryIndex |
| 462 | */ |
| 463 | _updatePopover(entryIndex) { |
| 464 | if (entryIndex === this._highlightedEntryIndex) { |
| 465 | this._updatePopoverOffset(); |
| 466 | return; |
| 467 | } |
| 468 | this._entryInfo.removeChildren(); |
| 469 | const popoverElement = this._dataProvider.prepareHighlightedEntryInfo(entryIndex); |
| 470 | if (popoverElement) { |
| 471 | this._entryInfo.appendChild(popoverElement); |
| 472 | this._updatePopoverOffset(); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | _updatePopoverOffset() { |
| 477 | const mouseX = this._lastMouseOffsetX; |
| 478 | const mouseY = this._lastMouseOffsetY; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 479 | const parentWidth = this._entryInfo.parentElement ? this._entryInfo.parentElement.clientWidth : 0; |
| 480 | const parentHeight = this._entryInfo.parentElement ? this._entryInfo.parentElement.clientHeight : 0; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 481 | const infoWidth = this._entryInfo.clientWidth; |
| 482 | const infoHeight = this._entryInfo.clientHeight; |
| 483 | const /** @const */ offsetX = 10; |
| 484 | const /** @const */ offsetY = 6; |
| 485 | let x; |
| 486 | let y; |
| 487 | for (let quadrant = 0; quadrant < 4; ++quadrant) { |
| 488 | const dx = quadrant & 2 ? -offsetX - infoWidth : offsetX; |
| 489 | const dy = quadrant & 1 ? -offsetY - infoHeight : offsetY; |
Jack Franklin | 1be909c | 2020-03-04 08:57:41 | [diff] [blame] | 490 | x = Platform.NumberUtilities.clamp(mouseX + dx, 0, parentWidth - infoWidth); |
| 491 | y = Platform.NumberUtilities.clamp(mouseY + dy, 0, parentHeight - infoHeight); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 492 | if (x >= mouseX || mouseX >= x + infoWidth || y >= mouseY || mouseY >= y + infoHeight) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 493 | break; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 494 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 495 | } |
| 496 | this._entryInfo.style.left = x + 'px'; |
| 497 | this._entryInfo.style.top = y + 'px'; |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * @param {!Event} event |
| 502 | */ |
| 503 | _onClick(event) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 504 | const mouseEvent = /** @type {!MouseEvent} */ (event); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 505 | this.focus(); |
| 506 | // onClick comes after dragStart and dragEnd events. |
| 507 | // So if there was drag (mouse move) in the middle of that events |
| 508 | // we skip the click. Otherwise we jump to the sources. |
| 509 | const /** @const */ clickThreshold = 5; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 510 | if (this._maxDragOffset > clickThreshold) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 511 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 512 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 513 | |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 514 | this._selectGroup(this._coordinatesToGroupIndex(mouseEvent.offsetX, mouseEvent.offsetY, false /* headerOnly */)); |
| 515 | this._toggleGroupExpand( |
| 516 | this._coordinatesToGroupIndex(mouseEvent.offsetX, mouseEvent.offsetY, true /* headerOnly */)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 517 | const timelineData = this._timelineData(); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 518 | if (mouseEvent.shiftKey && this._highlightedEntryIndex !== -1 && timelineData) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 519 | const start = timelineData.entryStartTimes[this._highlightedEntryIndex]; |
| 520 | const end = start + timelineData.entryTotalTimes[this._highlightedEntryIndex]; |
| 521 | this._chartViewport.setRangeSelection(start, end); |
| 522 | } else { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 523 | this._chartViewport.onClick(mouseEvent); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 524 | this.dispatchEventToListeners(Events.EntryInvoked, this._highlightedEntryIndex); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | |
| 528 | /** |
| 529 | * @param {number} groupIndex |
| 530 | */ |
| 531 | _selectGroup(groupIndex) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 532 | if (groupIndex < 0 || this._selectedGroup === groupIndex) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 533 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 534 | } |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 535 | if (!this._rawTimelineData) { |
| 536 | return; |
| 537 | } |
| 538 | |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 539 | const groups = this._rawTimelineData.groups; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 540 | if (!groups) { |
| 541 | return; |
| 542 | } |
| 543 | |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 544 | this._keyboardFocusedGroup = groupIndex; |
Anubha Mathur | 430a80f | 2019-12-12 00:26:11 | [diff] [blame] | 545 | this._scrollGroupIntoView(groupIndex); |
Michael Liao | 0bad0c3 | 2020-01-02 18:51:04 | [diff] [blame] | 546 | const groupName = groups[groupIndex].name; |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 547 | if (!groups[groupIndex].selectable) { |
| 548 | this._deselectAllGroups(); |
Michael Liao | 0bad0c3 | 2020-01-02 18:51:04 | [diff] [blame] | 549 | UI.ARIAUtils.alert(ls`${groupName} hovered`, this._canvas); |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 550 | } else { |
| 551 | this._selectedGroup = groupIndex; |
| 552 | this._flameChartDelegate.updateSelectedGroup(this, groups[groupIndex]); |
| 553 | this._resetCanvas(); |
| 554 | this._draw(); |
Michael Liao (WPT) | b54514b | 2019-08-16 23:11:53 | [diff] [blame] | 555 | UI.ARIAUtils.alert(ls`${groupName} selected`, this._canvas); |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 556 | } |
| 557 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 558 | |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 559 | _deselectAllGroups() { |
| 560 | this._selectedGroup = -1; |
| 561 | this._flameChartDelegate.updateSelectedGroup(this, null); |
| 562 | this._resetCanvas(); |
| 563 | this._draw(); |
| 564 | } |
| 565 | |
| 566 | _deselectAllEntries() { |
| 567 | this._selectedEntryIndex = -1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 568 | this._resetCanvas(); |
| 569 | this._draw(); |
| 570 | } |
| 571 | |
| 572 | /** |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 573 | * @param {number} index |
| 574 | */ |
| 575 | _isGroupFocused(index) { |
| 576 | return index === this._selectedGroup || index === this._keyboardFocusedGroup; |
| 577 | } |
| 578 | |
| 579 | /** |
Anubha Mathur | 430a80f | 2019-12-12 00:26:11 | [diff] [blame] | 580 | * @param {number} index |
| 581 | */ |
| 582 | _scrollGroupIntoView(index) { |
| 583 | if (index < 0) { |
| 584 | return; |
| 585 | } |
| 586 | |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 587 | if (!this._rawTimelineData) { |
| 588 | return; |
| 589 | } |
| 590 | |
Anubha Mathur | 430a80f | 2019-12-12 00:26:11 | [diff] [blame] | 591 | const groups = this._rawTimelineData.groups; |
| 592 | const groupOffsets = this._groupOffsets; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 593 | if (!groupOffsets || !groups) { |
| 594 | return; |
| 595 | } |
Anubha Mathur | 430a80f | 2019-12-12 00:26:11 | [diff] [blame] | 596 | const groupTop = groupOffsets[index]; |
| 597 | |
| 598 | let nextOffset = groupOffsets[index + 1]; |
| 599 | if (index === groups.length - 1) { |
| 600 | nextOffset += groups[index].style.padding; |
| 601 | } |
| 602 | |
| 603 | // For the top group, scroll all the way to the top of the chart |
| 604 | // to accommodate the bar with time markers |
| 605 | const scrollTop = index === 0 ? 0 : groupTop; |
| 606 | |
| 607 | const scrollHeight = Math.min(nextOffset - scrollTop, this._chartViewport.chartHeight()); |
| 608 | this._chartViewport.setScrollOffset(scrollTop, scrollHeight); |
| 609 | } |
| 610 | |
| 611 | /** |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 612 | * @param {number} groupIndex |
| 613 | */ |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 614 | _toggleGroupExpand(groupIndex) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 615 | if (groupIndex < 0 || !this._isGroupCollapsible(groupIndex)) { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 616 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 617 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 618 | |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 619 | if (!this._rawTimelineData || !this._rawTimelineData.groups) { |
| 620 | return; |
| 621 | } |
| 622 | |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 623 | this._expandGroup(groupIndex, !this._rawTimelineData.groups[groupIndex].expanded /* setExpanded */); |
| 624 | } |
| 625 | |
| 626 | /** |
| 627 | * @param {number} groupIndex |
| 628 | * @param {boolean=} setExpanded |
Michael Liao (WPT) | b54514b | 2019-08-16 23:11:53 | [diff] [blame] | 629 | * @param {boolean=} propagatedExpand |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 630 | */ |
Michael Liao (WPT) | b54514b | 2019-08-16 23:11:53 | [diff] [blame] | 631 | _expandGroup(groupIndex, setExpanded = true, propagatedExpand = false) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 632 | if (groupIndex < 0 || !this._isGroupCollapsible(groupIndex)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 633 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 634 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 635 | |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 636 | if (!this._rawTimelineData) { |
| 637 | return; |
| 638 | } |
| 639 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 640 | const groups = this._rawTimelineData.groups; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 641 | if (!groups) { |
| 642 | return; |
| 643 | } |
| 644 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 645 | const group = groups[groupIndex]; |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 646 | group.expanded = setExpanded; |
| 647 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 648 | this._groupExpansionState[group.name] = group.expanded; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 649 | if (this._groupExpansionSetting) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 650 | this._groupExpansionSetting.set(this._groupExpansionState); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 651 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 652 | this._updateLevelPositions(); |
| 653 | |
| 654 | this._updateHighlight(); |
| 655 | if (!group.expanded) { |
| 656 | const timelineData = this._timelineData(); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 657 | if (timelineData) { |
| 658 | const level = timelineData.entryLevels[this._selectedEntryIndex]; |
| 659 | if (this._selectedEntryIndex >= 0 && level >= group.startLevel && |
| 660 | (groupIndex >= groups.length - 1 || groups[groupIndex + 1].startLevel > level)) { |
| 661 | this._selectedEntryIndex = -1; |
| 662 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 663 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | this._updateHeight(); |
| 667 | this._resetCanvas(); |
| 668 | this._draw(); |
Michael Liao (WPT) | b54514b | 2019-08-16 23:11:53 | [diff] [blame] | 669 | |
Anubha Mathur | 430a80f | 2019-12-12 00:26:11 | [diff] [blame] | 670 | this._scrollGroupIntoView(groupIndex); |
Michael Liao (WPT) | b54514b | 2019-08-16 23:11:53 | [diff] [blame] | 671 | // We only want to read expanded/collapsed state on user inputted expand/collapse |
| 672 | if (!propagatedExpand) { |
| 673 | const groupName = groups[groupIndex].name; |
| 674 | const content = group.expanded ? ls`${groupName} expanded` : ls`${groupName} collapsed`; |
| 675 | UI.ARIAUtils.alert(content, this._canvas); |
| 676 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | /** |
Tim van der Lippe | bcd6b5c | 2021-01-13 12:31:51 | [diff] [blame^] | 680 | * @param {!KeyboardEvent} e |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 681 | */ |
| 682 | _onKeyDown(e) { |
Tim van der Lippe | bb76917 | 2020-02-12 15:32:44 | [diff] [blame] | 683 | if (!UI.KeyboardShortcut.KeyboardShortcut.hasNoModifiers(e) || !this._timelineData()) { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 684 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 685 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 686 | |
| 687 | const eventHandled = this._handleSelectionNavigation(e); |
| 688 | |
| 689 | // Handle keyboard navigation in groups |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 690 | if (!eventHandled && this._rawTimelineData && this._rawTimelineData.groups) { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 691 | this._handleKeyboardGroupNavigation(e); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 692 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | /** |
Ted Meyer | b0928d0 | 2020-06-23 05:12:45 | [diff] [blame] | 696 | * @param {string} eventName |
Tim van der Lippe | 6468891 | 2020-11-02 11:55:52 | [diff] [blame] | 697 | * @param {function(!Event):void} onEvent |
Ted Meyer | b0928d0 | 2020-06-23 05:12:45 | [diff] [blame] | 698 | */ |
| 699 | bindCanvasEvent(eventName, onEvent) { |
| 700 | this._canvas.addEventListener(eventName, onEvent); |
| 701 | } |
| 702 | |
| 703 | /** |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 704 | * @param {!Event} event |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 705 | */ |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 706 | _handleKeyboardGroupNavigation(event) { |
| 707 | const keyboardEvent = /** @type {!KeyboardEvent} */ (event); |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 708 | let handled = false; |
| 709 | let entrySelected = false; |
| 710 | |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 711 | if (keyboardEvent.code === 'ArrowUp') { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 712 | handled = this._selectPreviousGroup(); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 713 | } else if (keyboardEvent.code === 'ArrowDown') { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 714 | handled = this._selectNextGroup(); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 715 | } else if (keyboardEvent.code === 'ArrowLeft') { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 716 | if (this._keyboardFocusedGroup >= 0) { |
| 717 | this._expandGroup(this._keyboardFocusedGroup, false /* setExpanded */); |
| 718 | handled = true; |
| 719 | } |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 720 | } else if (keyboardEvent.code === 'ArrowRight') { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 721 | if (this._keyboardFocusedGroup >= 0) { |
| 722 | this._expandGroup(this._keyboardFocusedGroup, true /* setExpanded */); |
| 723 | this._selectFirstChild(); |
| 724 | handled = true; |
| 725 | } |
Tim van der Lippe | bcd6b5c | 2021-01-13 12:31:51 | [diff] [blame^] | 726 | } else if (keyboardEvent.key === 'Enter') { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 727 | entrySelected = this._selectFirstEntryInCurrentGroup(); |
| 728 | handled = entrySelected; |
| 729 | } |
| 730 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 731 | if (handled && !entrySelected) { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 732 | this._deselectAllEntries(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 733 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 734 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 735 | if (handled) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 736 | keyboardEvent.consume(true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 737 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | /** |
| 741 | * @return {boolean} |
| 742 | */ |
| 743 | _selectFirstEntryInCurrentGroup() { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 744 | if (!this._rawTimelineData) { |
| 745 | return false; |
| 746 | } |
| 747 | |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 748 | const allGroups = this._rawTimelineData.groups; |
| 749 | |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 750 | if (this._keyboardFocusedGroup < 0 || !allGroups) { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 751 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 752 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 753 | |
| 754 | const group = allGroups[this._keyboardFocusedGroup]; |
| 755 | const startLevelInGroup = group.startLevel; |
| 756 | |
| 757 | // Return if no levels in this group |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 758 | if (startLevelInGroup < 0) { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 759 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 760 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 761 | |
| 762 | // Make sure this is the innermost nested group with this startLevel |
| 763 | // This is because a parent group also contains levels of all its child groups |
| 764 | // So check if the next group has the same level, if it does, user should |
| 765 | // go to that child group to select this entry |
| 766 | if (this._keyboardFocusedGroup < allGroups.length - 1 && |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 767 | allGroups[this._keyboardFocusedGroup + 1].startLevel === startLevelInGroup) { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 768 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 769 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 770 | |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 771 | if (!this._timelineLevels) { |
| 772 | return false; |
| 773 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 774 | |
| 775 | // Get first (default) entry in startLevel of selected group |
| 776 | const firstEntryIndex = this._timelineLevels[startLevelInGroup][0]; |
| 777 | |
| 778 | this._expandGroup(this._keyboardFocusedGroup, true /* setExpanded */); |
| 779 | this.setSelectedEntry(firstEntryIndex); |
| 780 | return true; |
| 781 | } |
| 782 | |
| 783 | /** |
| 784 | * @return {boolean} |
| 785 | */ |
| 786 | _selectPreviousGroup() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 787 | if (this._keyboardFocusedGroup <= 0) { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 788 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 789 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 790 | |
| 791 | const groupIndexToSelect = this._getGroupIndexToSelect(-1 /* offset */); |
| 792 | this._selectGroup(groupIndexToSelect); |
| 793 | return true; |
| 794 | } |
| 795 | |
| 796 | /** |
| 797 | * @return {boolean} |
| 798 | */ |
| 799 | _selectNextGroup() { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 800 | if (!this._rawTimelineData || !this._rawTimelineData.groups) { |
| 801 | return false; |
| 802 | } |
| 803 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 804 | if (this._keyboardFocusedGroup >= this._rawTimelineData.groups.length - 1) { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 805 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 806 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 807 | |
| 808 | const groupIndexToSelect = this._getGroupIndexToSelect(1 /* offset */); |
| 809 | this._selectGroup(groupIndexToSelect); |
| 810 | return true; |
| 811 | } |
| 812 | |
| 813 | /** |
| 814 | * @param {number} offset |
| 815 | * @return {number} |
| 816 | */ |
| 817 | _getGroupIndexToSelect(offset) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 818 | if (!this._rawTimelineData || !this._rawTimelineData.groups) { |
| 819 | throw new Error('No raw timeline data'); |
| 820 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 821 | const allGroups = this._rawTimelineData.groups; |
| 822 | let groupIndexToSelect = this._keyboardFocusedGroup; |
| 823 | let groupName, groupWithSubNestingLevel; |
| 824 | |
| 825 | do { |
| 826 | groupIndexToSelect += offset; |
| 827 | groupName = this._rawTimelineData.groups[groupIndexToSelect].name; |
| 828 | groupWithSubNestingLevel = this._keyboardFocusedGroup !== -1 && |
| 829 | allGroups[groupIndexToSelect].style.nestingLevel > allGroups[this._keyboardFocusedGroup].style.nestingLevel; |
| 830 | } while (groupIndexToSelect > 0 && groupIndexToSelect < allGroups.length - 1 && |
| 831 | (!groupName || groupWithSubNestingLevel)); |
| 832 | |
| 833 | return groupIndexToSelect; |
| 834 | } |
| 835 | |
| 836 | _selectFirstChild() { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 837 | if (!this._rawTimelineData || !this._rawTimelineData.groups) { |
| 838 | return; |
| 839 | } |
| 840 | |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 841 | const allGroups = this._rawTimelineData.groups; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 842 | if (this._keyboardFocusedGroup < 0 || this._keyboardFocusedGroup >= allGroups.length - 1) { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 843 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 844 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 845 | |
| 846 | const groupIndexToSelect = this._keyboardFocusedGroup + 1; |
| 847 | if (allGroups[groupIndexToSelect].style.nestingLevel > allGroups[this._keyboardFocusedGroup].style.nestingLevel) { |
| 848 | this._selectGroup(groupIndexToSelect); |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | |
| 852 | /** |
Tim van der Lippe | bcd6b5c | 2021-01-13 12:31:51 | [diff] [blame^] | 853 | * @param {!KeyboardEvent} event |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 854 | * @return {boolean} |
| 855 | */ |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 856 | _handleSelectionNavigation(event) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 857 | if (this._selectedEntryIndex === -1) { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 858 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 859 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 860 | const timelineData = this._timelineData(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 861 | if (!timelineData) { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 862 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 863 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 864 | |
| 865 | /** |
| 866 | * @param {number} time |
| 867 | * @param {number} entryIndex |
| 868 | * @return {number} |
| 869 | */ |
| 870 | function timeComparator(time, entryIndex) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 871 | if (!timelineData) { |
| 872 | throw new Error('No timeline data'); |
| 873 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 874 | return time - timelineData.entryStartTimes[entryIndex]; |
| 875 | } |
| 876 | |
| 877 | /** |
| 878 | * @param {number} entry1 |
| 879 | * @param {number} entry2 |
| 880 | * @return {boolean} |
| 881 | */ |
| 882 | function entriesIntersect(entry1, entry2) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 883 | if (!timelineData) { |
| 884 | throw new Error('No timeline data'); |
| 885 | } |
| 886 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 887 | const start1 = timelineData.entryStartTimes[entry1]; |
| 888 | const start2 = timelineData.entryStartTimes[entry2]; |
| 889 | const end1 = start1 + timelineData.entryTotalTimes[entry1]; |
| 890 | const end2 = start2 + timelineData.entryTotalTimes[entry2]; |
| 891 | return start1 < end2 && start2 < end1; |
| 892 | } |
| 893 | |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 894 | const keyboardEvent = /** @type {!KeyboardEvent} */ (event); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 895 | const keys = UI.KeyboardShortcut.Keys; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 896 | if (keyboardEvent.keyCode === keys.Left.code || keyboardEvent.keyCode === keys.Right.code) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 897 | const level = timelineData.entryLevels[this._selectedEntryIndex]; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 898 | const levelIndexes = this._timelineLevels ? this._timelineLevels[level] : []; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 899 | let indexOnLevel = levelIndexes.lowerBound(this._selectedEntryIndex); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 900 | indexOnLevel += keyboardEvent.keyCode === keys.Left.code ? -1 : 1; |
| 901 | event.consume(true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 902 | if (indexOnLevel >= 0 && indexOnLevel < levelIndexes.length) { |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 903 | this.dispatchEventToListeners(Events.EntrySelected, levelIndexes[indexOnLevel]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 904 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 905 | return true; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 906 | } |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 907 | |
| 908 | if (keyboardEvent.keyCode === keys.Up.code || keyboardEvent.keyCode === keys.Down.code) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 909 | let level = timelineData.entryLevels[this._selectedEntryIndex]; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 910 | level += keyboardEvent.keyCode === keys.Up.code ? -1 : 1; |
| 911 | if (level < 0 || (this._timelineLevels && level >= this._timelineLevels.length)) { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 912 | this._deselectAllEntries(); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 913 | keyboardEvent.consume(true); |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 914 | return true; |
| 915 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 916 | const entryTime = timelineData.entryStartTimes[this._selectedEntryIndex] + |
| 917 | timelineData.entryTotalTimes[this._selectedEntryIndex] / 2; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 918 | const levelIndexes = this._timelineLevels ? this._timelineLevels[level] : []; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 919 | let indexOnLevel = levelIndexes.upperBound(entryTime, timeComparator) - 1; |
| 920 | if (!entriesIntersect(this._selectedEntryIndex, levelIndexes[indexOnLevel])) { |
| 921 | ++indexOnLevel; |
| 922 | if (indexOnLevel >= levelIndexes.length || |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 923 | !entriesIntersect(this._selectedEntryIndex, levelIndexes[indexOnLevel])) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 924 | if (keyboardEvent.code === 'ArrowDown') { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 925 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 926 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 927 | |
| 928 | // Stay in the current group and give focus to the parent group instead of entries |
| 929 | this._deselectAllEntries(); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 930 | keyboardEvent.consume(true); |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 931 | return true; |
| 932 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 933 | } |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 934 | keyboardEvent.consume(true); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 935 | this.dispatchEventToListeners(Events.EntrySelected, levelIndexes[indexOnLevel]); |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 936 | return true; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 937 | } |
Tim van der Lippe | bcd6b5c | 2021-01-13 12:31:51 | [diff] [blame^] | 938 | if (event.key === 'Enter') { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 939 | event.consume(true); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 940 | this.dispatchEventToListeners(Events.EntryInvoked, this._selectedEntryIndex); |
Michael Liao | 712bbc2 | 2019-10-15 19:21:51 | [diff] [blame] | 941 | return true; |
| 942 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 943 | return false; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | /** |
| 947 | * @param {number} x |
| 948 | * @param {number} y |
| 949 | * @return {number} |
| 950 | */ |
| 951 | _coordinatesToEntryIndex(x, y) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 952 | if (x < 0 || y < 0) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 953 | return -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 954 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 955 | const timelineData = this._timelineData(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 956 | if (!timelineData) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 957 | return -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 958 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 959 | y += this._chartViewport.scrollOffset(); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 960 | if (!this._visibleLevelOffsets) { |
| 961 | throw new Error('No visible level offsets'); |
| 962 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 963 | const cursorLevel = this._visibleLevelOffsets.upperBound(y) - 1; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 964 | if (cursorLevel < 0 || (this._visibleLevels && !this._visibleLevels[cursorLevel])) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 965 | return -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 966 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 967 | const offsetFromLevel = y - this._visibleLevelOffsets[cursorLevel]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 968 | if (offsetFromLevel > this._levelHeight(cursorLevel)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 969 | return -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 970 | } |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 971 | |
| 972 | // Check markers first. |
| 973 | for (const [index, pos] of this._markerPositions) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 974 | if (timelineData.entryLevels[index] !== cursorLevel) { |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 975 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 976 | } |
| 977 | if (pos.x <= x && x < pos.x + pos.width) { |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 978 | return /** @type {number} */ (index); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 979 | } |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | // Check regular entries. |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 983 | const entryStartTimes = timelineData.entryStartTimes; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 984 | /** @type {!Array.<number>} */ |
| 985 | const entriesOnLevel = this._timelineLevels ? this._timelineLevels[cursorLevel] : []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 986 | if (!entriesOnLevel || !entriesOnLevel.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 987 | return -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 988 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 989 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 990 | const cursorTime = this._chartViewport.pixelToTime(x); |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 991 | const indexOnLevel = Math.max( |
| 992 | entriesOnLevel.upperBound(cursorTime, (time, entryIndex) => time - entryStartTimes[entryIndex]) - 1, 0); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 993 | |
| 994 | /** |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 995 | * @this {FlameChart} |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 996 | * @param {number|undefined} entryIndex |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 997 | * @return {boolean} |
| 998 | */ |
| 999 | function checkEntryHit(entryIndex) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1000 | if (entryIndex === undefined) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1001 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1002 | } |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1003 | |
| 1004 | if (!timelineData) { |
| 1005 | return false; |
| 1006 | } |
| 1007 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1008 | const startTime = entryStartTimes[entryIndex]; |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 1009 | const duration = timelineData.entryTotalTimes[entryIndex]; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1010 | const startX = this._chartViewport.timeToPosition(startTime); |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 1011 | const endX = this._chartViewport.timeToPosition(startTime + duration); |
| 1012 | const barThresholdPx = 3; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1013 | return startX - barThresholdPx < x && x < endX + barThresholdPx; |
| 1014 | } |
| 1015 | |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 1016 | let entryIndex = entriesOnLevel[indexOnLevel]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1017 | if (checkEntryHit.call(this, entryIndex)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1018 | return entryIndex; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1019 | } |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 1020 | entryIndex = entriesOnLevel[indexOnLevel + 1]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1021 | if (checkEntryHit.call(this, entryIndex)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1022 | return entryIndex; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1023 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1024 | return -1; |
| 1025 | } |
| 1026 | |
| 1027 | /** |
| 1028 | * @param {number} x |
| 1029 | * @param {number} y |
| 1030 | * @param {boolean} headerOnly |
| 1031 | * @return {number} |
| 1032 | */ |
| 1033 | _coordinatesToGroupIndex(x, y, headerOnly) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1034 | if (!this._rawTimelineData || !this._rawTimelineData.groups || !this._groupOffsets) { |
| 1035 | return -1; |
| 1036 | } |
| 1037 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1038 | if (x < 0 || y < 0) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1039 | return -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1040 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1041 | y += this._chartViewport.scrollOffset(); |
| 1042 | const groups = this._rawTimelineData.groups || []; |
| 1043 | const group = this._groupOffsets.upperBound(y) - 1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1044 | if (group < 0 || group >= groups.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1045 | return -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1046 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1047 | const height = headerOnly ? groups[group].style.height : this._groupOffsets[group + 1] - this._groupOffsets[group]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1048 | if (y - this._groupOffsets[group] >= height) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1049 | return -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1050 | } |
| 1051 | if (!headerOnly) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1052 | return group; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1053 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1054 | |
| 1055 | const context = /** @type {!CanvasRenderingContext2D} */ (this._canvas.getContext('2d')); |
| 1056 | context.save(); |
| 1057 | context.font = groups[group].style.font; |
| 1058 | const right = this._headerLeftPadding + this._labelWidthForGroup(context, groups[group]); |
| 1059 | context.restore(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1060 | if (x > right) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1061 | return -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1062 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1063 | |
| 1064 | return group; |
| 1065 | } |
| 1066 | |
| 1067 | /** |
| 1068 | * @param {number} x |
| 1069 | * @return {number} |
| 1070 | */ |
| 1071 | _markerIndexAtPosition(x) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1072 | const timelineData = this._timelineData(); |
| 1073 | if (!timelineData) { |
| 1074 | return -1; |
| 1075 | } |
| 1076 | |
| 1077 | const markers = timelineData.markers; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1078 | if (!markers) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1079 | return -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1080 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1081 | const /** @const */ accurracyOffsetPx = 4; |
| 1082 | const time = this._chartViewport.pixelToTime(x); |
| 1083 | const leftTime = this._chartViewport.pixelToTime(x - accurracyOffsetPx); |
| 1084 | const rightTime = this._chartViewport.pixelToTime(x + accurracyOffsetPx); |
| 1085 | const left = this._markerIndexBeforeTime(leftTime); |
| 1086 | let markerIndex = -1; |
| 1087 | let distance = Infinity; |
| 1088 | for (let i = left; i < markers.length && markers[i].startTime() < rightTime; i++) { |
| 1089 | const nextDistance = Math.abs(markers[i].startTime() - time); |
| 1090 | if (nextDistance < distance) { |
| 1091 | markerIndex = i; |
| 1092 | distance = nextDistance; |
| 1093 | } |
| 1094 | } |
| 1095 | return markerIndex; |
| 1096 | } |
| 1097 | |
| 1098 | /** |
| 1099 | * @param {number} time |
| 1100 | * @return {number} |
| 1101 | */ |
| 1102 | _markerIndexBeforeTime(time) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1103 | const timelineData = this._timelineData(); |
| 1104 | if (!timelineData) { |
| 1105 | throw new Error('No timeline data'); |
| 1106 | } |
| 1107 | |
| 1108 | const markers = timelineData.markers; |
| 1109 | if (!markers) { |
| 1110 | throw new Error('No timeline markers'); |
| 1111 | } |
| 1112 | |
| 1113 | return timelineData.markers.lowerBound(time, (markerTimestamp, marker) => markerTimestamp - marker.startTime()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | _draw() { |
| 1117 | const timelineData = this._timelineData(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1118 | if (!timelineData) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1119 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1120 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1121 | |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1122 | const visibleLevelOffsets = this._visibleLevelOffsets ? this._visibleLevelOffsets : []; |
| 1123 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1124 | const width = this._offsetWidth; |
| 1125 | const height = this._offsetHeight; |
| 1126 | const context = /** @type {!CanvasRenderingContext2D} */ (this._canvas.getContext('2d')); |
| 1127 | context.save(); |
| 1128 | const ratio = window.devicePixelRatio; |
| 1129 | const top = this._chartViewport.scrollOffset(); |
| 1130 | context.scale(ratio, ratio); |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1131 | context.fillStyle = 'rgba(0, 0, 0, 0)'; |
| 1132 | context.fillRect(0, 0, width, height); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1133 | context.translate(0, -top); |
Tim van der Lippe | bb76917 | 2020-02-12 15:32:44 | [diff] [blame] | 1134 | const defaultFont = '11px ' + Host.Platform.fontFamily(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1135 | context.font = defaultFont; |
| 1136 | |
Paul Lewis | 49b1682 | 2020-02-21 14:22:03 | [diff] [blame] | 1137 | const candyStripePattern = context.createPattern(this._candyStripeCanvas, 'repeat'); |
| 1138 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1139 | const entryTotalTimes = timelineData.entryTotalTimes; |
| 1140 | const entryStartTimes = timelineData.entryStartTimes; |
| 1141 | const entryLevels = timelineData.entryLevels; |
| 1142 | const timeToPixel = this._chartViewport.timeToPixel(); |
| 1143 | |
| 1144 | const titleIndices = []; |
| 1145 | const markerIndices = []; |
| 1146 | const textPadding = this._textPadding; |
Mathias Bynens | 23ee1aa | 2020-03-02 12:06:38 | [diff] [blame] | 1147 | const minTextWidth = 2 * textPadding + UI.UIUtils.measureTextWidth(context, '…'); |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1148 | const minTextWidthDuration = this._chartViewport.pixelToTimeOffset(minTextWidth); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1149 | const minVisibleBarLevel = Math.max(visibleLevelOffsets.upperBound(top) - 1, 0); |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 1150 | this._markerPositions.clear(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1151 | |
Paul Lewis | 49b1682 | 2020-02-21 14:22:03 | [diff] [blame] | 1152 | let mainThreadTopLevel = -1; |
| 1153 | |
| 1154 | // Find the main thread so that we can mark tasks longer than 50ms. |
| 1155 | if ('groups' in timelineData && Array.isArray(timelineData.groups)) { |
Tim van der Lippe | 5adc1e0 | 2020-11-20 12:30:12 | [diff] [blame] | 1156 | const mainThread = timelineData.groups.find(group => { |
| 1157 | if (!group.track) { |
Paul Lewis | 49b1682 | 2020-02-21 14:22:03 | [diff] [blame] | 1158 | return false; |
| 1159 | } |
| 1160 | |
Tim van der Lippe | 5adc1e0 | 2020-11-20 12:30:12 | [diff] [blame] | 1161 | return group.track.name === 'CrRendererMain'; |
Paul Lewis | 49b1682 | 2020-02-21 14:22:03 | [diff] [blame] | 1162 | }); |
| 1163 | |
| 1164 | if (mainThread) { |
| 1165 | mainThreadTopLevel = mainThread.startLevel; |
| 1166 | } |
| 1167 | } |
| 1168 | |
Paul Lewis | 06985d4 | 2020-04-30 14:51:16 | [diff] [blame] | 1169 | /** @type {!Map<string, {indexes: !Array<number>}>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1170 | const colorBuckets = new Map(); |
| 1171 | for (let level = minVisibleBarLevel; level < this._dataProvider.maxStackDepth(); ++level) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1172 | if (this._levelToOffset(level) > top + height) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1173 | break; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1174 | } |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1175 | if (!this._visibleLevels || !this._visibleLevels[level]) { |
| 1176 | continue; |
| 1177 | } |
| 1178 | if (!this._timelineLevels) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1179 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1180 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1181 | |
| 1182 | // Entries are ordered by start time within a level, so find the last visible entry. |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1183 | /** @type {!Array.<number>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1184 | const levelIndexes = this._timelineLevels[level]; |
| 1185 | const rightIndexOnLevel = |
| 1186 | levelIndexes.lowerBound( |
| 1187 | this._chartViewport.windowRightTime(), (time, entryIndex) => time - entryStartTimes[entryIndex]) - |
| 1188 | 1; |
| 1189 | let lastDrawOffset = Infinity; |
| 1190 | for (let entryIndexOnLevel = rightIndexOnLevel; entryIndexOnLevel >= 0; --entryIndexOnLevel) { |
| 1191 | const entryIndex = levelIndexes[entryIndexOnLevel]; |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 1192 | const duration = entryTotalTimes[entryIndex]; |
| 1193 | if (isNaN(duration)) { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1194 | markerIndices.push(entryIndex); |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 1195 | continue; |
| 1196 | } |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1197 | if (duration >= minTextWidthDuration || |
| 1198 | (this._forceDecorationCache && this._forceDecorationCache[entryIndex])) { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1199 | titleIndices.push(entryIndex); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1200 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1201 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1202 | const entryStartTime = entryStartTimes[entryIndex]; |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1203 | const entryOffsetRight = entryStartTime + duration; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1204 | if (entryOffsetRight <= this._chartViewport.windowLeftTime()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1205 | break; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1206 | } |
| 1207 | if (this._useWebGL) { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1208 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1209 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1210 | |
| 1211 | const barX = this._timeToPositionClipped(entryStartTime); |
| 1212 | // Check if the entry entirely fits into an already drawn pixel, we can just skip drawing it. |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1213 | if (barX >= lastDrawOffset) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1214 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1215 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1216 | lastDrawOffset = barX; |
| 1217 | |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1218 | if (this._entryColorsCache) { |
| 1219 | const color = this._entryColorsCache[entryIndex]; |
| 1220 | let bucket = colorBuckets.get(color); |
| 1221 | if (!bucket) { |
| 1222 | bucket = {indexes: []}; |
| 1223 | colorBuckets.set(color, bucket); |
| 1224 | } |
| 1225 | bucket.indexes.push(entryIndex); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1226 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1230 | if (this._useWebGL) { |
| 1231 | this._drawGL(); |
| 1232 | } else { |
| 1233 | context.save(); |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1234 | this._forEachGroupInViewport((offset, index, group, isFirst, groupHeight) => { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 1235 | if (this._isGroupFocused(index)) { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1236 | context.fillStyle = this._selectedGroupBackroundColor; |
| 1237 | context.fillRect(0, offset, width, groupHeight - group.style.padding); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1238 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1239 | }); |
| 1240 | context.restore(); |
| 1241 | |
Paul Lewis | 06985d4 | 2020-04-30 14:51:16 | [diff] [blame] | 1242 | for (const [color, {indexes}] of colorBuckets) { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1243 | context.beginPath(); |
| 1244 | for (let i = 0; i < indexes.length; ++i) { |
| 1245 | const entryIndex = indexes[i]; |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 1246 | const duration = entryTotalTimes[entryIndex]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1247 | if (isNaN(duration)) { |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 1248 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1249 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1250 | const entryStartTime = entryStartTimes[entryIndex]; |
| 1251 | const barX = this._timeToPositionClipped(entryStartTime); |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1252 | const barLevel = entryLevels[entryIndex]; |
| 1253 | const barHeight = this._levelHeight(barLevel); |
| 1254 | const barY = this._levelToOffset(barLevel); |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1255 | const barRight = this._timeToPositionClipped(entryStartTime + duration); |
| 1256 | const barWidth = Math.max(barRight - barX, 1); |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 1257 | context.rect(barX, barY, barWidth - 0.4, barHeight - 1); |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1258 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1259 | context.fillStyle = color; |
| 1260 | context.fill(); |
Paul Lewis | 49b1682 | 2020-02-21 14:22:03 | [diff] [blame] | 1261 | |
| 1262 | // Draw long task regions. |
| 1263 | context.beginPath(); |
| 1264 | for (let i = 0; i < indexes.length; ++i) { |
| 1265 | const entryIndex = indexes[i]; |
| 1266 | const duration = entryTotalTimes[entryIndex]; |
Paul Lewis | 06985d4 | 2020-04-30 14:51:16 | [diff] [blame] | 1267 | const showLongDurations = entryLevels[entryIndex] === mainThreadTopLevel; |
Paul Lewis | 49b1682 | 2020-02-21 14:22:03 | [diff] [blame] | 1268 | |
| 1269 | if (!showLongDurations) { |
| 1270 | continue; |
| 1271 | } |
| 1272 | |
Paul Lewis | 06985d4 | 2020-04-30 14:51:16 | [diff] [blame] | 1273 | if (isNaN(duration) || duration < 50) { |
Paul Lewis | 49b1682 | 2020-02-21 14:22:03 | [diff] [blame] | 1274 | continue; |
| 1275 | } |
| 1276 | |
| 1277 | const entryStartTime = entryStartTimes[entryIndex]; |
| 1278 | const barX = this._timeToPositionClipped(entryStartTime + 50); |
| 1279 | const barLevel = entryLevels[entryIndex]; |
| 1280 | const barHeight = this._levelHeight(barLevel); |
| 1281 | const barY = this._levelToOffset(barLevel); |
| 1282 | const barRight = this._timeToPositionClipped(entryStartTime + duration); |
| 1283 | const barWidth = Math.max(barRight - barX, 1); |
| 1284 | context.rect(barX, barY, barWidth - 0.4, barHeight - 1); |
| 1285 | } |
| 1286 | |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1287 | if (candyStripePattern) { |
| 1288 | context.fillStyle = candyStripePattern; |
| 1289 | context.fill(); |
| 1290 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1291 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1292 | } |
| 1293 | |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 1294 | context.textBaseline = 'alphabetic'; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1295 | context.beginPath(); |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 1296 | let lastMarkerLevel = -1; |
| 1297 | let lastMarkerX = -Infinity; |
| 1298 | // Markers are sorted top to bottom, right to left. |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 1299 | for (let m = markerIndices.length - 1; m >= 0; --m) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1300 | const entryIndex = markerIndices[m]; |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 1301 | const title = this._dataProvider.entryTitle(entryIndex); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1302 | if (!title) { |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 1303 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1304 | } |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 1305 | const entryStartTime = entryStartTimes[entryIndex]; |
| 1306 | const level = entryLevels[entryIndex]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1307 | if (lastMarkerLevel !== level) { |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 1308 | lastMarkerX = -Infinity; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1309 | } |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 1310 | const x = Math.max(this._chartViewport.timeToPosition(entryStartTime), lastMarkerX); |
| 1311 | const y = this._levelToOffset(level); |
| 1312 | const h = this._levelHeight(level); |
| 1313 | const padding = 4; |
Tim van der Lippe | bb76917 | 2020-02-12 15:32:44 | [diff] [blame] | 1314 | const width = Math.ceil(UI.UIUtils.measureTextWidth(context, title)) + 2 * padding; |
Alexei Filippov | 214df61 | 2018-11-13 19:14:00 | [diff] [blame] | 1315 | lastMarkerX = x + width + 1; |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 1316 | lastMarkerLevel = level; |
| 1317 | this._markerPositions.set(entryIndex, {x, width}); |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 1318 | context.fillStyle = this._dataProvider.entryColor(entryIndex); |
| 1319 | context.fillRect(x, y, width, h - 1); |
| 1320 | context.fillStyle = 'white'; |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 1321 | context.fillText(title, x + padding, y + h - this._textBaseline); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1322 | } |
| 1323 | context.strokeStyle = 'rgba(0, 0, 0, 0.2)'; |
| 1324 | context.stroke(); |
| 1325 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1326 | for (let i = 0; i < titleIndices.length; ++i) { |
| 1327 | const entryIndex = titleIndices[i]; |
| 1328 | const entryStartTime = entryStartTimes[entryIndex]; |
| 1329 | const barX = this._timeToPositionClipped(entryStartTime); |
| 1330 | const barRight = Math.min(this._timeToPositionClipped(entryStartTime + entryTotalTimes[entryIndex]), width) + 1; |
| 1331 | const barWidth = barRight - barX; |
| 1332 | const barLevel = entryLevels[entryIndex]; |
| 1333 | const barY = this._levelToOffset(barLevel); |
| 1334 | let text = this._dataProvider.entryTitle(entryIndex); |
| 1335 | if (text && text.length) { |
| 1336 | context.font = this._dataProvider.entryFont(entryIndex) || defaultFont; |
Tim van der Lippe | bb76917 | 2020-02-12 15:32:44 | [diff] [blame] | 1337 | text = UI.UIUtils.trimTextMiddle(context, text, barWidth - 2 * textPadding); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1338 | } |
| 1339 | const unclippedBarX = this._chartViewport.timeToPosition(entryStartTime); |
| 1340 | const barHeight = this._levelHeight(barLevel); |
| 1341 | if (this._dataProvider.decorateEntry( |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1342 | entryIndex, context, text, barX, barY, barWidth, barHeight, unclippedBarX, timeToPixel)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1343 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1344 | } |
| 1345 | if (!text || !text.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1346 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1347 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1348 | context.fillStyle = this._dataProvider.textColor(entryIndex); |
| 1349 | context.fillText(text, barX + textPadding, barY + barHeight - this._textBaseline); |
| 1350 | } |
| 1351 | |
| 1352 | context.restore(); |
| 1353 | |
| 1354 | this._drawGroupHeaders(width, height); |
| 1355 | this._drawFlowEvents(context, width, height); |
| 1356 | this._drawMarkers(); |
Paul Lewis | 2cfa94e | 2020-01-13 10:30:15 | [diff] [blame] | 1357 | const dividersData = TimelineGrid.calculateGridOffsets(this); |
Paul Lewis | ead4575 | 2020-06-23 09:51:36 | [diff] [blame] | 1358 | const navStartTimes = Array.from(this._dataProvider.navStartTimes().values()); |
| 1359 | |
| 1360 | let navStartTimeIndex = 0; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1361 | /** |
| 1362 | * @param {number} time |
| 1363 | */ |
Paul Lewis | ead4575 | 2020-06-23 09:51:36 | [diff] [blame] | 1364 | const drawAdjustedTime = time => { |
| 1365 | if (navStartTimes.length === 0) { |
| 1366 | return this.formatValue(time, dividersData.precision); |
| 1367 | } |
| 1368 | |
| 1369 | // Track when the time crosses the boundary to the next nav start record, |
| 1370 | // and when it does, move the nav start array index accordingly. |
| 1371 | const hasNextNavStartTime = navStartTimes.length > navStartTimeIndex + 1; |
| 1372 | if (hasNextNavStartTime && time > navStartTimes[navStartTimeIndex + 1].startTime) { |
| 1373 | navStartTimeIndex++; |
| 1374 | } |
| 1375 | |
| 1376 | // Adjust the time by the nearest nav start marker's value. |
| 1377 | const nearestMarker = navStartTimes[navStartTimeIndex]; |
| 1378 | if (nearestMarker) { |
| 1379 | time -= nearestMarker.startTime - this.zeroTime(); |
| 1380 | } |
| 1381 | |
| 1382 | return this.formatValue(time, dividersData.precision); |
| 1383 | }; |
| 1384 | |
Paul Lewis | 2cfa94e | 2020-01-13 10:30:15 | [diff] [blame] | 1385 | TimelineGrid.drawCanvasGrid(context, dividersData); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1386 | if (this._rulerEnabled) { |
Paul Lewis | ead4575 | 2020-06-23 09:51:36 | [diff] [blame] | 1387 | TimelineGrid.drawCanvasHeaders(context, dividersData, drawAdjustedTime, 3, HeaderHeight); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | this._updateElementPosition(this._highlightElement, this._highlightedEntryIndex); |
| 1391 | this._updateElementPosition(this._selectedElement, this._selectedEntryIndex); |
| 1392 | this._updateMarkerHighlight(); |
| 1393 | } |
| 1394 | |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1395 | _initWebGL() { |
| 1396 | const gl = /** @type {?WebGLRenderingContext} */ (this._canvasGL.getContext('webgl')); |
| 1397 | if (!gl) { |
| 1398 | console.error('Failed to obtain WebGL context.'); |
| 1399 | this._useWebGL = false; // Fallback to use canvas. |
| 1400 | return; |
| 1401 | } |
| 1402 | |
| 1403 | const vertexShaderSource = ` |
| 1404 | attribute vec2 aVertexPosition; |
Alexei Filippov | af3ffed | 2018-08-18 01:56:09 | [diff] [blame] | 1405 | attribute float aVertexColor; |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1406 | |
| 1407 | uniform vec2 uScalingFactor; |
| 1408 | uniform vec2 uShiftVector; |
| 1409 | |
Alexei Filippov | af3ffed | 2018-08-18 01:56:09 | [diff] [blame] | 1410 | varying mediump vec2 vPalettePosition; |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1411 | |
| 1412 | void main() { |
| 1413 | vec2 shiftedPosition = aVertexPosition - uShiftVector; |
| 1414 | gl_Position = vec4(shiftedPosition * uScalingFactor + vec2(-1.0, 1.0), 0.0, 1.0); |
Alexei Filippov | af3ffed | 2018-08-18 01:56:09 | [diff] [blame] | 1415 | vPalettePosition = vec2(aVertexColor, 0.5); |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1416 | }`; |
| 1417 | |
| 1418 | const fragmentShaderSource = ` |
Alexei Filippov | af3ffed | 2018-08-18 01:56:09 | [diff] [blame] | 1419 | varying mediump vec2 vPalettePosition; |
| 1420 | uniform sampler2D uSampler; |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1421 | |
| 1422 | void main() { |
Alexei Filippov | af3ffed | 2018-08-18 01:56:09 | [diff] [blame] | 1423 | gl_FragColor = texture2D(uSampler, vPalettePosition); |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1424 | }`; |
| 1425 | |
| 1426 | /** |
| 1427 | * @param {!WebGLRenderingContext} gl |
| 1428 | * @param {number} type |
| 1429 | * @param {string} source |
| 1430 | * @return {?WebGLShader} |
| 1431 | */ |
| 1432 | function loadShader(gl, type, source) { |
| 1433 | const shader = gl.createShader(type); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1434 | if (!shader) { |
| 1435 | return null; |
| 1436 | } |
| 1437 | |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1438 | gl.shaderSource(shader, source); |
| 1439 | gl.compileShader(shader); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1440 | if (gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1441 | return shader; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1442 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1443 | console.error('Shader compile error: ' + gl.getShaderInfoLog(shader)); |
| 1444 | gl.deleteShader(shader); |
| 1445 | return null; |
| 1446 | } |
| 1447 | |
| 1448 | const vertexShader = loadShader(gl, gl.VERTEX_SHADER, vertexShaderSource); |
| 1449 | const fragmentShader = loadShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource); |
| 1450 | |
| 1451 | const shaderProgram = gl.createProgram(); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1452 | if (!shaderProgram || !vertexShader || !fragmentShader) { |
| 1453 | return; |
| 1454 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1455 | gl.attachShader(shaderProgram, vertexShader); |
| 1456 | gl.attachShader(shaderProgram, fragmentShader); |
| 1457 | gl.linkProgram(shaderProgram); |
| 1458 | |
| 1459 | if (gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) { |
| 1460 | this._shaderProgram = shaderProgram; |
| 1461 | gl.useProgram(shaderProgram); |
| 1462 | } else { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1463 | this._shaderProgram = null; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1464 | throw new Error('Unable to initialize the shader program: ' + gl.getProgramInfoLog(shaderProgram)); |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1465 | } |
Alexei Filippov | af3ffed | 2018-08-18 01:56:09 | [diff] [blame] | 1466 | |
| 1467 | this._vertexBuffer = gl.createBuffer(); |
| 1468 | this._colorBuffer = gl.createBuffer(); |
| 1469 | |
| 1470 | this._uScalingFactor = gl.getUniformLocation(shaderProgram, 'uScalingFactor'); |
| 1471 | this._uShiftVector = gl.getUniformLocation(shaderProgram, 'uShiftVector'); |
| 1472 | const uSampler = gl.getUniformLocation(shaderProgram, 'uSampler'); |
| 1473 | gl.uniform1i(uSampler, 0); |
| 1474 | this._aVertexPosition = gl.getAttribLocation(this._shaderProgram, 'aVertexPosition'); |
| 1475 | this._aVertexColor = gl.getAttribLocation(this._shaderProgram, 'aVertexColor'); |
| 1476 | gl.enableVertexAttribArray(this._aVertexPosition); |
| 1477 | gl.enableVertexAttribArray(this._aVertexColor); |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | _setupGLGeometry() { |
| 1481 | const gl = /** @type {?WebGLRenderingContext} */ (this._canvasGL.getContext('webgl')); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1482 | if (!gl) { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1483 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1484 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1485 | |
| 1486 | const timelineData = this._timelineData(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1487 | if (!timelineData) { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1488 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1489 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1490 | |
| 1491 | const entryTotalTimes = timelineData.entryTotalTimes; |
| 1492 | const entryStartTimes = timelineData.entryStartTimes; |
| 1493 | const entryLevels = timelineData.entryLevels; |
| 1494 | |
Alexei Filippov | af3ffed | 2018-08-18 01:56:09 | [diff] [blame] | 1495 | const verticesPerBar = 6; |
| 1496 | const vertexArray = new Float32Array(entryTotalTimes.length * verticesPerBar * 2); |
| 1497 | let colorArray = new Uint8Array(entryTotalTimes.length * verticesPerBar); |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1498 | let vertex = 0; |
Alexei Filippov | af3ffed | 2018-08-18 01:56:09 | [diff] [blame] | 1499 | /** @type {!Map<string, number>} */ |
Alexei Filippov | c34372c | 2018-08-16 20:37:39 | [diff] [blame] | 1500 | const parsedColorCache = new Map(); |
Alexei Filippov | af3ffed | 2018-08-18 01:56:09 | [diff] [blame] | 1501 | /** @type {!Array<number>} */ |
| 1502 | const colors = []; |
| 1503 | |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1504 | const visibleLevels = this._visibleLevels || []; |
| 1505 | const rawTimelineData = this._rawTimelineData || {groups: []}; |
| 1506 | |
| 1507 | const collapsedOverviewLevels = new Array(visibleLevels.length); |
| 1508 | const groups = rawTimelineData.groups || []; |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1509 | this._forEachGroup((offset, index, group) => { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1510 | if (group.style.useFirstLineForOverview || !this._isGroupCollapsible(index) || group.expanded) { |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1511 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1512 | } |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1513 | let nextGroup = index + 1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1514 | while (nextGroup < groups.length && groups[nextGroup].style.nestingLevel > group.style.nestingLevel) { |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1515 | ++nextGroup; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1516 | } |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1517 | const endLevel = nextGroup < groups.length ? groups[nextGroup].startLevel : this._dataProvider.maxStackDepth(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1518 | for (let i = group.startLevel; i < endLevel; ++i) { |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1519 | collapsedOverviewLevels[i] = offset; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1520 | } |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1521 | }); |
| 1522 | |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1523 | for (let i = 0; i < entryTotalTimes.length; ++i) { |
| 1524 | const level = entryLevels[i]; |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1525 | const collapsedGroupOffset = collapsedOverviewLevels[level]; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1526 | if (!visibleLevels[level] && !collapsedGroupOffset) { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1527 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1528 | } |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1529 | if (!this._entryColorsCache) { |
| 1530 | continue; |
| 1531 | } |
| 1532 | |
Alexei Filippov | e519762 | 2018-08-18 03:04:33 | [diff] [blame] | 1533 | const color = this._entryColorsCache[i]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1534 | if (!color) { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1535 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1536 | } |
Alexei Filippov | af3ffed | 2018-08-18 01:56:09 | [diff] [blame] | 1537 | let colorIndex = parsedColorCache.get(color); |
| 1538 | if (colorIndex === undefined) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1539 | const parsedColor = Common.Color.Color.parse(color); |
| 1540 | if (parsedColor) { |
| 1541 | const rgba = parsedColor.canonicalRGBA(); |
| 1542 | rgba[3] = Math.round(rgba[3] * 255); |
| 1543 | colorIndex = colors.length / 4; |
| 1544 | colors.push(...rgba); |
| 1545 | if (colorIndex === 256) { |
| 1546 | colorArray = new Uint8Array(colorArray); |
| 1547 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1548 | } |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1549 | |
| 1550 | if (colorIndex) { |
| 1551 | parsedColorCache.set(color, colorIndex); |
| 1552 | } |
Alexei Filippov | c34372c | 2018-08-16 20:37:39 | [diff] [blame] | 1553 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1554 | for (let j = 0; j < verticesPerBar; ++j) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1555 | if (colorIndex) { |
| 1556 | colorArray[vertex + j] = colorIndex; |
| 1557 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1558 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1559 | |
| 1560 | const vpos = vertex * 2; |
| 1561 | const x0 = entryStartTimes[i] - this._minimumBoundary; |
| 1562 | const x1 = x0 + entryTotalTimes[i]; |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1563 | const y0 = collapsedGroupOffset || this._levelToOffset(level); |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1564 | const y1 = y0 + this._levelHeight(level) - 1; |
| 1565 | vertexArray[vpos + 0] = x0; |
| 1566 | vertexArray[vpos + 1] = y0; |
| 1567 | vertexArray[vpos + 2] = x1; |
| 1568 | vertexArray[vpos + 3] = y0; |
| 1569 | vertexArray[vpos + 4] = x0; |
| 1570 | vertexArray[vpos + 5] = y1; |
| 1571 | vertexArray[vpos + 6] = x0; |
| 1572 | vertexArray[vpos + 7] = y1; |
| 1573 | vertexArray[vpos + 8] = x1; |
| 1574 | vertexArray[vpos + 9] = y0; |
| 1575 | vertexArray[vpos + 10] = x1; |
| 1576 | vertexArray[vpos + 11] = y1; |
| 1577 | |
Alexei Filippov | af3ffed | 2018-08-18 01:56:09 | [diff] [blame] | 1578 | vertex += verticesPerBar; |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1579 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1580 | this._vertexCount = vertex; |
| 1581 | |
Alexei Filippov | af3ffed | 2018-08-18 01:56:09 | [diff] [blame] | 1582 | const paletteTexture = gl.createTexture(); |
| 1583 | gl.bindTexture(gl.TEXTURE_2D, paletteTexture); |
| 1584 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
| 1585 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
| 1586 | gl.activeTexture(gl.TEXTURE0); |
| 1587 | |
| 1588 | const numColors = colors.length / 4; |
| 1589 | const useShortForColors = numColors >= 256; |
| 1590 | const width = !useShortForColors ? 256 : Math.min(1 << 16, gl.getParameter(gl.MAX_TEXTURE_SIZE)); |
| 1591 | console.assert(numColors <= width, 'Too many colors'); |
| 1592 | const height = 1; |
| 1593 | const colorIndexType = useShortForColors ? gl.UNSIGNED_SHORT : gl.UNSIGNED_BYTE; |
| 1594 | if (useShortForColors) { |
| 1595 | const factor = (1 << 16) / width; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1596 | for (let i = 0; i < vertex; ++i) { |
Alexei Filippov | af3ffed | 2018-08-18 01:56:09 | [diff] [blame] | 1597 | colorArray[i] *= factor; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1598 | } |
Alexei Filippov | af3ffed | 2018-08-18 01:56:09 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | const pixels = new Uint8Array(width * 4); |
| 1602 | pixels.set(colors); |
| 1603 | gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, pixels); |
| 1604 | |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1605 | if (this._vertexBuffer && this._aVertexPosition) { |
| 1606 | gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer); |
| 1607 | gl.bufferData(gl.ARRAY_BUFFER, vertexArray, gl.STATIC_DRAW); |
| 1608 | gl.vertexAttribPointer(this._aVertexPosition, /* vertexComponents */ 2, gl.FLOAT, false, 0, 0); |
| 1609 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1610 | |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1611 | if (this._colorBuffer && this._aVertexColor) { |
| 1612 | gl.bindBuffer(gl.ARRAY_BUFFER, this._colorBuffer); |
| 1613 | gl.bufferData(gl.ARRAY_BUFFER, colorArray, gl.STATIC_DRAW); |
| 1614 | gl.vertexAttribPointer(this._aVertexColor, /* colorComponents */ 1, colorIndexType, true, 0, 0); |
| 1615 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | _drawGL() { |
| 1619 | const gl = /** @type {?WebGLRenderingContext} */ (this._canvasGL.getContext('webgl')); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1620 | if (!gl) { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1621 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1622 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1623 | const timelineData = this._timelineData(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1624 | if (!timelineData) { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1625 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1626 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1627 | |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1628 | if (!this._prevTimelineData || timelineData.entryTotalTimes !== this._prevTimelineData.entryTotalTimes) { |
| 1629 | this._prevTimelineData = timelineData; |
| 1630 | this._setupGLGeometry(); |
| 1631 | } |
| 1632 | |
Alexei Filippov | c34372c | 2018-08-16 20:37:39 | [diff] [blame] | 1633 | gl.viewport(0, 0, this._canvasGL.width, this._canvasGL.height); |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1634 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1635 | if (!this._vertexCount) { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1636 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1637 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1638 | |
Alexei Filippov | c34372c | 2018-08-16 20:37:39 | [diff] [blame] | 1639 | const viewportScale = [2.0 / this.boundarySpan(), -2.0 * window.devicePixelRatio / this._canvasGL.height]; |
| 1640 | const viewportShift = [this.minimumBoundary() - this.zeroTime(), this._chartViewport.scrollOffset()]; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1641 | if (this._uScalingFactor) { |
| 1642 | gl.uniform2fv(this._uScalingFactor, viewportScale); |
| 1643 | } |
| 1644 | |
| 1645 | if (this._uShiftVector) { |
| 1646 | gl.uniform2fv(this._uShiftVector, viewportShift); |
| 1647 | } |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 1648 | |
| 1649 | gl.drawArrays(gl.TRIANGLES, 0, this._vertexCount); |
| 1650 | } |
| 1651 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1652 | /** |
| 1653 | * @param {number} width |
| 1654 | * @param {number} height |
| 1655 | */ |
| 1656 | _drawGroupHeaders(width, height) { |
| 1657 | const context = /** @type {!CanvasRenderingContext2D} */ (this._canvas.getContext('2d')); |
| 1658 | const top = this._chartViewport.scrollOffset(); |
| 1659 | const ratio = window.devicePixelRatio; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1660 | if (!this._rawTimelineData) { |
| 1661 | return; |
| 1662 | } |
| 1663 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1664 | const groups = this._rawTimelineData.groups || []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1665 | if (!groups.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1666 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1667 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1668 | |
| 1669 | const groupOffsets = this._groupOffsets; |
| 1670 | const lastGroupOffset = Array.prototype.peekLast.call(groupOffsets); |
Paul Lewis | ca569a5 | 2020-09-09 16:11:51 | [diff] [blame] | 1671 | const colorUsage = ThemeSupport.ThemeSupport.ColorUsage; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1672 | |
| 1673 | context.save(); |
| 1674 | context.scale(ratio, ratio); |
| 1675 | context.translate(0, -top); |
Tim van der Lippe | bb76917 | 2020-02-12 15:32:44 | [diff] [blame] | 1676 | const defaultFont = '11px ' + Host.Platform.fontFamily(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1677 | context.font = defaultFont; |
| 1678 | |
Paul Lewis | ca569a5 | 2020-09-09 16:11:51 | [diff] [blame] | 1679 | context.fillStyle = ThemeSupport.ThemeSupport.instance().patchColorText('#fff', colorUsage.Background); |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1680 | this._forEachGroupInViewport((offset, index, group) => { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1681 | const paddingHeight = group.style.padding; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1682 | if (paddingHeight < 5) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1683 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1684 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1685 | context.fillRect(0, offset - paddingHeight + 2, width, paddingHeight - 4); |
| 1686 | }); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1687 | if (groups.length && lastGroupOffset < top + height) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1688 | context.fillRect(0, lastGroupOffset + 2, width, top + height - lastGroupOffset); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1689 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1690 | |
Paul Lewis | ca569a5 | 2020-09-09 16:11:51 | [diff] [blame] | 1691 | context.strokeStyle = ThemeSupport.ThemeSupport.instance().patchColorText('#eee', colorUsage.Background); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1692 | context.beginPath(); |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1693 | this._forEachGroupInViewport((offset, index, group, isFirst) => { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1694 | if (isFirst || group.style.padding < 4) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1695 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1696 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1697 | hLine(offset - 2.5); |
| 1698 | }); |
| 1699 | hLine(lastGroupOffset + 1.5); |
| 1700 | context.stroke(); |
| 1701 | |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1702 | this._forEachGroupInViewport((offset, index, group) => { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1703 | if (group.style.useFirstLineForOverview) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1704 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1705 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1706 | if (!this._isGroupCollapsible(index) || group.expanded) { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 1707 | if (!group.style.shareHeaderLine && this._isGroupFocused(index)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1708 | context.fillStyle = group.style.backgroundColor; |
| 1709 | context.fillRect(0, offset, width, group.style.height); |
| 1710 | } |
| 1711 | return; |
| 1712 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1713 | if (this._useWebGL) { |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1714 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1715 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1716 | let nextGroup = index + 1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1717 | while (nextGroup < groups.length && groups[nextGroup].style.nestingLevel > group.style.nestingLevel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1718 | nextGroup++; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1719 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1720 | const endLevel = nextGroup < groups.length ? groups[nextGroup].startLevel : this._dataProvider.maxStackDepth(); |
Alexei Filippov | 23428d4 | 2018-04-28 01:09:07 | [diff] [blame] | 1721 | this._drawCollapsedOverviewForGroup(group, offset, endLevel); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1722 | }); |
| 1723 | |
| 1724 | context.save(); |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1725 | this._forEachGroupInViewport((offset, index, group) => { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1726 | context.font = group.style.font; |
| 1727 | if (this._isGroupCollapsible(index) && !group.expanded || group.style.shareHeaderLine) { |
| 1728 | const width = this._labelWidthForGroup(context, group) + 2; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1729 | if (this._isGroupFocused(index)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1730 | context.fillStyle = this._selectedGroupBackroundColor; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1731 | } else { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1732 | const parsedColor = Common.Color.Color.parse(group.style.backgroundColor); |
| 1733 | if (parsedColor) { |
| 1734 | context.fillStyle = /** @type {string} */ (parsedColor.setAlpha(0.8).asString(null)); |
| 1735 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1736 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1737 | |
| 1738 | context.fillRect( |
| 1739 | this._headerLeftPadding - this._headerLabelXPadding, offset + this._headerLabelYPadding, width, |
| 1740 | group.style.height - 2 * this._headerLabelYPadding); |
| 1741 | } |
| 1742 | context.fillStyle = group.style.color; |
| 1743 | context.fillText( |
| 1744 | group.name, Math.floor(this._expansionArrowIndent * (group.style.nestingLevel + 1) + this._arrowSide), |
| 1745 | offset + group.style.height - this._textBaseline); |
| 1746 | }); |
| 1747 | context.restore(); |
| 1748 | |
Paul Lewis | ca569a5 | 2020-09-09 16:11:51 | [diff] [blame] | 1749 | context.fillStyle = ThemeSupport.ThemeSupport.instance().patchColorText('#6e6e6e', colorUsage.Foreground); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1750 | context.beginPath(); |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1751 | this._forEachGroupInViewport((offset, index, group) => { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1752 | if (this._isGroupCollapsible(index)) { |
| 1753 | drawExpansionArrow.call( |
| 1754 | this, this._expansionArrowIndent * (group.style.nestingLevel + 1), |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 1755 | offset + group.style.height - this._textBaseline - this._arrowSide / 2, Boolean(group.expanded)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1756 | } |
| 1757 | }); |
| 1758 | context.fill(); |
| 1759 | |
Paul Lewis | ca569a5 | 2020-09-09 16:11:51 | [diff] [blame] | 1760 | context.strokeStyle = ThemeSupport.ThemeSupport.instance().patchColorText('#ddd', colorUsage.Background); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1761 | context.beginPath(); |
| 1762 | context.stroke(); |
| 1763 | |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1764 | this._forEachGroupInViewport((offset, index, group, isFirst, groupHeight) => { |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 1765 | if (this._isGroupFocused(index)) { |
Alexei Filippov | 23428d4 | 2018-04-28 01:09:07 | [diff] [blame] | 1766 | const lineWidth = 2; |
| 1767 | const bracketLength = 10; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1768 | context.fillStyle = this._selectedGroupBorderColor; |
Alexei Filippov | 23428d4 | 2018-04-28 01:09:07 | [diff] [blame] | 1769 | context.fillRect(0, offset - lineWidth, lineWidth, groupHeight - group.style.padding + 2 * lineWidth); |
| 1770 | context.fillRect(0, offset - lineWidth, bracketLength, lineWidth); |
| 1771 | context.fillRect(0, offset + groupHeight - group.style.padding, bracketLength, lineWidth); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1772 | } |
| 1773 | }); |
| 1774 | |
| 1775 | context.restore(); |
| 1776 | |
| 1777 | /** |
| 1778 | * @param {number} y |
| 1779 | */ |
| 1780 | function hLine(y) { |
| 1781 | context.moveTo(0, y); |
| 1782 | context.lineTo(width, y); |
| 1783 | } |
| 1784 | |
| 1785 | /** |
| 1786 | * @param {number} x |
| 1787 | * @param {number} y |
| 1788 | * @param {boolean} expanded |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 1789 | * @this {FlameChart} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1790 | */ |
| 1791 | function drawExpansionArrow(x, y, expanded) { |
| 1792 | const arrowHeight = this._arrowSide * Math.sqrt(3) / 2; |
| 1793 | const arrowCenterOffset = Math.round(arrowHeight / 2); |
| 1794 | context.save(); |
| 1795 | context.translate(x, y); |
| 1796 | context.rotate(expanded ? Math.PI / 2 : 0); |
| 1797 | context.moveTo(-arrowCenterOffset, -this._arrowSide / 2); |
| 1798 | context.lineTo(-arrowCenterOffset, this._arrowSide / 2); |
| 1799 | context.lineTo(arrowHeight - arrowCenterOffset, 0); |
| 1800 | context.restore(); |
| 1801 | } |
| 1802 | } |
| 1803 | |
| 1804 | /** |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1805 | * @param {function(number, number, !Group, boolean, number):void} callback |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1806 | */ |
| 1807 | _forEachGroup(callback) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1808 | if (!this._rawTimelineData) { |
| 1809 | return; |
| 1810 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1811 | const groups = this._rawTimelineData.groups || []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1812 | if (!groups.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1813 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1814 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1815 | const groupOffsets = this._groupOffsets; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1816 | if (!groupOffsets) { |
| 1817 | return; |
| 1818 | } |
| 1819 | |
| 1820 | /** @type {!Array<{nestingLevel: number, visible: boolean}>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1821 | const groupStack = [{nestingLevel: -1, visible: true}]; |
| 1822 | for (let i = 0; i < groups.length; ++i) { |
| 1823 | const groupTop = groupOffsets[i]; |
| 1824 | const group = groups[i]; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1825 | let firstGroup = true; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1826 | let last = groupStack.peekLast(); |
| 1827 | while (last && last.nestingLevel >= group.style.nestingLevel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1828 | groupStack.pop(); |
| 1829 | firstGroup = false; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1830 | last = groupStack.peekLast(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1831 | } |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1832 | last = groupStack.peekLast(); |
| 1833 | const parentGroupVisible = last ? last.visible : false; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1834 | const thisGroupVisible = parentGroupVisible && (!this._isGroupCollapsible(i) || group.expanded); |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 1835 | groupStack.push({nestingLevel: group.style.nestingLevel, visible: Boolean(thisGroupVisible)}); |
Alexei Filippov | 23428d4 | 2018-04-28 01:09:07 | [diff] [blame] | 1836 | const nextOffset = i === groups.length - 1 ? groupOffsets[i + 1] + group.style.padding : groupOffsets[i + 1]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1837 | if (!parentGroupVisible) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1838 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1839 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1840 | callback(groupTop, i, group, firstGroup, nextOffset - groupTop); |
| 1841 | } |
| 1842 | } |
| 1843 | |
| 1844 | /** |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1845 | * @param {function(number, number, !Group, boolean, number):void} callback |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1846 | */ |
| 1847 | _forEachGroupInViewport(callback) { |
| 1848 | const top = this._chartViewport.scrollOffset(); |
| 1849 | this._forEachGroup((groupTop, index, group, firstGroup, height) => { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1850 | if (groupTop - group.style.padding > top + this._offsetHeight) { |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1851 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1852 | } |
| 1853 | if (groupTop + height < top) { |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1854 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1855 | } |
Alexei Filippov | 5f6b11d | 2018-08-18 03:30:28 | [diff] [blame] | 1856 | callback(groupTop, index, group, firstGroup, height); |
| 1857 | }); |
| 1858 | } |
| 1859 | |
| 1860 | /** |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1861 | * @param {!CanvasRenderingContext2D} context |
Tim van der Lippe | 8ef250c | 2020-02-20 16:29:25 | [diff] [blame] | 1862 | * @param {!Group} group |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1863 | * @return {number} |
| 1864 | */ |
| 1865 | _labelWidthForGroup(context, group) { |
Tim van der Lippe | bb76917 | 2020-02-12 15:32:44 | [diff] [blame] | 1866 | return UI.UIUtils.measureTextWidth(context, group.name) + |
| 1867 | this._expansionArrowIndent * (group.style.nestingLevel + 1) + 2 * this._headerLabelXPadding; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | /** |
Tim van der Lippe | 8ef250c | 2020-02-20 16:29:25 | [diff] [blame] | 1871 | * @param {!Group} group |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1872 | * @param {number} y |
| 1873 | * @param {number} endLevel |
| 1874 | */ |
| 1875 | _drawCollapsedOverviewForGroup(group, y, endLevel) { |
Tim van der Lippe | bb76917 | 2020-02-12 15:32:44 | [diff] [blame] | 1876 | const range = new Common.SegmentedRange.SegmentedRange(mergeCallback); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1877 | const timeWindowLeft = this._chartViewport.windowLeftTime(); |
| 1878 | const timeWindowRight = this._chartViewport.windowRightTime(); |
| 1879 | const context = /** @type {!CanvasRenderingContext2D} */ (this._canvas.getContext('2d')); |
| 1880 | const barHeight = group.style.height; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1881 | if (!this._rawTimelineData) { |
| 1882 | return; |
| 1883 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1884 | const entryStartTimes = this._rawTimelineData.entryStartTimes; |
| 1885 | const entryTotalTimes = this._rawTimelineData.entryTotalTimes; |
| 1886 | const timeToPixel = this._chartViewport.timeToPixel(); |
| 1887 | |
| 1888 | for (let level = group.startLevel; level < endLevel; ++level) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1889 | /** @type {!Array.<number>} */ |
| 1890 | const levelIndexes = this._timelineLevels ? this._timelineLevels[level] : []; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1891 | const rightIndexOnLevel = |
| 1892 | levelIndexes.lowerBound(timeWindowRight, (time, entryIndex) => time - entryStartTimes[entryIndex]) - 1; |
| 1893 | let lastDrawOffset = Infinity; |
| 1894 | |
| 1895 | for (let entryIndexOnLevel = rightIndexOnLevel; entryIndexOnLevel >= 0; --entryIndexOnLevel) { |
| 1896 | const entryIndex = levelIndexes[entryIndexOnLevel]; |
| 1897 | const entryStartTime = entryStartTimes[entryIndex]; |
| 1898 | const barX = this._timeToPositionClipped(entryStartTime); |
| 1899 | const entryEndTime = entryStartTime + entryTotalTimes[entryIndex]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1900 | if (isNaN(entryEndTime) || barX >= lastDrawOffset) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1901 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1902 | } |
| 1903 | if (entryEndTime <= timeWindowLeft) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1904 | break; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1905 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1906 | lastDrawOffset = barX; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1907 | const color = this._entryColorsCache ? this._entryColorsCache[entryIndex] : ''; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1908 | const endBarX = this._timeToPositionClipped(entryEndTime); |
| 1909 | if (group.style.useDecoratorsForOverview && this._dataProvider.forceDecoration(entryIndex)) { |
| 1910 | const unclippedBarX = this._chartViewport.timeToPosition(entryStartTime); |
| 1911 | const barWidth = endBarX - barX; |
| 1912 | context.beginPath(); |
| 1913 | context.fillStyle = color; |
| 1914 | context.fillRect(barX, y, barWidth, barHeight - 1); |
| 1915 | this._dataProvider.decorateEntry( |
| 1916 | entryIndex, context, '', barX, y, barWidth, barHeight, unclippedBarX, timeToPixel); |
| 1917 | continue; |
| 1918 | } |
Tim van der Lippe | bb76917 | 2020-02-12 15:32:44 | [diff] [blame] | 1919 | range.append(new Common.SegmentedRange.Segment(barX, endBarX, color)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1920 | } |
| 1921 | } |
| 1922 | |
| 1923 | const segments = range.segments().slice().sort((a, b) => a.data.localeCompare(b.data)); |
| 1924 | let lastColor; |
| 1925 | context.beginPath(); |
| 1926 | for (let i = 0; i < segments.length; ++i) { |
| 1927 | const segment = segments[i]; |
| 1928 | if (lastColor !== segments[i].data) { |
| 1929 | context.fill(); |
| 1930 | context.beginPath(); |
| 1931 | lastColor = segments[i].data; |
| 1932 | context.fillStyle = lastColor; |
| 1933 | } |
Alexei Filippov | 23428d4 | 2018-04-28 01:09:07 | [diff] [blame] | 1934 | context.rect(segment.begin, y, segment.end - segment.begin, barHeight); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1935 | } |
| 1936 | context.fill(); |
| 1937 | |
| 1938 | /** |
Tim van der Lippe | bb76917 | 2020-02-12 15:32:44 | [diff] [blame] | 1939 | * @param {!Common.SegmentedRange.Segment} a |
| 1940 | * @param {!Common.SegmentedRange.Segment} b |
| 1941 | * @return {?Common.SegmentedRange.Segment} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1942 | */ |
| 1943 | function mergeCallback(a, b) { |
| 1944 | return a.data === b.data && a.end + 0.4 > b.end ? a : null; |
| 1945 | } |
| 1946 | } |
| 1947 | |
| 1948 | /** |
| 1949 | * @param {!CanvasRenderingContext2D} context |
| 1950 | * @param {number} height |
| 1951 | * @param {number} width |
| 1952 | */ |
| 1953 | _drawFlowEvents(context, width, height) { |
| 1954 | context.save(); |
| 1955 | const ratio = window.devicePixelRatio; |
| 1956 | const top = this._chartViewport.scrollOffset(); |
| 1957 | const arrowWidth = 6; |
| 1958 | context.scale(ratio, ratio); |
| 1959 | context.translate(0, -top); |
| 1960 | |
| 1961 | context.fillStyle = '#7f5050'; |
| 1962 | context.strokeStyle = '#7f5050'; |
| 1963 | const td = this._timelineData(); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 1964 | if (!td) { |
| 1965 | return; |
| 1966 | } |
| 1967 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1968 | const endIndex = td.flowStartTimes.lowerBound(this._chartViewport.windowRightTime()); |
| 1969 | |
| 1970 | context.lineWidth = 0.5; |
| 1971 | for (let i = 0; i < endIndex; ++i) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1972 | if (!td.flowEndTimes[i] || td.flowEndTimes[i] < this._chartViewport.windowLeftTime()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1973 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1974 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1975 | const startX = this._chartViewport.timeToPosition(td.flowStartTimes[i]); |
| 1976 | const endX = this._chartViewport.timeToPosition(td.flowEndTimes[i]); |
| 1977 | const startLevel = td.flowStartLevels[i]; |
| 1978 | const endLevel = td.flowEndLevels[i]; |
| 1979 | const startY = this._levelToOffset(startLevel) + this._levelHeight(startLevel) / 2; |
| 1980 | const endY = this._levelToOffset(endLevel) + this._levelHeight(endLevel) / 2; |
| 1981 | |
| 1982 | |
| 1983 | const segment = Math.min((endX - startX) / 4, 40); |
| 1984 | const distanceTime = td.flowEndTimes[i] - td.flowStartTimes[i]; |
| 1985 | const distanceY = (endY - startY) / 10; |
| 1986 | const spread = 30; |
| 1987 | const lineY = distanceTime < 1 ? startY : spread + Math.max(0, startY + distanceY * (i % spread)); |
| 1988 | |
| 1989 | const p = []; |
| 1990 | p.push({x: startX, y: startY}); |
| 1991 | p.push({x: startX + arrowWidth, y: startY}); |
| 1992 | p.push({x: startX + segment + 2 * arrowWidth, y: startY}); |
| 1993 | p.push({x: startX + segment, y: lineY}); |
| 1994 | p.push({x: startX + segment * 2, y: lineY}); |
| 1995 | p.push({x: endX - segment * 2, y: lineY}); |
| 1996 | p.push({x: endX - segment, y: lineY}); |
| 1997 | p.push({x: endX - segment - 2 * arrowWidth, y: endY}); |
| 1998 | p.push({x: endX - arrowWidth, y: endY}); |
| 1999 | |
| 2000 | context.beginPath(); |
| 2001 | context.moveTo(p[0].x, p[0].y); |
| 2002 | context.lineTo(p[1].x, p[1].y); |
| 2003 | context.bezierCurveTo(p[2].x, p[2].y, p[3].x, p[3].y, p[4].x, p[4].y); |
| 2004 | context.lineTo(p[5].x, p[5].y); |
| 2005 | context.bezierCurveTo(p[6].x, p[6].y, p[7].x, p[7].y, p[8].x, p[8].y); |
| 2006 | context.stroke(); |
| 2007 | |
| 2008 | context.beginPath(); |
| 2009 | context.arc(startX, startY, 2, -Math.PI / 2, Math.PI / 2, false); |
| 2010 | context.fill(); |
| 2011 | |
| 2012 | context.beginPath(); |
| 2013 | context.moveTo(endX, endY); |
| 2014 | context.lineTo(endX - arrowWidth, endY - 3); |
| 2015 | context.lineTo(endX - arrowWidth, endY + 3); |
| 2016 | context.fill(); |
| 2017 | } |
| 2018 | context.restore(); |
| 2019 | } |
| 2020 | |
| 2021 | _drawMarkers() { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2022 | const timelineData = this._timelineData(); |
| 2023 | if (!timelineData) { |
| 2024 | return; |
| 2025 | } |
| 2026 | const markers = timelineData.markers; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2027 | const left = this._markerIndexBeforeTime(this.minimumBoundary()); |
| 2028 | const rightBoundary = this.maximumBoundary(); |
| 2029 | const timeToPixel = this._chartViewport.timeToPixel(); |
| 2030 | |
| 2031 | const context = /** @type {!CanvasRenderingContext2D} */ (this._canvas.getContext('2d')); |
| 2032 | context.save(); |
| 2033 | const ratio = window.devicePixelRatio; |
| 2034 | context.scale(ratio, ratio); |
| 2035 | context.translate(0, 3); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2036 | const height = HeaderHeight - 1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2037 | for (let i = left; i < markers.length; i++) { |
| 2038 | const timestamp = markers[i].startTime(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2039 | if (timestamp > rightBoundary) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2040 | break; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2041 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2042 | markers[i].draw(context, this._chartViewport.timeToPosition(timestamp), height, timeToPixel); |
| 2043 | } |
| 2044 | context.restore(); |
| 2045 | } |
| 2046 | |
| 2047 | _updateMarkerHighlight() { |
| 2048 | const element = this._markerHighlighElement; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2049 | if (element.parentElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2050 | element.remove(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2051 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2052 | const markerIndex = this._highlightedMarkerIndex; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2053 | if (markerIndex === -1) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2054 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2055 | } |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2056 | const timelineData = this._timelineData(); |
| 2057 | if (!timelineData) { |
| 2058 | return; |
| 2059 | } |
| 2060 | const marker = timelineData.markers[markerIndex]; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2061 | const barX = this._timeToPositionClipped(marker.startTime()); |
Tim van der Lippe | 70842f3 | 2020-11-23 16:56:57 | [diff] [blame] | 2062 | UI.Tooltip.Tooltip.install(element, marker.title() || ''); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2063 | const style = element.style; |
| 2064 | style.left = barX + 'px'; |
| 2065 | style.backgroundColor = marker.color(); |
| 2066 | this._viewportElement.appendChild(element); |
| 2067 | } |
| 2068 | |
| 2069 | /** |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2070 | * @param {?TimelineData} timelineData |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2071 | */ |
| 2072 | _processTimelineData(timelineData) { |
| 2073 | if (!timelineData) { |
| 2074 | this._timelineLevels = null; |
| 2075 | this._visibleLevelOffsets = null; |
| 2076 | this._visibleLevels = null; |
| 2077 | this._groupOffsets = null; |
| 2078 | this._rawTimelineData = null; |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 2079 | this._forceDecorationCache = null; |
Alexei Filippov | e519762 | 2018-08-18 03:04:33 | [diff] [blame] | 2080 | this._entryColorsCache = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2081 | this._rawTimelineDataLength = 0; |
| 2082 | this._selectedGroup = -1; |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 2083 | this._keyboardFocusedGroup = -1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2084 | this._flameChartDelegate.updateSelectedGroup(this, null); |
| 2085 | return; |
| 2086 | } |
| 2087 | |
| 2088 | this._rawTimelineData = timelineData; |
| 2089 | this._rawTimelineDataLength = timelineData.entryStartTimes.length; |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 2090 | this._forceDecorationCache = new Int8Array(this._rawTimelineDataLength); |
Alexei Filippov | e519762 | 2018-08-18 03:04:33 | [diff] [blame] | 2091 | this._entryColorsCache = new Array(this._rawTimelineDataLength); |
| 2092 | for (let i = 0; i < this._rawTimelineDataLength; ++i) { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 2093 | this._forceDecorationCache[i] = this._dataProvider.forceDecoration(i) ? 1 : 0; |
Alexei Filippov | e519762 | 2018-08-18 03:04:33 | [diff] [blame] | 2094 | this._entryColorsCache[i] = this._dataProvider.entryColor(i); |
| 2095 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2096 | |
| 2097 | const entryCounters = new Uint32Array(this._dataProvider.maxStackDepth() + 1); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2098 | for (let i = 0; i < timelineData.entryLevels.length; ++i) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2099 | ++entryCounters[timelineData.entryLevels[i]]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2100 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2101 | const levelIndexes = new Array(entryCounters.length); |
| 2102 | for (let i = 0; i < levelIndexes.length; ++i) { |
| 2103 | levelIndexes[i] = new Uint32Array(entryCounters[i]); |
| 2104 | entryCounters[i] = 0; |
| 2105 | } |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 2106 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2107 | for (let i = 0; i < timelineData.entryLevels.length; ++i) { |
| 2108 | const level = timelineData.entryLevels[i]; |
| 2109 | levelIndexes[level][entryCounters[level]++] = i; |
| 2110 | } |
| 2111 | this._timelineLevels = levelIndexes; |
| 2112 | const groups = this._rawTimelineData.groups || []; |
| 2113 | for (let i = 0; i < groups.length; ++i) { |
| 2114 | const expanded = this._groupExpansionState[groups[i].name]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2115 | if (expanded !== undefined) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2116 | groups[i].expanded = expanded; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2117 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2118 | } |
| 2119 | this._updateLevelPositions(); |
| 2120 | this._updateHeight(); |
| 2121 | |
| 2122 | this._selectedGroup = timelineData.selectedGroup ? groups.indexOf(timelineData.selectedGroup) : -1; |
Anubha Mathur | 72dd582 | 2019-06-13 23:05:19 | [diff] [blame] | 2123 | this._keyboardFocusedGroup = this._selectedGroup; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2124 | this._flameChartDelegate.updateSelectedGroup(this, timelineData.selectedGroup); |
| 2125 | } |
| 2126 | |
| 2127 | _updateLevelPositions() { |
| 2128 | const levelCount = this._dataProvider.maxStackDepth(); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2129 | const groups = this._rawTimelineData ? (this._rawTimelineData.groups || []) : []; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2130 | this._visibleLevelOffsets = new Uint32Array(levelCount + 1); |
| 2131 | this._visibleLevelHeights = new Uint32Array(levelCount); |
| 2132 | this._visibleLevels = new Uint16Array(levelCount); |
| 2133 | this._groupOffsets = new Uint32Array(groups.length + 1); |
| 2134 | |
| 2135 | let groupIndex = -1; |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2136 | let currentOffset = this._rulerEnabled ? HeaderHeight + 2 : 2; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2137 | let visible = true; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2138 | /** @type {!Array<{nestingLevel: number, visible: boolean}>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2139 | const groupStack = [{nestingLevel: -1, visible: true}]; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2140 | const lastGroupLevel = |
| 2141 | Math.max(levelCount, groups.length ? /** @type {!Group} */ (groups.peekLast()).startLevel + 1 : 0); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2142 | let level; |
| 2143 | for (level = 0; level < lastGroupLevel; ++level) { |
| 2144 | let parentGroupIsVisible = true; |
| 2145 | let style; |
| 2146 | while (groupIndex < groups.length - 1 && level === groups[groupIndex + 1].startLevel) { |
| 2147 | ++groupIndex; |
| 2148 | style = groups[groupIndex].style; |
| 2149 | let nextLevel = true; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2150 | let last = groupStack.peekLast(); |
| 2151 | while (last && last.nestingLevel >= style.nestingLevel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2152 | groupStack.pop(); |
| 2153 | nextLevel = false; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2154 | last = groupStack.peekLast(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2155 | } |
| 2156 | const thisGroupIsVisible = |
| 2157 | groupIndex >= 0 && this._isGroupCollapsible(groupIndex) ? groups[groupIndex].expanded : true; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2158 | |
| 2159 | last = groupStack.peekLast(); |
| 2160 | parentGroupIsVisible = last ? last.visible : false; |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 2161 | visible = Boolean(thisGroupIsVisible) && parentGroupIsVisible; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2162 | groupStack.push({nestingLevel: style.nestingLevel, visible: visible}); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2163 | if (parentGroupIsVisible) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2164 | currentOffset += nextLevel ? 0 : style.padding; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2165 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2166 | this._groupOffsets[groupIndex] = currentOffset; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2167 | if (parentGroupIsVisible && !style.shareHeaderLine) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2168 | currentOffset += style.height; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2169 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2170 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2171 | if (level >= levelCount) { |
Yang Guo | 8fb3ac5 | 2019-07-31 20:17:50 | [diff] [blame] | 2172 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2173 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2174 | const isFirstOnLevel = groupIndex >= 0 && level === groups[groupIndex].startLevel; |
| 2175 | const thisLevelIsVisible = |
| 2176 | parentGroupIsVisible && (visible || isFirstOnLevel && groups[groupIndex].style.useFirstLineForOverview); |
Yang Guo | 8fb3ac5 | 2019-07-31 20:17:50 | [diff] [blame] | 2177 | let height; |
| 2178 | if (groupIndex >= 0) { |
| 2179 | const group = groups[groupIndex]; |
| 2180 | const styleB = group.style; |
| 2181 | height = isFirstOnLevel && !styleB.shareHeaderLine || (styleB.collapsible && !group.expanded) ? |
| 2182 | styleB.height : |
| 2183 | (styleB.itemsHeight || this._barHeight); |
| 2184 | } else { |
| 2185 | height = this._barHeight; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2186 | } |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2187 | this._visibleLevels[level] = thisLevelIsVisible ? 1 : 0; |
Yang Guo | 8fb3ac5 | 2019-07-31 20:17:50 | [diff] [blame] | 2188 | this._visibleLevelOffsets[level] = currentOffset; |
| 2189 | this._visibleLevelHeights[level] = height; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2190 | if (thisLevelIsVisible || (parentGroupIsVisible && style && style.shareHeaderLine && isFirstOnLevel)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2191 | currentOffset += this._visibleLevelHeights[level]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2192 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2193 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2194 | if (groupIndex >= 0) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2195 | this._groupOffsets[groupIndex + 1] = currentOffset; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2196 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2197 | this._visibleLevelOffsets[level] = currentOffset; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2198 | if (this._useWebGL) { |
Alexei Filippov | 57ccafb | 2018-08-14 20:59:05 | [diff] [blame] | 2199 | this._setupGLGeometry(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2200 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | /** |
| 2204 | * @param {number} index |
| 2205 | */ |
| 2206 | _isGroupCollapsible(index) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2207 | if (!this._rawTimelineData) { |
| 2208 | return; |
| 2209 | } |
| 2210 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2211 | const groups = this._rawTimelineData.groups || []; |
| 2212 | const style = groups[index].style; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2213 | if (!style.shareHeaderLine || !style.collapsible) { |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 2214 | return Boolean(style.collapsible); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2215 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2216 | const isLastGroup = index + 1 >= groups.length; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2217 | if (!isLastGroup && groups[index + 1].style.nestingLevel > style.nestingLevel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2218 | return true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2219 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2220 | const nextGroupLevel = isLastGroup ? this._dataProvider.maxStackDepth() : groups[index + 1].startLevel; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2221 | if (nextGroupLevel !== groups[index].startLevel + 1) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2222 | return true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2223 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2224 | // For groups that only have one line and share header line, pretend these are not collapsible |
| 2225 | // unless the itemsHeight does not match the headerHeight |
| 2226 | return style.height !== style.itemsHeight; |
| 2227 | } |
| 2228 | |
| 2229 | /** |
| 2230 | * @param {number} entryIndex |
| 2231 | */ |
| 2232 | setSelectedEntry(entryIndex) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2233 | if (this._selectedEntryIndex === entryIndex) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2234 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2235 | } |
| 2236 | if (entryIndex !== -1) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2237 | this._chartViewport.hideRangeSelection(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2238 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2239 | this._selectedEntryIndex = entryIndex; |
| 2240 | this._revealEntry(entryIndex); |
| 2241 | this._updateElementPosition(this._selectedElement, this._selectedEntryIndex); |
| 2242 | } |
| 2243 | |
| 2244 | /** |
| 2245 | * @param {!Element} element |
| 2246 | * @param {number} entryIndex |
| 2247 | */ |
| 2248 | _updateElementPosition(element, entryIndex) { |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 2249 | const elementMinWidthPx = 2; |
| 2250 | element.classList.add('hidden'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2251 | if (entryIndex === -1) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2252 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2253 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2254 | const timelineData = this._timelineData(); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2255 | if (!timelineData) { |
| 2256 | return; |
| 2257 | } |
| 2258 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2259 | const startTime = timelineData.entryStartTimes[entryIndex]; |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 2260 | const duration = timelineData.entryTotalTimes[entryIndex]; |
Alexei Filippov | 6510650 | 2018-11-29 05:16:19 | [diff] [blame] | 2261 | let barX = 0; |
| 2262 | let barWidth = 0; |
| 2263 | let visible = true; |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 2264 | if (Number.isNaN(duration)) { |
| 2265 | const position = this._markerPositions.get(entryIndex); |
Alexei Filippov | 6510650 | 2018-11-29 05:16:19 | [diff] [blame] | 2266 | if (position) { |
| 2267 | barX = position.x; |
| 2268 | barWidth = position.width; |
| 2269 | } else { |
| 2270 | visible = false; |
| 2271 | } |
Alexei Filippov | 6c622e9 | 2018-11-10 02:13:59 | [diff] [blame] | 2272 | } else { |
| 2273 | barX = this._chartViewport.timeToPosition(startTime); |
| 2274 | barWidth = duration * this._chartViewport.timeToPixel(); |
| 2275 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2276 | if (barX + barWidth <= 0 || barX >= this._offsetWidth) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2277 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2278 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2279 | const barCenter = barX + barWidth / 2; |
| 2280 | barWidth = Math.max(barWidth, elementMinWidthPx); |
| 2281 | barX = barCenter - barWidth / 2; |
| 2282 | const entryLevel = timelineData.entryLevels[entryIndex]; |
| 2283 | const barY = this._levelToOffset(entryLevel) - this._chartViewport.scrollOffset(); |
| 2284 | const barHeight = this._levelHeight(entryLevel); |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2285 | const style = /** @type {!HTMLElement} */ (element).style; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2286 | style.left = barX + 'px'; |
| 2287 | style.top = barY + 'px'; |
| 2288 | style.width = barWidth + 'px'; |
| 2289 | style.height = barHeight - 1 + 'px'; |
Alexei Filippov | 6510650 | 2018-11-29 05:16:19 | [diff] [blame] | 2290 | element.classList.toggle('hidden', !visible); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2291 | this._viewportElement.appendChild(element); |
| 2292 | } |
| 2293 | |
| 2294 | /** |
| 2295 | * @param {number} time |
| 2296 | * @return {number} |
| 2297 | */ |
| 2298 | _timeToPositionClipped(time) { |
Jack Franklin | 1be909c | 2020-03-04 08:57:41 | [diff] [blame] | 2299 | return Platform.NumberUtilities.clamp(this._chartViewport.timeToPosition(time), 0, this._offsetWidth); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | /** |
| 2303 | * @param {number} level |
| 2304 | * @return {number} |
| 2305 | */ |
| 2306 | _levelToOffset(level) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2307 | if (!this._visibleLevelOffsets) { |
| 2308 | throw new Error('No visible level offsets'); |
| 2309 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2310 | return this._visibleLevelOffsets[level]; |
| 2311 | } |
| 2312 | |
| 2313 | /** |
| 2314 | * @param {number} level |
| 2315 | * @return {number} |
| 2316 | */ |
| 2317 | _levelHeight(level) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2318 | if (!this._visibleLevelHeights) { |
| 2319 | throw new Error('No visible level heights'); |
| 2320 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2321 | return this._visibleLevelHeights[level]; |
| 2322 | } |
| 2323 | |
| 2324 | _updateBoundaries() { |
| 2325 | this._totalTime = this._dataProvider.totalTime(); |
| 2326 | this._minimumBoundary = this._dataProvider.minimumBoundary(); |
| 2327 | this._chartViewport.setBoundaries(this._minimumBoundary, this._totalTime); |
| 2328 | } |
| 2329 | |
| 2330 | _updateHeight() { |
Alexei Filippov | 23428d4 | 2018-04-28 01:09:07 | [diff] [blame] | 2331 | const height = this._levelToOffset(this._dataProvider.maxStackDepth()) + 2; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2332 | this._chartViewport.setContentHeight(height); |
| 2333 | } |
| 2334 | |
| 2335 | /** |
| 2336 | * @override |
| 2337 | */ |
| 2338 | onResize() { |
| 2339 | this.scheduleUpdate(); |
| 2340 | } |
| 2341 | |
| 2342 | /** |
| 2343 | * @override |
| 2344 | */ |
| 2345 | update() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2346 | if (!this._timelineData()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2347 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2348 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2349 | this._resetCanvas(); |
| 2350 | this._updateHeight(); |
| 2351 | this._updateBoundaries(); |
| 2352 | this._draw(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2353 | if (!this._chartViewport.isDragging()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2354 | this._updateHighlight(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2355 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | reset() { |
| 2359 | this._chartViewport.reset(); |
| 2360 | this._rawTimelineData = null; |
| 2361 | this._rawTimelineDataLength = 0; |
| 2362 | this._highlightedMarkerIndex = -1; |
| 2363 | this._highlightedEntryIndex = -1; |
| 2364 | this._selectedEntryIndex = -1; |
| 2365 | /** @type {!Map<string,!Map<string,number>>} */ |
| 2366 | this._textWidth = new Map(); |
| 2367 | this._chartViewport.scheduleUpdate(); |
| 2368 | } |
| 2369 | |
| 2370 | scheduleUpdate() { |
| 2371 | this._chartViewport.scheduleUpdate(); |
| 2372 | } |
| 2373 | |
| 2374 | _enabled() { |
| 2375 | return this._rawTimelineDataLength !== 0; |
| 2376 | } |
| 2377 | |
| 2378 | /** |
| 2379 | * @override |
| 2380 | * @param {number} time |
| 2381 | * @return {number} |
| 2382 | */ |
| 2383 | computePosition(time) { |
| 2384 | return this._chartViewport.timeToPosition(time); |
| 2385 | } |
| 2386 | |
| 2387 | /** |
| 2388 | * @override |
| 2389 | * @param {number} value |
| 2390 | * @param {number=} precision |
| 2391 | * @return {string} |
| 2392 | */ |
| 2393 | formatValue(value, precision) { |
| 2394 | return this._dataProvider.formatValue(value - this.zeroTime(), precision); |
| 2395 | } |
| 2396 | |
| 2397 | /** |
| 2398 | * @override |
| 2399 | * @return {number} |
| 2400 | */ |
| 2401 | maximumBoundary() { |
| 2402 | return this._chartViewport.windowRightTime(); |
| 2403 | } |
| 2404 | |
| 2405 | /** |
| 2406 | * @override |
| 2407 | * @return {number} |
| 2408 | */ |
| 2409 | minimumBoundary() { |
| 2410 | return this._chartViewport.windowLeftTime(); |
| 2411 | } |
| 2412 | |
| 2413 | /** |
| 2414 | * @override |
| 2415 | * @return {number} |
| 2416 | */ |
| 2417 | zeroTime() { |
| 2418 | return this._dataProvider.minimumBoundary(); |
| 2419 | } |
| 2420 | |
| 2421 | /** |
| 2422 | * @override |
| 2423 | * @return {number} |
| 2424 | */ |
| 2425 | boundarySpan() { |
Alexei Filippov | 2578eb0 | 2018-04-11 08:15:05 | [diff] [blame] | 2426 | return this.maximumBoundary() - this.minimumBoundary(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2427 | } |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2428 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2429 | |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2430 | export const HeaderHeight = 15; |
| 2431 | export const MinimalTimeWindowMs = 0.5; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2432 | |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2433 | export class TimelineData { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2434 | /** |
| 2435 | * @param {!Array<number>|!Uint16Array} entryLevels |
| 2436 | * @param {!Array<number>|!Float32Array} entryTotalTimes |
| 2437 | * @param {!Array<number>|!Float64Array} entryStartTimes |
Tim van der Lippe | 8ef250c | 2020-02-20 16:29:25 | [diff] [blame] | 2438 | * @param {?Array<!Group>} groups |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2439 | */ |
| 2440 | constructor(entryLevels, entryTotalTimes, entryStartTimes, groups) { |
| 2441 | this.entryLevels = entryLevels; |
| 2442 | this.entryTotalTimes = entryTotalTimes; |
| 2443 | this.entryStartTimes = entryStartTimes; |
Tim van der Lippe | dfbb48f | 2020-11-19 14:49:15 | [diff] [blame] | 2444 | this.groups = groups || []; |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2445 | /** @type {!Array.<!FlameChartMarker>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2446 | this.markers = []; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2447 | /** @type {!Array.<number>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2448 | this.flowStartTimes = []; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2449 | /** @type {!Array.<number>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2450 | this.flowStartLevels = []; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2451 | /** @type {!Array.<number>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2452 | this.flowEndTimes = []; |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2453 | /** @type {!Array.<number>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2454 | this.flowEndLevels = []; |
Tim van der Lippe | 8ef250c | 2020-02-20 16:29:25 | [diff] [blame] | 2455 | /** @type {?Group} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2456 | this.selectedGroup = null; |
| 2457 | } |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2458 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2459 | |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2460 | /** |
| 2461 | * @interface |
| 2462 | */ |
| 2463 | export class FlameChartDataProvider { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2464 | /** |
| 2465 | * @return {number} |
| 2466 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2467 | minimumBoundary() { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2468 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2469 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2470 | |
| 2471 | /** |
| 2472 | * @return {number} |
| 2473 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2474 | totalTime() { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2475 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2476 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2477 | |
| 2478 | /** |
| 2479 | * @param {number} value |
| 2480 | * @param {number=} precision |
| 2481 | * @return {string} |
| 2482 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2483 | formatValue(value, precision) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2484 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2485 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2486 | |
| 2487 | /** |
| 2488 | * @return {number} |
| 2489 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2490 | maxStackDepth() { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2491 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2492 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2493 | |
| 2494 | /** |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2495 | * @return {?TimelineData} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2496 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2497 | timelineData() { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2498 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2499 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2500 | |
| 2501 | /** |
| 2502 | * @param {number} entryIndex |
| 2503 | * @return {?Element} |
| 2504 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2505 | prepareHighlightedEntryInfo(entryIndex) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2506 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2507 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2508 | |
| 2509 | /** |
| 2510 | * @param {number} entryIndex |
| 2511 | * @return {boolean} |
| 2512 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2513 | canJumpToEntry(entryIndex) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2514 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2515 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2516 | |
| 2517 | /** |
| 2518 | * @param {number} entryIndex |
| 2519 | * @return {?string} |
| 2520 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2521 | entryTitle(entryIndex) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2522 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2523 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2524 | |
| 2525 | /** |
| 2526 | * @param {number} entryIndex |
| 2527 | * @return {?string} |
| 2528 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2529 | entryFont(entryIndex) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2530 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2531 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2532 | |
| 2533 | /** |
| 2534 | * @param {number} entryIndex |
| 2535 | * @return {string} |
| 2536 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2537 | entryColor(entryIndex) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2538 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2539 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2540 | |
| 2541 | /** |
| 2542 | * @param {number} entryIndex |
| 2543 | * @param {!CanvasRenderingContext2D} context |
| 2544 | * @param {?string} text |
| 2545 | * @param {number} barX |
| 2546 | * @param {number} barY |
| 2547 | * @param {number} barWidth |
| 2548 | * @param {number} barHeight |
| 2549 | * @param {number} unclippedBarX |
| 2550 | * @param {number} timeToPixelRatio |
| 2551 | * @return {boolean} |
| 2552 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2553 | decorateEntry(entryIndex, context, text, barX, barY, barWidth, barHeight, unclippedBarX, timeToPixelRatio) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2554 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2555 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2556 | |
| 2557 | /** |
| 2558 | * @param {number} entryIndex |
| 2559 | * @return {boolean} |
| 2560 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2561 | forceDecoration(entryIndex) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2562 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2563 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2564 | |
| 2565 | /** |
| 2566 | * @param {number} entryIndex |
| 2567 | * @return {string} |
| 2568 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2569 | textColor(entryIndex) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2570 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2571 | } |
Paul Lewis | ead4575 | 2020-06-23 09:51:36 | [diff] [blame] | 2572 | |
| 2573 | /** |
| 2574 | * @return {!Map<string, !SDK.TracingModel.Event>} |
| 2575 | */ |
| 2576 | navStartTimes() { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2577 | throw new Error('Not implemented'); |
Paul Lewis | ead4575 | 2020-06-23 09:51:36 | [diff] [blame] | 2578 | } |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2579 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2580 | |
| 2581 | /** |
| 2582 | * @interface |
| 2583 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2584 | export class FlameChartMarker { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2585 | /** |
| 2586 | * @return {number} |
| 2587 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2588 | startTime() { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2589 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2590 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2591 | |
| 2592 | /** |
| 2593 | * @return {string} |
| 2594 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2595 | color() { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2596 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2597 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2598 | |
| 2599 | /** |
Alexei Filippov | 72d792d | 2018-11-06 07:15:04 | [diff] [blame] | 2600 | * @return {?string} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2601 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2602 | title() { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2603 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2604 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2605 | |
| 2606 | /** |
| 2607 | * @param {!CanvasRenderingContext2D} context |
| 2608 | * @param {number} x |
| 2609 | * @param {number} height |
| 2610 | * @param {number} pixelsPerMillisecond |
| 2611 | */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2612 | draw(context, x, height, pixelsPerMillisecond) { |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2613 | throw new Error('Not implemented'); |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2614 | } |
| 2615 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2616 | |
| 2617 | /** @enum {symbol} */ |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2618 | export const Events = { |
Michael Liao | 712bbc2 | 2019-10-15 19:21:51 | [diff] [blame] | 2619 | CanvasFocused: Symbol('CanvasFocused'), |
| 2620 | EntryInvoked: Symbol('EntryInvoked'), |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2621 | EntrySelected: Symbol('EntrySelected'), |
| 2622 | EntryHighlighted: Symbol('EntryHighlighted') |
| 2623 | }; |
| 2624 | |
Tim van der Lippe | fd2b2ce | 2020-01-03 15:05:18 | [diff] [blame] | 2625 | export const Colors = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2626 | SelectedGroupBackground: 'hsl(215, 85%, 98%)', |
| 2627 | SelectedGroupBorder: 'hsl(216, 68%, 54%)', |
| 2628 | }; |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 2629 | |
| 2630 | /** |
| 2631 | * @typedef {!{ |
Tim van der Lippe | 3b1f745 | 2021-01-08 11:25:13 | [diff] [blame] | 2632 | * name: !Platform.UIString.LocalizedString, |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 2633 | * startLevel: number, |
| 2634 | * expanded: (boolean|undefined), |
| 2635 | * selectable: (boolean|undefined), |
Tim van der Lippe | dfbb48f | 2020-11-19 14:49:15 | [diff] [blame] | 2636 | * style: !GroupStyle, |
| 2637 | * track: (?TimelineModel.TimelineModel.Track|undefined), |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 2638 | * }} |
| 2639 | */ |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2640 | // @ts-ignore Typedef |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 2641 | export let Group; |
| 2642 | |
| 2643 | /** |
| 2644 | * @typedef {!{ |
| 2645 | * height: number, |
| 2646 | * padding: number, |
| 2647 | * collapsible: boolean, |
| 2648 | * font: string, |
| 2649 | * color: string, |
| 2650 | * backgroundColor: string, |
| 2651 | * nestingLevel: number, |
| 2652 | * itemsHeight: (number|undefined), |
| 2653 | * shareHeaderLine: (boolean|undefined), |
| 2654 | * useFirstLineForOverview: (boolean|undefined), |
| 2655 | * useDecoratorsForOverview: (boolean|undefined) |
| 2656 | * }} |
| 2657 | */ |
Paul Lewis | cf1f8a4 | 2020-11-04 21:05:24 | [diff] [blame] | 2658 | // @ts-ignore Typedef |
Tim van der Lippe | cec9b76 | 2020-02-13 15:31:22 | [diff] [blame] | 2659 | export let GroupStyle; |