MCPcopy Create free account
hub / github.com/carbonplan/maps / AverageDisplay

Function AverageDisplay

demo/components/region-controls.js:5–37  ·  view source on GitHub ↗
({ band, data: { value } })

Source from the content-addressed store, hash-verified

3import { XCircle } from '@carbonplan/icons'
4
5const AverageDisplay = ({ band, data: { value } }) => {
6 if (!value || !value.climate) {
7 return 'loading...'
8 }
9
10 let result
11 const filteredData = value.climate.filter((d) => d !== 9.969209968386869e36)
12 if (filteredData.length === 0) {
13 result = 'no data in region'
14 } else {
15 const average =
16 filteredData.reduce((a, b) => a + b, 0) / filteredData.length
17 if (band === 'prec') {
18 result = `Average: ${average.toFixed(2)}`
19 } else {
20 result = `Average: ${average.toFixed(2)}ºC`
21 }
22 }
23
24 return (
25 <Box
26 sx={{
27 ml: [2],
28 mt: ['-1px'],
29 fontFamily: 'mono',
30 letterSpacing: 'mono',
31 textTransform: 'uppercase',
32 }}
33 >
34 {result}
35 </Box>
36 )
37}
38
39const RegionControls = ({
40 band,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected