work : виджет стал более "горизонтальным"

This commit is contained in:
Fedorov Dmitriy
2026-09-20 11:28:48 +03:00
parent 33cdb205b3
commit fdb798a430
9 changed files with 379 additions and 47 deletions
+42
View File
@@ -220,6 +220,48 @@ export function airQuality(co2) {
return { label: "Нужна вентиляция", tone: "bad", pct: Math.min(100, value / 20) };
}
const AIR_METER_STOPS = [
[400, [35, 143, 83]],
[700, [46, 166, 99]],
[820, [82, 181, 111]],
[900, [190, 153, 55]],
[1200, [214, 128, 45]],
[1500, [215, 83, 55]],
[2000, [188, 48, 72]],
];
const interpolateChannel = (start, end, amount) => Math.round(start + (end - start) * amount);
export function airMeterPalette(co2) {
const value = Number(co2);
if (!Number.isFinite(value)) {
return {
color: "rgb(105, 137, 158)",
glow: "rgba(83, 123, 150, .2)",
};
}
const bounded = Math.max(AIR_METER_STOPS[0][0], Math.min(AIR_METER_STOPS.at(-1)[0], value));
let lower = AIR_METER_STOPS[0];
let upper = AIR_METER_STOPS.at(-1);
for (let index = 1; index < AIR_METER_STOPS.length; index += 1) {
if (bounded <= AIR_METER_STOPS[index][0]) {
lower = AIR_METER_STOPS[index - 1];
upper = AIR_METER_STOPS[index];
break;
}
}
const amount = upper[0] === lower[0] ? 0 : (bounded - lower[0]) / (upper[0] - lower[0]);
const [red, green, blue] = lower[1].map((channel, index) => interpolateChannel(channel, upper[1][index], amount));
return {
color: `rgb(${red}, ${green}, ${blue})`,
glow: `rgba(${red}, ${green}, ${blue}, .26)`,
};
}
export function modeInfo(status) {
const schedule = status?.schedule || {};
if (!schedule.available) return { label: "Без расписания", detail: "Недоступно", tone: "muted" };