-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathRow.tsx
89 lines (83 loc) · 2.41 KB
/
Row.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
import styled from "@emotion/styled";
import { WindsAloftAltitude, WindsAloftHour } from "../../models/WindsAloft";
import Altitude from "./cells/Altitude";
import Temperature from "./cells/Temperature";
import WindDirection from "./cells/WindDirection";
import WindSpeed from "./cells/WindSpeed";
import { css } from "@emotion/react";
import { vectorDifferenceMagnitude } from "../../helpers/vector";
const DELTA_WINDSPEED_VECTOR_THRESHOLD_KPH = 16;
const TableRow = styled.tr<{ opaque: boolean }>`
${({ opaque }) =>
opaque &&
css`
opacity: 0.5;
`}
`;
interface RowProps {
datum: WindsAloftAltitude;
index: number;
displayedRapData: WindsAloftAltitude[];
surfaceLevel: number;
windsAloftHour: WindsAloftHour;
}
export default function Row({
datum,
index,
displayedRapData,
surfaceLevel,
windsAloftHour,
}: RowProps) {
function negativeAltitude(datum: WindsAloftAltitude): boolean {
return !!(datum.altitudeInM - surfaceLevel < 0);
}
const shearEligible =
displayedRapData[index - 1] &&
vectorDifferenceMagnitude(
datum.windSpeedInKph,
datum.windDirectionInDeg,
displayedRapData[index - 1]?.windSpeedInKph,
displayedRapData[index - 1]?.windDirectionInDeg,
) > DELTA_WINDSPEED_VECTOR_THRESHOLD_KPH;
return (
<TableRow key={index} opaque={negativeAltitude(datum)}>
<td>
<Altitude
heightInMeters={datum.altitudeInM}
surfaceLevelInMeters={surfaceLevel}
pressure={datum.pressure}
/>
</td>
<td>
<Temperature
temperature={datum.temperatureInC}
dewpoint={datum.dewpointInC}
lapseRate={
displayedRapData[index - 1]
? -(
(datum.temperatureInC -
displayedRapData[index - 1].temperatureInC) /
(datum.altitudeInM - displayedRapData[index - 1].altitudeInM)
)
: undefined
}
pressure={datum.pressure}
hour={new Date(windsAloftHour.date)}
/>
</td>
<td>
<WindDirection
curr={datum.windDirectionInDeg}
prev={displayedRapData[index - 1]?.windDirectionInDeg}
shearEligible={shearEligible}
/>
</td>
<td>
<WindSpeed
curr={datum.windSpeedInKph}
prev={displayedRapData[index - 1]?.windSpeedInKph}
/>
</td>
</TableRow>
);
}