|
| 1 | +import * as React from 'react'; |
| 2 | +import Box from '@mui/material/Box'; |
| 3 | +import Stack from '@mui/material/Stack'; |
| 4 | +import TextField from '@mui/material/TextField'; |
| 5 | +import MenuItem from '@mui/material/MenuItem'; |
| 6 | +import { feature as topojsonFeature } from 'topojson-client'; |
| 7 | +import countriesTopology from 'world-atlas/countries-110m.json'; |
| 8 | +import { Unstable_ChartsGeoDataProviderPremium as ChartsGeoDataProviderPremium } from '@mui/x-charts-premium/ChartsGeoDataProviderPremium'; |
| 9 | +import { GeoDataPlot, MapShapePlot } from '@mui/x-charts-premium/Map'; |
| 10 | +import { ChartsSurface } from '@mui/x-charts/ChartsSurface'; |
| 11 | +import { ChartsTooltip } from '@mui/x-charts-premium/ChartsTooltip'; |
| 12 | + |
| 13 | +const countries = topojsonFeature(countriesTopology, 'countries'); |
| 14 | + |
| 15 | +const americas = [ |
| 16 | + 'Argentina', |
| 17 | + 'Bolivia', |
| 18 | + 'Brazil', |
| 19 | + 'Chile', |
| 20 | + 'Colombia', |
| 21 | + 'Ecuador', |
| 22 | + 'Paraguay', |
| 23 | + 'Peru', |
| 24 | + 'Uruguay', |
| 25 | + 'Venezuela', |
| 26 | +]; |
| 27 | + |
| 28 | +const europe = [ |
| 29 | + 'France', |
| 30 | + 'Germany', |
| 31 | + 'Italy', |
| 32 | + 'Poland', |
| 33 | + 'Portugal', |
| 34 | + 'Romania', |
| 35 | + 'Spain', |
| 36 | + 'Sweden', |
| 37 | + 'United Kingdom', |
| 38 | +]; |
| 39 | + |
| 40 | +export default function HighlightedMapShape() { |
| 41 | + const [highlight, setHighlight] = React.useState('item'); |
| 42 | + const [fade, setFade] = React.useState('global'); |
| 43 | + |
| 44 | + return ( |
| 45 | + <Stack |
| 46 | + direction={{ xs: 'column', md: 'row' }} |
| 47 | + spacing={2} |
| 48 | + sx={{ width: '100%' }} |
| 49 | + > |
| 50 | + <Box sx={{ flexGrow: 1, maxWidth: 800 }}> |
| 51 | + <ChartsGeoDataProviderPremium |
| 52 | + geoData={countries} |
| 53 | + projection="naturalEarth1" |
| 54 | + height={360} |
| 55 | + series={[ |
| 56 | + { |
| 57 | + type: 'mapShape', |
| 58 | + label: 'South America', |
| 59 | + color: '#43a047', |
| 60 | + highlightScope: { highlight, fade }, |
| 61 | + data: americas.map((name) => ({ name })), |
| 62 | + }, |
| 63 | + { |
| 64 | + type: 'mapShape', |
| 65 | + label: 'Europe', |
| 66 | + color: '#1e88e5', |
| 67 | + highlightScope: { highlight, fade }, |
| 68 | + data: europe.map((name) => ({ name })), |
| 69 | + }, |
| 70 | + ]} |
| 71 | + > |
| 72 | + <ChartsSurface> |
| 73 | + <GeoDataPlot fill="#f5f5f5" stroke="#bdbdbd" /> |
| 74 | + <MapShapePlot /> |
| 75 | + </ChartsSurface> |
| 76 | + <ChartsTooltip trigger="item" /> |
| 77 | + </ChartsGeoDataProviderPremium> |
| 78 | + </Box> |
| 79 | + <Stack spacing={2} sx={{ minWidth: 150 }}> |
| 80 | + <TextField |
| 81 | + select |
| 82 | + label="highlight" |
| 83 | + value={highlight} |
| 84 | + onChange={(event) => setHighlight(event.target.value)} |
| 85 | + > |
| 86 | + <MenuItem value="none">none</MenuItem> |
| 87 | + <MenuItem value="item">item</MenuItem> |
| 88 | + <MenuItem value="series">series</MenuItem> |
| 89 | + </TextField> |
| 90 | + <TextField |
| 91 | + select |
| 92 | + label="fade" |
| 93 | + value={fade} |
| 94 | + onChange={(event) => setFade(event.target.value)} |
| 95 | + > |
| 96 | + <MenuItem value="none">none</MenuItem> |
| 97 | + <MenuItem value="series">series</MenuItem> |
| 98 | + <MenuItem value="global">global</MenuItem> |
| 99 | + </TextField> |
| 100 | + </Stack> |
| 101 | + </Stack> |
| 102 | + ); |
| 103 | +} |
0 commit comments