@@ -95,72 +95,91 @@ const StateRoute = (props: StateRouteProps) => {
95
95
let INPColor : String ;
96
96
97
97
// adjust the strings that represent colors of the webmetrics performance bar for 'Largest Contentful Paint (LCP)', 'First Input Delay (FID)', 'First Contentfuly Paint (FCP)', and 'Time to First Byte (TTFB)' based on webMetrics outputs.
98
- if ( webMetrics . LCP <= 2000 ) LCPColor = '#0bce6b' ;
99
- if ( webMetrics . LCP > 2000 && webMetrics . LCP < 4000 ) LCPColor = '#E56543' ;
100
- if ( webMetrics . LCP > 4000 ) LCPColor = '#fc2000' ;
101
- if ( webMetrics . FID <= 100 ) FIDColor = '#0bce6b' ;
102
- if ( webMetrics . FID > 100 && webMetrics . FID <= 300 ) FIDColor = '#fc5a03' ;
103
- if ( webMetrics . FID > 300 ) FIDColor = '#fc2000' ;
104
- if ( webMetrics . FCP <= 900 ) FCPColor = '#0bce6b' ;
105
- if ( webMetrics . FCP > 900 && webMetrics . FCP <= 1100 ) FCPColor = '#fc5a03' ;
106
- if ( webMetrics . FCP > 1100 ) FCPColor = '#fc2000' ;
107
- if ( webMetrics . TTFB <= 600 ) TTFBColor = '#0bce6b' ;
108
- if ( webMetrics . TTFB > 600 ) TTFBColor = '#fc2000' ;
109
- if ( webMetrics . CLS <= 0.1 ) CLSColor = '#0bce6b' ;
110
- if ( webMetrics . CLS > 0.1 && webMetrics . CLS <= 0.25 ) CLSColor = '#E56543' ;
111
- if ( webMetrics . CLS > 0.25 ) CLSColor = '#fc2000' ;
112
- if ( webMetrics . INP <= 200 ) INPColor = '#0bce6b' ;
113
- if ( webMetrics . INP <= 500 ) INPColor = '#E56543' ;
114
- if ( webMetrics . INP > 500 ) INPColor = '#fc2000' ;
98
+ if ( webMetrics . LCP <= 2500 ) LCPColor = [ '#0bce6b' ] ;
99
+ if ( webMetrics . LCP > 2500 && webMetrics . LCP < 4000 ) LCPColor = [ '#fc5a03' ] ;
100
+ if ( webMetrics . LCP > 4000 && webMetrics . LCP <= 7000 ) LCPColor = [ '#fc2000' ] ;
101
+ if ( webMetrics . LCP > 7000 ) LCPColor = [ '#fc2000' , '#000000' ] ;
102
+
103
+ if ( webMetrics . FID <= 100 ) FIDColor = [ '#0bce6b' ] ;
104
+ if ( webMetrics . FID > 100 && webMetrics . FID <= 300 ) FIDColor = [ '#fc5a03' ] ;
105
+ if ( webMetrics . FID > 300 && webMetrics . FID <= 500 ) FIDColor = [ '#fc2000' ] ;
106
+ if ( webMetrics . FID > 500 ) FIDColor = [ '#fc2000' , '#000000' ] ;
107
+
108
+ if ( webMetrics . FCP <= 1800 ) FCPColor = [ '#0bce6b' ] ;
109
+ if ( webMetrics . FCP > 1800 && webMetrics . FCP <= 3000 ) FCPColor = [ '#fc5a03' ] ;
110
+ if ( webMetrics . FCP > 3000 && webMetrics . FCP <= 5000 ) FCPColor = [ '#fc2000' ] ;
111
+ if ( webMetrics . FCP > 5000 ) FCPColor = [ '#fc2000' , '#000000' ] ;
112
+
113
+ if ( webMetrics . TTFB <= 800 ) TTFBColor = [ '#0bce6b' ] ;
114
+ if ( webMetrics . TTFB > 800 && webMetrics . TTFB <= 1800 ) TTFBColor = [ '#fc5a03' ] ;
115
+ if ( webMetrics . TTFB > 1800 && webMetrics . TTFB <= 3000 ) TTFBColor = [ '#fc2000' ] ;
116
+ if ( webMetrics . TTFB > 3000 ) TTFBColor = [ '#fc2000' , '#000000' ] ;
117
+
118
+ if ( webMetrics . CLS <= 0.1 ) CLSColor = [ '#0bce6b' ] ;
119
+ if ( webMetrics . CLS > 0.1 && webMetrics . CLS <= 0.25 ) CLSColor = [ '#fc5a03' ] ;
120
+ if ( webMetrics . CLS > 0.25 && webMetrics . CLS <= 0.5 ) CLSColor = [ '#fc2000' ] ;
121
+ if ( webMetrics . CLS > 0.5 ) CLSColor = [ '#fc2000' , '#000000' ] ;
122
+
123
+ if ( webMetrics . INP <= 200 ) INPColor = [ '#0bce6b' ] ;
124
+ if ( webMetrics . INP > 200 && webMetrics . INP <= 500 ) INPColor = [ '#fc5a03' ] ;
125
+ if ( webMetrics . INP > 500 && webMetrics . INP <= 700 ) INPColor = [ '#fc2000' ] ;
126
+ if ( webMetrics . INP > 700 ) INPColor = [ '#fc2000' , '#000000' ] ;
127
+
128
+ const fakeLCP = 7500 ;
129
+
130
+ if ( fakeLCP <= 2500 ) LCPColor = [ '#0bce6b' ] ;
131
+ if ( fakeLCP > 2500 && fakeLCP < 4000 ) LCPColor = [ '#fc5a03' ] ;
132
+ if ( fakeLCP > 4000 && fakeLCP <= 7000 ) LCPColor = [ '#fc2000' ] ;
133
+ if ( fakeLCP > 7000 ) LCPColor = [ '#fc2000' , '#000000' ] ;
115
134
116
135
return (
117
136
< div className = 'web-metrics-container' >
118
137
< WebMetrics
119
138
color = { LCPColor }
120
- series = { ( webMetrics . LCP / 2500 ) * 100 }
121
- formatted = { ( val ) =>
122
- Number . isNaN ( val ) ? '- ms' : `${ ( ( val / 100 ) * 2500 ) . toFixed ( 2 ) } ms`
139
+ series = { webMetrics . LCP ? [ webMetrics . LCP / 70 < 100 ? webMetrics . LCP / 70 : 100 ] : 0 }
140
+ formatted = { ( _ ) =>
141
+ typeof webMetrics . LCP !== 'number' ? '- ms' : `${ ( webMetrics . LCP ) . toFixed ( 2 ) } ms`
123
142
}
124
143
label = 'Largest Contentful Paint'
125
144
name = 'Largest Contentful Paint'
126
145
description = 'Measures loading performance. The benchmark is less than 2500 ms.'
127
146
/>
128
147
< WebMetrics
129
148
color = { FIDColor }
130
- series = { webMetrics . FID * 25 }
131
- formatted = { ( val ) => ( Number . isNaN ( val ) ? '- ms' : `${ ( val / 25 ) . toFixed ( 2 ) } ms` ) }
149
+ series = { webMetrics . FID ? [ webMetrics . FID / 5 < 100 ? webMetrics . FID / 5 : 100 ] : 0 }
150
+ formatted = { ( _ ) => typeof webMetrics . FID !== 'number' ? '- ms' : `${ ( webMetrics . FID ) . toFixed ( 2 ) } ms` }
132
151
label = 'First Input Delay'
133
152
name = 'First Input Delay'
134
153
description = 'Measures interactivity. The benchmark is less than 100 ms.'
135
154
/>
136
155
< WebMetrics
137
156
color = { FCPColor }
138
- series = { ( webMetrics . FCP / 1000 ) * 100 }
139
- formatted = { ( val ) => ` ${ ( ( val / 100 ) * 1000 ) . toFixed ( 2 ) } ms`}
157
+ series = { webMetrics . FCP ? [ webMetrics . FCP / 50 < 100 ? webMetrics . FCP / 50 : 100 ] : 0 }
158
+ formatted = { ( _ ) => typeof webMetrics . FCP !== 'number' ? '- ms' : ` ${ ( webMetrics . FCP ) . toFixed ( 2 ) } ms`}
140
159
label = 'First Contentful Paint'
141
160
name = 'First Contentful Paint'
142
161
description = 'Measures the time it takes the browser to render the first piece of DOM content. No benchmark.'
143
162
/>
144
163
< WebMetrics
145
164
color = { TTFBColor }
146
- series = { ( webMetrics . TTFB / 10 ) * 100 }
147
- formatted = { ( val ) => ` ${ ( ( val / 100 ) * 10 ) . toFixed ( 2 ) } ms`}
165
+ series = { webMetrics . TTFB ? [ webMetrics . TTFB / 30 < 100 ? webMetrics . TTFB / 30 : 100 ] : 0 }
166
+ formatted = { ( _ ) => typeof webMetrics . TTFB !== 'number' ? '- ms' : ` ${ ( webMetrics . TTFB ) . toFixed ( 2 ) } ms`}
148
167
label = 'Time To First Byte'
149
168
name = 'Time to First Byte'
150
169
description = 'Measures the time it takes for a browser to receive the first byte of page content. The benchmark is 600 ms.'
151
170
/>
152
171
< WebMetrics
153
172
color = { CLSColor }
154
- series = { webMetrics . CLS * 10 }
155
- formatted = { ( val ) => `CLS Score: ${ ( Number . isNaN ( val ) ? 'N/A' : `${ val / 10 < 0 .01 ? 0 : ( val / 10 ) . toFixed ( 2 ) } ` ) } ` }
173
+ series = { webMetrics . CLS ? [ webMetrics . CLS * 200 < 100 ? webMetrics . CLS * 200 : 100 ] : 0 }
174
+ formatted = { ( _ ) => `CLS Score: ${ typeof webMetrics . CLS !== 'number' ? 'N/A' : `${ webMetrics . CLS < .01 ? '~0' : ( webMetrics . CLS ) . toFixed ( 2 ) } ` } ` }
156
175
label = 'Cumulative Layout Shift'
157
176
name = 'Cumulative Layout Shift'
158
177
description = { `Quantifies the visual stability of a web page by measuring layout shifts during the application's loading and interaction.` }
159
178
/>
160
179
< WebMetrics
161
180
color = { INPColor }
162
- series = { ( webMetrics . INP / 10 ) * 100 }
163
- formatted = { ( val ) => ` INP Value: ${ ( Number . isNaN ( val ) ? 'N/A ' : `${ val / 10 } ` ) } `}
181
+ series = { webMetrics . INP ? [ webMetrics . INP / 7 < 100 ? webMetrics . INP / 7 : 100 ] : 0 }
182
+ formatted = { ( _ ) => typeof webMetrics . INP !== 'number' ? '- ms ' : `${ ( webMetrics . INP ) . toFixed ( 2 ) } ms ` }
164
183
label = 'Interaction to Next Paint'
165
184
name = 'Interaction to Next Paint'
166
185
description = { `Assesses a page's overall responsiveness to user interactions by observing the latency of all click, tap, and keyboard interactions that occur throughout the lifespan of a user's visit to a page` }
0 commit comments