@@ -26,7 +26,7 @@ interface margin { top: number; right: number; bottom: number; left: number };
26
26
27
27
interface TooltipData {
28
28
bar : SeriesPoint < snapshot > ;
29
- key : CityName ;
29
+ key : string ;
30
30
index : number ;
31
31
height : number ;
32
32
width : number ;
@@ -56,8 +56,13 @@ const tooltipStyles = {
56
56
57
57
/* DATA HANDLING HELPER FUNCTIONS */
58
58
59
- // traverses a snapshot - returns all rendering times OR component state types. Depends on 2nd arg
60
- const traverse = ( snapshot , data = { } ) => {
59
+ // traverses a snapshot - returns object of rendering times OR component state types. Depends on 2nd arg
60
+
61
+ interface data {
62
+ snapshotId ?: string ;
63
+ }
64
+
65
+ const traverse = ( snapshot , data : data = { } ) => {
61
66
if ( ! snapshot . children [ 0 ] ) return ;
62
67
for ( let i = 0 ; i < snapshot . children . length ; i ++ ) {
63
68
const componentName = snapshot . children [ i ] . name + - [ i + 1 ] ;
@@ -87,14 +92,13 @@ const getSnapshotIds = (obj, snapshotIds = []) => {
87
92
} ;
88
93
89
94
// Returns array of snapshot objs each with components and corresponding render times
90
- const getPerfMetrics = ( snapshots , snapshotsIds ) => {
91
- snapshots . reduce ( ( perfSnapshots , curSnapshot , idx ) => {
92
- perfSnapshots . concat ( traverse ( curSnapshot , { snapshotId : snapshotsIds [ idx ] } ) ) ;
95
+ const getPerfMetrics = ( snapshots , snapshotsIds ) : any [ ] => {
96
+ return snapshots . reduce ( ( perfSnapshots , curSnapshot , idx ) => {
97
+ return perfSnapshots . concat ( traverse ( curSnapshot , { snapshotId : snapshotsIds [ idx ] } ) ) ;
93
98
} , [ ] ) ;
94
99
} ;
95
100
96
101
/* EXPORT COMPONENT */
97
-
98
102
const PerformanceVisx = ( props : BarStackProps ) => {
99
103
100
104
const { width, height, snapshots, hierarchy } = props ;
@@ -108,13 +112,12 @@ const PerformanceVisx = (props: BarStackProps) => {
108
112
const { containerRef, TooltipInPortal } = useTooltipInPortal ( ) ;
109
113
110
114
// filter and structure incoming data for VISX
115
+
111
116
const data = getPerfMetrics ( snapshots , getSnapshotIds ( hierarchy ) ) ;
112
- const keys = Object . keys ( data [ 0 ] ) . filter ( d => d !== 'snapshotId' ) as CityName [ ] ;
113
- const allComponentStates = traverse ( snapshots [ 0 ] ) ;
114
117
115
- console . log ( snapshots ) ;
116
- console . log ( hierarchy ) ;
117
- console . log ( 'margin' , margin ) ;
118
+ const keys = Object . keys ( data [ 0 ] ) . filter ( d => d !== 'snapshotId' ) as [ ] ;
119
+
120
+ const allComponentStates = traverse ( snapshots [ 0 ] ) ;
118
121
119
122
// create array of total render times for each snapshot
120
123
const totalRenderArr = data . reduce ( ( totalRender , curSnapshot ) => {
@@ -142,7 +145,7 @@ const PerformanceVisx = (props: BarStackProps) => {
142
145
nice : true ,
143
146
} ) ;
144
147
145
- const colorScale = scaleOrdinal < CityName , string > ( {
148
+ const colorScale = scaleOrdinal < string > ( {
146
149
domain : keys ,
147
150
range : schemeSet3 ,
148
151
} ) ;
@@ -179,7 +182,7 @@ const PerformanceVisx = (props: BarStackProps) => {
179
182
xOffset = { snapshotIdScale . bandwidth ( ) / 2 }
180
183
/>
181
184
< Group top = { margin . top } left = { margin . left } >
182
- < BarStack < snapshot , CityName >
185
+ < BarStack
183
186
data = { data }
184
187
keys = { keys }
185
188
x = { getSnapshotId }
0 commit comments