Skip to content

Commit 4d10ba4

Browse files
authored
Merge pull request #93 from oslabs-beta/staging
Staging
2 parents f5cc313 + 2e41fdd commit 4d10ba4

File tree

5 files changed

+67
-44
lines changed

5 files changed

+67
-44
lines changed

src/app/components/PerfView.tsx

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
/* eslint-disable no-plusplus */
77
/* eslint-disable func-names */
88
/* eslint-disable no-shadow */
9-
/* eslint-disable no-multi-spaces */
109
/* eslint-disable newline-per-chained-call */
1110
/* eslint-disable object-curly-newline */
1211
/* eslint-disable object-property-newline */
1312
/* eslint-disable class-methods-use-this */
1413
// eslint-disable-next-line object-curly-newline
15-
/* eslint-disable comma-dangle */
1614
/* eslint-disable indent */
1715
/* eslint-disable no-console */
1816

@@ -23,15 +21,16 @@ import { schemeSet1 as colorScheme } from 'd3';
2321
// import { addNewSnapshots } from '../actions/actions.ts';
2422

2523
interface PerfViewProps {
26-
snapshots:any[];
27-
viewIndex:number;
24+
snapshots:any[];
25+
viewIndex:number;
2826
width: number;
2927
height: number;
28+
setNoRenderData: any;
3029
}
3130

3231
const PerfView = (props:PerfViewProps) => {
33-
const { snapshots, viewIndex, width, height } = props
34-
let adjustedSize = Math.min(width, height);
32+
const { snapshots, viewIndex, width, height, setNoRenderData } = props;
33+
const adjustedSize = Math.min(width, height);
3534
const svgRef = useRef(null);
3635

3736
// Figure out which snapshot index to use
@@ -42,7 +41,7 @@ const PerfView = (props:PerfViewProps) => {
4241
// Set up color scaling function
4342
const colorScale = d3.scaleLinear()
4443
.domain([0, 7])
45-
.range(['hsl(200,60%,60%)', 'hsl(255,30%,60%)'])
44+
.range(['hsl(200,60%,60%)', 'hsl(255,30%,40%)'])
4645
.interpolate(d3.interpolateHcl);
4746

4847
// Set up circle-packing layout function
@@ -55,6 +54,10 @@ const PerfView = (props:PerfViewProps) => {
5554
.sort((a:{value:number}, b:{value:number}) => { return b.value - a.value; }));
5655
}, [adjustedSize]);
5756

