Skip to content

Commit 81aae05

Browse files
(added) TS-interface data
1 parent 31e80e5 commit 81aae05

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/app/components/PerformanceVisx.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface margin { top: number; right: number; bottom: number; left: number };
2626

2727
interface TooltipData {
2828
bar: SeriesPoint<snapshot>;
29-
key: CityName;
29+
key: string;
3030
index: number;
3131
height: number;
3232
width: number;
@@ -56,8 +56,13 @@ const tooltipStyles = {
5656

5757
/* DATA HANDLING HELPER FUNCTIONS */
5858

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 = {}) => {
6166
if (!snapshot.children[0]) return;
6267
for (let i = 0; i < snapshot.children.length; i++) {
6368
const componentName = snapshot.children[i].name + -[i + 1];
@@ -87,14 +92,13 @@ const getSnapshotIds = (obj, snapshotIds = []) => {
8792
};
8893

8994
// 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] }));
9398
}, []);
9499
};
95100

96101
/* EXPORT COMPONENT */
97-
98102
const PerformanceVisx = (props: BarStackProps) => {
99103

100104
const { width, height, snapshots, hierarchy } = props;
@@ -108,13 +112,12 @@ const PerformanceVisx = (props: BarStackProps) => {
108112
const { containerRef, TooltipInPortal } = useTooltipInPortal();
109113

110114
// filter and structure incoming data for VISX
115+
111116
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]);
114117

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]);
118121

119122
// create array of total render times for each snapshot
120123
const totalRenderArr = data.reduce((totalRender, curSnapshot) => {
@@ -142,7 +145,7 @@ const PerformanceVisx = (props: BarStackProps) => {
142145
nice: true,
143146
});
144147

145-
const colorScale = scaleOrdinal<CityName, string>({
148+
const colorScale = scaleOrdinal<string>({
146149
domain: keys,
147150
range: schemeSet3,
148151
});
@@ -179,7 +182,7 @@ const PerformanceVisx = (props: BarStackProps) => {
179182
xOffset={snapshotIdScale.bandwidth() / 2}
180183
/>
181184
<Group top={margin.top} left={margin.left}>
182-
<BarStack <snapshot, CityName>
185+
<BarStack
183186
data={data}
184187
keys={keys}
185188
x={getSnapshotId}

0 commit comments

Comments
 (0)