-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy pathHeatMapChartBasic.Example.tsx
346 lines (341 loc) · 9.92 KB
/
HeatMapChartBasic.Example.tsx
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
import * as React from 'react';
import { HeatMapChart, IHeatMapChartProps, DataVizPalette, getColorFromToken } from '@fluentui/react-charting';
import { Label, ThemeContext } from '@fluentui/react';
export const HeatMapChartBasicExample: React.FunctionComponent<{}> = () => {
const theme = React.useContext(ThemeContext);
const [width, setWidth] = React.useState<number>(450);
const [height, setHeight] = React.useState<number>(350);
const rootStyle = { width: `${width}px`, height: `${height}px` };
const yPointMapping: { [key: string]: string } = {
p1: 'Ohio',
p2: 'Alaska',
p3: 'Texas',
p4: 'DC',
p5: 'NYC',
};
const yPoint: string[] = ['p1', 'p2', 'p3', 'p4', 'p5'];
const xPoint: Date[] = [
new Date('2020-03-03'), // 0
new Date('2020-03-04'), // 1
new Date('2020-03-05'), // 2
new Date('2020-03-06'), // 3
new Date('2020-03-07'), // 4
new Date('2020-03-08'), // 5
new Date('2020-03-09'), // 6
new Date('2020-03-10'), // 7
];
const HeatMapData: IHeatMapChartProps['data'] = [
{
value: 100,
legend: 'Excellent (0-200)',
data: [
{
x: xPoint[2],
y: yPoint[2],
value: 46,
rectText: 46,
ratio: [46, 2391],
descriptionMessage: 'air quality seems to be excellent today',
},
],
},
{
value: 250,
legend: 'Good (201-300)',
data: [
{
x: xPoint[0],
y: yPoint[1],
value: 265,
rectText: 265,
ratio: [265, 2479],
descriptionMessage: 'today we have good air quality in Alaska',
},
{
x: xPoint[1],
y: yPoint[0],
value: 250,
rectText: 250,
ratio: [250, 2043],
descriptionMessage: 'a sudden rise of 150 units in Ohio today',
},
{
x: xPoint[2],
y: yPoint[0],
value: 235,
rectText: 235,
ratio: [235, 2043],
descriptionMessage: 'air quality seems to have decreased by only 15 units from yesterday',
},
{
x: xPoint[6],
y: yPoint[2],
value: 300,
rectText: 300,
ratio: [300, 2391],
descriptionMessage: 'air comes to control a little bit more than yesterday',
},
{
x: xPoint[0],
y: yPoint[3],
value: 290,
rectText: 290,
ratio: [290, 2462],
descriptionMessage: '1st day in the week, DC witnesses good air quality',
},
{
x: xPoint[4],
y: yPoint[4],
value: 280,
rectText: 280,
ratio: [280, 2486],
descriptionMessage: `Air quality index decreases by exactly 300 units,
giving the people of NYC good hope`,
},
{
x: xPoint[5],
y: yPoint[3],
value: 300,
rectText: 300,
ratio: [300, 2462],
descriptionMessage: '60 units decreased from yesterday.',
},
],
},
{
value: 350,
legend: 'Medium (301-400)',
data: [
{
x: xPoint[1],
y: yPoint[1],
value: 345,
rectText: 345,
ratio: [345, 2479],
descriptionMessage: 'Alaska has just reported nearly 100 units hike in air quality',
},
{
x: xPoint[6],
y: yPoint[1],
value: 325,
rectText: 325,
ratio: [325, 2479],
descriptionMessage: `Alaska to 300`,
},
{
x: xPoint[5],
y: yPoint[2],
value: 390,
rectText: 390,
ratio: [390, 2391],
descriptionMessage: 'air comes to control a little bit',
},
{
x: xPoint[1],
y: yPoint[3],
value: 385,
rectText: 385,
ratio: [385, 2462],
descriptionMessage: 'Washington DC witnesses a hike of nearly 100 units in air quality',
},
{
x: xPoint[4],
y: yPoint[3],
value: 360,
rectText: 360,
ratio: [360, 2462],
descriptionMessage: 'a 200% hike in the air quality index',
},
{
x: xPoint[1],
y: yPoint[2],
value: 400,
rectText: 400,
ratio: [400, 2391],
descriptionMessage: 'a sudden spike in the badness of the air quality',
},
{
x: xPoint[3],
y: yPoint[0],
value: 400,
rectText: 400,
ratio: [400, 2043],
descriptionMessage: 'situation got worse in air quality due to industrial smoke',
},
],
},
{
value: 450,
legend: 'Danger (401-500)',
data: [
{
x: xPoint[4],
y: yPoint[0],
value: 423,
rectText: 423,
ratio: [423, 2043],
descriptionMessage: 'we can see an increase of 23 units',
},
{
x: xPoint[2],
y: yPoint[1],
value: 463,
rectText: 463,
ratio: [463, 2479],
descriptionMessage: 'day by day, situation is getting worse in Alaska',
},
{
x: xPoint[3],
y: yPoint[2],
value: 480,
rectText: 480,
ratio: [480, 2391],
descriptionMessage: 'same story, today also air quality decreases. a bad day in Texas',
},
{
x: xPoint[2],
y: yPoint[3],
value: 491,
rectText: 491,
ratio: [491, 2462],
descriptionMessage: 'Day by day, 100 units are increasing in air quality',
},
{
x: xPoint[1],
y: yPoint[4],
value: 433,
rectText: 433,
ratio: [433, 2486],
descriptionMessage: `They say good things stay for a short time, today
this saying became reality. New York has witnessed nearly 300% bad air quality`,
},
{
x: xPoint[5],
y: yPoint[4],
value: 473,
rectText: 473,
ratio: [473, 2486],
descriptionMessage: `Today is the same fate as the 2nd day. still, air quality
stays above 400`,
},
],
},
{
value: 550,
legend: 'Very Danger (501-600)',
data: [
{
x: xPoint[5],
y: yPoint[0],
value: 600,
rectText: 600,
ratio: [600, 2043],
descriptionMessage: 'looks like god has cursed us with poisonous air. worst air quality index',
},
{
x: xPoint[5],
y: yPoint[1],
value: 536,
rectText: 536,
ratio: [536, 2479],
descriptionMessage: `shh!, all the hopes were washed away in the rain yesterday,
with another hike of 400% in air quality`,
},
{
x: xPoint[3],
y: yPoint[1],
value: 520,
rectText: 520,
ratio: [520, 2479],
descriptionMessage: 'Alaska planning to build air purifier to control the air quality',
},
{
x: xPoint[4],
y: yPoint[2],
value: 525,
rectText: 525,
ratio: [525, 2391],
descriptionMessage: 'air worsens badly today due to farmers burning the harvest',
},
{
x: xPoint[6],
y: yPoint[3],
value: 560,
rectText: 560,
ratio: [560, 2462],
descriptionMessage: `Due to industrial pollution and the
burning of harvest, it resulted in bad air quality in Washington DC`,
},
{
x: xPoint[3],
y: yPoint[4],
value: 580,
rectText: 580,
ratio: [580, 2486],
descriptionMessage: `Air quality index is becoming worse day by day, leaving the
people of NYC in very bad medical conditions.`,
},
{
x: xPoint[6],
y: yPoint[4],
value: 590,
rectText: 590,
ratio: [590, 2486],
descriptionMessage: `finally, the weekend ends with very bad air quality in New York City`,
},
],
},
];
const _onWidthChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setWidth(parseInt(e.target.value, 10));
};
const _onHeightChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setHeight(parseInt(e.target.value, 10));
};
return (
<div className="containerDiv">
<label htmlFor="changeWidth_Example">Change Width:</label>
<input
type="range"
value={width}
min={200}
max={1000}
onChange={_onWidthChange}
id="changeWidth_Example"
aria-valuetext={`ChangeWidthSlider${width}`}
/>
<label htmlFor="changeHeight_Example">Change Height:</label>
<input
type="range"
value={height}
min={200}
max={1000}
id="changeHeight_Example"
onChange={_onHeightChange}
aria-valuetext={`ChangeHeightSlider${height}`}
/>
<Label>Heat map explaining the Air Quality Index</Label>
<div style={rootStyle}>
<HeatMapChart
culture={window.navigator.language}
chartTitle="Heat map chart basic example"
data={HeatMapData}
// eslint-disable-next-line react/jsx-no-bind
yAxisStringFormatter={(point: string) => yPointMapping[point as string]}
xAxisNumberFormatString=".7s"
yAxisNumberFormatString=".3s"
width={width}
height={height}
domainValuesForColorScale={[0, 200, 400, 600]}
rangeValuesForColorScale={[
getColorFromToken(DataVizPalette.success, theme?.isInverted),
getColorFromToken(DataVizPalette.warning, theme?.isInverted),
getColorFromToken(DataVizPalette.error, theme?.isInverted),
getColorFromToken(DataVizPalette.highError, theme?.isInverted),
]}
enableReflow={true}
/>
</div>
</div>
);
};