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