|
1 | 1 | import * as React from 'react'; |
| 2 | +import { useTheme } from '@mui/material/styles'; |
2 | 3 | import Box from '@mui/material/Box'; |
3 | 4 | import Stack from '@mui/material/Stack'; |
4 | 5 | import Typography from '@mui/material/Typography'; |
| 6 | +import Checkbox from '@mui/material/Checkbox'; |
| 7 | +import FormControlLabel from '@mui/material/FormControlLabel'; |
5 | 8 | import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; |
6 | 9 | import ToggleButton from '@mui/material/ToggleButton'; |
7 | 10 | import { interpolateBlues } from 'd3-scale-chromatic'; |
@@ -36,20 +39,35 @@ type ColorMapType = 'continuous' | 'piecewise'; |
36 | 39 |
|
37 | 40 | export default function ColorScaleMapShape() { |
38 | 41 | const [colorMap, setColorMap] = React.useState<ColorMapType>('continuous'); |
| 42 | + const [unknownColor, setUnknownColor] = React.useState(true); |
39 | 43 |
|
| 44 | + const theme = useTheme(); |
40 | 45 | return ( |
41 | 46 | <Stack spacing={2} sx={{ width: '100%', maxWidth: 800 }}> |
42 | | - <ToggleButtonGroup |
43 | | - color="primary" |
44 | | - size="small" |
45 | | - exclusive |
46 | | - value={colorMap} |
47 | | - onChange={(_, value: ColorMapType | null) => value && setColorMap(value)} |
48 | | - aria-label="color map" |
| 47 | + <Stack |
| 48 | + direction="row" |
| 49 | + sx={{ alignItems: 'center', justifyContent: 'space-between' }} |
49 | 50 | > |
50 | | - <ToggleButton value="continuous">continuous</ToggleButton> |
51 | | - <ToggleButton value="piecewise">piecewise</ToggleButton> |
52 | | - </ToggleButtonGroup> |
| 51 | + <ToggleButtonGroup |
| 52 | + color="primary" |
| 53 | + size="small" |
| 54 | + exclusive |
| 55 | + value={colorMap} |
| 56 | + onChange={(_, value: ColorMapType | null) => value && setColorMap(value)} |
| 57 | + aria-label="color map" |
| 58 | + > |
| 59 | + <ToggleButton value="continuous">continuous</ToggleButton> |
| 60 | + <ToggleButton value="piecewise">piecewise</ToggleButton> |
| 61 | + </ToggleButtonGroup> |
| 62 | + <FormControlLabel |
| 63 | + checked={unknownColor} |
| 64 | + control={ |
| 65 | + <Checkbox onChange={(event) => setUnknownColor(event.target.checked)} /> |
| 66 | + } |
| 67 | + label="Use unknown color" |
| 68 | + labelPlacement="end" |
| 69 | + /> |
| 70 | + </Stack> |
53 | 71 | <Typography variant="body2" component="h6" sx={{ textAlign: 'end' }}> |
54 | 72 | Share of the population using the Internet in 2020 |
55 | 73 | </Typography> |
@@ -79,11 +97,13 @@ export default function ColorScaleMapShape() { |
79 | 97 | min: 0, |
80 | 98 | max: 100, |
81 | 99 | color: ['#e3f2fd', '#0d47a1'], |
| 100 | + unknownColor: unknownColor ? 'gray' : undefined, |
82 | 101 | } |
83 | 102 | : { |
84 | 103 | type: 'piecewise', |
85 | 104 | thresholds: [25, 50, 75], |
86 | 105 | colors: [0.25, 0.5, 0.75, 1].map(interpolateBlues), |
| 106 | + unknownColor: unknownColor ? 'gray' : undefined, |
87 | 107 | }, |
88 | 108 | }, |
89 | 109 | ]} |
|
0 commit comments