Skip to content

Commit 3619c3b

Browse files
caitlinchan23Nkmailind-taniartviner
committed
refactored perfData to include max render time for all snapshots, later used to determine graph height
Co-authored-by: Nkmai <[email protected]> Co-authored-by: lind-tania <[email protected]> Co-authored-by: rtviner <[email protected]> Co-authored-by: caitlinchan23 <[email protected]>
1 parent 1c579b6 commit 3619c3b

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/app/components/PerformanceVisx.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,17 @@ const tooltipStyles = {
7171
};
7272

7373
/* DATA HANDLING HELPER FUNCTIONS */
74-
const traverse = (snapshot, data) => {
74+
const traverse = (snapshot, data, currMaxTotalRender = 0) => {
7575
if (!snapshot.children[0]) return;
76-
76+
// data.maxTotalRender
7777
// loop through snapshots
7878
snapshot.children.forEach((child, idx) => {
7979
const componentName = child.name + -[idx + 1];
8080

8181
// Get component Rendering Time
8282
const renderTime = Number(Number.parseFloat(child.componentData.actualDuration).toPrecision(5));
83-
83+
// sums render time for all children
84+
currMaxTotalRender += renderTime;
8485
// components as keys and set the value to their rendering time
8586
data['barStack'][data.barStack.length - 1][componentName] = renderTime;
8687

@@ -103,8 +104,10 @@ const traverse = (snapshot, data) => {
103104
data.componentData[componentName].totalRenderTime += renderTime;
104105
// Get rtid for the hovering feature
105106
data.componentData[componentName].rtid = child.rtid;
106-
traverse(snapshot.children[idx], data);
107+
traverse(snapshot.children[idx], data, currMaxTotalRender);
107108
})
109+
// reassigns total render time to max render time
110+
data.maxTotalRender = Math.max(currMaxTotalRender, data.maxTotalRender);
108111
return data;
109112
};
110113

@@ -123,6 +126,7 @@ const getPerfMetrics = (snapshots, snapshotsIds): any[] => {
123126
const perfData = {
124127
barStack: [],
125128
componentData: {},
129+
maxTotalRender: 0
126130
};
127131
snapshots.forEach((snapshot, i) => {
128132
perfData.barStack.push({snapshotId: snapshotsIds[i]});
@@ -147,16 +151,6 @@ const PerformanceVisx = (props: BarStackProps) => {
147151
const data = getPerfMetrics(snapshots, getSnapshotIds(hierarchy));
148152
const keys = Object.keys(data.componentData);
149153

150-
// create array of total render times for each snapshot
151-
const totalRenderArr = data.barStack.reduce((totalRender, curSnapshot) => {
152-
const curRenderTotal = keys.reduce((acc, cur) => {
153-
acc += Number(curSnapshot[cur]);
154-
return acc;
155-
}, 0);
156-
totalRender.push(curRenderTotal);
157-
return totalRender;
158-
}, [] as number[]);
159-
160154
// data accessor (used to generate scales) and formatter (add units for on hover box)
161155
const getSnapshotId = (d: snapshot) => d.snapshotId;
162156
const formatSnapshotId = (id) => `Snapshot ID: ${id}`;
@@ -169,11 +163,10 @@ const PerformanceVisx = (props: BarStackProps) => {
169163
});
170164

171165
const renderingScale = scaleLinear<number>({
172-
domain: [0, Math.max(...totalRenderArr)],
166+
domain: [0, data.maxTotalRender],
173167
nice: true,
174168
});
175169

176-
177170
const colorScale = scaleOrdinal<string>({
178171
domain: keys,
179172
range: schemeSet3,
@@ -220,7 +213,13 @@ const PerformanceVisx = (props: BarStackProps) => {
220213
>
221214
{barStacks =>
222215
barStacks.map(barStack =>
223-
barStack.bars.map(((bar, idx) => (
216+
barStack.bars.map(((bar, idx) => {
217+
// hides new components if components don't exist in previous snapshots
218+
if (Number.isNaN(bar.bar[1])) {
219+
console.log('bar is NaN: ', bar.bar);
220+
bar.height = 0;
221+
}
222+
return (
224223
<rect
225224
key={`bar-stack-${barStack.index}-${bar.index}`}
226225
x={bar.x}
@@ -231,6 +230,7 @@ const PerformanceVisx = (props: BarStackProps) => {
231230
/* TIP TOOL EVENT HANDLERS */
232231
// Hides tool tip once cursor moves off the current rect
233232
onMouseLeave={() => {
233+
console.log('bar: ', bar)
234234
dispatch(onHoverExit(data.componentData[bar.key].rtid),
235235
tooltipTimeout = window.setTimeout(() => {
236236
hideTooltip()
@@ -249,7 +249,7 @@ const PerformanceVisx = (props: BarStackProps) => {
249249
});
250250
}}
251251
/>
252-
)))
252+
)}))
253253
)
254254
}
255255
</BarStack>

0 commit comments

Comments
 (0)