@@ -24,11 +24,12 @@ import {
2424 rectEqualToRect ,
2525 View ,
2626} from '../view-base' ;
27- import { BORDER_SIZE , COLORS , SNAPSHOT_HEIGHT } from './constants' ;
27+ import { BORDER_SIZE , COLORS , SNAPSHOT_SCRUBBER_SIZE } from './constants' ;
2828
2929type OnHover = ( node : Snapshot | null ) => void ;
3030
3131export class SnapshotsView extends View {
32+ _hoverLocation : Point | null = null ;
3233 _intrinsicSize : Size ;
3334 _profilerData : ReactProfilerData ;
3435
@@ -39,7 +40,7 @@ export class SnapshotsView extends View {
3940
4041 this . _intrinsicSize = {
4142 width : profilerData . duration ,
42- height : SNAPSHOT_HEIGHT ,
43+ height : profilerData . snapshotHeight ,
4344 } ;
4445 this . _profilerData = profilerData ;
4546 }
@@ -49,6 +50,7 @@ export class SnapshotsView extends View {
4950 }
5051
5152 draw ( context : CanvasRenderingContext2D ) {
53+ const snapshotHeight = this . _profilerData . snapshotHeight ;
5254 const { visibleArea} = this ;
5355
5456 context . fillStyle = COLORS . BACKGROUND ;
@@ -72,8 +74,8 @@ export class SnapshotsView extends View {
7274 break ;
7375 }
7476
75- const scaledHeight = SNAPSHOT_HEIGHT ;
76- const scaledWidth = ( snapshot . width * SNAPSHOT_HEIGHT ) / snapshot . height ;
77+ const scaledHeight = snapshotHeight ;
78+ const scaledWidth = ( snapshot . width * snapshotHeight ) / snapshot . height ;
7779
7880 const imageRect : Rect = {
7981 origin : {
@@ -96,6 +98,28 @@ export class SnapshotsView extends View {
9698
9799 x += scaledWidth + BORDER_SIZE ;
98100 }
101+
102+ const hoverLocation = this . _hoverLocation ;
103+ if ( hoverLocation !== null ) {
104+ const scrubberWidth = SNAPSHOT_SCRUBBER_SIZE + BORDER_SIZE * 2 ;
105+ const scrubberOffset = scrubberWidth / 2 ;
106+
107+ context . fillStyle = COLORS . SCRUBBER_BORDER ;
108+ context . fillRect (
109+ hoverLocation . x - scrubberOffset ,
110+ visibleArea . origin . y ,
111+ scrubberWidth ,
112+ visibleArea . size . height ,
113+ ) ;
114+
115+ context . fillStyle = COLORS . SCRUBBER_BACKGROUND ;
116+ context . fillRect (
117+ hoverLocation . x - scrubberOffset + BORDER_SIZE ,
118+ visibleArea . origin . y ,
119+ SNAPSHOT_SCRUBBER_SIZE ,
120+ visibleArea . size . height ,
121+ ) ;
122+ }
99123 }
100124
101125 handleInteraction ( interaction : Interaction , viewRefs : ViewRefs ) {
@@ -208,15 +232,29 @@ export class SnapshotsView extends View {
208232 }
209233
210234 if ( ! rectContainsPoint ( location , visibleArea ) ) {
235+ if ( this . _hoverLocation !== null ) {
236+ this . _hoverLocation = null ;
237+
238+ this . setNeedsDisplay ( ) ;
239+ }
240+
211241 onHover ( null ) ;
212242 return ;
213243 }
214244
215245 const snapshot = this . _findClosestSnapshot ( location . x ) ;
216246 if ( snapshot !== null ) {
247+ this . _hoverLocation = location ;
248+
217249 onHover ( snapshot ) ;
218250 } else {
251+ this . _hoverLocation = null ;
252+
219253 onHover ( null ) ;
220254 }
255+
256+ // Any time the mouse moves within the boundaries of this view, we need to re-render.
257+ // This is because we draw a scrubbing bar that shows the location corresponding to the current tooltip.
258+ this . setNeedsDisplay ( ) ;
221259 }
222260}
0 commit comments