Skip to content

Commit cdb5f88

Browse files
authored
Merge pull request #19 from C-STYR/cole-feature
Implemented radial graph functionality in WebMetrics Tab
2 parents dfdc1bc + b67a75a commit cdb5f88

File tree

9 files changed

+236
-8
lines changed

9 files changed

+236
-8
lines changed

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"jest-diff": "^26.1.0",
100100
"jest-puppeteer": "^4.4.0",
101101
"jest-runner-eslint": "^0.7.7",
102+
"jscharting-react": "^1.2.1",
102103
"puppeteer": "^5.1.0",
103104
"sass": "^1.26.10",
104105
"sass-loader": "^7.3.1",
@@ -138,25 +139,29 @@
138139
"@visx/zoom": "^1.0.0",
139140
"acorn": "^7.3.1",
140141
"acorn-jsx": "^5.2.0",
142+
"apexcharts": "^3.23.1",
141143
"cookie": "^0.4.1",
142144
"d3": "^5.16.0",
143145
"d3-scale-chromatic": "^2.0.0",
144146
"d3-shape": "^2.0.0",
145147
"d3-zoom": "^1.8.3",
146148
"immer": "^3.3.0",
147149
"jest-runner": "^26.1.0",
150+
"jscharting": "^3.0.2",
148151
"jsondiffpatch": "^0.3.11",
149152
"mixpanel": "^0.11.0",
150153
"mixpanel-browser": "^2.39.0",
151154
"prop-types": "^15.7.2",
152155
"rc-slider": "^8.7.1",
153156
"rc-tooltip": "^3.7.3",
154157
"react": "^16.13.1",
158+
"react-apexcharts": "^1.3.7",
155159
"react-dom": "^16.13.1",
156160
"react-html-parser": "^2.0.2",
157161
"react-json-tree": "^0.11.2",
158162
"react-router-dom": "^5.2.0",
159163
"react-select": "^3.1.0",
160-
"recoil": "0.0.10"
164+
"recoil": "0.0.10",
165+
"web-vitals": "^1.1.0"
161166
}
162167
}

src/app/components/StateRoute.tsx

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { useStoreContext } from '../store';
2020
import PerformanceVisx from './PerformanceVisx';
2121
import Legend from './AtomsRelationshipLegend';
2222
import AtomsRelationship from './AtomsRelationship';
23+
import WebMetrics from './WebMetrics';
24+
2325

2426
const History = require('./History').default;
2527
const ErrorHandler = require('./ErrorHandler').default;
@@ -37,14 +39,16 @@ export interface StateRouteProps {
3739
children?: any[];
3840
atomsComponents?: any;
3941
atomSelectors?: any;
42+
4043
};
4144
hierarchy: any;
4245
snapshots: [];
4346
viewIndex: number;
47+
webMetrics: object;
4448
}
4549

