From 517bd6931a52f8fc9c5f299137b3d5de99475f7f Mon Sep 17 00:00:00 2001 From: LucasWolfgang <39681420+LucasWolfgang@users.noreply.github.com> Date: Fri, 15 Apr 2022 23:55:40 -0300 Subject: [PATCH] :tada: Added more functionalities to color range Now the Range can be inverted and doesn't use the message anymore --- README.md | 6 ++++-- action.yml | 10 ++++++++-- index.js | 15 ++++++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9a0ae1d..9f15a86 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,10 @@ Gist Parameter | Description `logoPosition` | The position of the logo. `style` | The style like "flat" or "social". `cacheSeconds` | The cache lifetime in seconds (must be greater than 300). -`maxColorRange` | Maximum value for the value passaed as message. Used to define the message color. -`minColorRange` | Minimum value for the value passaed as message. Used to define the message color. +`valColorRange` | Numerical value used to define the message color. +`maxColorRange` | Maximum value in the range used to define the message color. +`minColorRange` | Minimum value in the range used to define the message color. +`invertColorRange` | If the range should be inverted, causing a smaller value to have green color. ### Using Environment Variables as Parameters [![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/schneegans/2ab8f1d386f13aaebccbd87dac94068d/raw/answer.json)](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/schneegans/2ab8f1d386f13aaebccbd87dac94068d/raw/answer.json) diff --git a/action.yml b/action.yml index 467f186..bcbb430 100644 --- a/action.yml +++ b/action.yml @@ -49,11 +49,17 @@ inputs: cacheSeconds: description: 'The cache lifetime in seconds (must be greater than 300)' required: false + valColorRange: + description: 'Numerical value used to define the message color.' + required: false maxColorRange: - description: 'Maximum value for the value passaed as message. Used to define the message color.' + description: 'Maximum value in the range used to define the message color.' required: false minColorRange: - description: 'Minimum value for the value passaed as message. Used to define the message color.' + description: 'Minimum value in the range used to define the message color.' + required: false + invertColorRange: + description: 'If the range should be inverted, causing a smaller value to have green color.' required: false runs: using: 'node12' diff --git a/index.js b/index.js index 7a542a9..5e282e8 100644 --- a/index.js +++ b/index.js @@ -24,20 +24,29 @@ try { const logoPosition = core.getInput('logoPosition'); const style = core.getInput('style'); const cacheSeconds = core.getInput('cacheSeconds'); + const valColorRange = core.getInput('valColorRange'); const minColorRange = core.getInput('minColorRange'); const maxColorRange = core.getInput('maxColorRange'); + const invertColorRange = core.getInput('invertColorRange'); if (labelColor != '') { content.labelColor = labelColor; } - if (minColorRange != '' && maxColorRange != '') { + if (minColorRange != '' && maxColorRange != '' && valColorRange != '') { var max = parseFloat(maxColorRange); var min = parseFloat(minColorRange); - var val = parseFloat(content.message); + var val = parseFloat(valColorRange); if (val < min) val = min; if (val > max) val = max; - let hue = Math.floor((val - min) / (max - min) * 100); + var hue = 0 + if (invertColorRange == '') { + hue = Math.floor((val - min) / (max - min) * 100); + message = val + " / " + max + " " + message + } else { + hue = Math.floor((max - val) / (max - min) * 100); + message = val + " " + message + } content.color = "hsl(" + hue + ", 100%, 50%)"; } else if (color != '') { content.color = color;