Skip to content

Commit 621c7d5

Browse files
committed
added simple data verification for actualDuration inside d3
1 parent 9213d03 commit 621c7d5

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/app/components/ErrorHandler.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ErrorHandler extends React.Component {
1212
}
1313

1414
render() {
15-
return this.state.errorOccurred ? <h1>Something went wrong!</h1> : this.props.children
15+
return this.state.errorOccurred ? <h1>An error occurred</h1> : this.props.children
1616
}
1717
}
1818

src/app/components/PerfView.jsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { schemeSet1 as colorScheme } from 'd3';
2424

2525

2626
const PerfView = ({ snapshots, viewIndex, width = 600, height = 600 }) => {
27-
console.log('***** constructor *****');
27+
// console.log('***** constructor *****');
2828
const svgRef = useRef(null);
2929

3030
// Figure out which snapshot index to use
@@ -43,25 +43,28 @@ const PerfView = ({ snapshots, viewIndex, width = 600, height = 600 }) => {
4343
return d3.pack()
4444
.size([width, height])
4545
.padding(3)(d3.hierarchy(data)
46-
.sum(d => { return d.componentData.actualDuration; })
46+
.sum(d => { return d.componentData.actualDuration || 0; })
4747
.sort((a, b) => { return b.value - a.value; }));
4848
}, [width, height]);
4949

5050
// If indexToDisplay changes, clear old tree nodes
5151
useEffect(() => {
52-
console.log('***** useEffect - CLEARING');
52+
// console.log('***** useEffect - CLEARING');
5353
while (svgRef.current.hasChildNodes()) {
5454
svgRef.current.removeChild(svgRef.current.lastChild);
5555
}
5656
}, [indexToDisplay, svgRef]);
5757

5858
useEffect(() => {
59-
console.log(`***** useEffect - MAIN -> snapshots[${indexToDisplay}]`, snapshots[indexToDisplay]);
59+
// console.log(`***** useEffect - MAIN -> snapshots[${indexToDisplay}]`, snapshots[indexToDisplay]);
60+
61+
// Error, no App-level component present
62+
if (snapshots[indexToDisplay].children.length < 1) return;
6063

6164
// Generate tree with our data
6265
const packedRoot = packFunc(snapshots[indexToDisplay]);
6366

64-
// Set initial focus root node
67+
// Set initial focus to root node
6568
let curFocus = packedRoot;
6669

6770
// View [x, y, r]
@@ -93,7 +96,7 @@ const PerfView = ({ snapshots, viewIndex, width = 600, height = 600 }) => {
9396
.style('fill-opacity', d => (d.parent === packedRoot ? 1 : 0))
9497
.style('display', d => (d.parent === packedRoot ? 'inline' : 'none'))
9598
.text(d => `${d.data.name}: \
96-
${Number.parseFloat(d.data.componentData.actualDuration).toFixed(2)}ms`);
99+
${Number.parseFloat(d.data.componentData.actualDuration || 0).toFixed(2)}ms`);
97100

98101
// Remove any unused nodes
99102
label.exit().remove();
@@ -115,7 +118,6 @@ const PerfView = ({ snapshots, viewIndex, width = 600, height = 600 }) => {
115118
// Transition visibility of labels
116119
function zoomToNode(newFocus) {
117120
// console.log("zoom -> d", d);
118-
119121
const transition = svg.transition()
120122
.duration(d3.event.altKey ? 7500 : 750)
121123
.tween('zoom', d => {

0 commit comments

Comments
 (0)