-
Notifications
You must be signed in to change notification settings - Fork 208
/
RenderCommandBreakdown.ts
79 lines (66 loc) · 2.31 KB
/
RenderCommandBreakdown.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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Widgets
*/
import { IModelApp } from "@itwin/core-frontend";
import { createCheckBox } from "../ui/CheckBox";
export class RenderCommandBreakdown {
private readonly _div: HTMLDivElement;
private readonly _cellDiv: HTMLDivElement;
private _curIntervalId?: number;
private readonly _cells = new Map<string, HTMLElement>();
private readonly _total: HTMLElement;
public constructor(parent: HTMLElement) {
createCheckBox({
parent,
name: "Render Commands",
id: "renderCommandBreakdown",
handler: () => this.toggle(),
});
parent.appendChild(this._div = document.createElement("div"));
this._div.style.display = "none";
this._div.style.textAlign = "right";
this._div.appendChild(this._cellDiv = document.createElement("div"));
this._div.appendChild(this._total = document.createElement("div"));
this._total.innerText = "Total: 0";
}
public dispose(): void {
this.clearInterval();
}
private toggle(): void {
if (undefined !== this._curIntervalId) {
this._div.style.display = "none";
this.clearInterval();
} else {
this._div.style.display = "block";
this.update();
this._curIntervalId = window.setInterval(() => this.update(), 500);
}
}
private clearInterval(): void {
if (undefined !== this._curIntervalId) {
window.clearInterval(this._curIntervalId);
this._curIntervalId = undefined;
}
}
private update(): void {
const ctrl = IModelApp.viewManager.selectedView?.target.debugControl;
if (!ctrl)
return;
const cmds = ctrl.getRenderCommands();
let total = 0;
for (const cmd of cmds) {
let cell = this._cells.get(cmd.name);
if (!cell) {
this._cellDiv.appendChild(cell = document.createElement("div"));
this._cells.set(cmd.name, cell);
}
total += cmd.count;
cell.innerText = `${cmd.name}: ${cmd.count}`;
}
this._total.innerText = `Total: ${total}`;
}
}