1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {CSSColor, DOM, SVG, V8CustomElement} from '../helper.mjs';
6
7import {TimelineTrackBase} from './timeline-track-base.mjs'
8import {TimelineTrackStackedBase} from './timeline-track-stacked-base.mjs'
9
10DOM.defineCustomElement(
11    'view/timeline/timeline-track', 'timeline-track-timer',
12    (templateText) =>
13        class TimelineTrackTimer extends TimelineTrackStackedBase {
14      constructor() {
15        super(templateText);
16      }
17
18      _prepareDrawableItems() {
19        const stack = [];
20        let maxDepth = 0;
21        for (let i = 0; i < this._timeline.length; i++) {
22          const timer = this._timeline.at(i);
23          let insertDepth = -1;
24          for (let depth = 0; depth < stack.length; depth++) {
25            const pendingTimer = stack[depth];
26            if (pendingTimer === undefined) {
27              if (insertDepth === -1) insertDepth = depth;
28            } else if (pendingTimer.endTime <= timer.startTime) {
29              stack[depth] == undefined;
30              if (insertDepth === -1) insertDepth = depth;
31            }
32          }
33          if (insertDepth === -1) insertDepth = stack.length;
34          stack[insertDepth] = timer;
35          timer.depth = insertDepth;
36          maxDepth = Math.max(maxDepth, insertDepth);
37        }
38        this._drawableItems = this._timeline;
39        this._adjustStackDepth(maxDepth++);
40      }
41    });