4650
const StateRoute = (props: StateRouteProps) => {
47-
const { snapshot, hierarchy, snapshots, viewIndex } = props;
51+
const { snapshot, hierarchy, snapshots, viewIndex, webMetrics } = props;
4852
const [{ tabs, currentTab }, dispatch] = useStoreContext();
4953
const { hierarchy, sliderIndex, viewIndex } = tabs[currentTab];
5054
const isRecoil = snapshot.atomsComponents ? true : false;
@@ -111,6 +115,37 @@ const StateRoute = (props: StateRouteProps) => {
111115
return <Tree snapshot={snapshot} />;
112116
}
113117
return <div className="noState">{NO_STATE_MSG}</div>;
118+
119+
};
120+
const renderWebMetrics = () => {
121+
let LCPColor, FIDColor, CLSColor, FCPColor, TTFBColor;
122+
123+
if (webMetrics.LCP <= 2000) LCPColor = "#0bce6b";
124+
if (webMetrics.LCP > 2000 && webMetrics.LCP < 4000) LCPColor = "#E56543";
125+
if (webMetrics.LCP > 4000 ) LCPColor = "#fc2000";
126+
if (webMetrics.FID <= 100) FIDColor = "#0bce6b";
127+
if (webMetrics.FID > 100 && webMetrics.FID <= 300 ) FIDColor = "#fc5a03";
128+
if (webMetrics.FID > 300 ) FIDColor = "#fc2000";
129+
if (webMetrics.CLS <= 0.1) FIDColor = "#0bce6b";
130+
if (webMetrics.CLS > 0.1 && webMetrics.CLS <= 0.25 ) CLSColor = "#fc5a03";
131+
if (webMetrics.CLS > 0.25 ) CLSColor = "#fc2000";
132+
if (webMetrics.FCP <= 9000) FCPColor = "#0bce6b";
133+
if (webMetrics.FCP > 900 && webMetrics.FCP <= 1100 ) FCPColor = "#fc5a03";
134+
if (webMetrics.FCP > 1100 ) FCPColor = "#fc2000";
135+
if (webMetrics.TTFB <= 600) TTFBColor = "#0bce6b";
136+
if (webMetrics.TTFB > 600 ) TTFBColor = "#fc2000";
137+
138+
139+
140+
return (
141+
<div className="web-metrics-container">
142+
<WebMetrics color={LCPColor} series={(webMetrics.LCP / 2500) * 100} formatted={(val) => ((val / 100) * 2500).toFixed(2) + ' ms'} label="LCP"/>
143+
<WebMetrics color={FIDColor} series={(webMetrics.FID) * 25} formatted={(val) => ((val / 25)).toFixed(2) + ' ms'} label="FID"/>
144+
{/* <WebMetrics color={CLSColor} series={(webMetrics.CLS * 50) * 100} formatted={(val) => ((val / 100) / 50).toFixed(2)} label="CLS"/> */}
145+
<WebMetrics color={FCPColor} series={(webMetrics.FCP / 1000) * 100} formatted={(val) => ((val / 100) * 1000).toFixed(2) + ' ms'} label="FCP"/>
146+
<WebMetrics color={TTFBColor} series={(webMetrics.TTFB / 10) * 100} formatted={(val) => ((val / 100) * 10).toFixed(2) + ' ms'} label="TTFB"/>
147+
</div>
148+
)
114149
};
115150

