Skip to content

Commit de45587

Browse files
committed
feat: add labels to split graph
1 parent 9476781 commit de45587

File tree

5 files changed

+74
-15
lines changed

5 files changed

+74
-15
lines changed

packages/vscode-js-profile-flame/src/realtime/baseMetric.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,15 @@ export abstract class Metric {
8282
public abstract format(metric: number): string;
8383

8484
/**
85-
* Returns th ename of the metric.
85+
* Returns the name of the metric.
8686
*/
8787
public abstract name(): string;
8888

89+
/**
90+
* Returns a short label for the metric.
91+
*/
92+
public abstract short(): string;
93+
8994
/**
9095
* Adds a new metric to the internal series.
9196
*/

packages/vscode-js-profile-flame/src/realtime/chart.css

+8
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,18 @@
8787
position: absolute;
8888
}
8989

90+
.maxContainer.split .maxLabel {
91+
display: inline;
92+
}
93+
9094
.maxContainer.split .max::before {
9195
content: none !important;
9296
}
9397

98+
.maxLabel {
99+
display: none;
100+
}
101+
94102
.max {
95103
display: inline;
96104
}

packages/vscode-js-profile-flame/src/realtime/chart.ts

+23-8
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ export class Chart {
7777
* Update the chart metrics
7878
*/
7979
public updateMetrics() {
80+
const { allMetrics, enabledMetrics } = this.settings;
81+
82+
if (!this.hasAnyData) {
83+
const enabled = enabledMetrics.filter(m => m.hasData());
84+
this.settings.setEnabledMetrics(enabled.length ? enabled : [allMetrics[0], allMetrics[1]]);
85+
}
86+
8087
this.frameCanvas.updateMetrics();
8188

8289
if (this.configOpen) {
@@ -182,8 +189,10 @@ export class Chart {
182189
val.parentElement?.removeChild(val);
183190
}
184191

185-
maxContainer.classList[this.settings.value.splitCharts ? 'add' : 'remove'](styles.split);
192+
const split = this.settings.value.splitCharts;
193+
maxContainer.classList[split ? 'add' : 'remove'](styles.split);
186194
labelList.innerHTML = '';
195+
maxContainer.innerHTML = '';
187196
this.valElements = [];
188197

189198
for (let i = 0; i < this.settings.enabledMetrics.length; i++) {
@@ -198,13 +207,19 @@ export class Chart {
198207
val.innerText = metric.format(metric.current);
199208
label.appendChild(val);
200209

201-
const max = document.createElement('div');
202-
max.classList.add(styles.max, styles.primary);
203-
max.innerText = metric.format(metric.maxY);
204-
max.style.top = `${(i / this.settings.enabledMetrics.length) * 100}%`;
205-
maxContainer.appendChild(max);
206-
207-
this.valElements.push([metric, { max, val }]);
210+
const maxWrapper = document.createElement('div');
211+
maxWrapper.classList.add(styles.max);
212+
maxWrapper.style.top = `${(i / this.settings.enabledMetrics.length) * 100}%`;
213+
const maxLabel = document.createElement('span');
214+
maxWrapper.classList.add(styles.maxLabel);
215+
maxLabel.innerText = `${metric.short()} `;
216+
const maxValue = document.createElement('span');
217+
maxValue.innerText = metric.format(metric.maxY);
218+
maxWrapper.appendChild(maxLabel);
219+
maxWrapper.appendChild(maxValue);
220+
maxContainer.appendChild(maxWrapper);
221+
222+
this.valElements.push([metric, { max: maxValue, val }]);
208223
}
209224
}
210225
}

packages/vscode-js-profile-flame/src/realtime/metrics.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export class CpuMetric extends DerivativeMetric {
4040
return 'CPU Usage';
4141
}
4242

43+
public short(): string {
44+
return 'CPU';
45+
}
46+
4347
protected recalcMax() {
4448
return 1;
4549
}
@@ -58,6 +62,10 @@ export class HeapMetric extends Metric {
5862
return wholeNumberFormat.format(metric) + 'B';
5963
}
6064

65+
public short(): string {
66+
return 'Heap';
67+
}
68+
6169
public name(): string {
6270
return 'Heap Used';
6371
}
@@ -74,6 +82,10 @@ export class DOMNodes extends Metric {
7482
return wholeNumberFormat.format(metric);
7583
}
7684

85+
public short(): string {
86+
return 'DOM Nodes';
87+
}
88+
7789
public name(): string {
7890
return 'DOM Nodes';
7991
}
@@ -90,6 +102,10 @@ export class LayoutCount extends DerivativeMetric {
90102
return wholeNumberFormat.format(metric);
91103
}
92104

105+
public short(): string {
106+
return 'Relayouts';
107+
}
108+
93109
public name(): string {
94110
return 'DOM Relayouts / s';
95111
}
@@ -106,8 +122,12 @@ export class StyleRecalcs extends DerivativeMetric {
106122
return wholeNumberFormat.format(metric);
107123
}
108124

125+
public short(): string {
126+
return 'Restyles';
127+
}
128+
109129
public name(): string {
110-
return 'Style Recalculations / s';
130+
return 'Style Recalcs / s';
111131
}
112132
}
113133

packages/vscode-js-profile-flame/src/realtime/settings.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,30 @@ export class Settings {
6464
return () => (this.changeListeners = this.changeListeners.filter(c => c !== listener));
6565
}
6666

67-
public toggleMetric(metric: Metric) {
68-
const enabledMetrics = this.enabledMetrics.includes(metric)
69-
? this.enabledMetrics.filter(e => e !== metric)
70-
: this.enabledMetrics.concat(metric);
67+
public setEnabledMetrics(metrics: ReadonlyArray<Metric>) {
68+
if (
69+
metrics.length === this.enabledMetrics.length &&
70+
!metrics.some(m => !this.enabledMetrics.includes(m))
71+
) {
72+
return;
73+
}
7174

7275
this.api.postMessage({
7376
type: MessageType.SetEnabledMetrics,
74-
keys: enabledMetrics.map(m => this.allMetrics.indexOf(m)),
77+
keys: metrics.map(m => this.allMetrics.indexOf(m)),
7578
});
7679

7780
this.fireChange();
7881
}
7982

83+
public toggleMetric(metric: Metric) {
84+
const enabledMetrics = this.enabledMetrics.includes(metric)
85+
? this.enabledMetrics.filter(e => e !== metric)
86+
: this.enabledMetrics.concat(metric);
87+
88+
this.setEnabledMetrics(enabledMetrics);
89+
}
90+
8091
public update(newValue: ISettings) {
8192
this.value = newValue;
8293
this.steps = getSteps(newValue);

0 commit comments

Comments
 (0)