Skip to content

Commit c1c8698

Browse files
(updated) traverse function to get component rtid (unique identifier for DOM highlighting feature
1 parent 9dc14c4 commit c1c8698

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/app/components/PerformanceVisx.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { scaleBand, scaleLinear, scaleOrdinal } from '@visx/scale';
88
import { useTooltip, useTooltipInPortal, defaultStyles } from '@visx/tooltip';
99
import { Text } from '@visx/text';
1010
import { schemeSet3 } from 'd3-scale-chromatic';
11+
import snapshots from './snapshots';
1112

1213
/* NOTES
1314
Issue - Not fully compatible with recoil apps. Reference the recoil-todo-test.
@@ -67,22 +68,25 @@ const tooltipStyles = {
6768

6869
// traverses a snapshot - returns object of rendering times OR component state types. Depends on 2nd arg
6970

70-
const traverse = (snapshot, data: data = {}) => {
71+
const traverse = (snapshot, fetchData, data = {}) => {
7172
if (!snapshot.children[0]) return;
72-
for (let i = 0; i < snapshot.children.length; i++) {
73-
const componentName = snapshot.children[i].name + -[i + 1];
73+
snapshot.children.forEach((child, idx) => {
74+
const componentName = child.name + -[idx + 1];
7475
// Get component Type
75-
if (!data.snapshotId) {
76-
if (snapshot.children[i].state !== 'stateless') data[componentName] = 'STATEFUL';
77-
else data[componentName] = snapshot.children[i].state;
76+
if (fetchData === 'componentType') {
77+
if (child.state !== 'stateless') data[componentName] = 'STATEFUL';
78+
else data[componentName] = child.state;
7879
}
7980
// Get component Rendering Time
80-
else if (snapshot.children[i].componentData.actualDuration) {
81-
const renderTime = Number(Number.parseFloat(snapshot.children[i].componentData.actualDuration).toPrecision(5));
81+
else if (fetchData === 'renderTime') {
82+
const renderTime = Number(Number.parseFloat(child.componentData.actualDuration).toPrecision(5));
8283
data[componentName] = renderTime;
8384
}
84-
traverse(snapshot.children[i], data);
85-
}
85+
else if (fetchData === 'rtid') {
86+
data[componentName] = child.rtid;
87+
}
88+
traverse(snapshot.children[idx], fetchData, data);
89+
})
8690
return data;
8791
};
8892

@@ -99,7 +103,7 @@ const getSnapshotIds = (obj, snapshotIds = []) => {
99103
// Returns array of snapshot objs each with components and corresponding render times
100104
const getPerfMetrics = (snapshots, snapshotsIds):any[] => {
101105
return snapshots.reduce((perfSnapshots, curSnapshot, idx) => {
102-
return perfSnapshots.concat(traverse(curSnapshot, { snapshotId: snapshotsIds[idx] }));
106+
return perfSnapshots.concat(traverse(curSnapshot, 'renderTime', { snapshotId: snapshotsIds[idx] }));
103107
}, []);
104108
};
105109

@@ -108,6 +112,8 @@ const PerformanceVisx = (props: BarStackProps) => {
108112

109113
const { width, height, snapshots, hierarchy } = props;
110114

115+
console.log('snapshots', snapshots);
116+
111117
const {
112118
tooltipOpen, tooltipLeft, tooltipTop, tooltipData, hideTooltip, showTooltip,
113119
} = useTooltip<TooltipData>();
@@ -206,6 +212,7 @@ const PerformanceVisx = (props: BarStackProps) => {
206212
/* TIP TOOL EVENT HANDLERS */
207213
// Hides tool tip once cursor moves off the current rect
208214
onMouseLeave={() => {
215+
console.log('datafrommouse', data)
209216
tooltipTimeout = window.setTimeout(() => {
210217
hideTooltip();
211218
}, 300);

0 commit comments

Comments
 (0)