Upate logic of how we calculate svg length

This commit is contained in:
2024-10-02 20:50:36 +10:00
parent cba5a0109f
commit ded61890e4
+4 -16
View File
@@ -288,23 +288,11 @@ func (handler *BadgesHandler) generateSVG(c *gin.Context, colorScheme ColorSchem
label := metric.Label
valueRectWidth := 40
labelContainerWidth := 120
// TODO find a better way to handle this
if len(label) <= 10 {
labelContainerWidth = 74
} else if len(label) >= 20 && len(label) < 25 {
labelContainerWidth = 150
} else if len(label) >= 25 {
labelContainerWidth = 174
}
labelContainerWidth := 110
// Calculate labelContainerWidth based on label length
labelContainerWidth = len(label)*6 + 20
if metricValue > 10000 && metricValue < 100000 {
valueRectWidth = 50
} else if metricValue >= 100000 {
valueRectWidth = 66
} else if metricValue >= 1000000 {
valueRectWidth = 82
}
valueRectWidth = len(strconv.Itoa(metricValue))*6 + 21
badgeWidth := labelContainerWidth + valueRectWidth
w := c.Writer