@@ -8,6 +8,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
10
import { schemeSet3 } from 'd3-scale-chromatic' ;
11
+ import snapshots from './snapshots' ;
11
12
12
13
/* NOTES
13
14
Issue - Not fully compatible with recoil apps. Reference the recoil-todo-test.
@@ -67,22 +68,25 @@ const tooltipStyles = {
67
68
68
69
// traverses a snapshot - returns object of rendering times OR component state types. Depends on 2nd arg
69
70
70
- const traverse = ( snapshot , data : data = { } ) => {
71
+ const traverse = ( snapshot , fetchData , data = { } ) => {
71
72
if ( ! snapshot . children [ 0 ] ) return ;
72
- for ( let i = 0 ; i < snapshot . children . length ; i ++ ) {
73
- const componentName = snapshot . children [ i ] . name + - [ i + 1 ] ;
73
+ snapshot . children . forEach ( ( child , idx ) => {
74
+ const componentName = child . name + - [ idx + 1 ] ;
74
75
// Get component Type
75
- if ( ! data . snapshotId ) {
76
- if ( snapshot . children [ i ] . state !== 'stateless' ) data [ componentName ] = 'STATEFUL' ;
77
- else data [ componentName ] = snapshot . children [ i ] . state ;
76
+ if ( fetchData === 'componentType' ) {
77
+ if ( child . state !== 'stateless' ) data [ componentName ] = 'STATEFUL' ;
78
+ else data [ componentName ] = child . state ;
78
79
}
79
80
// Get component Rendering Time
80
- else if ( snapshot . children [ i ] . componentData . actualDuration ) {
81
- const renderTime = Number ( Number . parseFloat ( snapshot . children [ i ] . componentData . actualDuration ) . toPrecision ( 5 ) ) ;
81
+ else if ( fetchData === 'renderTime' ) {
82
+ const renderTime = Number ( Number . parseFloat ( child . componentData . actualDuration ) . toPrecision ( 5 ) ) ;
82
83
data [ componentName ] = renderTime ;
83
84
}
84
- traverse ( snapshot . children [ i ] , data ) ;
85
- }
85
+ else if ( fetchData === 'rtid' ) {
86
+ data [ componentName ] = child . rtid ;
87
+ }
88
+ traverse ( snapshot . children [ idx ] , fetchData , data ) ;
89
+ } )
86
90
return data ;
87
91
} ;
88
92
@@ -99,7 +103,7 @@ const getSnapshotIds = (obj, snapshotIds = []) => {
99
103
// Returns array of snapshot objs each with components and corresponding render times
100
104
const getPerfMetrics = ( snapshots , snapshotsIds ) :any [ ] => {
101
105
return snapshots . reduce ( ( perfSnapshots , curSnapshot , idx ) => {
102
- return perfSnapshots . concat ( traverse ( curSnapshot , { snapshotId : snapshotsIds [ idx ] } ) ) ;
106
+ return perfSnapshots . concat ( traverse ( curSnapshot , 'renderTime' , { snapshotId : snapshotsIds [ idx ] } ) ) ;
103
107
} , [ ] ) ;
104
108
} ;
105
109
@@ -108,6 +112,8 @@ const PerformanceVisx = (props: BarStackProps) => {
108
112
109
113
const { width, height, snapshots, hierarchy } = props ;
110
114
115
+ console . log ( 'snapshots' , snapshots ) ;
116
+
111
117
const {
112
118
tooltipOpen, tooltipLeft, tooltipTop, tooltipData, hideTooltip, showTooltip,
113
119
} = useTooltip < TooltipData > ( ) ;
@@ -206,6 +212,7 @@ const PerformanceVisx = (props: BarStackProps) => {
206
212
/* TIP TOOL EVENT HANDLERS */
207
213
// Hides tool tip once cursor moves off the current rect
208
214
onMouseLeave = { ( ) => {
215
+ console . log ( 'datafrommouse' , data )
209
216
tooltipTimeout = window . setTimeout ( ( ) => {
210
217
hideTooltip ( ) ;
211
218
} , 300 ) ;
0 commit comments