@@ -7,7 +7,7 @@ import { AxisBottom } from "@visx/axis";
7
7
import { scaleBand , scaleLinear , scaleOrdinal } from "@visx/scale" ;
8
8
import { useTooltip , useTooltipInPortal , defaultStyles } from "@visx/tooltip" ;
9
9
import { LegendOrdinal } from "@visx/legend" ;
10
- import snapshots from "./snapshots" ;
10
+ // import snapshots from "./snapshots";
11
11
12
12
13
13
/* TYPESCRIPT */
@@ -29,6 +29,7 @@ export type BarStackProps = {
29
29
height : number ;
30
30
margin ?: { top : number ; right : number ; bottom : number ; left : number } ;
31
31
events ?: boolean ;
32
+ snapshots ?: any ;
32
33
} ;
33
34
34
35
/* DEFAULT STYLING */
@@ -45,10 +46,49 @@ const tooltipStyles = {
45
46
color : "white"
46
47
} ;
47
48
48
- /* DATA PREP */
49
- const data = [ ...snapshots ] ;
49
+ /* DATA PREP FUNCTIONS */
50
+ const getPerfMetrics = snapshots => {
51
+ return snapshots . reduce ( ( perfSnapshots , curSnapshot , idx ) => {
52
+ return perfSnapshots . concat ( traverse ( curSnapshot , { snapshot :idx + 1 } ) )
53
+ } , [ ] )
54
+ }
55
+
56
+ const traverse = ( snapshot , perfSnapshot = { } ) => {
57
+ if ( ! snapshot . children [ 0 ] ) return ;
58
+ perfSnapshot [ snapshot . name ] = snapshot . componentData . actualDuration ;
59
+ for ( let i = 0 ; i < snapshot . children . length ; i ++ ) {
60
+ perfSnapshot [ snapshot . children [ i ] . name + i ] = snapshot . children [ i ] . componentData . actualDuration ;
61
+ traverse ( snapshot . children [ i ] , perfSnapshot ) ;
62
+ }
63
+ return perfSnapshot ;
64
+ }
65
+
66
+
67
+ /* EXPORT COMPONENT */
68
+ export default function PerformanceVisx ( {
69
+ width,
70
+ height,
71
+ events = false ,
72
+ margin = defaultMargin ,
73
+ snapshots
74
+ } : BarStackProps )
75
+
76
+ {
77
+ const {
78
+ tooltipOpen,
79
+ tooltipLeft,
80
+ tooltipTop,
81
+ tooltipData,
82
+ hideTooltip,
83
+ showTooltip
84
+ } = useTooltip < TooltipData > ( ) ;
85
+
86
+ /* DATA PREP */
87
+ const data = getPerfMetrics ( snapshots ) ;
88
+ console . log ( data )
50
89
51
- // array of all object keys
90
+
91
+ // array of all object keys
52
92
const keys = Object . keys ( data [ 0 ] ) . filter ( ( d ) => d !== "snapshot" ) as CityName [ ] ;
53
93
54
94
// ARRAY OF TOTAL VALUES PER SNAPSHOT
@@ -61,15 +101,6 @@ const temperatureTotals = data.reduce((allTotals, currentDate) => {
61
101
return allTotals ;
62
102
} , [ ] as number [ ] ) ;
63
103
64
-
65
- /* ACCESSORS */
66
- const getSnapshot = ( d : snapshot ) => d . snapshot ;
67
-
68
- /* SCALE */
69
- const dateScale = scaleBand < string > ( {
70
- domain : data . map ( getSnapshot ) ,
71
- padding : 0.2
72
- } ) ;
73
104
const temperatureScale = scaleLinear < number > ( {
74
105
domain : [ 0 , Math . max ( ...temperatureTotals ) ] ,
75
106
nice : true
@@ -81,21 +112,15 @@ const colorScale = scaleOrdinal<CityName, string>({
81
112
82
113
let tooltipTimeout : number ;
83
114
84
- /* EXPORT COMPONENT */
85
- export default function PerformanceVisx ( {
86
- width,
87
- height,
88
- events = false ,
89
- margin = defaultMargin
90
- } : BarStackProps ) {
91
- const {
92
- tooltipOpen,
93
- tooltipLeft,
94
- tooltipTop,
95
- tooltipData,
96
- hideTooltip,
97
- showTooltip
98
- } = useTooltip < TooltipData > ( ) ;
115
+
116
+ /* ACCESSORS */
117
+ const getSnapshot = ( d : snapshot ) => d . snapshot ;
118
+
119
+ /* SCALE */
120
+ const dateScale = scaleBand < string > ( {
121
+ domain : data . map ( getSnapshot ) ,
122
+ padding : 0.2
123
+ } ) ;
99
124
100
125
const { containerRef, TooltipInPortal } = useTooltipInPortal ( ) ;
101
126
@@ -171,7 +196,7 @@ export default function PerformanceVisx({
171
196
/>
172
197
) ) ,
173
198
)
174
- }
199
+ }
175
200
</ BarStack >
176
201
</ Group >
177
202
< AxisBottom
0 commit comments