Small fix for colors in vaccination widget

This commit is contained in:
Benny 2021-07-05 12:14:08 +02:00
parent fa1244787d
commit e32aa1a7ca

View file

@ -3,9 +3,11 @@
// icon-color: red; icon-glyph: syringe; // icon-color: red; icon-glyph: syringe;
/************** /**************
Version 2.0.0 Version 2.0.1
Changelog: Changelog:
v2.0.1
- Use different colors for the circules
v2.0.0 v2.0.0
- Show "at least one" and "fully" vaccination in Medium and small widget - Show "at least one" and "fully" vaccination in Medium and small widget
- Upgrade to v2 of the API - Upgrade to v2 of the API
@ -136,21 +138,12 @@ function creatProgress(percentage) {
} }
function getDiagram(percentage, percentage2) { function getDiagram(percentage, percentage2) {
function drawArc(ctr, rad, w, deg) { function drawArc(ctr, rad, w, deg, color) {
bgx = ctr.x - rad bgx = ctr.x - rad
bgy = ctr.y - rad bgy = ctr.y - rad
bgd = 2 * rad bgd = 2 * rad
bgr = new Rect(bgx, bgy, bgd, bgd) bgr = new Rect(bgx, bgy, bgd, bgd)
let color
if (percentage > thresholds.green) {
color = Color.green()
} else if (percentage > thresholds.amber) {
color = Color.orange()
} else {
color = Color.red()
}
canvas.setFillColor(color) canvas.setFillColor(color)
canvas.setStrokeColor(Color.gray()) canvas.setStrokeColor(Color.gray())
canvas.setLineWidth(w) canvas.setLineWidth(w)
@ -180,18 +173,35 @@ function getDiagram(percentage, percentage2) {
canvas.opaque = false canvas.opaque = false
canvas.size = new Size(canvSize, canvSize) canvas.size = new Size(canvSize, canvSize)
canvas.respectScreenScale = true canvas.respectScreenScale = true
let color, color2
if (percentage > thresholds.green) {
color = Color.green()
} else if (percentage > thresholds.amber) {
color = Color.orange()
} else {
color = Color.red()
}
if (percentage2 > thresholds.green) {
color2 = Color.green()
} else if (percentage > thresholds.amber) {
color2 = Color.orange()
} else {
color2 = Color.red()
}
drawArc( drawArc(
new Point(canvSize / 2, canvSize / 2), new Point(canvSize / 2, canvSize / 2),
canvRadius, canvRadius,
canvWidth, canvWidth,
Math.floor(percentage * 3.6) Math.floor(percentage * 3.6),
color
) )
drawArc( drawArc(
new Point(canvSize / 2, canvSize / 2), new Point(canvSize / 2, canvSize / 2),
canvRadius - 15, canvRadius - 15,
canvWidth, canvWidth,
Math.floor(percentage2 * 3.6) Math.floor(percentage2 * 3.6),
color2
) )
const canvTextRect = new Rect( const canvTextRect = new Rect(