Skip to content

Commit 3607fe6

Browse files
committed
Merge branch 'master' into feature4
2 parents 98c5a49 + c864bf1 commit 3607fe6

File tree

11 files changed

+9870
-71
lines changed

11 files changed

+9870
-71
lines changed

.gitmodules

Whitespace-only changes.

src/app/components/PerfView.tsx

Lines changed: 22 additions & 19 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,14 +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
32+
const { snapshots, viewIndex, width, height, setNoRenderData } = props;
33+
const adjustedSize = Math.min(width, height);
3434
const svgRef = useRef(null);
3535

3636
// Figure out which snapshot index to use
@@ -41,19 +41,22 @@ const PerfView = (props:PerfViewProps) => {
4141
// Set up color scaling function
4242
const colorScale = d3.scaleLinear()
4343
.domain([0, 7])
44-
.range(['hsl(200,60%,60%)', 'hsl(255,30%,30%)'])
45-
// .range(['hsl(152,30%,80%)', 'hsl(228,30%,40%)'])
44+
.range(['hsl(200,60%,60%)', 'hsl(255,30%,40%)'])
4645
.interpolate(d3.interpolateHcl);
4746

4847
// Set up circle-packing layout function
4948
const packFunc = useCallback((data:object) => {
5049
return d3.pack()
51-
.size([width, height])
50+
.size([adjustedSize, adjustedSize])
5251
// .radius(d => { return d.r; })
5352
.padding(3)(d3.hierarchy(data)
5453
.sum((d:{componentData?:{actualDuration?:number}}) => { return d.componentData.actualDuration || 0; })
5554
.sort((a:{value:number}, b:{value:number}) => { return b.value - a.value; }));
56-
}, [width, height]);
55+
}, [adjustedSize]);
56+
57+
function handleNoRenderData(isNoRenderData) {
58+
setNoRenderData(isNoRenderData);
59+
}
5760

