@@ -18,14 +18,13 @@ import React, { PureComponent } from 'react';
18
18
import { FixedSizeList as List } from 'react-window' ;
19
19
import AutoSizer from 'react-virtualized-auto-sizer' ;
20
20
import NoInteractionsMessage from './NoInteractionsMessage' ;
21
- import { scale } from './constants' ;
21
+ import { getGradientColor , scale } from './constants' ;
22
22
23
23
const INTERACTION_SIZE = 4 ;
24
24
const ITEM_SIZE = 25 ;
25
25
const SNAPSHOT_SIZE = 10 ;
26
26
27
27
type SelectInteraction = ( interaction : Interaction ) => void ;
28
- type ViewSnapshot = ( snapshot : Snapshot ) => void ;
29
28
30
29
type ChartItem = { |
31
30
interaction : Interaction ,
@@ -35,6 +34,7 @@ type ChartItem = {|
35
34
36
35
type ChartData = { |
37
36
items : Array < ChartItem > ,
37
+ maxDuration : number ,
38
38
stopTime : number ,
39
39
| } ;
40
40
@@ -47,38 +47,37 @@ type ItemData = {|
47
47
selectedSnapshot : Snapshot ,
48
48
selectInteraction : SelectInteraction ,
49
49
theme : Theme ,
50
- viewSnapshot : ViewSnapshot ,
51
50
| } ;
52
51
53
52
type Props = { |
54
53
cacheInteractionData : CacheInteractionData ,
55
54
getCachedInteractionData : GetCachedInteractionData ,
56
55
hasMultipleRoots : boolean ,
57
56
interactionsToSnapshots : Map < Interaction , Set < Snapshot> > ,
57
+ maxDuration : number ,
58
58
selectedInteraction : Interaction | null ,
59
59
selectedSnapshot : Snapshot ,
60
60
selectInteraction : SelectInteraction ,
61
61
theme : Theme ,
62
62
timestampsToInteractions : Map < number , Set < Interaction> > ,
63
- viewSnapshot : ViewSnapshot ,
64
63
| } ;
65
64
66
65
const InteractionTimeline = ( {
67
66
cacheInteractionData,
68
67
getCachedInteractionData,
69
68
hasMultipleRoots,
70
69
interactionsToSnapshots,
70
+ maxDuration,
71
71
selectedInteraction,
72
72
selectedSnapshot,
73
73
selectInteraction,
74
74
theme,
75
75
timestampsToInteractions,
76
- viewSnapshot,
77
76
} : Props ) => {
78
77
// Cache data in ProfilerStore so we only have to compute it the first time the interactions tab is shown
79
78
let chartData = getCachedInteractionData ( selectedSnapshot . root ) ;
80
79
if ( chartData === null ) {
81
- chartData = getChartData ( interactionsToSnapshots , timestampsToInteractions ) ;
80
+ chartData = getChartData ( interactionsToSnapshots , maxDuration , timestampsToInteractions ) ;
82
81
cacheInteractionData ( selectedSnapshot . root , chartData ) ;
83
82
}
84
83
@@ -94,7 +93,6 @@ const InteractionTimeline = ({
94
93
selectInteraction = { selectInteraction }
95
94
theme = { theme }
96
95
width = { width }
97
- viewSnapshot = { viewSnapshot }
98
96
/>
99
97
) }
100
98
</ AutoSizer >
@@ -109,7 +107,6 @@ type InteractionsListProps = {|
109
107
selectedSnapshot : Snapshot ,
110
108
selectInteraction : SelectInteraction ,
111
109
theme : Theme ,
112
- viewSnapshot : ViewSnapshot ,
113
110
width : number ,
114
111
| } ;
115
112
@@ -153,7 +150,6 @@ class InteractionsList extends PureComponent<InteractionsListProps, void> {
153
150
selectedSnapshot,
154
151
selectInteraction,
155
152
theme,
156
- viewSnapshot,
157
153
width,
158
154
} = this . props ;
159
155
@@ -176,7 +172,6 @@ class InteractionsList extends PureComponent<InteractionsListProps, void> {
176
172
selectedSnapshot ,
177
173
selectInteraction ,
178
174
theme ,
179
- viewSnapshot ,
180
175
width ,
181
176
) ;
182
177
@@ -214,44 +209,36 @@ type ListItemProps = {|
214
209
| } ;
215
210
type ListItemState = { |
216
211
isHovered : boolean ,
217
- hoveredSnapshot : Snapshot | null ,
218
212
| } ;
219
213
220
214
class ListItem extends PureComponent < ListItemProps , ListItemState > {
221
215
state = {
222
216
isHovered : false ,
223
- hoveredSnapshot : null ,
224
217
} ;
225
218
226
- handleMouseEnter = ( snapshot : Snapshot | null ) => this . setState ( {
227
- isHovered : true ,
228
- hoveredSnapshot : snapshot ,
229
- } ) ;
230
-
219
+ handleMouseEnter = ( ) => this . setState ( { isHovered : true } ) ;
231
220
handleMouseLeave = ( ) => this . setState ( { isHovered : false } ) ;
232
221
233
222
render ( ) {
234
223
const { data : itemData , index : itemIndex , style } = this . props ;
235
- const { isHovered, hoveredSnapshot } = this . state ;
224
+ const { isHovered } = this . state ;
236
225
237
226
const { chartData, labelColumnWidth, scaleX, selectedInteraction, selectedSnapshot, theme } = itemData ;
238
- const { items } = chartData ;
227
+ const { items, maxDuration } = chartData ;
239
228
240
229
const item : ChartItem = items [ itemIndex ] ;
241
230
const { interaction, lastSnapshotCommitTime } = item ;
242
231
243
- const showRowHover = isHovered && hoveredSnapshot === null ;
244
-
245
232
return (
246
233
< div
247
234
onClick = { ( ) => itemData . selectInteraction ( interaction ) }
248
- onMouseEnter = { ( ) => this . handleMouseEnter ( null ) }
235
+ onMouseEnter = { this . handleMouseEnter }
249
236
onMouseLeave = { this . handleMouseLeave }
250
237
style = { {
251
238
...style ,
252
239
display : 'flex' ,
253
240
alignItems : 'center' ,
254
- backgroundColor : showRowHover ? theme . state03 : ( selectedInteraction === interaction ? theme . base01 : 'transparent' ) ,
241
+ backgroundColor : isHovered ? theme . state03 : ( selectedInteraction === interaction ? theme . base01 : 'transparent' ) ,
255
242
borderBottom : `1px solid ${ theme . base01 } ` ,
256
243
cursor : 'pointer' ,
257
244
} }
@@ -265,8 +252,8 @@ class ListItem extends PureComponent<ListItemProps, ListItemState> {
265
252
lineHeight : `${ ITEM_SIZE } px` ,
266
253
boxSizing : 'border-box' ,
267
254
padding : '0 0.25rem' ,
268
- color : showRowHover ? theme . state00 : theme . base05 ,
269
- textDecoration : showRowHover ? 'underline' : 'none' ,
255
+ color : isHovered ? theme . state00 : theme . base05 ,
256
+ textDecoration : isHovered ? 'underline' : 'none' ,
270
257
userSelect : 'none' ,
271
258
} }
272
259
title = { interaction . name }
@@ -283,32 +270,35 @@ class ListItem extends PureComponent<ListItemProps, ListItemState> {
283
270
borderRadius : '0.125rem' ,
284
271
} }
285
272
/>
286
- { item . snapshots . map ( ( snapshot , snapshotIndex ) => (
287
- < div
288
- key = { snapshotIndex }
289
- onClick = { ( ) => itemData . viewSnapshot ( snapshot ) }
290
- onMouseEnter = { ( ) => this . handleMouseEnter ( snapshot ) }
291
- onMouseLeave = { ( ) => this . handleMouseEnter ( null ) }
292
- style = { {
293
- position : 'absolute' ,
294
- left : `${ labelColumnWidth + scaleX ( snapshot . commitTime ) } px` ,
295
- width : `${ SNAPSHOT_SIZE } px` ,
296
- height : `${ SNAPSHOT_SIZE } px` ,
297
- borderRadius : `${ SNAPSHOT_SIZE } px` ,
298
- backgroundColor : hoveredSnapshot === snapshot || selectedSnapshot === snapshot ? theme . state00 : theme . base00 ,
299
- border : `2px solid ${ theme . state00 } ` ,
300
- boxSizing : 'border-box' ,
301
- cursor : 'pointer' ,
302
- } }
303
- />
304
- ) ) }
273
+ { item . snapshots . map ( ( snapshot , snapshotIndex ) => {
274
+ // Guard against commits with duration 0
275
+ const percentage = Math . min ( 1 , Math . max ( 0 , snapshot . duration / maxDuration ) ) || 0 ;
276
+
277
+ return (
278
+ < div
279
+ key = { snapshotIndex }
280
+ style = { {
281
+ position : 'absolute' ,
282
+ left : `${ labelColumnWidth + scaleX ( snapshot . commitTime ) } px` ,
283
+ width : `${ SNAPSHOT_SIZE } px` ,
284
+ height : `${ SNAPSHOT_SIZE } px` ,
285
+ backgroundColor : selectedSnapshot === snapshot
286
+ ? theme . state06
287
+ : getGradientColor ( percentage ) ,
288
+ boxSizing : 'border-box' ,
289
+ cursor : 'pointer' ,
290
+ } }
291
+ />
292
+ ) ;
293
+ } ) }
305
294
</ div >
306
295
) ;
307
296
}
308
297
}
309
298
310
299
const getChartData = memoize ( (
311
300
interactionsToSnapshots : Map < Interaction , Set < Snapshot >> ,
301
+ maxDuration : number ,
312
302
timestampsToInteractions : Map < number , Set < Interaction >> ,
313
303
) : ChartData => {
314
304
const items : Array < ChartItem > = [];
@@ -332,6 +322,7 @@ const getChartData = memoize((
332
322
333
323
return {
334
324
items ,
325
+ maxDuration ,
335
326
stopTime ,
336
327
} ;
337
328
} ) ;
@@ -342,7 +333,6 @@ const getItemData = memoize((
342
333
selectedSnapshot : Snapshot ,
343
334
selectInteraction : SelectInteraction ,
344
335
theme : Theme ,
345
- viewSnapshot : ViewSnapshot ,
346
336
width : number ,
347
337
) : ItemData => {
348
338
const labelColumnWidth = Math . min ( 200 , width / 5 ) ;
@@ -357,7 +347,6 @@ const getItemData = memoize((
357
347
selectedSnapshot,
358
348
selectInteraction,
359
349
theme,
360
- viewSnapshot,
361
350
} ;
362
351
} );
363
352
0 commit comments