forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorScale.js
More file actions
167 lines (164 loc) · 5.26 KB
/
ColorScale.js
File metadata and controls
167 lines (164 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import * as React from 'react';
import { LineChart } from '@mui/x-charts/LineChart';
import Stack from '@mui/material/Stack';
import TextField from '@mui/material/TextField';
import MenuItem from '@mui/material/MenuItem';
import { HighlightedCode } from '@mui/internal-core-docs/HighlightedCode';
import FormControlLabel from '@mui/material/FormControlLabel';
import Checkbox from '@mui/material/Checkbox';
export default function ColorScale() {
const [colorX, setColorX] = React.useState('None');
const [colorY, setColorY] = React.useState('piecewise');
const [colorArea, setColorArea] = React.useState(true);
return (
<Stack direction="column" spacing={1} sx={{ width: '100%', maxWidth: 600 }}>
<Stack direction="row" spacing={1} flexWrap="wrap">
<TextField
select
sx={{ minWidth: 150 }}
label="x-axis colorMap"
value={colorX}
onChange={(event) => setColorX(event.target.value)}
>
<MenuItem value="None">None</MenuItem>
<MenuItem value="piecewise">piecewise</MenuItem>
<MenuItem value="continuous">continuous</MenuItem>
</TextField>
<TextField
select
sx={{ minWidth: 150 }}
label="y-axis colorMap"
value={colorY}
onChange={(event) => setColorY(event.target.value)}
>
<MenuItem value="None">None</MenuItem>
<MenuItem value="piecewise">piecewise</MenuItem>
<MenuItem value="continuous">continuous</MenuItem>
</TextField>
<FormControlLabel
checked={colorArea}
control={
<Checkbox onChange={(event) => setColorArea(event.target.checked)} />
}
label="Show chart area"
labelPlacement="end"
/>
</Stack>
<LineChart
height={300}
grid={{ horizontal: true }}
series={[
{
data: [-2, -9, 12, 11, 6, -4],
area: colorArea,
showMark: true,
},
]}
yAxis={[
{
colorMap:
(colorY === 'continuous' && {
type: 'continuous',
min: -10,
max: 10,
color: ['red', 'green'],
}) ||
(colorY === 'piecewise' && {
type: 'piecewise',
thresholds: [0, 10],
colors: ['red', 'green', 'blue'],
}) ||
undefined,
},
]}
xAxis={[
{
scaleType: 'time',
data: [
new Date(2019, 0, 1),
new Date(2020, 0, 1),
new Date(2021, 0, 1),
new Date(2022, 0, 1),
new Date(2023, 0, 1),
new Date(2024, 0, 1),
],
valueFormatter: (value) => value.getFullYear().toString(),
colorMap:
(colorX === 'continuous' && {
type: 'continuous',
min: new Date(2019, 1, 1),
max: new Date(2024, 1, 1),
color: ['green', 'orange'],
}) ||
(colorX === 'piecewise' && {
type: 'piecewise',
thresholds: [new Date(2021, 1, 1), new Date(2023, 1, 1)],
colors: ['blue', 'red', 'blue'],
}) ||
undefined,
},
]}
/>
<HighlightedCode
code={[
`<LineChart`,
' /* ... */',
` series={[{data: [-2, -9, 12, 11, 6, -4], area: ${colorArea}}]}`,
// ColorX
...(colorX === 'None' ? [' xAxis={[{}]}'] : []),
...(colorX === 'continuous'
? [
' xAxis={[{',
` colorMap: {`,
` type: 'continuous',`,
` min: new Date(2019, 1, 1),`,
` max: new Date(2024, 1, 1),`,
` color: ['green', 'orange']`,
` }`,
' }]}',
]
: []),
...(colorX === 'piecewise'
? [
' xAxis={[{',
` colorMap: {`,
` type: 'piecewise',`,
` thresholds: [new Date(2021, 1, 1), new Date(2023, 1, 1)],`,
` colors: ['blue', 'red', 'blue'],`,
` }`,
' }]}',
]
: []),
// ColorY
...(colorY === 'None' ? [' yAxis={[{}]}'] : []),
...(colorY === 'continuous'
? [
' yAxis={[{',
` colorMap: {`,
` type: 'continuous',`,
` min: -10,`,
` max: 10,`,
` color: ['red', 'green'],`,
` }`,
' }]}',
]
: []),
...(colorY === 'piecewise'
? [
' yAxis={[{',
` colorMap: {`,
` type: 'piecewise',`,
` thresholds: [0, 10],`,
` colors: ['red', 'green', 'blue'],`,
` }`,
' }]}',
]
: []),
`/>`,
].join('\n')}
language="jsx"
copyButtonHidden
/>
</Stack>
);
}