57+
function handleNoRenderData(isNoRenderData) {
58+
setNoRenderData(isNoRenderData);
59+
}
60+
5861
// If indexToDisplay changes, clear old tree nodes
5962
useEffect(() => {
6063
while (svgRef.current.hasChildNodes()) {
@@ -70,19 +73,15 @@ const PerfView = (props:PerfViewProps) => {
7073

7174
// Generate tree with our data
7275
const packedRoot = packFunc(snapshots[indexToDisplay]);
73-
console.log('PerfView -> packedRoot', packedRoot);
76+
// console.log('PerfView -> packedRoot', packedRoot);
7477

7578
// Set initial focus to root node
7679
let curFocus = packedRoot;
7780

7881
// View [x, y, r]
7982
let view;
8083

81-
// Set up viewBox dimensions and onClick for parent svg
82-
83-
// console.log("PerfView -> height", height)
84-
// console.log("PerfView -> width", width)
85-
// console.log("PerfView -> adjustedSize", adjustedSize)
84+
// Set up viewBox dimensions and onClick for parent svg
8685
const svg = d3.select(svgRef.current)
8786
.attr('viewBox', `-${adjustedSize / 2} -${adjustedSize / 2} ${width} ${height}`)
8887
.on('click', () => zoomToNode(packedRoot));
@@ -106,8 +105,12 @@ const PerfView = (props:PerfViewProps) => {
106105
.enter().append('text')
107106
.style('fill-opacity', (d:{parent:object}) => (d.parent === packedRoot ? 1 : 0))
108107
.style('display', (d:{parent?:object}) => (d.parent === packedRoot ? 'inline' : 'none'))
109-
.text((d:{data:{name:string, componentData?:{actualDuration:any}}}) => {
110-
return `${d.data.name}: ${Number.parseFloat(d.data.componentData.actualDuration || 0).toFixed(2)}ms`});
108+
.text((d:{data:{name:string, componentData?:{actualDuration:any}}}) => {
109+
// console.log("PerfView -> d.data", d.data);
110+
if (!d.data.componentData.actualDuration) handleNoRenderData(true);
111+
else handleNoRenderData(false);
112+
return `${d.data.name}: ${Number.parseFloat(d.data.componentData.actualDuration || 0).toFixed(2)}ms`;
113+
});
111114

112115
// Remove any unused nodes
113116
label.exit().remove();
@@ -154,8 +157,4 @@ const PerfView = (props:PerfViewProps) => {
154157
);
155158
};
156159

157-
export default PerfView;
158-
159-
160-
// d3.quantize(d3.interpolateHcl('#60c96e', '#4d4193'), 10);
161-
// const colorScale = d3.scaleOrdinal(colorScheme);
160+
export default PerfView;

src/app/components/StateRoute.tsx

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1+
/* eslint-disable @typescript-eslint/no-unused-vars */
2+
/* eslint-disable react/jsx-first-prop-new-line */
3+
/* eslint-disable no-trailing-spaces */
4+
/* eslint-disable react/jsx-indent-props */
5+
/* eslint-disable react/jsx-one-expression-per-line */
16
/* eslint-disable max-len */
27
/* eslint-disable object-curly-newline */
3-
import React from 'react';
8+
import React, { useState } from 'react';
49
import { MemoryRouter as Router, Route, NavLink, Switch } from 'react-router-dom';
5-
6-
7-
const Chart = require('./Chart').default;
810
import Tree from './Tree';
911
import PerfView from './PerfView';
12+
import { spawn } from 'child_process';
13+
14+
const Chart = require('./Chart').default;
1015
const ErrorHandler = require('./ErrorHandler').default;
1116

1217
const NO_STATE_MSG = 'No state change detected. Trigger an event to change state';
1318
// eslint-disable-next-line react/prop-types
1419

15-
1620
interface StateRouteProps {
17-
snapshot: { name?: string; componentData?: object; state?: string | object; stateSnaphot?: object; children?: any[]; };
18-
hierarchy: object;
19-
snapshots: [];
21+
snapshot: { name?: string; componentData?: object; state?: string | object; stateSnaphot?: object; children?: any[]; };
22+
hierarchy: object;
23+
snapshots: [];
2024
viewIndex: number;
2125
}
2226

2327
const StateRoute = (props:StateRouteProps) => {
24-
const { snapshot, hierarchy, snapshots, viewIndex } = props
28+
const { snapshot, hierarchy, snapshots, viewIndex } = props;
29+
const [noRenderData, setNoRenderData] = useState(false);
30+
2531
// gabi :: the hierarchy get set on the first click in the page, when page in refreshed we don't have a hierarchy so we need to check if hierarchy was initialize involk render chart
2632
const renderChart = () => {
2733
if (hierarchy) {
@@ -38,28 +44,39 @@ const StateRoute = (props:StateRouteProps) => {
3844
return <div className="noState">{NO_STATE_MSG}</div>;
3945
};
4046

47+
let perfChart;
48+
if (!noRenderData) {
49+
perfChart = (
50+
<PerfView viewIndex={viewIndex}
51+
snapshots={snapshots}
52+
setNoRenderData={setNoRenderData}
53+
width={600}
54+
height={1000}
55+
/>
56+
);
57+
} else {
58+
perfChart = <div className="no-data-message">Rendering Data is not available for this application</div>;
59+
}
60+
4161
const renderPerfView = () => {
42-
if (hierarchy) {
43-
return (
44-
<ErrorHandler>
45-
<PerfView viewIndex={viewIndex} snapshots={snapshots} width={600} height={1000}/>
46-
</ErrorHandler>
47-
);
48-
}
49-
return <div className="noState">{NO_STATE_MSG}</div>;
62+
return (
63+
<ErrorHandler>
64+
{perfChart}
65+
</ErrorHandler>
66+
);
5067
};
5168

5269
return (
5370
<Router>
5471
<div className="navbar">
5572
<NavLink className="router-link" activeClassName="is-active" exact to="/">
56-
Tree
73+
Tree
5774
</NavLink>
5875
<NavLink className="router-link" activeClassName="is-active" to="/chart">
59-
History
76+
History
6077
</NavLink>
6178
<NavLink className="router-link" activeClassName="is-active" to="/performance">
62-
Performance
79+
Performance
6380
</NavLink>
6481
</div>
6582
<Switch>
@@ -71,4 +88,4 @@ const StateRoute = (props:StateRouteProps) => {
7188
);
7289
};
7390

74-
export default StateRoute;
91+
export default StateRoute;

src/app/components/Tree.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ interface TreeProps {
1414

1515
const Tree = (props:TreeProps) => {
1616
const { snapshot } = props;
17-
18-
console.log('Tree -> snapshot', snapshot);
17+
// console.log('Tree -> snapshot', snapshot);
1918

2019
return (
2120
<>

src/app/styles/components/d3graph.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,4 @@ div.tooltip {
122122
fill: #2a2f3a;
123123
pointer-events: none;
124124
text-anchor: middle;
125-
};
125+
};

src/app/styles/layout/_stateContainer.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
@extend %disable-highlight
4141
}
4242

43+
44+
.no-data-message {
45+
font: 1.2em sans-serif;
46+
padding: 10px;
47+
// margin: 10px;
48+
color: hsl(0%, 50%, 50%);
49+
}
50+
4351
.state-container {
4452
.main-navbar-text {
4553
margin: 6px;

0 commit comments

Comments
 (0)