From 92e30b87064ceaa392b1e82829ff701efc4912d1 Mon Sep 17 00:00:00 2001 From: NorielSylvire Date: Sun, 28 Apr 2024 02:06:32 +0200 Subject: [PATCH 1/2] Editted fill attribute depending on nb of hours --- features/logtimes.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/features/logtimes.js b/features/logtimes.js index 9ea1d68..296086c 100644 --- a/features/logtimes.js +++ b/features/logtimes.js @@ -10,6 +10,23 @@ /* */ /* ************************************************************************** */ +function addBackgroundToDays(ltDays) { + for (let i = 0; i < ltDays.length; i++) { + let originalTitle = ltDays[i].getAttribute("data-original-title"); + if (!originalTitle.includes("0h00")) { + let rect = ltDays[i].getElementsByTagName("rect")[0]; + let alpha = Math.floor((parseFloat(originalTitle.charAt(0)) / 24) * 255) + .toString(16); + if (alpha.length < 2) { + alpha = "0" + alpha; + } + rect.setAttribute("fill", + getComputedStyle(rect).getPropertyValue("--theme-color") + + alpha); + } + } +} + function getLogTimes(settings) { return new Promise(function(resolve, reject) { const httpReq = new XMLHttpRequest(); @@ -207,6 +224,9 @@ function applyLogTimeChartFixes(ltSvg, settings) { if (optionIsActive(settings, "logsum-week")) { cumWeekLogTime(ltDays, settings); } + + // fill day background + addBackgroundToDays(ltDays); } if (window.location.pathname == "/" || window.location.pathname.indexOf("/users/") == 0) { From a66ddb50c7ac843d696cf57a06d0a0e6738f2de1 Mon Sep 17 00:00:00 2001 From: NorielSylvire Date: Sun, 28 Apr 2024 11:33:53 +0200 Subject: [PATCH 2/2] Changed the color ranges so that it never reaches 255, to improve readability --- features/logtimes.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/features/logtimes.js b/features/logtimes.js index 296086c..4587009 100644 --- a/features/logtimes.js +++ b/features/logtimes.js @@ -10,13 +10,17 @@ /* */ /* ************************************************************************** */ +// calculates the background color based on the theme color and nb of hours function addBackgroundToDays(ltDays) { for (let i = 0; i < ltDays.length; i++) { let originalTitle = ltDays[i].getAttribute("data-original-title"); if (!originalTitle.includes("0h00")) { let rect = ltDays[i].getElementsByTagName("rect")[0]; - let alpha = Math.floor((parseFloat(originalTitle.charAt(0)) / 24) * 255) - .toString(16); + let alpha = Math.floor((parseFloat(originalTitle.split("h")[0]) / 24) * 255); + if (alpha > 200) { + alpha = 200; + } + alpha = alpha.toString(16); if (alpha.length < 2) { alpha = "0" + alpha; }