Percentage change in price dom.

This commit is contained in:
Mario Zechner 2023-05-25 07:03:21 +02:00
parent 00c396644d
commit b9cf3f9e3c

View File

@ -102,7 +102,12 @@ function itemToDOM(item) {
let storeDom = dom("td", item.store);
let nameDom = dom("td", itemToStoreLink(item));
let unitDom = dom("td", item.unit ? item.unit : "");
let priceDomText = item.price + (item.priceHistory.length > 1 ? (item.priceHistory[0].price > item.priceHistory[1].price ? " 📈" : " 📉") + " (" + (item.priceHistory.length - 1) + ")" : "");
let increase = "";
if (item.priceHistory.length > 1) {
let percentageChange = Math.round((item.priceHistory[0].price - item.priceHistory[1].price) / item.priceHistory[1].price * 100);
increase = (percentageChange > 0 ? "+" + percentageChange : percentageChange) + "%";
}
let priceDomText = item.price + (item.priceHistory.length > 1 ? (item.priceHistory[0].price > item.priceHistory[1].price ? " 📈" : " 📉") + " " + increase + " (" + (item.priceHistory.length - 1) + ")" : "");
let pricesText = "";
for (let i = 0; i < item.priceHistory.length; i++) {
const date = item.priceHistory[i].date;