Skip to content

Commit 2da148c

Browse files
author
Brian Vaughn
committed
Scheduling Profiler: Inline snapshots
Iterated a little bit on the snapshot UI to add borders and improve the UX when scrolling (so the hovered tooltip image now updates)
1 parent 54e170c commit 2da148c

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

packages/react-devtools-scheduling-profiler/src/EventTooltip.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
user-select: none;
1212
pointer-events: none;
1313
background-color: var(--color-tooltip-background);
14-
border: 1px solid var(border);
1514
box-shadow: 1px 1px 2px var(--color-shadow);
1615
color: var(--color-tooltip-text);
1716
font-size: 11px;
@@ -72,4 +71,8 @@
7271
.InfoText,
7372
.WarningText {
7473
color: var(--color-warning-text-color);
74+
}
75+
76+
.Image {
77+
border: 1px solid var(--color-border);
7578
}

packages/react-devtools-scheduling-profiler/src/EventTooltip.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ const TooltipSnapshot = ({
315315
return (
316316
<div className={styles.Tooltip} ref={tooltipRef}>
317317
<img
318+
className={styles.Image}
318319
src={snapshot.imageSource}
319320
style={{width: snapshot.width / 2, height: snapshot.height / 2}}
320321
/>

packages/react-devtools-scheduling-profiler/src/content-views/SnapshotsView.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import type {Snapshot, ReactProfilerData} from '../types';
1111
import type {
1212
Interaction,
13-
MouseMoveInteraction,
13+
Point,
1414
Rect,
1515
Size,
1616
Surface,
@@ -67,6 +67,10 @@ export class SnapshotsView extends View {
6767
// draw them at fixed intervals and just show the nearest one.
6868
while (x < visibleArea.origin.x + visibleArea.size.width) {
6969
const snapshot = this._findClosestSnapshot(x);
70+
if (snapshot === null) {
71+
// This shold never happen.
72+
break;
73+
}
7074

7175
const scaledHeight = SNAPSHOT_HEIGHT;
7276
const scaledWidth = (snapshot.width * SNAPSHOT_HEIGHT) / snapshot.height;
@@ -97,7 +101,11 @@ export class SnapshotsView extends View {
97101
handleInteraction(interaction: Interaction, viewRefs: ViewRefs) {
98102
switch (interaction.type) {
99103
case 'mousemove':
100-
this._handleMouseMove(interaction, viewRefs);
104+
case 'wheel-control':
105+
case 'wheel-meta':
106+
case 'wheel-plain':
107+
case 'wheel-shift':
108+
this._updateHover(interaction.payload.location, viewRefs);
101109
break;
102110
}
103111
}
@@ -125,6 +133,14 @@ export class SnapshotsView extends View {
125133
context.clip();
126134
}
127135

136+
context.fillStyle = COLORS.REACT_RESIZE_BAR_BORDER;
137+
context.fillRect(
138+
imageRect.origin.x,
139+
imageRect.origin.y,
140+
imageRect.size.width,
141+
imageRect.size.height,
142+
);
143+
128144
// $FlowFixMe Flow doesn't know about the 9 argument variant of drawImage()
129145
context.drawImage(
130146
snapshot.image,
@@ -138,20 +154,20 @@ export class SnapshotsView extends View {
138154
snapshot.height,
139155

140156
// Canvas coordinates
141-
imageRect.origin.x,
142-
imageRect.origin.y,
157+
imageRect.origin.x + BORDER_SIZE,
158+
imageRect.origin.y + BORDER_SIZE,
143159

144160
// Scaled image size
145-
imageRect.size.width,
146-
imageRect.size.height,
161+
imageRect.size.width - BORDER_SIZE * 2,
162+
imageRect.size.height - BORDER_SIZE * 2,
147163
);
148164

149165
if (shouldClip) {
150166
context.restore();
151167
}
152168
}
153169

154-
_findClosestSnapshot(x: number): Snapshot {
170+
_findClosestSnapshot(x: number): Snapshot | null {
155171
const frame = this.frame;
156172
const scaleFactor = positioningScaleFactor(
157173
this._intrinsicSize.width,
@@ -178,26 +194,25 @@ export class SnapshotsView extends View {
178194
}
179195
}
180196

181-
return snapshots[stopIndex];
197+
return snapshots[stopIndex] || null;
182198
}
183199

184200
/**
185201
* @private
186202
*/
187-
_handleMouseMove(interaction: MouseMoveInteraction, viewRefs: ViewRefs) {
203+
_updateHover(location: Point, viewRefs: ViewRefs) {
188204
const {onHover, visibleArea} = this;
189205
if (!onHover) {
190206
return;
191207
}
192208

193-
const {location} = interaction.payload;
194209
if (!rectContainsPoint(location, visibleArea)) {
195210
onHover(null);
196211
return;
197212
}
198213

199214
const snapshot = this._findClosestSnapshot(location.x);
200-
if (snapshot) {
215+
if (snapshot !== null) {
201216
this.currentCursor = 'context-menu';
202217
viewRefs.hoveredView = this;
203218
onHover(snapshot);

packages/react-devtools-scheduling-profiler/src/content-views/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const REACT_MEASURE_HEIGHT = 14;
2323
export const BORDER_SIZE = 1;
2424
export const FLAMECHART_FRAME_HEIGHT = 14;
2525
export const TEXT_PADDING = 3;
26-
export const SNAPSHOT_HEIGHT = 50;
26+
export const SNAPSHOT_HEIGHT = 35;
2727

2828
export const INTERVAL_TIMES = [
2929
1,

0 commit comments

Comments
 (0)