Skip to content

Commit b9aee99

Browse files
(added) comments to helper functions, tooltip, and current issue
1 parent 8ba57c7 commit b9aee99

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/app/components/PerformanceVisx.tsx

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@ import { AxisBottom, AxisLeft } from "@visx/axis";
77
import { scaleBand, scaleLinear, scaleOrdinal } from "@visx/scale";
88
import { useTooltip, useTooltipInPortal, defaultStyles } from "@visx/tooltip";
99
import { Text } from '@visx/text';
10-
import { schemeSet1,schemeSet3 } from "d3-scale-chromatic";
10+
import { schemeSet3 } from "d3-scale-chromatic";
11+
12+
13+
/* NOTES
14+
Current issues
15+
1. Not fully compatible with recoil apps. Reference the recoil-todo-test.
16+
Barstacks display inconsistently...however, almost always displays upon initial test app load or
17+
when empty button is clicked. Updating state after initial app load typically makes bars disappear.
18+
However, cycling between updating state and then emptying sometimes fixes the stack bars. Important to note - all snapshots
19+
do render (check HTML doc) within the chrome extension but they do not display because height is not consistently passed to each bar.
20+
This side effect is only seen in recoil apps...
21+
*/
1122

1223

1324
/* TYPESCRIPT */
@@ -32,10 +43,10 @@ export type BarStackProps = {
3243
hierarchy?: any;
3344
};
3445

35-
/* DEFAULT STYLING */
46+
/* DEFAULTS */
47+
const defaultMargin = { top: 60, right: 30, bottom: 0, left: 50 };
3648
const axisColor = '#679DCA';
3749
const background = "#242529";
38-
const defaultMargin = { top: 60, right: 30, bottom: 0, left: 50 };
3950
const tooltipStyles = {
4051
...defaultStyles,
4152
minWidth: 60,
@@ -50,15 +61,17 @@ const getPerfMetrics = (snapshots, snapshotsIds) => {
5061
}, [])
5162
}
5263

53-
// traverse can either return all component rendering times or type of state component depending if 2nd argument is passed
64+
// traverses a single snapshot either returning all component rendering times OR all component state types. Depends on 2nd arg
5465
const traverse = (snapshot, data = {}) => {
5566
if (!snapshot.children[0]) return
5667
for (let i = 0; i < snapshot.children.length; i++){
5768
const componentName = snapshot.children[i].name+-[i+1]
69+
// Get component Type
5870
if (!data.snapshotId){
5971
if(snapshot.children[i].state !== 'stateless') data[componentName] = 'STATEFUL'
6072
else data[componentName] = snapshot.children[i].state;
6173
}
74+
// Get component Rendering Time
6275
else if (snapshot.children[i].componentData.actualDuration){
6376
const renderTime = Number(Number.parseFloat(snapshot.children[i].componentData.actualDuration).toPrecision(5));
6477
data[componentName] = renderTime;
@@ -127,7 +140,7 @@ const getSnapshotId = (d: snapshot) => d.snapshotId;
127140
const formatSnapshotId = id => 'Snapshot ID: ' + id;
128141
const formatRenderTime = time => time + ' ms ';
129142

130-
// create visualization SCALES with filtered data
143+
// create visualization SCALES with cleaned data
131144
const snapshotIdScale = scaleBand<string>({
132145
domain: data.map(getSnapshotId),
133146
padding: 0.2
@@ -143,7 +156,7 @@ const colorScale = scaleOrdinal<CityName, string>({
143156
range: schemeSet3
144157
});
145158

146-
const { containerRef, TooltipInPortal } = useTooltipInPortal();
159+
const { containerRef, TooltipInPortal } = useTooltipInPortal();
147160

148161
// setting max dimensions and scale ranges
149162
if (width < 10) return null;
@@ -200,7 +213,6 @@ console.log('height', height)
200213
width={bar.width}
201214
fill={bar.color}
202215
/* TIP TOOL EVENT HANDLERS */
203-
204216
// Hides tool tip once cursor moves off the current rect
205217
onMouseLeave={() => {
206218
tooltipTimeout = window.setTimeout(() => {
@@ -285,18 +297,11 @@ console.log('height', height)
285297
left={tooltipLeft}
286298
style={tooltipStyles}
287299
>
288-
<div style={{ color: colorScale(tooltipData.key) }}>
289-
<strong>{tooltipData.key}</strong>
290-
</div>
291-
300+
// Displays: component name, component state type, render time, snapshotID
301+
<div style={{ color: colorScale(tooltipData.key) }}> <strong>{tooltipData.key}</strong> </div>
292302
<div>{allComponentStates[tooltipData.key]}</div>
293-
294-
<div>
295-
{formatRenderTime(tooltipData.bar.data[tooltipData.key])}
296-
</div>
297-
<div>
298-
<small>{formatSnapshotId(getSnapshotId(tooltipData.bar.data))}</small>
299-
</div>
303+
<div> {formatRenderTime(tooltipData.bar.data[tooltipData.key])} </div>
304+
<div> <small>{formatSnapshotId(getSnapshotId(tooltipData.bar.data))}</small></div>
300305
</TooltipInPortal>
301306
)}
302307
</div>

0 commit comments

Comments
 (0)