Skip to content

Commit f414fd8

Browse files
committed
new algorithm for state
1 parent 51b0784 commit f414fd8

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

control-station/src/components/BarIndicator/BarIndicator.module.scss

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,14 @@
2727
transition: width 0.1s ease-in-out;
2828
}
2929

30-
.icon {
31-
32-
}
33-
3430
.title {
3531
opacity: .8;
3632
font-size: 24px;
3733
font-style: italic;
3834
font-weight: 300;
3935
}
4036

41-
.title
42-
4337
.value {
4438
opacity: .8;
4539
font-size: 32px;
46-
}
47-
48-
.unit {
49-
5040
}

control-station/src/components/BarIndicator/BarIndicator.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ interface Props {
99
}
1010

1111
export const BarIndicator = ({icon, title, measurement}: Props) => {
12-
13-
measurement.value.last = 30;
12+
1413
const state = getState(measurement);
1514
const percentage = getPercentFromRange(measurement.value.last, measurement.safeRange[0]!!, measurement.safeRange[1]!!)
1615

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)