@@ -24,11 +24,13 @@ import {
24
24
rectEqualToRect ,
25
25
View ,
26
26
} from '../view-base' ;
27
- import { BORDER_SIZE , COLORS , SNAPSHOT_HEIGHT } from './constants' ;
27
+ import { BORDER_SIZE , COLORS , SNAPSHOT_SCRUBBER_SIZE } from './constants' ;
28
28
29
29
type OnHover = ( node : Snapshot | null ) => void ;
30
30
31
31
export class SnapshotsView extends View {
32
+ _hoverLocation : Point | null = null ;
33
+ _hoveredSnapshot : Snapshot | null = null ;
32
34
_intrinsicSize : Size ;
33
35
_profilerData : ReactProfilerData ;
34
36
@@ -39,7 +41,7 @@ export class SnapshotsView extends View {
39
41
40
42
this . _intrinsicSize = {
41
43
width : profilerData . duration ,
42
- height : SNAPSHOT_HEIGHT ,
44
+ height : profilerData . snapshotHeight ,
43
45
} ;
44
46
this . _profilerData = profilerData ;
45
47
}
@@ -49,6 +51,7 @@ export class SnapshotsView extends View {
49
51
}
50
52
51
53
draw ( context : CanvasRenderingContext2D ) {
54
+ const snapshotHeight = this . _profilerData . snapshotHeight ;
52
55
const { visibleArea} = this ;
53
56
54
57
context . fillStyle = COLORS . BACKGROUND ;
@@ -72,8 +75,8 @@ export class SnapshotsView extends View {
72
75
break ;
73
76
}
74
77
75
- const scaledHeight = SNAPSHOT_HEIGHT ;
76
- const scaledWidth = ( snapshot . width * SNAPSHOT_HEIGHT ) / snapshot . height ;
78
+ const scaledHeight = snapshotHeight ;
79
+ const scaledWidth = ( snapshot . width * snapshotHeight ) / snapshot . height ;
77
80
78
81
const imageRect : Rect = {
79
82
origin : {
@@ -96,6 +99,28 @@ export class SnapshotsView extends View {
96
99
97
100
x += scaledWidth + BORDER_SIZE ;
98
101
}
102
+
103
+ const hoverLocation = this . _hoverLocation ;
104
+ if ( hoverLocation !== null ) {
105
+ const scrubberWidth = SNAPSHOT_SCRUBBER_SIZE + BORDER_SIZE * 2 ;
106
+ const scrubberOffset = scrubberWidth / 2 ;
107
+
108
+ context . fillStyle = COLORS . SCRUBBER_BORDER ;
109
+ context . fillRect (
110
+ hoverLocation . x - scrubberOffset ,
111
+ visibleArea . origin . y ,
112
+ scrubberWidth ,
113
+ visibleArea . size . height ,
114
+ ) ;
115
+
116
+ context . fillStyle = COLORS . SCRUBBER_BACKGROUND ;
117
+ context . fillRect (
118
+ hoverLocation . x - scrubberOffset + BORDER_SIZE ,
119
+ visibleArea . origin . y ,
120
+ SNAPSHOT_SCRUBBER_SIZE ,
121
+ visibleArea . size . height ,
122
+ ) ;
123
+ }
99
124
}
100
125
101
126
handleInteraction ( interaction : Interaction , viewRefs : ViewRefs ) {
@@ -110,6 +135,18 @@ export class SnapshotsView extends View {
110
135
}
111
136
}
112
137
138
+ setHoveredSnapshot ( hoveredSnapshot : Snapshot | null ) {
139
+ if ( hoveredSnapshot === null ) {
140
+ if ( this . _hoveredSnapshot !== null ) {
141
+ this . setNeedsDisplay ( ) ;
142
+ }
143
+ } else {
144
+ this . setNeedsDisplay ( ) ;
145
+ }
146
+
147
+ this . _hoveredSnapshot = hoveredSnapshot ;
148
+ }
149
+
113
150
_drawSnapshotImage (
114
151
context : CanvasRenderingContext2D ,
115
152
snapshot : Snapshot ,
@@ -214,9 +251,17 @@ export class SnapshotsView extends View {
214
251
215
252
const snapshot = this . _findClosestSnapshot ( location . x ) ;
216
253
if ( snapshot !== null ) {
254
+ this . _hoverLocation = location ;
255
+
217
256
onHover ( snapshot ) ;
218
257
} else {
258
+ this . _hoverLocation = null ;
259
+
219
260
onHover ( null ) ;
220
261
}
262
+
263
+ // Any time the mouse moves within the boundaries of this view, we need to re-render.
264
+ // This is because we draw a scrubbing bar that shows the location corresponding to the current tooltip.
265
+ this . setNeedsDisplay ( ) ;
221
266
}
222
267
}
0 commit comments