Skip to content

Commit d3a766e

Browse files
committed
fix displaying NaN when there is no metric data
1 parent 2fc9b4b commit d3a766e

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/app/components/StateRoute.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const StateRoute = (props: StateRouteProps) => {
116116
return <div className='noState'>{NO_STATE_MSG}</div>;
117117
};
118118
const renderWebMetrics = () => {
119-
let LCPColor, FIDColor, CLSColor, FCPColor, TTFBColor;
119+
let LCPColor, FIDColor, FCPColor, TTFBColor;
120120

121121
if (webMetrics.LCP <= 2000) LCPColor = "#0bce6b";
122122
if (webMetrics.LCP > 2000 && webMetrics.LCP < 4000) LCPColor = "#E56543";
@@ -125,8 +125,7 @@ const StateRoute = (props: StateRouteProps) => {
125125
if (webMetrics.FID > 100 && webMetrics.FID <= 300 ) FIDColor = "#fc5a03";
126126
if (webMetrics.FID > 300 ) FIDColor = "#fc2000";
127127
if (webMetrics.CLS <= 0.1) FIDColor = "#0bce6b";
128-
if (webMetrics.CLS > 0.1 && webMetrics.CLS <= 0.25 ) CLSColor = "#fc5a03";
129-
if (webMetrics.CLS > 0.25 ) CLSColor = "#fc2000";
128+
130129
if (webMetrics.FCP <= 9000) FCPColor = "#0bce6b";
131130
if (webMetrics.FCP > 900 && webMetrics.FCP <= 1100 ) FCPColor = "#fc5a03";
132131
if (webMetrics.FCP > 1100 ) FCPColor = "#fc2000";
@@ -138,10 +137,10 @@ const StateRoute = (props: StateRouteProps) => {
138137
return (
139138
<div className="web-metrics-container">
140139
<WebMetrics color={LCPColor} series={(webMetrics.LCP / 2500) * 100}
141-
formatted={(val) => { return (Number.isNaN(val)) ? '-- ms' : (((val / 100) * 2500).toFixed(2) + ' ms')}}
140+
formatted={(val) => { return (Number.isNaN(val)) ? '- ms' : (((val / 100) * 2500).toFixed(2) + ' ms')}}
142141
label="LCP" />
143142
<WebMetrics color={FIDColor} series={(webMetrics.FID) * 25}
144-
formatted={(val) => { return (Number.isNaN(val)) ? '-- ms' : ((val / 25).toFixed(2) + ' ms')}}
143+
formatted={(val) => { return (Number.isNaN(val)) ? '- ms' : ((val / 25).toFixed(2) + ' ms')}}
145144
label="FID" />
146145
<WebMetrics color={FCPColor} series={(webMetrics.FCP / 1000) * 100} formatted={(val) => ((val / 100) * 1000).toFixed(2) + ' ms'} label="FCP"/>
147146
<WebMetrics color={TTFBColor} series={(webMetrics.TTFB / 10) * 100} formatted={(val) => ((val / 100) * 10).toFixed(2) + ' ms'} label="TTFB"/>

src/app/components/WebMetrics.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useState, useEffect, Component } from 'react';
22
import Charts from 'react-apexcharts';
3-
import useForceUpdate from './useForceUpdate';
43

54
const radialGraph = (props) => {
65

@@ -88,16 +87,13 @@ const radialGraph = (props) => {
8887
};
8988

9089

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-
)
90+
return (
91+
<div id="card">
92+
<div id="chart">
93+
<Charts options={state.options} series={state.series} type="radialBar" height={250} width={250}/>
94+
</div>
95+
</div>
96+
)
10197
}
10298

10399

0 commit comments

Comments
 (0)