|
| 1 | +import { Box, Typography } from '@mui/material' |
| 2 | +import { alpha } from '@mui/material/styles' |
| 3 | + |
| 4 | +import { OverlayType } from './types' |
| 5 | + |
| 6 | +interface OverlayLegendConfig { |
| 7 | + title: [string, string] |
| 8 | + imageSrc: string |
| 9 | + max: string |
| 10 | + min: string |
| 11 | +} |
| 12 | + |
| 13 | +const LEGEND_CONFIG: Record< |
| 14 | + Exclude<OverlayType, OverlayType.None>, |
| 15 | + OverlayLegendConfig |
| 16 | +> = { |
| 17 | + [OverlayType.Precipitation]: { |
| 18 | + title: ['Annual', 'Precipitation'], |
| 19 | + imageSrc: '/img/climateLegend.png', |
| 20 | + max: '10577 mm', |
| 21 | + min: '13 mm', |
| 22 | + }, |
| 23 | + [OverlayType.HistoricalMinTemp]: { |
| 24 | + title: ['Minimum', 'Temperature'], |
| 25 | + imageSrc: '/img/climateLegendFlip.png', |
| 26 | + max: '31.9 °C', |
| 27 | + min: '-27.8 °C', |
| 28 | + }, |
| 29 | + [OverlayType.HistoricalMaxTemp]: { |
| 30 | + title: ['Maximum', 'Temperature'], |
| 31 | + imageSrc: '/img/climateLegendFlip.png', |
| 32 | + max: '31.9 °C', |
| 33 | + min: '-27.8 °C', |
| 34 | + }, |
| 35 | +} |
| 36 | + |
| 37 | +interface OverlayLegendProps { |
| 38 | + overlay: OverlayType |
| 39 | +} |
| 40 | + |
| 41 | +const OverlayLegend = ({ overlay }: OverlayLegendProps) => { |
| 42 | + if (overlay === OverlayType.None) return null |
| 43 | + |
| 44 | + const { title, imageSrc, max, min } = LEGEND_CONFIG[overlay] |
| 45 | + |
| 46 | + return ( |
| 47 | + <Box |
| 48 | + sx={(theme) => ({ |
| 49 | + display: 'flex', |
| 50 | + flexDirection: 'column', |
| 51 | + alignItems: 'flex-start', |
| 52 | + gap: theme.spacing(0.5), |
| 53 | + padding: theme.spacing(1), |
| 54 | + borderRadius: theme.spacing(1), |
| 55 | + backgroundColor: alpha(theme.palette.background.active, 0.4), |
| 56 | + boxShadow: '0 8px 24px rgba(0, 0, 0, 0.18)', |
| 57 | + border: `1px solid ${alpha(theme.palette.background.edge, 0.7)}`, |
| 58 | + backdropFilter: 'blur(8px)', |
| 59 | + WebkitBackdropFilter: 'blur(8px)', |
| 60 | + })} |
| 61 | + > |
| 62 | + {/* Title */} |
| 63 | + <Box> |
| 64 | + {title.map((line) => ( |
| 65 | + <Typography |
| 66 | + key={line} |
| 67 | + variant='caption' |
| 68 | + sx={(theme) => ({ |
| 69 | + display: 'block', |
| 70 | + color: theme.palette.text.primary, |
| 71 | + fontWeight: 600, |
| 72 | + lineHeight: 1.2, |
| 73 | + })} |
| 74 | + > |
| 75 | + {line} |
| 76 | + </Typography> |
| 77 | + ))} |
| 78 | + </Box> |
| 79 | + |
| 80 | + {/* Scale image with max/min labels */} |
| 81 | + <Box sx={{ display: 'flex', flexDirection: 'row', gap: 0.75 }}> |
| 82 | + <Box |
| 83 | + component='img' |
| 84 | + src={imageSrc} |
| 85 | + sx={{ width: 16, height: 160, display: 'block' }} |
| 86 | + /> |
| 87 | + <Box |
| 88 | + sx={{ |
| 89 | + display: 'flex', |
| 90 | + flexDirection: 'column', |
| 91 | + justifyContent: 'space-between', |
| 92 | + height: 160, |
| 93 | + }} |
| 94 | + > |
| 95 | + <Typography variant='caption' sx={{ lineHeight: 1 }}> |
| 96 | + {max} |
| 97 | + </Typography> |
| 98 | + <Typography variant='caption' sx={{ lineHeight: 1 }}> |
| 99 | + {min} |
| 100 | + </Typography> |
| 101 | + </Box> |
| 102 | + </Box> |
| 103 | + </Box> |
| 104 | + ) |
| 105 | +} |
| 106 | + |
| 107 | +export default OverlayLegend |
0 commit comments