change color and icon to match iqair
This commit is contained in:
parent
08fbf9fe02
commit
a8e40f9cd8
109
static/card.html
109
static/card.html
|
@ -13,6 +13,20 @@
|
|||
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
|
||||
<script src="//code.iconify.design/1/1.0.6/iconify.min.js"></script>
|
||||
<style>
|
||||
:root {
|
||||
--good-color: #ABD162;
|
||||
--moderate-color: #F7D460;
|
||||
--unhealthy-sensitive-color: #FD9760;
|
||||
--unhealthy-color: #F7666E;
|
||||
--very-unhealthy-color: #A37CBB;
|
||||
--hazardous-color: #A07685;
|
||||
--icon-good: /images/aqi-icon-l1.svg;
|
||||
--icon-moderate: /images/aqi-icon-l2.svg;
|
||||
--icon-unhealthy-sensitive: /images/aqi-icon-l3.svg;
|
||||
--icon-unhealthy: /images/aqi-icon-l4.svg;
|
||||
--icon-very-unhealthy: /images/aqi-icon-l5.svg;
|
||||
--icon-hazardous: /images/aqi-icon-l6.svg;
|
||||
}
|
||||
body {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
@ -153,6 +167,11 @@
|
|||
margin-top: 7px;
|
||||
margin-bottom: 7px;
|
||||
}
|
||||
#health_icon {
|
||||
transform: scale(2);
|
||||
padding-top: 30px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
|
@ -161,7 +180,8 @@
|
|||
<p class="title_text" id="title">Loading . . .</p>
|
||||
<div class="top_element" id="top_element">
|
||||
<div class="health_icon_frame" id="health_icon_frame">
|
||||
<span class="iconify" data-icon="mdi-close" id="health_icon"></span>
|
||||
<!-- <span class="iconify" data-icon="mdi-close" id="health_icon"></span> -->
|
||||
<img id="health_icon" src="">
|
||||
<p class="health_text" , id="health_text">Loading</p>
|
||||
</div>
|
||||
<div class="top_frame_label_block">
|
||||
|
@ -193,6 +213,15 @@
|
|||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
function darkenColor(color, percent) {
|
||||
var num = parseInt(color.replace("#",""), 16),
|
||||
amt = Math.round(2.55 * percent),
|
||||
R = (num >> 16) + amt,
|
||||
G = (num >> 8 & 0x00FF) + amt,
|
||||
B = (num & 0x0000FF) + amt;
|
||||
return "#" + (0x1000000 + (R<255?R<1?0:R:255)*0x10000 + (G<255?G<1?0:G:255)*0x100 + (B<255?B<1?0:B:255)).toString(16).slice(1);
|
||||
}
|
||||
|
||||
// Fetch data from API
|
||||
function fetchData() {
|
||||
var current_path = window.location.pathname;
|
||||
|
@ -233,38 +262,64 @@
|
|||
$("#outdoor-humid").text("Humidity: " + data.humidity_outdoor.toFixed(1) + "%");
|
||||
|
||||
// Is outdoor AQI healthy?
|
||||
// If AQI is less than 50, it is healthy
|
||||
// If AQI is between 50 and 100, it is unhealthy
|
||||
// If AQI is more than 100, it is very unhealthy
|
||||
var oldIcon = document.getElementById("health_icon");
|
||||
oldIcon.parentNode.removeChild(oldIcon);
|
||||
var newIcon = document.createElement("span");
|
||||
newIcon.setAttribute("class", "iconify");
|
||||
|
||||
newIcon.setAttribute("data-inline", "false");
|
||||
newIcon.id = "health_icon";
|
||||
// If AQI is less than 50, it is good
|
||||
// If AQI is between 50 and 100, it is moderate
|
||||
// If AQI is between 100 and 150, it is unhealthy for sensitive groups
|
||||
// If AQI is between 150 and 200, it is unhealthy
|
||||
// If AQI is between 200 and 300, it is very unhealthy
|
||||
// If AQI is more than 300, it is hazardous
|
||||
let root = document.documentElement;
|
||||
let root_css = getComputedStyle(root);
|
||||
let frame_darken_pct = -4;
|
||||
if (data.aqi_outdoor < 50) {
|
||||
newIcon.setAttribute("data-icon", "mdi-heart");
|
||||
Iconify.scanDOM();
|
||||
let icon_path = root_css.getPropertyValue('--icon-good').trim();
|
||||
let bg_color = root_css.getPropertyValue('--good-color').trim();
|
||||
let frame_color = darkenColor(bg_color, frame_darken_pct);
|
||||
$("#health_text").text("Healthy");
|
||||
$("#top_element").css("background-color", "#97FF55");
|
||||
$("#health_icon_frame").css("background-color", "#7bdb3f");
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#top_element").css("background-color", bg_color);
|
||||
$("#health_icon_frame").css("background-color", frame_color);
|
||||
} else if (data.aqi_outdoor >= 50 && data.aqi_outdoor < 100) {
|
||||
newIcon.setAttribute("data-icon", "mdi-smog");
|
||||
Iconify.scanDOM();
|
||||
let icon_path = root_css.getPropertyValue('--icon-moderate').trim();
|
||||
let bg_color = root_css.getPropertyValue('--moderate-color').trim();
|
||||
let frame_color = darkenColor(bg_color, frame_darken_pct);
|
||||
$("#health_text").text("Moderate");
|
||||
$("#top_element").css("background-color", "#FFD300");
|
||||
$("#health_icon_frame").css("background-color", "#f9c300");
|
||||
} else {
|
||||
newIcon.setAttribute("data-icon", "mdi-skull-crossbones");
|
||||
Iconify.scanDOM();
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#top_element").css("background-color", bg_color);
|
||||
$("#health_icon_frame").css("background-color", frame_color);
|
||||
} else if (data.aqi_outdoor >= 100 && data.aqi_outdoor < 150) {
|
||||
let icon_path = root_css.getPropertyValue('--icon-unhealthy-sensitive').trim();
|
||||
let bg_color = root_css.getPropertyValue('--unhealthy-sensitive-color').trim();
|
||||
let frame_color = darkenColor(bg_color, frame_darken_pct);
|
||||
$("#health_text").text("Unhealthy");
|
||||
$("#top_element").css("background-color", "#FF6969");
|
||||
$("#health_icon_frame").css("background-color", "#A54444");
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#top_element").css("background-color", bg_color);
|
||||
$("#health_icon_frame").css("background-color", frame_color);
|
||||
} else if (data.aqi_outdoor >= 150 && data.aqi_outdoor < 200) {
|
||||
let icon_path = root_css.getPropertyValue('--icon-unhealthy').trim();
|
||||
let bg_color = root_css.getPropertyValue('--unhealthy-color').trim();
|
||||
let frame_color = darkenColor(bg_color, frame_darken_pct);
|
||||
$("#health_text").text("Unhealthy");
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#top_element").css("background-color", bg_color);
|
||||
$("#health_icon_frame").css("background-color", frame_color);
|
||||
} else if (data.aqi_outdoor >= 200 && data.aqi_outdoor < 300) {
|
||||
let icon_path = root_css.getPropertyValue('--icon-very-unhealthy').trim();
|
||||
let bg_color = root_css.getPropertyValue('--very-unhealthy-color').trim();
|
||||
let frame_color = darkenColor(bg_color, frame_darken_pct);
|
||||
$("#health_text").text("Very Unhealthy");
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#top_element").css("background-color", bg_color);
|
||||
$("#health_icon_frame").css("background-color", frame_color);
|
||||
} else {
|
||||
let icon_path = root_css.getPropertyValue('--icon-hazardous').trim();
|
||||
let bg_color = root_css.getPropertyValue('--hazardous-color').trim();
|
||||
let frame_color = darkenColor(bg_color, frame_darken_pct);
|
||||
$("#health_text").text("Hazardous");
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#top_element").css("background-color", bg_color);
|
||||
$("#health_icon_frame").css("background-color", frame_color);
|
||||
}
|
||||
|
||||
document.getElementById("health_icon_frame").appendChild(newIcon);
|
||||
Iconify.scanDOM();
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -77,6 +77,25 @@
|
|||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
:root {
|
||||
--good-color: #ABD162;
|
||||
--moderate-color: #F7D460;
|
||||
--unhealthy-sensitive-color: #FD9760;
|
||||
--unhealthy-color: #F7666E;
|
||||
--very-unhealthy-color: #A37CBB;
|
||||
--hazardous-color: #A07685;
|
||||
--icon-good: /images/aqi-icon-l1.svg;
|
||||
--icon-moderate: /images/aqi-icon-l2.svg;
|
||||
--icon-unhealthy-sensitive: /images/aqi-icon-l3.svg;
|
||||
--icon-unhealthy: /images/aqi-icon-l4.svg;
|
||||
--icon-very-unhealthy: /images/aqi-icon-l5.svg;
|
||||
--icon-hazardous: /images/aqi-icon-l6.svg;
|
||||
}
|
||||
#health_icon {
|
||||
transform: scale(1.7);
|
||||
padding-top: 15px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
|
@ -85,7 +104,7 @@
|
|||
<div class="aqi_block" id="top_element">
|
||||
<p class="aqi_text" id="outdoor-aqi">0</p>
|
||||
</div>
|
||||
<span class="iconify" data-icon="mdi-heart" id="health_icon"></span>
|
||||
<img id="health_icon" src="">
|
||||
<p class="health_text" , id="health_text">Healthy</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -129,35 +148,51 @@
|
|||
$("#outdoor-aqi").text("AQI : "+data.aqi_outdoor);
|
||||
|
||||
// Is outdoor AQI healthy?
|
||||
// If AQI is less than 50, it is healthy
|
||||
// If AQI is between 50 and 100, it is unhealthy
|
||||
// If AQI is more than 100, it is very unhealthy
|
||||
var oldIcon = document.getElementById("health_icon");
|
||||
oldIcon.parentNode.removeChild(oldIcon);
|
||||
var newIcon = document.createElement("span");
|
||||
newIcon.setAttribute("class", "iconify");
|
||||
|
||||
newIcon.setAttribute("data-inline", "false");
|
||||
newIcon.id = "health_icon";
|
||||
// If AQI is less than 50, it is good
|
||||
// If AQI is between 50 and 100, it is moderate
|
||||
// If AQI is between 100 and 150, it is unhealthy for sensitive groups
|
||||
// If AQI is between 150 and 200, it is unhealthy
|
||||
// If AQI is between 200 and 300, it is very unhealthy
|
||||
// If AQI is more than 300, it is hazardous
|
||||
let root = document.documentElement;
|
||||
let root_css = getComputedStyle(root);
|
||||
if (data.aqi_outdoor < 50) {
|
||||
newIcon.setAttribute("data-icon", "mdi-heart");
|
||||
Iconify.scanDOM();
|
||||
let icon_path = root_css.getPropertyValue('--icon-good').trim();
|
||||
let bg_color = root_css.getPropertyValue('--good-color').trim();
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#health_text").text("Healthy");
|
||||
$("#health_icon_frame").css("background-color", "#7bdb3f");
|
||||
$("#health_icon_frame").css("background-color", bg_color);
|
||||
} else if (data.aqi_outdoor >= 50 && data.aqi_outdoor < 100) {
|
||||
newIcon.setAttribute("data-icon", "mdi-smog");
|
||||
Iconify.scanDOM();
|
||||
let icon_path = root_css.getPropertyValue('--icon-moderate').trim();
|
||||
let bg_color = root_css.getPropertyValue('--moderate-color').trim();
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#health_text").text("Moderate");
|
||||
$("#health_icon_frame").css("background-color", "#f9c300");
|
||||
} else {
|
||||
newIcon.setAttribute("data-icon", "mdi-skull-crossbones");
|
||||
Iconify.scanDOM();
|
||||
$("#health_icon_frame").css("background-color", bg_color);
|
||||
} else if (data.aqi_outdoor >= 100 && data.aqi_outdoor < 150) {
|
||||
let icon_path = root_css.getPropertyValue('--icon-unhealthy-sensitive').trim();
|
||||
let bg_color = root_css.getPropertyValue('--unhealthy-sensitive-color').trim();
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#health_text").text("Unhealthy for Sensitive Groups");
|
||||
$("#health_icon_frame").css("background-color", bg_color);
|
||||
} else if (data.aqi_outdoor >= 150 && data.aqi_outdoor < 200) {
|
||||
let icon_path = root_css.getPropertyValue('--icon-unhealthy').trim();
|
||||
let bg_color = root_css.getPropertyValue('--unhealthy-color').trim();
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#health_text").text("Unhealthy");
|
||||
$("#health_icon_frame").css("background-color", "#A54444");
|
||||
$("#health_icon_frame").css("background-color", bg_color);
|
||||
} else if (data.aqi_outdoor >= 200 && data.aqi_outdoor < 300) {
|
||||
let icon_path = root_css.getPropertyValue('--icon-very-unhealthy').trim();
|
||||
let bg_color = root_css.getPropertyValue('--very-unhealthy-color').trim();
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#health_text").text("Very Unhealthy");
|
||||
$("#health_icon_frame").css("background-color", bg_color);
|
||||
} else if (data.aqi_outdoor >= 300) {
|
||||
let icon_path = root_css.getPropertyValue('--icon-hazardous').trim();
|
||||
let bg_color = root_css.getPropertyValue('--hazardous-color').trim();
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#health_text").text("Hazardous");
|
||||
$("#health_icon_frame").css("background-color", bg_color);
|
||||
}
|
||||
|
||||
document.getElementById("health_icon_frame").appendChild(newIcon);
|
||||
Iconify.scanDOM();
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in New Issue