Skip to content

Commit ecede41

Browse files
(updated) converted TS types margin, TooltipData, BarStackProps to TS interfaces
1 parent af640d3 commit ecede41

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

src/app/components/PerformanceVisx.tsx

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ import { Text } from '@visx/text';
1010
import { schemeSet3 } from 'd3-scale-chromatic';
1111

1212
/* 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.
1514
Barstacks display inconsistently...however, almost always displays upon initial test app load or
1615
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...
2020
*/
2121

2222
/* TYPESCRIPT */
23-
type margin = { top: number; right: number; bottom: number; left: number };
2423
type snapshot = any;
25-
type TooltipData = {
24+
25+
interface margin { top: number; right: number; bottom: number; left: number };
26+
27+
interface TooltipData {
2628
bar: SeriesPoint<snapshot>;
2729
key: CityName;
2830
index: number;
@@ -31,17 +33,15 @@ type TooltipData = {
3133
x: number;
3234
y: number;
3335
color: string;
34-
};
36+
}
3537

3638
// typescript for PROPS from StateRoute.tsx
37-
type BarStackProps = {
39+
interface BarStackProps {
3840
width: number;
3941
height: number;
4042
snapshots: [];
4143
hierarchy: any;
42-
};
43-
44-
44+
}
4545

4646
/* DEFAULTS */
4747
const margin = { top: 60, right: 30, bottom: 0, left: 50 };
@@ -56,10 +56,7 @@ const tooltipStyles = {
5656

5757
/* DATA HANDLING HELPER FUNCTIONS */
5858

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
6360
const traverse = (snapshot, data = {}) => {
6461
if (!snapshot.children[0]) return;
6562
for (let i = 0; i < snapshot.children.length; i++) {
@@ -89,19 +86,21 @@ const getSnapshotIds = (obj, snapshotIds = []) => {
8986
return snapshotIds;
9087
};
9188

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+
9296
/* EXPORT COMPONENT */
9397

9498
const PerformanceVisx = (props: BarStackProps) => {
9599

96100
const { width, height, snapshots, hierarchy } = props;
97101

98102
const {
99-
tooltipOpen,
100-
tooltipLeft,
101-
tooltipTop,
102-
tooltipData,
103-
hideTooltip,
104-
showTooltip,
103+
tooltipOpen, tooltipLeft, tooltipTop, tooltipData, hideTooltip, showTooltip,
105104
} = useTooltip<TooltipData>();
106105

107106
let tooltipTimeout: number;

0 commit comments

Comments
 (0)