116151
const renderPerfView = () => {
@@ -155,6 +190,13 @@ const StateRoute = (props: StateRouteProps) => {
155190
>
156191
History
157192
</NavLink>
193+
<NavLink
194+
className="router-link"
195+
activeClassName="is-active"
196+
to="/webMetrics"
197+
>
198+
Web Metrics
199+
</NavLink>
158200
<NavLink
159201
className="router-link"
160202
activeClassName="is-active"
@@ -176,6 +218,7 @@ const StateRoute = (props: StateRouteProps) => {
176218
<Route path="/performance" render={renderPerfView} />
177219
<Route path="/history" render={renderHistory} />
178220
<Route path="/relationship" render={renderAtomsRelationship} />
221+
<Route path="/webMetrics" render={renderWebMetrics} />
179222
<Route path="/tree" render={renderTree} />
180223
<Route path="/" render={renderComponentMap} />
181224
</Switch>

src/app/components/WebMetrics.tsx

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import React, { useState, useEffect, Component } from 'react';
2+
import Charts from 'react-apexcharts';
3+
import useForceUpdate from './useForceUpdate';
4+
5+
const radialGraph = (props) => {
6+
7+
const state = {
8+
9+
series: [props.series],
10+
options: {
11+
colors: [props.color],
12+
chart: {
13+
height: 100,
14+
width: 100,
15+
type: 'radialBar',
16+
toolbar: {
17+
show: false,
18+
}
19+
},
20+
plotOptions: {
21+
radialBar: {
22+
startAngle: -135,
23+
endAngle: 135,
24+
hollow: {
25+
margin: 0,
26+
size: '75%',
27+
background: '#242529',
28+
image: undefined,
29+
imageOffsetX: 0,
30+
imageOffsetY: 0,
31+
position: 'front',
32+
dropShadow: {
33+
enabled: false,
34+
top: 3,
35+
left: 0,
36+
blur: 4,
37+
opacity: 0.24
38+
}
39+
},
40+
track: {
41+
background: '#fff',
42+
strokeWidth: '3%',
43+
margin: 0, // margin is in pixels
44+
dropShadow: {
45+
enabled: true,
46+
top: -3,
47+
left: 0,
48+
blur: 4,
49+
opacity: 0.35
50+
}
51+
},
52+
53+
dataLabels: {
54+
show: true,
55+
name: {
56+
offsetY: -10,
57+
show: true,
58+
color: '#fff',
59+
fontSize: '24px'
60+
},
61+
value: {
62+
formatter: props.formatted,
63+
color: '#fff',
64+
fontSize: '16px',
65+
show: true,
66+
}
67+
}
68+
}
69+
},
70+
fill: {
71+
type: 'solid',
72+
gradient: {
73+
shade: 'dark',
74+
type: 'horizontal',
75+
shadeIntensity: 0.1,
76+
gradientToColors: [props.color],
77+
inverseColors: false,
78+
opacityFrom: 1,
79+
opacityTo: 1,
80+
stops: [0, 100]
81+
}
82+
},
83+
stroke: {
84+
lineCap: 'flat'
85+
},
86+
labels: [props.label],
87+
},
88+
};
89+
90+
91+
return (
92+
93+
94+
<div id="card">
95+
<div id="chart">
96+
<Charts options={state.options} series={state.series} type="radialBar" height={250} width={250}/>
97+
</div>
98+
</div>
99+
100+
)
101+
}
102+
103+
104+
export default radialGraph;

src/app/containers/ActionContainer.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,13 @@ function ActionContainer(props) {
115115
);
116116

117117
if (!timeTravel) {
118-
console.log("should be false:", timeTravel)
119118
return (
120119
//returns an empty div when timeTravel is false
121120

122121
<div></div>
123122
)
124123
}
125124
else {
126-
console.log("Should be true:", timeTravel);
127125
// this is not logging; the prop is not being udpdated or the component is not being re-rendered.
128126
return (
129127
<div className="action-container">

src/app/containers/MainContainer.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,11 @@ function MainContainer(): any {
151151
</div>
152152
);
153153
}
154-
const { viewIndex, sliderIndex, snapshots, hierarchy } = tabs[currentTab];
154+
const { viewIndex, sliderIndex, snapshots, hierarchy, webMetrics } = tabs[currentTab];
155155
// if viewIndex is -1, then use the sliderIndex instead
156+
console.log('webMetrics in MainContainer >>>', webMetrics);
157+
158+
156159
const snapshotView =
157160
viewIndex === -1 ? snapshots[sliderIndex] : snapshots[viewIndex];
158161
// cleaning hierarchy and snapshotView from stateless data
@@ -222,6 +225,7 @@ function MainContainer(): any {
222225
{snapshots.length ? (
223226
<StateContainer
224227
toggleActionContainer={toggleActionContainer}
228+
webMetrics={webMetrics}
225229
viewIndex={viewIndex}
226230
snapshot={snapshotDisplay}
227231
hierarchy={hierarchyDisplay}

src/app/containers/StateContainer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface StateContainerProps {
2424
}
2525
>;
2626
toggleActionContainer?: any;
27+
webMetrics: object;
2728
AtomsRelationship?: any[];
2829
hierarchy: Record<string, unknown>;
2930
snapshots: [];
@@ -33,7 +34,7 @@ interface StateContainerProps {
3334

3435
// eslint-disable-next-line react/prop-types
3536
const StateContainer = (props: StateContainerProps): JSX.Element => {
36-
const { snapshot, hierarchy, snapshots, viewIndex, toggleActionContainer } = props;
37+
const { snapshot, hierarchy, snapshots, viewIndex, toggleActionContainer, webMetrics } = props;
3738
const [Text, setText] = useState('State');
3839

3940
return (
@@ -74,6 +75,7 @@ const StateContainer = (props: StateContainerProps): JSX.Element => {
7475
setText('State');
7576
return (
7677
<StateRoute
78+
webMetrics={webMetrics}
7779
viewIndex={viewIndex}
7880
snapshot={snapshot}
7981
hierarchy={hierarchy}

src/app/styles/layout/_stateContainer.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,17 @@
194194
.router-link-performance.is-active {
195195
font-weight: 600;
196196
}
197+
198+
// Web Metrics Container
199+
.web-metrics-container {
200+
201+
// padding: 3rem;
202+
// display: grid;
203+
display: flex;
204+
align-items: center;
205+
justify-content: center;
206+
flex-wrap: wrap;
207+
margin-top: 3rem;
208+
// grid-template-columns: repeat(2, 1fr);
209+
// grid-template-rows: repeat(2, 1fr);
210+
}

0 commit comments

Comments
 (0)