There is one “problem” with the active stroke, it is already full around 85%
I think that is because the start of the active border is not in the middle (but on the left) of the rect?
custom_fields:
RectP: |
[[[
const state = states['sensor.afzuigkap_programma_voortgang'].state;
let bgActiveColor;
if (state >= 90) {
bgActiveColor = '#00ae5b';
} else if (state >= 50) {
bgActiveColor = '#ffbe3e';
} else if (state >= 25) {
bgActiveColor = '#ff9532';
} else if (state >= 0) {
bgActiveColor = '#ff3e3e';
} else {
bgActiveColor = 'rgba(217,217,217,0.1)';
}
const value = Math.abs(states['sensor.afzuigkap_programma_voortgang'].state);
const fill = 'rgba(255,255,255,0.7)';
const bgColor = '#d9d9d9';
const width = 60;
const height = 26;
const dashArray = 2 * (width + height);
const dashOffset = dashArray * (1 - value / 100);
return `
<svg viewBox="0 0 75 75">
<rect x="8" y="8" width="${width}" height="${height}"
rx="12" ry="12"
stroke="${bgColor}" stroke-width="1" fill="${fill}" />
<rect x="8" y="8" width="${width}" height="${height}"
rx="12" ry="12"
stroke="${bgActiveColor}" stroke-width="2" fill="none"
stroke-dasharray="${dashArray}" stroke-dashoffset="${dashOffset}" />
<text x="38" y="23" fill="rgba(62, 62, 62, 1.0);"
font-weight="normal" font-size="16" font-family="Sans-serif"
text-anchor="middle" dominant-baseline="middle" alignment-baseline="middle">
${value}%
</text>
</svg>`;
]]]