/
TimelineFlameChartView.ts
562 lines (498 loc) · 22.9 KB
/
TimelineFlameChartView.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as Common from '../../core/common/common.js';
import * as i18n from '../../core/i18n/i18n.js';
import * as Platform from '../../core/platform/platform.js';
import * as SDK from '../../core/sdk/sdk.js';
import * as Bindings from '../../models/bindings/bindings.js';
import * as TimelineModel from '../../models/timeline_model/timeline_model.js';
import * as TraceEngine from '../../models/trace/trace.js';
import * as TraceBounds from '../../services/trace_bounds/trace_bounds.js';
import * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
import * as UI from '../../ui/legacy/legacy.js';
import {CountersGraph} from './CountersGraph.js';
import {type PerformanceModel} from './PerformanceModel.js';
import {TimelineDetailsView} from './TimelineDetailsView.js';
import {TimelineRegExp} from './TimelineFilters.js';
import {
Events as TimelineFlameChartDataProviderEvents,
TimelineFlameChartDataProvider,
} from './TimelineFlameChartDataProvider.js';
import {TimelineFlameChartNetworkDataProvider} from './TimelineFlameChartNetworkDataProvider.js';
import {type TimelineModeViewDelegate} from './TimelinePanel.js';
import {TimelineSelection} from './TimelineSelection.js';
import {AggregatedTimelineTreeView} from './TimelineTreeView.js';
import {type TimelineMarkerStyle, TimelineUIUtils} from './TimelineUIUtils.js';
const UIStrings = {
/**
*@description Text in Timeline Flame Chart View of the Performance panel
*@example {Frame} PH1
*@example {10ms} PH2
*/
sAtS: '{PH1} at {PH2}',
};
const str_ = i18n.i18n.registerUIStrings('panels/timeline/TimelineFlameChartView.ts', UIStrings);
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
export class TimelineFlameChartView extends UI.Widget.VBox implements PerfUI.FlameChart.FlameChartDelegate,
UI.SearchableView.Searchable {
private readonly delegate: TimelineModeViewDelegate;
private model: PerformanceModel|null;
private searchResults!: number[]|undefined;
private eventListeners: Common.EventTarget.EventDescriptor[];
// TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private readonly showMemoryGraphSetting: Common.Settings.Setting<any>;
private readonly networkSplitWidget: UI.SplitWidget.SplitWidget;
private mainDataProvider: TimelineFlameChartDataProvider;
private readonly mainFlameChart: PerfUI.FlameChart.FlameChart;
// TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private readonly networkFlameChartGroupExpansionSetting: Common.Settings.Setting<any>;
private networkDataProvider: TimelineFlameChartNetworkDataProvider;
private readonly networkFlameChart: PerfUI.FlameChart.FlameChart;
private readonly networkPane: UI.Widget.VBox;
private readonly splitResizer: HTMLElement;
private readonly chartSplitWidget: UI.SplitWidget.SplitWidget;
private brickGame?: PerfUI.BrickBreaker.BrickBreaker;
private readonly countersView: CountersGraph;
private readonly detailsSplitWidget: UI.SplitWidget.SplitWidget;
private readonly detailsView: TimelineDetailsView;
private readonly onMainEntrySelected: (event: Common.EventTarget.EventTargetEvent<number>) => void;
private readonly onNetworkEntrySelected: (event: Common.EventTarget.EventTargetEvent<number>) => void;
private readonly boundRefresh: () => void;
#selectedEvents: TraceEngine.Types.TraceEvents.TraceEventData[]|null;
// TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private readonly groupBySetting: Common.Settings.Setting<any>;
private searchableView!: UI.SearchableView.SearchableView;
private needsResizeToPreferredHeights?: boolean;
private selectedSearchResult?: number;
private searchRegex?: RegExp;
#traceEngineData: TraceEngine.Handlers.Types.TraceParseData|null;
#selectedGroupName: string|null = null;
#onTraceBoundsChangeBound = this.#onTraceBoundsChange.bind(this);
#gameKeyMatches = 0;
#gameTimeout = setTimeout(() => ({}), 0);
constructor(delegate: TimelineModeViewDelegate) {
super();
this.element.classList.add('timeline-flamechart');
this.delegate = delegate;
this.model = null;
this.eventListeners = [];
this.#traceEngineData = null;
this.showMemoryGraphSetting = Common.Settings.Settings.instance().createSetting('timeline-show-memory', false);
// Create main and network flamecharts.
this.networkSplitWidget = new UI.SplitWidget.SplitWidget(false, false, 'timeline-flamechart-main-view', 150);
// Ensure that the network panel & resizer appears above the main thread.
this.networkSplitWidget.sidebarElement().style.zIndex = '120';
const mainViewGroupExpansionSetting =
Common.Settings.Settings.instance().createSetting('timeline-flamechart-main-view-group-expansion', {});
this.mainDataProvider = new TimelineFlameChartDataProvider();
this.mainDataProvider.addEventListener(
TimelineFlameChartDataProviderEvents.DataChanged, () => this.mainFlameChart.scheduleUpdate());
this.mainFlameChart = new PerfUI.FlameChart.FlameChart(this.mainDataProvider, this, mainViewGroupExpansionSetting);
this.mainFlameChart.alwaysShowVerticalScroll();
this.mainFlameChart.enableRuler(false);
this.networkFlameChartGroupExpansionSetting =
Common.Settings.Settings.instance().createSetting('timeline-flamechart-network-view-group-expansion', {});
this.networkDataProvider = new TimelineFlameChartNetworkDataProvider();
this.networkFlameChart =
new PerfUI.FlameChart.FlameChart(this.networkDataProvider, this, this.networkFlameChartGroupExpansionSetting);
this.networkFlameChart.alwaysShowVerticalScroll();
this.networkPane = new UI.Widget.VBox();
this.networkPane.setMinimumSize(23, 23);
this.networkFlameChart.show(this.networkPane.element);
this.splitResizer = this.networkPane.element.createChild('div', 'timeline-flamechart-resizer');
this.networkSplitWidget.hideDefaultResizer(true);
this.networkSplitWidget.installResizer(this.splitResizer);
this.networkSplitWidget.setMainWidget(this.mainFlameChart);
this.networkSplitWidget.setSidebarWidget(this.networkPane);
// Create counters chart splitter.
this.chartSplitWidget = new UI.SplitWidget.SplitWidget(false, true, 'timeline-counters-split-view-state');
this.countersView = new CountersGraph(this.delegate);
this.chartSplitWidget.setMainWidget(this.networkSplitWidget);
this.chartSplitWidget.setSidebarWidget(this.countersView);
this.chartSplitWidget.hideDefaultResizer();
this.chartSplitWidget.installResizer((this.countersView.resizerElement() as Element));
this.updateCountersGraphToggle();
// Create top level properties splitter.
this.detailsSplitWidget = new UI.SplitWidget.SplitWidget(false, true, 'timeline-panel-details-split-view-state');
this.detailsSplitWidget.element.classList.add('timeline-details-split');
this.detailsView = new TimelineDetailsView(delegate);
this.detailsSplitWidget.installResizer(this.detailsView.headerElement());
this.detailsSplitWidget.setMainWidget(this.chartSplitWidget);
this.detailsSplitWidget.setSidebarWidget(this.detailsView);
this.detailsSplitWidget.show(this.element);
this.onMainEntrySelected = this.onEntrySelected.bind(this, this.mainDataProvider);
this.onNetworkEntrySelected = this.onEntrySelected.bind(this, this.networkDataProvider);
this.mainFlameChart.addEventListener(PerfUI.FlameChart.Events.EntrySelected, this.onMainEntrySelected, this);
this.mainFlameChart.addEventListener(PerfUI.FlameChart.Events.EntryInvoked, this.onMainEntrySelected, this);
this.networkFlameChart.addEventListener(PerfUI.FlameChart.Events.EntrySelected, this.onNetworkEntrySelected, this);
this.networkFlameChart.addEventListener(PerfUI.FlameChart.Events.EntryInvoked, this.onNetworkEntrySelected, this);
this.mainFlameChart.addEventListener(PerfUI.FlameChart.Events.EntryHighlighted, this.onEntryHighlighted, this);
this.element.addEventListener('keydown', this.#keydownHandler.bind(this));
this.boundRefresh = this.#reset.bind(this);
this.#selectedEvents = null;
this.mainDataProvider.setEventColorMapping(TimelineUIUtils.eventColor);
this.groupBySetting = Common.Settings.Settings.instance().createSetting(
'timeline-tree-group-by', AggregatedTimelineTreeView.GroupBy.None);
this.groupBySetting.addChangeListener(this.updateColorMapper, this);
this.updateColorMapper();
TraceBounds.TraceBounds.onChange(this.#onTraceBoundsChangeBound);
}
#keydownHandler(event: KeyboardEvent): void {
const keyCombo = 'fixme';
if (event.key === keyCombo[this.#gameKeyMatches]) {
this.#gameKeyMatches++;
clearTimeout(this.#gameTimeout);
this.#gameTimeout = setTimeout(() => {
this.#gameKeyMatches = 0;
}, 2000);
} else {
this.#gameKeyMatches = 0;
clearTimeout(this.#gameTimeout);
}
if (this.#gameKeyMatches !== keyCombo.length) {
return;
}
this.fixMe();
}
fixMe(): void {
if ([...this.element.childNodes].find(child => child instanceof PerfUI.BrickBreaker.BrickBreaker)) {
return;
}
this.brickGame = new PerfUI.BrickBreaker.BrickBreaker(this.mainFlameChart);
this.brickGame.classList.add('brick-game');
this.element.append(this.brickGame);
}
#onTraceBoundsChange(event: TraceBounds.TraceBounds.StateChangedEvent): void {
if (event.updateType === 'MINIMAP_BOUNDS') {
// If the update type was a changing of the minimap bounds, we do not
// need to redraw the timeline.
return;
}
const visibleWindow = event.state.milli.timelineTraceWindow;
const shouldAnimate = Boolean(event.options.shouldAnimate);
this.mainFlameChart.setWindowTimes(visibleWindow.min, visibleWindow.max, shouldAnimate);
this.networkDataProvider.setWindowTimes(visibleWindow.min, visibleWindow.max);
this.networkFlameChart.setWindowTimes(visibleWindow.min, visibleWindow.max, shouldAnimate);
this.updateSearchResults(false, false);
}
isNetworkTrackShownForTests(): boolean {
return this.networkSplitWidget.showMode() !== UI.SplitWidget.ShowMode.OnlyMain;
}
getMainDataProvider(): TimelineFlameChartDataProvider {
return this.mainDataProvider;
}
updateColorMapper(): void {
if (!this.model) {
return;
}
this.mainDataProvider.setEventColorMapping(TimelineUIUtils.eventColor);
this.mainFlameChart.update();
}
windowChanged(
windowStartTime: TraceEngine.Types.Timing.MilliSeconds, windowEndTime: TraceEngine.Types.Timing.MilliSeconds,
animate: boolean): void {
TraceBounds.TraceBounds.BoundsManager.instance().setTimelineVisibleWindow(
TraceEngine.Helpers.Timing.traceWindowFromMilliSeconds(
TraceEngine.Types.Timing.MilliSeconds(windowStartTime),
TraceEngine.Types.Timing.MilliSeconds(windowEndTime),
),
{shouldAnimate: animate},
);
}
updateRangeSelection(startTime: number, endTime: number): void {
this.delegate.select(TimelineSelection.fromRange(startTime, endTime));
}
getMainFlameChart(): PerfUI.FlameChart.FlameChart {
return this.mainFlameChart;
}
updateSelectedGroup(flameChart: PerfUI.FlameChart.FlameChart, group: PerfUI.FlameChart.Group|null): void {
if (flameChart !== this.mainFlameChart || this.#selectedGroupName === group?.name) {
return;
}
this.#selectedGroupName = group?.name || null;
this.#selectedEvents = group ? this.mainDataProvider.groupTreeEvents(group) : null;
this.#updateDetailViews();
}
setModel(
model: PerformanceModel|null, newTraceEngineData: TraceEngine.Handlers.Types.TraceParseData|null,
isCpuProfile = false): void {
if (model === this.model) {
return;
}
this.#selectedGroupName = null;
this.#traceEngineData = newTraceEngineData;
Common.EventTarget.removeEventListeners(this.eventListeners);
this.model = model;
this.#selectedEvents = null;
this.mainDataProvider.setModel(this.model, newTraceEngineData, isCpuProfile);
this.networkDataProvider.setModel(newTraceEngineData);
this.#reset();
const traceBoundsState = TraceBounds.TraceBounds.BoundsManager.instance().state();
if (!traceBoundsState) {
throw new Error('TimelineFlameChartView could not set the window bounds.');
}
const visibleWindow = traceBoundsState.milli.timelineTraceWindow;
this.mainFlameChart.setWindowTimes(visibleWindow.min, visibleWindow.max);
this.networkDataProvider.setWindowTimes(visibleWindow.min, visibleWindow.max);
this.networkFlameChart.setWindowTimes(visibleWindow.min, visibleWindow.max);
this.updateSearchResults(false, false);
this.updateColorMapper();
this.#updateFlameCharts();
}
#reset(): void {
if (this.networkDataProvider.isEmpty()) {
this.mainFlameChart.enableRuler(true);
this.networkSplitWidget.hideSidebar();
} else {
this.mainFlameChart.enableRuler(false);
this.networkSplitWidget.showBoth();
this.resizeToPreferredHeights();
}
this.mainFlameChart.reset();
this.networkFlameChart.reset();
this.updateSearchResults(false, false);
}
#updateDetailViews(): void {
this.countersView.setModel(this.#traceEngineData, this.#selectedEvents);
// TODO(crbug.com/1459265): Change to await after migration work.
void this.detailsView.setModel(this.model, this.#traceEngineData, this.#selectedEvents);
}
#updateFlameCharts(): void {
this.mainFlameChart.scheduleUpdate();
this.networkFlameChart.scheduleUpdate();
}
private onEntryHighlighted(commonEvent: Common.EventTarget.EventTargetEvent<number>): void {
SDK.OverlayModel.OverlayModel.hideDOMNodeHighlight();
const entryIndex = commonEvent.data;
// TODO(crbug.com/1431166): explore how we can make highlighting agnostic
// and take either legacy events, or new trace engine events. Currently if
// this highlight comes from a TrackAppender, we create a new legacy event
// from the event payload, mainly to satisfy this method.
const event = this.mainDataProvider.eventByIndex(entryIndex);
if (!event) {
return;
}
const target = this.model && this.model.timelineModel().targetByEvent(event);
if (!target) {
return;
}
let backendNodeIds;
// Events for tracks that are migrated to the new engine won't use
// TimelineModel.TimelineData.
if (event instanceof TraceEngine.Legacy.Event) {
const timelineData = TimelineModel.TimelineModel.EventOnTimelineData.forEvent(event);
backendNodeIds = timelineData.backendNodeIds;
} else if (TraceEngine.Types.TraceEvents.isTraceEventLayoutShift(event)) {
const impactedNodes = event.args.data?.impacted_nodes ?? [];
backendNodeIds = impactedNodes.map(node => node.node_id);
}
if (!backendNodeIds) {
return;
}
for (let i = 0; i < backendNodeIds.length; ++i) {
new SDK.DOMModel.DeferredDOMNode(target, backendNodeIds[i]).highlight();
}
}
highlightEvent(event: TraceEngine.Legacy.Event|null): void {
const entryIndex =
event ? this.mainDataProvider.entryIndexForSelection(TimelineSelection.fromTraceEvent(event)) : -1;
if (entryIndex >= 0) {
this.mainFlameChart.highlightEntry(entryIndex);
} else {
this.mainFlameChart.hideHighlight();
}
}
override willHide(): void {
this.networkFlameChartGroupExpansionSetting.removeChangeListener(this.resizeToPreferredHeights, this);
this.showMemoryGraphSetting.removeChangeListener(this.updateCountersGraphToggle, this);
Bindings.IgnoreListManager.IgnoreListManager.instance().removeChangeListener(this.boundRefresh);
}
override wasShown(): void {
this.networkFlameChartGroupExpansionSetting.addChangeListener(this.resizeToPreferredHeights, this);
this.showMemoryGraphSetting.addChangeListener(this.updateCountersGraphToggle, this);
Bindings.IgnoreListManager.IgnoreListManager.instance().addChangeListener(this.boundRefresh);
if (this.needsResizeToPreferredHeights) {
this.resizeToPreferredHeights();
}
this.#updateFlameCharts();
}
private updateCountersGraphToggle(): void {
if (this.showMemoryGraphSetting.get()) {
this.chartSplitWidget.showBoth();
} else {
this.chartSplitWidget.hideSidebar();
}
}
setSelection(selection: TimelineSelection|null): void {
let index = this.mainDataProvider.entryIndexForSelection(selection);
this.mainFlameChart.setSelectedEntry(index);
index = this.networkDataProvider.entryIndexForSelection(selection);
this.networkFlameChart.setSelectedEntry(index);
if (this.detailsView) {
// TODO(crbug.com/1459265): Change to await after migration work.
void this.detailsView.setSelection(selection);
}
}
private onEntrySelected(
dataProvider: PerfUI.FlameChart.FlameChartDataProvider,
event: Common.EventTarget.EventTargetEvent<number>): void {
const entryIndex = event.data;
if (dataProvider === this.mainDataProvider) {
if (this.mainDataProvider.buildFlowForInitiator(entryIndex)) {
this.mainFlameChart.scheduleUpdate();
}
}
this.delegate.select((dataProvider as TimelineFlameChartNetworkDataProvider | TimelineFlameChartDataProvider)
.createSelection(entryIndex));
}
resizeToPreferredHeights(): void {
if (!this.isShowing()) {
this.needsResizeToPreferredHeights = true;
return;
}
this.needsResizeToPreferredHeights = false;
this.networkPane.element.classList.toggle(
'timeline-network-resizer-disabled', !this.networkDataProvider.isExpanded());
this.networkSplitWidget.setSidebarSize(
this.networkDataProvider.preferredHeight() + this.splitResizer.clientHeight + PerfUI.FlameChart.RulerHeight +
2);
}
setSearchableView(searchableView: UI.SearchableView.SearchableView): void {
this.searchableView = searchableView;
}
// UI.SearchableView.Searchable implementation
jumpToNextSearchResult(): void {
if (!this.searchResults || !this.searchResults.length) {
return;
}
const index =
typeof this.selectedSearchResult !== 'undefined' ? this.searchResults.indexOf(this.selectedSearchResult) : -1;
this.selectSearchResult(Platform.NumberUtilities.mod(index + 1, this.searchResults.length));
}
jumpToPreviousSearchResult(): void {
if (!this.searchResults || !this.searchResults.length) {
return;
}
const index =
typeof this.selectedSearchResult !== 'undefined' ? this.searchResults.indexOf(this.selectedSearchResult) : 0;
this.selectSearchResult(Platform.NumberUtilities.mod(index - 1, this.searchResults.length));
}
supportsCaseSensitiveSearch(): boolean {
return true;
}
supportsRegexSearch(): boolean {
return true;
}
private selectSearchResult(index: number): void {
this.searchableView.updateCurrentMatchIndex(index);
if (this.searchResults) {
this.selectedSearchResult = this.searchResults[index];
this.delegate.select(this.mainDataProvider.createSelection(this.selectedSearchResult));
this.mainFlameChart.showPopoverForSearchResult(this.selectedSearchResult);
}
}
private updateSearchResults(shouldJump: boolean, jumpBackwards?: boolean): void {
const traceBoundsState = TraceBounds.TraceBounds.BoundsManager.instance().state();
if (!traceBoundsState) {
return;
}
const oldSelectedSearchResult = (this.selectedSearchResult as number);
delete this.selectedSearchResult;
this.searchResults = [];
if (!this.searchRegex || !this.model) {
return;
}
const regExpFilter = new TimelineRegExp(this.searchRegex);
const visibleWindow = traceBoundsState.milli.timelineTraceWindow;
this.searchResults = this.mainDataProvider.search(visibleWindow.min, visibleWindow.max, regExpFilter);
this.searchableView.updateSearchMatchesCount(this.searchResults.length);
if (!shouldJump || !this.searchResults.length) {
return;
}
let selectedIndex = this.searchResults.indexOf(oldSelectedSearchResult);
if (selectedIndex === -1) {
selectedIndex = jumpBackwards ? this.searchResults.length - 1 : 0;
}
this.selectSearchResult(selectedIndex);
}
/**
* Returns the indexes of the elements that matched the most recent
* query. Elements are indexed by the data provider and correspond
* to their position in the data provider entry data array.
* Public only for tests.
*/
getSearchResults(): number[]|undefined {
return this.searchResults;
}
onSearchCanceled(): void {
if (typeof this.selectedSearchResult !== 'undefined') {
this.delegate.select(null);
}
delete this.searchResults;
delete this.selectedSearchResult;
delete this.searchRegex;
}
performSearch(searchConfig: UI.SearchableView.SearchConfig, shouldJump: boolean, jumpBackwards?: boolean): void {
this.searchRegex = searchConfig.toSearchRegex().regex;
this.updateSearchResults(shouldJump, jumpBackwards);
}
}
export class Selection {
timelineSelection: TimelineSelection;
entryIndex: number;
constructor(selection: TimelineSelection, entryIndex: number) {
this.timelineSelection = selection;
this.entryIndex = entryIndex;
}
}
export const FlameChartStyle = {
textColor: '#333',
};
export class TimelineFlameChartMarker implements PerfUI.FlameChart.FlameChartMarker {
private readonly startTimeInternal: number;
private readonly startOffset: number;
private style: TimelineMarkerStyle;
constructor(startTime: number, startOffset: number, style: TimelineMarkerStyle) {
this.startTimeInternal = startTime;
this.startOffset = startOffset;
this.style = style;
}
startTime(): number {
return this.startTimeInternal;
}
color(): string {
return this.style.color;
}
title(): string|null {
if (this.style.lowPriority) {
return null;
}
const startTime = i18n.TimeUtilities.millisToString(this.startOffset);
return i18nString(UIStrings.sAtS, {PH1: this.style.title, PH2: startTime});
}
draw(context: CanvasRenderingContext2D, x: number, height: number, pixelsPerMillisecond: number): void {
const lowPriorityVisibilityThresholdInPixelsPerMs = 4;
if (this.style.lowPriority && pixelsPerMillisecond < lowPriorityVisibilityThresholdInPixelsPerMs) {
return;
}
context.save();
if (this.style.tall) {
context.strokeStyle = this.style.color;
context.lineWidth = this.style.lineWidth;
context.translate(this.style.lineWidth < 1 || (this.style.lineWidth & 1) ? 0.5 : 0, 0.5);
context.beginPath();
context.moveTo(x, 0);
context.setLineDash(this.style.dashStyle);
context.lineTo(x, context.canvas.height);
context.stroke();
}
context.restore();
}
}
export const enum ColorBy {
URL = 'URL',
}