Skip to content

Commit 3d5e510

Browse files
committed
fix: show the hovered value in the configurator as well
Fixes microsoft/vscode#107833
1 parent 785f30a commit 3d5e510

File tree

4 files changed

+45
-28
lines changed

4 files changed

+45
-28
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,9 @@ export class Chart {
8686
this.settings.setEnabledMetrics(enabled.length ? enabled : [allMetrics[0], allMetrics[1]]);
8787
}
8888

89+
this.configurator.updateMetrics();
8990
this.frameCanvas.updateMetrics();
9091

91-
if (this.configOpen) {
92-
this.configurator.updateMetrics();
93-
}
94-
9592
this.updateMaxElements();
9693
if (this.frameCanvas.hoveredIndex === undefined) {
9794
this.updateValueElements();
@@ -103,11 +100,12 @@ export class Chart {
103100
private updateValueElements() {
104101
for (const [metric, { val }] of this.valElements) {
105102
if (this.frameCanvas.hoveredIndex) {
106-
val.innerText = metric.format(
107-
metric.valueAt(this.frameCanvas.hoveredIndex) ?? metric.current,
108-
);
103+
const value = metric.valueAt(this.frameCanvas.hoveredIndex) ?? metric.current;
104+
val.innerText = metric.format(value);
105+
this.configurator.updateMetric(metric, value);
109106
} else {
110107
val.innerText = metric.format(metric.current);
108+
this.configurator.updateMetric(metric, metric.current);
111109
}
112110
}
113111
}
@@ -134,7 +132,6 @@ export class Chart {
134132

135133
this.configOpen = isOpen;
136134
if (isOpen) {
137-
this.configurator.updateMetrics();
138135
this.elem.appendChild(this.configurator.elem);
139136
this.elem.removeChild(this.elements.labelList);
140137
document.body.style.overflowY = 'auto';

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ window.addEventListener('message', evt => {
3333
settings.allMetrics[i].setData(data.data[i]);
3434
}
3535
chart.updateMetrics();
36+
updateSize();
3637
break;
3738
case MessageType.ClearData:
3839
for (const metric of settings.allMetrics) {
3940
metric.setData([]);
4041
}
4142
chart.updateMetrics();
43+
updateSize();
4244
break;
4345
default:
4446
// ignored

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
border: 2px solid var(--vscode-debugIcon-breakpointUnverifiedForeground);
2424
}
2525

26-
.metric.available {
26+
.metric.available,
27+
.metric.enabled {
2728
display: flex;
2829
}
2930

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

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import styles from './configurator.css';
77
import { Settings } from './settings';
88

99
export class Configurator {
10-
private metrics: {
11-
metric: Metric;
12-
element: HTMLElement;
13-
value: HTMLElement;
14-
enabled: boolean;
15-
available: boolean;
16-
}[] = [];
10+
private metrics = new Map<
11+
Metric,
12+
{
13+
element: HTMLElement;
14+
value: HTMLElement;
15+
enabled: boolean;
16+
available: boolean;
17+
}
18+
>();
1719

1820
public elem = document.createElement('div');
1921

@@ -36,12 +38,12 @@ export class Configurator {
3638
value.classList.add(styles.value);
3739
element.appendChild(value);
3840

39-
this.metrics.push({ metric, element, enabled: false, available: false, value });
41+
this.metrics.set(metric, { element, enabled: false, available: false, value });
4042
this.elem.appendChild(element);
4143
}
4244

4345
// move inactive items to the bottom always
44-
for (const { element, enabled } of this.metrics) {
46+
for (const { element, enabled } of this.metrics.values()) {
4547
if (!enabled) {
4648
this.elem.appendChild(element);
4749
}
@@ -54,23 +56,38 @@ export class Configurator {
5456
* Updates the configurator state for the metrics.
5557
*/
5658
public updateMetrics() {
57-
for (const m of this.metrics) {
58-
if (m.metric.hasData() !== m.available) {
59-
m.available = m.metric.hasData();
60-
m.element.classList[m.metric.hasData() ? 'add' : 'remove'](styles.available);
59+
for (const [metric, m] of this.metrics) {
60+
if (metric.hasData() !== m.available) {
61+
m.available = metric.hasData();
62+
m.element.classList[metric.hasData() ? 'add' : 'remove'](styles.available);
6163
}
64+
}
65+
}
6266

63-
if (m.available) {
64-
m.value.innerText = m.metric.format(m.metric.current);
65-
}
67+
/**
68+
* Updates the value displayed for the given metric.
69+
*/
70+
public updateMetric(metric: Metric, currentValue: number) {
71+
const m = this.metrics.get(metric);
72+
if (!m) {
73+
return;
74+
}
75+
76+
if (metric.hasData() !== m.available) {
77+
m.available = metric.hasData();
78+
m.element.classList[metric.hasData() ? 'add' : 'remove'](styles.available);
79+
}
80+
81+
if (m.available) {
82+
m.value.innerText = metric.format(currentValue);
6683
}
6784
}
6885

6986
private applySettings() {
70-
for (const m of this.metrics) {
71-
m.enabled = this.settings.enabledMetrics.includes(m.metric);
87+
for (const [metric, m] of this.metrics.entries()) {
88+
m.enabled = this.settings.enabledMetrics.includes(metric);
7289
m.element.classList[m.enabled ? 'add' : 'remove'](styles.enabled);
73-
m.element.style.setProperty('--metric-color', this.settings.metricColor(m.metric));
90+
m.element.style.setProperty('--metric-color', this.settings.metricColor(metric));
7491
}
7592
}
7693
}

0 commit comments

Comments
 (0)