@@ -7,7 +7,18 @@ import { AxisBottom, AxisLeft } from "@visx/axis";
7
7
import { scaleBand , scaleLinear , scaleOrdinal } from "@visx/scale" ;
8
8
import { useTooltip , useTooltipInPortal , defaultStyles } from "@visx/tooltip" ;
9
9
import { Text } from '@visx/text' ;
10
- import { schemeSet1 , schemeSet3 } from "d3-scale-chromatic" ;
10
+ import { schemeSet3 } from "d3-scale-chromatic" ;
11
+
12
+
13
+ /* NOTES
14
+ Current issues
15
+ 1. Not fully compatible with recoil apps. Reference the recoil-todo-test.
16
+ Barstacks display inconsistently...however, almost always displays upon initial test app load or
17
+ when empty button is clicked. Updating state after initial app load typically makes bars disappear.
18
+ However, cycling between updating state and then emptying sometimes fixes the stack bars. Important to note - all snapshots
19
+ do render (check HTML doc) within the chrome extension but they do not display because height is not consistently passed to each bar.
20
+ This side effect is only seen in recoil apps...
21
+ */
11
22
12
23
13
24
/* TYPESCRIPT */
@@ -32,10 +43,10 @@ export type BarStackProps = {
32
43
hierarchy ?: any ;
33
44
} ;
34
45
35
- /* DEFAULT STYLING */
46
+ /* DEFAULTS */
47
+ const defaultMargin = { top : 60 , right : 30 , bottom : 0 , left : 50 } ;
36
48
const axisColor = '#679DCA' ;
37
49
const background = "#242529" ;
38
- const defaultMargin = { top : 60 , right : 30 , bottom : 0 , left : 50 } ;
39
50
const tooltipStyles = {
40
51
...defaultStyles ,
41
52
minWidth : 60 ,
@@ -50,15 +61,17 @@ const getPerfMetrics = (snapshots, snapshotsIds) => {
50
61
} , [ ] )
51
62
}
52
63
53
- // traverse can either return all component rendering times or type of state component depending if 2nd argument is passed
64
+ // traverses a single snapshot either returning all component rendering times OR all component state types. Depends on 2nd arg
54
65
const traverse = ( snapshot , data = { } ) => {
55
66
if ( ! snapshot . children [ 0 ] ) return
56
67
for ( let i = 0 ; i < snapshot . children . length ; i ++ ) {
57
68
const componentName = snapshot . children [ i ] . name + - [ i + 1 ]
69
+ // Get component Type
58
70
if ( ! data . snapshotId ) {
59
71
if ( snapshot . children [ i ] . state !== 'stateless' ) data [ componentName ] = 'STATEFUL'
60
72
else data [ componentName ] = snapshot . children [ i ] . state ;
61
73
}
74
+ // Get component Rendering Time
62
75
else if ( snapshot . children [ i ] . componentData . actualDuration ) {
63
76
const renderTime = Number ( Number . parseFloat ( snapshot . children [ i ] . componentData . actualDuration ) . toPrecision ( 5 ) ) ;
64
77
data [ componentName ] = renderTime ;
@@ -127,7 +140,7 @@ const getSnapshotId = (d: snapshot) => d.snapshotId;
127
140
const formatSnapshotId = id => 'Snapshot ID: ' + id ;
128
141
const formatRenderTime = time => time + ' ms ' ;
129
142
130
- // create visualization SCALES with filtered data
143
+ // create visualization SCALES with cleaned data
131
144
const snapshotIdScale = scaleBand < string > ( {
132
145
domain : data . map ( getSnapshotId ) ,
133
146
padding : 0.2
@@ -143,7 +156,7 @@ const colorScale = scaleOrdinal<CityName, string>({
143
156
range : schemeSet3
144
157
} ) ;
145
158
146
- const { containerRef, TooltipInPortal } = useTooltipInPortal ( ) ;
159
+ const { containerRef, TooltipInPortal } = useTooltipInPortal ( ) ;
147
160
148
161
// setting max dimensions and scale ranges
149
162
if ( width < 10 ) return null ;
@@ -200,7 +213,6 @@ console.log('height', height)
200
213
width = { bar . width }
201
214
fill = { bar . color }
202
215
/* TIP TOOL EVENT HANDLERS */
203
-
204
216
// Hides tool tip once cursor moves off the current rect
205
217
onMouseLeave = { ( ) => {
206
218
tooltipTimeout = window . setTimeout ( ( ) => {
@@ -285,18 +297,11 @@ console.log('height', height)
285
297
left = { tooltipLeft }
286
298
style = { tooltipStyles }
287
299
>
288
- < div style = { { color : colorScale ( tooltipData . key ) } } >
289
- < strong > { tooltipData . key } </ strong >
290
- </ div >
291
-
300
+ // Displays: component name, component state type, render time, snapshotID
301
+ < div style = { { color : colorScale ( tooltipData . key ) } } > < strong > { tooltipData . key } </ strong > </ div >
292
302
< div > { allComponentStates [ tooltipData . key ] } </ div >
293
-
294
- < div >
295
- { formatRenderTime ( tooltipData . bar . data [ tooltipData . key ] ) }
296
- </ div >
297
- < div >
298
- < small > { formatSnapshotId ( getSnapshotId ( tooltipData . bar . data ) ) } </ small >
299
- </ div >
303
+ < div > { formatRenderTime ( tooltipData . bar . data [ tooltipData . key ] ) } </ div >
304
+ < div > < small > { formatSnapshotId ( getSnapshotId ( tooltipData . bar . data ) ) } </ small > </ div >
300
305
</ TooltipInPortal >
301
306
) }
302
307
</ div >
0 commit comments