work : виджет стал более "горизонтальным"
This commit is contained in:
@@ -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" };
|
||||
|
||||
Reference in New Issue
Block a user