@@ -10,19 +10,21 @@ import { Text } from '@visx/text';
10
10
import { schemeSet3 } from 'd3-scale-chromatic' ;
11
11
12
12
/* NOTES
13
- Current issues
14
- 1. Not fully compatible with recoil apps. Reference the recoil-todo-test.
13
+ Issue - Not fully compatible with recoil apps. Reference the recoil-todo-test.
15
14
Barstacks display inconsistently...however, almost always displays upon initial test app load or
16
15
when empty button is clicked. Updating state after initial app load typically makes bars disappear.
17
- However, cycling between updating state and then emptying sometimes fixes the stack bars. Important to note - all snapshots
18
- do render (check HTML doc) within the chrome extension but they do not display because height is not consistently passed to each bar.
19
- This side effect is only seen in recoil apps...
16
+ However, cycling between updating state and then emptying sometimes fixes the stack bars. Important
17
+ to note - all snapshots do render (check HTML doc) within the chrome extension but they do
18
+ not display because height is not consistently passed to each bar. This side effect is only
19
+ seen in recoil apps...
20
20
*/
21
21
22
22
/* TYPESCRIPT */
23
- type margin = { top : number ; right : number ; bottom : number ; left : number } ;
24
23
type snapshot = any ;
25
- type TooltipData = {
24
+
25
+ interface margin { top : number ; right : number ; bottom : number ; left : number } ;
26
+
27
+ interface TooltipData {
26
28
bar : SeriesPoint < snapshot > ;
27
29
key : CityName ;
28
30
index : number ;
@@ -31,17 +33,15 @@ type TooltipData = {
31
33
x : number ;
32
34
y : number ;
33
35
color : string ;
34
- } ;
36
+ }
35
37
36
38
// typescript for PROPS from StateRoute.tsx
37
- type BarStackProps = {
39
+ interface BarStackProps {
38
40
width : number ;
39
41
height : number ;
40
42
snapshots : [ ] ;
41
43
hierarchy : any ;
42
- } ;
43
-
44
-
44
+ }
45
45
46
46
/* DEFAULTS */
47
47
const margin = { top : 60 , right : 30 , bottom : 0 , left : 50 } ;
@@ -56,10 +56,7 @@ const tooltipStyles = {
56
56
57
57
/* DATA HANDLING HELPER FUNCTIONS */
58
58
59
- // Returns an array of objects (snapshots) with key-value pairs of each component and corresponding render time
60
- const getPerfMetrics = ( snapshots , snapshotsIds ) => snapshots . reduce ( ( perfSnapshots , curSnapshot , idx ) => perfSnapshots . concat ( traverse ( curSnapshot , { snapshotId : snapshotsIds [ idx ] } ) ) , [ ] ) ;
61
-
62
- // traverses a single snapshot - returns either all component rendering times OR all component state types. Depends on 2nd arg
59
+ // traverses a snapshot - returns all rendering times OR component state types. Depends on 2nd arg
63
60
const traverse = ( snapshot , data = { } ) => {
64
61
if ( ! snapshot . children [ 0 ] ) return ;
65
62
for ( let i = 0 ; i < snapshot . children . length ; i ++ ) {
@@ -89,19 +86,21 @@ const getSnapshotIds = (obj, snapshotIds = []) => {
89
86
return snapshotIds ;
90
87
} ;
91
88
89
+ // 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 ] } ) ) ;
93
+ } , [ ] ) ;
94
+ } ;
95
+
92
96
/* EXPORT COMPONENT */
93
97
94
98
const PerformanceVisx = ( props : BarStackProps ) => {
95
99
96
100
const { width, height, snapshots, hierarchy } = props ;
97
101
98
102
const {
99
- tooltipOpen,
100
- tooltipLeft,
101
- tooltipTop,
102
- tooltipData,
103
- hideTooltip,
104
- showTooltip,
103
+ tooltipOpen, tooltipLeft, tooltipTop, tooltipData, hideTooltip, showTooltip,
105
104
} = useTooltip < TooltipData > ( ) ;
106
105
107
106
let tooltipTimeout : number ;
0 commit comments