Skip to content

Commit 3f34214

Browse files
committed
Add typeguard and typecast to plumevariable
1 parent eaed559 commit 3f34214

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

apps/class-solid/src/components/Analysis.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,13 @@ export function VerticalProfilePlot({
251251
const classVariable = () =>
252252
variableOptions[analysis.variable as keyof typeof variableOptions];
253253

254-
const showPlume = createMemo(() => {
255-
return ["theta", "qt", "thetav", "T", "Td", "rh", "w"].includes(
256-
classVariable(),
257-
);
258-
});
254+
255+
type PlumeVariable = "theta" | "qt" | "thetav" | "T" | "Td" | "rh" | "w";
256+
function isPlumeVariable(v: string): v is PlumeVariable {
257+
return ["theta", "qt", "thetav", "T", "Td", "rh", "w"].includes(v);
258+
}
259+
260+
const showPlume = createMemo(() => isPlumeVariable(classVariable()));
259261

260262
const observations = () =>
261263
flatObservations().map((o) => observationsForProfile(o, classVariable()));
@@ -274,15 +276,15 @@ export function VerticalProfilePlot({
274276
const firePlumes = () =>
275277
flatExperiments().map((e, i) => {
276278
const { config, output, ...formatting } = e;
277-
if (config.sw_fire && showPlume()) {
279+
if (config.sw_fire && isPlumeVariable(classVariable())) {
278280
const plume = transposePlumeData(
279281
calculatePlume(config, profileData()[i].data),
280282
);
281283
return {
282284
...formatting,
283285
linestyle: "4",
284286
data: plume.z.map((z, i) => ({
285-
x: plume[classVariable()][i],
287+
x: plume[classVariable() as PlumeVariable][i],
286288
y: z,
287289
})),
288290
};

0 commit comments

Comments
 (0)