Skip to content

Commit eeaf72b

Browse files
authored
Merge pull request #140 from HyperloopUPV-H8/control-station/linear-indicator
[control-station] Bar Indicator
2 parents b83285e + f414fd8 commit eeaf72b

4 files changed

Lines changed: 89 additions & 8 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.background {
2+
position: relative;
3+
height: 3rem;
4+
width: 100%;
5+
background-color: #000;
6+
overflow: hidden;
7+
}
8+
9+
.infoContainer {
10+
position: absolute;
11+
padding: 0rem 2rem;
12+
width: 100%;
13+
height: 100%;
14+
display: flex;
15+
justify-content: space-between;
16+
align-items: center;
17+
}
18+
19+
.bar {
20+
position: absolute;
21+
top: -25%;
22+
left: -2%;
23+
filter: blur(10px);
24+
background-color: red;
25+
width: 40%;
26+
height: 150%;
27+
transition: width 0.1s ease-in-out;
28+
}
29+
30+
.title {
31+
opacity: .8;
32+
font-size: 24px;
33+
font-style: italic;
34+
font-weight: 300;
35+
}
36+
37+
.value {
38+
opacity: .8;
39+
font-size: 32px;
40+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { NumericMeasurement, useMeasurementsStore } from "common";
2+
import styles from "./BarIndicator.module.scss";
3+
import { getPercentFromRange, getState, stateToColor, stateToColorBackground } from "state";
4+
5+
interface Props {
6+
icon?: string;
7+
title: string;
8+
measurement: NumericMeasurement;
9+
}
10+
11+
export const BarIndicator = ({icon, title, measurement}: Props) => {
12+
13+
const state = getState(measurement);
14+
const percentage = getPercentFromRange(measurement.value.last, measurement.safeRange[0]!!, measurement.safeRange[1]!!)
15+
16+
return (
17+
<div
18+
className={styles.background}
19+
style={{backgroundColor: stateToColorBackground[state]}}
20+
>
21+
<div
22+
className={styles.bar}
23+
style={{width: percentage + "%", backgroundColor: stateToColor[state]}}
24+
></div>
25+
26+
<div className={styles.infoContainer}>
27+
<div>
28+
<div className={styles.icon}>{icon}</div>
29+
<div className={styles.title}>{title}</div>
30+
</div>
31+
<div>
32+
<div className={styles.value}>{measurement.value.last}</div>
33+
<div className={styles.unit}>{measurement.units}</div>
34+
</div>
35+
</div>
36+
</div>
37+
)
38+
}

control-station/src/components/GaugeTag/Gauge/Gauge.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ export const Gauge = ({
4545
radius={radius}
4646
strokeWidth={strokeWidth}
4747
></BackgroundArc>
48-
49-
{/* <BackgroundArc
50-
sweep={sweep}
51-
className={styles.radialShadowArc}
52-
percentage={percentage}
53-
radius={radius}
54-
strokeWidth={strokeWidth}
55-
></BackgroundArc> */}
5648
</svg>
5749
);
5850
};

control-station/src/state.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export const stateToColor = {
1919
fault: "hsl(356, 90%, 61%)",
2020
};
2121

22+
export const stateToColorBackground = {
23+
stable: "hsl(92, 82%, 86%)",
24+
warning: "hsl(52, 90%, 86%)",
25+
fault: "hsl(356, 90%, 86%)",
26+
};
27+
2228
export function getState(meas: Measurement): State {
2329
if (isNumericMeasurement(meas)) {
2430
return getStateFromRange(
@@ -63,3 +69,8 @@ export function getStateFromRange(
6369

6470
return "fault";
6571
}
72+
73+
export function getPercentFromRange(value: number, min: number, max: number): number {
74+
const normValue = Math.max(Math.min(value, max), min);
75+
return ((normValue - min) / (max - min)) * 100;
76+
}

0 commit comments

Comments
 (0)