5861
// If indexToDisplay changes, clear old tree nodes
5962
useEffect(() => {
@@ -70,17 +73,17 @@ 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
84+
// Set up viewBox dimensions and onClick for parent svg
8285
const svg = d3.select(svgRef.current)
83-
.attr('viewBox', `-${width / 2} -${height / 2} ${width} ${height}`)
86+
.attr('viewBox', `-${adjustedSize / 2} -${adjustedSize / 2} ${width} ${height}`)
8487
.on('click', () => zoomToNode(packedRoot));
8588

8689
// Connect circles below root to data
@@ -102,8 +105,12 @@ const PerfView = (props:PerfViewProps) => {
102105
.enter().append('text')
103106
.style('fill-opacity', (d:{parent:object}) => (d.parent === packedRoot ? 1 : 0))
104107
.style('display', (d:{parent?:object}) => (d.parent === packedRoot ? 'inline' : 'none'))
105-
.text((d:{data:{name:string, componentData?:{actualDuration:any}}}) => {
106-
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+
});
107114

108115
// Remove any unused nodes
109116
label.exit().remove();
@@ -150,8 +157,4 @@ const PerfView = (props:PerfViewProps) => {
150157
);
151158
};
152159

153-
export default PerfView;
154-
155-
156-
// d3.quantize(d3.interpolateHcl('#60c96e', '#4d4193'), 10);
157-
// 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={600}/>
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: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import React from 'react';
22
import JSONTree from 'react-json-tree';
33

4-
54
const getItemString = (type, data:{state?:object|string, name:string, children:[]}) => {
6-
// check to make sure that we are on the tree node, not anything else
7-
if (
8-
Object.keys(data).length > 3
9-
&& typeof data.state === 'object'
10-
&& typeof data.name === 'string'
11-
&& Array.isArray(data.children)
12-
) {
5+
if (data && data.name) {
136
return <span>{data.name}</span>;
147
}
15-
return null;
8+
return <span />;
169
};
1710

1811
interface TreeProps {
@@ -21,6 +14,7 @@ interface TreeProps {
2114

2215
const Tree = (props:TreeProps) => {
2316
const { snapshot } = props;
17+
// console.log('Tree -> snapshot', snapshot);
2418

2519
return (
2620
<>
@@ -30,7 +24,9 @@ const Tree = (props:TreeProps) => {
3024
theme={{ tree: () => ({ className: 'json-tree' }) }}
3125
shouldExpandNode={() => true}
3226
getItemString={getItemString}
33-
labelRenderer={(raw:any[]) => (typeof raw[0] !== 'number' ? <span>{raw[0]}</span> : null)}
27+
labelRenderer={(raw:any[]) => {
28+
return (typeof raw[0] !== 'number' ? <span>{raw[0]}</span> : null)
29+
}}
3430
/>
3531
)}
3632
</>

src/app/styles/components/d3graph.css

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ div.tooltip {
5454
max-width: 250px;
5555
overflow-wrap: break-word;
5656
padding: 6px;
57-
color: #1a2229;
57+
color: #320a5c;
5858
font-size: 12px;
5959
font-family: "Overpass Mono", monospace;
60-
background: #6699C4;
60+
background: #9cf4df;
6161
border-radius: 8px;
6262
pointer-events: none;
6363
}
6464

6565
.d3-tip {
6666
line-height: 1;
6767
padding: 6px;
68-
background: #6699C4;
69-
color: #1a2229;
68+
background: #9cf4df;
69+
color: #320a5c;
7070
border-radius: 4px;
7171
font-size: 13px;
7272
max-width: 400px;
@@ -80,7 +80,7 @@ div.tooltip {
8080
display: inline;
8181
font-size: 15px;
8282
line-height: 1;
83-
color: #6699C4;
83+
color: #9cf4df;
8484
content: "\25BC";
8585
position: absolute;
8686
text-align: center;
@@ -102,9 +102,9 @@ div.tooltip {
102102
}
103103

104104
.perf-d3-container {
105-
display: flex;
106-
flex-direction: column;
107-
justify-content: space-between;
105+
/* display: flex; */
106+
/* flex-direction: column; */
107+
/* justify-content: space-between; */
108108
height: calc(100% - 70px);
109109
/* border: 2px solid red; */
110110
}
@@ -115,10 +115,11 @@ div.tooltip {
115115

116116
.perf-chart-labels {
117117
font: 1.3em sans-serif;
118+
font-weight: bold;
118119
/* font-size: calc(12px + .8vw); */
119120
/* color: white; */
120121
/* fill: rgb(231, 231, 231); */
121122
fill: #2a2f3a;
122123
pointer-events: none;
123124
text-anchor: middle;
124-
};
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;

src/backend/reactWorkTags.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/extension/contentScript.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// import 'core-js';
2+
// const reactimeBackend = require('../../dev-reactime/index.js');
3+
4+
let firstMessage: boolean = true;
5+
6+
// listening for messages from npm package
7+
window.addEventListener('message', msg => { // runs automatically every second
8+
// window listener picks up the message it sends, so we should filter
9+
// messages sent by contentscrip
10+
if (firstMessage) {
11+
// tell the background script that the tab has reloaded
12+
chrome.runtime.sendMessage({ action: 'tabReload' });
13+
firstMessage = false;
14+
}
15+
16+
// post initial Message to background.js
17+
const { action }: { action: string } = msg.data;
18+
19+
if (action === 'recordSnap') { // this is firing on page load
20+
chrome.runtime.sendMessage(msg.data);
21+
}
22+
});
23+
24+
// listening for messages from the UI
25+
chrome.runtime.onMessage.addListener(request => { // seems to never fire
26+
// send the message to npm package
27+
const { action }: { action: string } = request;
28+
switch (action) {
29+
case 'jumpToSnap':
30+
chrome.runtime.sendMessage(request);
31+
window.postMessage(request, '*');
32+
break;
33+
case 'setLock':
34+
case 'setPause':
35+
window.postMessage(request, '*');
36+
break;
37+
default:
38+
break;
39+
}
40+
return true; // attempt to fix port closing console error
41+
});
42+
43+
chrome.runtime.sendMessage({ action: 'injectScript' });

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const config = {
1010
// app: './src/app/index.js',
1111
app: './src/app/index.tsx',
1212
background: './src/extension/background.js',
13-
content: './src/extension/contentScript.js',
13+
content: './src/extension/contentScript.ts',
1414
backend: './src/backend/index.ts',
1515
},
1616
output: {

0 commit comments

Comments
 (0)