Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new feature to allow a color range #11

Merged
merged 9 commits into from Apr 18, 2022
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -80,6 +80,12 @@ 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).
`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.
`colorRangeSaturation` | Saturation used by the color range feature. Defaults to 100%.
`colorRangeLightness` | Lightness used by the color range feature. Defaults to 40%.

LucasWolfgang marked this conversation as resolved.
Show resolved Hide resolved
### 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)

Expand Down
18 changes: 18 additions & 0 deletions action.yml
Expand Up @@ -49,6 +49,24 @@ 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 in the range used to define the message color.'
required: false
minColorRange:
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
colorRangeSaturation:
description: 'Saturation used by the color range feature. Defaults to 100%.'
required: false
colorRangeLightness:
description: 'Lightness used by the color range feature. Defaults to 40%.
required: false
runs:
LucasWolfgang marked this conversation as resolved.
Show resolved Hide resolved
using: 'node12'
main: 'index.js'
29 changes: 28 additions & 1 deletion index.js
Expand Up @@ -24,12 +24,39 @@ 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');
const colorRangeSaturation = core.getInput('colorRangeSaturation');
const colorRangeLightness = core.getInput('colorRangeLightness');

LucasWolfgang marked this conversation as resolved.
Show resolved Hide resolved
if (labelColor != '') {
content.labelColor = labelColor;
}

if (color != '') {
if (minColorRange != '' && maxColorRange != '' && valColorRange != '') {
const max = parseFloat(maxColorRange);
const min = parseFloat(minColorRange);
const val = parseFloat(valColorRange);
if (val < min) val = min;
if (val > max) val = max;
let hue = 0;
if (invertColorRange == '') {
hue = Math.floor((val - min) / (max - min) * 120);
} else {
hue = Math.floor((max - val) / (max - min) * 120);
}
let sat = 100;
if(colorRangeSaturation != '') {
sat = colorRangeSaturation;
}
let lig = 40;
if(colorRangeLightness != '') {
lig = colorRangeLightness;
}
content.color = "hsl(" + hue + ", " + sat + "%, " + lig + "%)";
} else if (color != '') {
content.color = color;
}

Expand Down