@@ -74,32 +74,52 @@ const tooltipStyles = {
74
74
75
75
/* DATA HANDLING HELPER FUNCTIONS */
76
76
77
- // traverses a snapshot for data: rendering time, component type, or rtid
78
- const traverse = ( snapshot , fetchData , data = { } ) => {
79
- console . log ( "data in beg of traverse: " , data )
77
+ const traverse = ( snapshot , data = { } ) => {
80
78
if ( ! snapshot . children [ 0 ] ) return ;
81
79
snapshot . children . forEach ( ( child , idx ) => {
82
80
const componentName = child . name + - [ idx + 1 ] ;
83
- // Get component Type
84
- if ( fetchData === 'getComponentType' ) {
85
- if ( child . state !== 'stateless' ) data [ componentName ] = 'stateful' ;
86
- else data [ componentName ] = child . state ;
81
+ if ( ! data . hasOwnProperty ( componentName ) ) {
82
+ data [ componentName ] = { } ;
87
83
}
84
+ // Get component Type
85
+ if ( child . state !== 'stateless' ) data [ componentName ] . componentState = 'stateful' ;
86
+ else data [ componentName ] . componentState = child . state ;
88
87
// Get component Rendering Time
89
- else if ( fetchData === 'getRenderTime' ) {
90
- const renderTime = Number ( Number . parseFloat ( child . componentData . actualDuration ) . toPrecision ( 5 ) ) ;
91
- data [ componentName ] = renderTime ;
92
- }
93
- else if ( fetchData === 'getRtid' ) {
94
- data [ componentName ] = child . rtid ;
95
- }
96
- traverse ( snapshot . children [ idx ] , fetchData , data ) ;
88
+ const renderTime = Number ( Number . parseFloat ( child . componentData . actualDuration ) . toPrecision ( 5 ) ) ;
89
+ data [ componentName ] . renderTime = renderTime ;
90
+ // Get rtid
91
+ data [ componentName ] . rtid = child . rtid ;
92
+ traverse ( snapshot . children [ idx ] , data ) ;
97
93
} )
98
- console . log ( "data in end of traverse: " , data )
99
94
return data ;
100
95
} ;
101
96
102
- const getSnapshotIds = ( obj , snapshotIds = [ ] ) :string [ ] => {
97
+ // traverses a snapshot for data: rendering time, component type, or rtid
98
+ // const traverse = (snapshot, fetchData, data = {}) => {
99
+ // // console.log("data in beg of traverse: ", data )
100
+ // if (!snapshot.children[0]) return;
101
+ // snapshot.children.forEach((child, idx) => {
102
+ // const componentName = child.name + -[idx + 1];
103
+ // // Get component Type
104
+ // if (fetchData === 'getComponentType') {
105
+ // if (child.state !== 'stateless') data[componentName] = 'stateful';
106
+ // else data[componentName] = child.state;
107
+ // }
108
+ // // Get component Rendering Time
109
+ // else if (fetchData === 'getRenderTime') {
110
+ // const renderTime = Number(Number.parseFloat(child.componentData.actualDuration).toPrecision(5));
111
+ // data[componentName] = renderTime;
112
+ // }
113
+ // else if (fetchData === 'getRtid') {
114
+ // data[componentName] = child.rtid;
115
+ // }
116
+ // traverse(snapshot.children[idx], fetchData, data);
117
+ // })
118
+ // // console.log("data in end of traverse: ", data )
119
+ // return data;
120
+ // };
121
+
122
+ const getSnapshotIds = ( obj , snapshotIds = [ ] ) : string [ ] => {
103
123
snapshotIds . push ( `${ obj . name } .${ obj . branch } ` ) ;
104
124
if ( obj . children ) {
105
125
obj . children . forEach ( child => {
@@ -110,15 +130,15 @@ const getSnapshotIds = (obj, snapshotIds = []):string[] => {
110
130
} ;
111
131
112
132
// Returns array of snapshot objs each with components and corresponding render times
113
- const getPerfMetrics = ( snapshots , snapshotsIds ) :any [ ] => {
133
+ const getPerfMetrics = ( snapshots , snapshotsIds ) : any [ ] => {
134
+ console . log ( 'snapshots: ' , snapshots )
114
135
return snapshots . reduce ( ( perfSnapshots , curSnapshot , idx ) => {
115
- return perfSnapshots . concat ( traverse ( curSnapshot , 'getRenderTime' , { snapshotId : snapshotsIds [ idx ] } ) ) ;
136
+ return perfSnapshots . concat ( traverse ( curSnapshot , { snapshotId : snapshotsIds [ idx ] } ) ) ;
116
137
} , [ ] ) ;
117
138
} ;
118
139
119
140
/* EXPORT COMPONENT */
120
141
const PerformanceVisx = ( props : BarStackProps ) => {
121
-
122
142
// hook used to dispatch onhover action in rect
123
143
const [ { tabs, currentTab } , dispatch ] = useStoreContext ( ) ;
124
144
@@ -128,19 +148,40 @@ const PerformanceVisx = (props: BarStackProps) => {
128
148
tooltipOpen, tooltipLeft, tooltipTop, tooltipData, hideTooltip, showTooltip,
129
149
} = useTooltip < TooltipData > ( ) ;
130
150
let tooltipTimeout : number ;
131
-
151
+ console . log ( 'tooltipdata: ' , tooltipData )
132
152
const { containerRef, TooltipInPortal } = useTooltipInPortal ( ) ;
133
153
134
154
// filter and structure incoming data for VISX
135
155
const data = getPerfMetrics ( snapshots , getSnapshotIds ( hierarchy ) ) ;
156
+ console . log ( 'data:' , data ) ;
136
157
const keys = Object . keys ( data [ 0 ] ) . filter ( d => d !== 'snapshotId' ) ;
137
- const allComponentStates = traverse ( snapshots [ 0 ] , 'getComponentType' ) ;
138
- const allComponentRtids = traverse ( snapshots [ snapshots . length - 1 ] , 'getRtid' ) ;
158
+ // const allComponentStates = traverse(snapshots[0], 'getComponentType');
159
+ // const allComponentRtids = traverse(snapshots[snapshots.length - 1], 'getRtid');
160
+ // console.log('allComponentRtids: ', allComponentRtids);
161
+ // const allComponentRtids = data.filter()
162
+ const getBarstackData = ( data ) => {
163
+ const dataArr = [ ] ;
164
+ data . forEach ( snapshot => {
165
+ const dataObj = { } ;
166
+ for ( let key in snapshot ) {
167
+ if ( key !== 'snapshotId' ) {
168
+ dataObj [ key ] = snapshot [ key ] [ 'renderTime' ] ;
169
+ } else {
170
+ dataObj [ key ] = snapshot [ key ] ;
171
+ }
172
+ }
173
+ dataArr . push ( dataObj ) ;
174
+ } ) ;
175
+ return dataArr ;
176
+ } ;
177
+ const barstackData = getBarstackData ( data ) ;
139
178
140
179
// create array of total render times for each snapshot
141
180
const totalRenderArr = data . reduce ( ( totalRender , curSnapshot ) => {
181
+ // console.log('curSnapshot: ', curSnapshot);
182
+ // console.log('keys: ', keys);
142
183
const curRenderTotal = keys . reduce ( ( acc , cur ) => {
143
- acc += Number ( curSnapshot [ cur ] ) ;
184
+ acc += Number ( curSnapshot [ cur ] . renderTime ) ;
144
185
return acc ;
145
186
} , 0 ) ;
146
187
totalRender . push ( curRenderTotal ) ;
@@ -149,11 +190,26 @@ const PerformanceVisx = (props: BarStackProps) => {
149
190
150
191
// data accessor (used to generate scales) and formatter (add units for on hover box)
151
192
const getSnapshotId = ( d : snapshot ) => d . snapshotId ;
152
-
193
+
153
194
const formatSnapshotId = ( id ) => `Snapshot ID: ${ id } ` ;
154
-
195
+
155
196
const formatRenderTime = ( time ) => `${ time } ms ` ;
156
197
198
+ const getTooltipStates = ( data ) => {
199
+ const snapshotObj = { } ;
200
+ data . forEach ( snapshot => {
201
+ snapshotObj [ snapshot . snapshotId ] = { } ;
202
+ for ( let key in snapshot ) {
203
+ if ( key !== 'snapshotId' ) {
204
+ snapshotObj [ snapshot . snapshotId ] [ key ] = snapshot [ key ] . componentState ;
205
+ }
206
+ }
207
+ } ) ;
208
+ return snapshotObj ;
209
+ }
210
+ const tooltipStates = getTooltipStates ( data ) ;
211
+ console . log ( 'tooltipStates: ' , tooltipStates ) ;
212
+
157
213
// create visualization SCALES with cleaned data
158
214
const snapshotIdScale = scaleBand < string > ( {
159
215
domain : data . map ( getSnapshotId ) ,
@@ -203,15 +259,15 @@ const PerformanceVisx = (props: BarStackProps) => {
203
259
/>
204
260
< Group top = { margin . top } left = { margin . left } >
205
261
< BarStack
206
- data = { data }
262
+ data = { barstackData }
207
263
keys = { keys }
208
264
x = { getSnapshotId }
209
265
xScale = { snapshotIdScale }
210
266
yScale = { renderingScale }
211
267
color = { colorScale }
212
268
>
213
- { barStacks =>
214
- barStacks . map ( barStack =>
269
+ { barStacks =>
270
+ barStacks . map ( barStack =>
215
271
barStack . bars . map ( ( ( bar , idx ) => (
216
272
< rect
217
273
key = { `bar-stack-${ barStack . index } -${ bar . index } ` }
@@ -223,14 +279,17 @@ const PerformanceVisx = (props: BarStackProps) => {
223
279
/* TIP TOOL EVENT HANDLERS */
224
280
// Hides tool tip once cursor moves off the current rect
225
281
onMouseLeave = { ( ) => {
226
- dispatch ( onHoverExit ( allComponentRtids [ bar . key ] ) ,
227
- tooltipTimeout = window . setTimeout ( ( ) => {
228
- hideTooltip ( )
229
- } , 300 ) )
282
+ console . log ( 'bar: ' , bar ) ;
283
+ console . log ( 'barstack' , barStack ) ;
284
+ console . log ( 'onHoverExit arg:' , data [ data . length - 1 ] [ bar . key ] . rtid ) ;
285
+ dispatch ( onHoverExit ( data [ data . length - 1 ] [ bar . key ] [ 'rtid' ] ) ,
286
+ tooltipTimeout = window . setTimeout ( ( ) => {
287
+ hideTooltip ( )
288
+ } , 300 ) )
230
289
} }
231
- // Cursor position in window updates position of the tool tip
290
+ // Cursor position in window updates position of the tool tip
232
291
onMouseMove = { event => {
233
- dispatch ( onHover ( allComponentRtids [ bar . key ] ) )
292
+ dispatch ( onHover ( data [ data . length - 1 ] [ bar . key ] [ 'rtid' ] ) )
234
293
if ( tooltipTimeout ) clearTimeout ( tooltipTimeout ) ;
235
294
const top = event . clientY - margin . top - bar . height ;
236
295
const left = bar . x + bar . width / 2 ;
@@ -290,7 +349,7 @@ const PerformanceVisx = (props: BarStackProps) => {
290
349
< strong > { tooltipData . key } </ strong >
291
350
{ ' ' }
292
351
</ div >
293
- < div > { allComponentStates [ tooltipData . key ] } </ div >
352
+ < div > { tooltipStates [ tooltipData . bar . data . snapshotId ] [ tooltipData . key ] } </ div >
294
353
< div >
295
354
{ ' ' }
296
355
{ formatRenderTime ( tooltipData . bar . data [ tooltipData . key ] ) }
0 commit comments