mirror of
https://github.com/wahyd4/badger.git
synced 2026-08-13 15:26:11 +10:00
refactoring
This commit is contained in:
@@ -1 +1,2 @@
|
||||
.vscode
|
||||
.idea
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# Badger
|
||||
|
||||
Create badge from your prometheus metrics
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
@@ -24,6 +24,8 @@ const (
|
||||
fontSize = 12
|
||||
textMarginX = 5.0
|
||||
textMarginY = -2.0
|
||||
badgeWidth = 180
|
||||
badgeHeight = 20
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -73,7 +75,7 @@ func generateBadge(client api.Client, c *gin.Context) error {
|
||||
}
|
||||
metric := queryMetric(client, query)
|
||||
|
||||
dc := gg.NewContext(180, 22)
|
||||
dc := gg.NewContext(badgeWidth, badgeHeight)
|
||||
fontPath := filepath.Join("fonts", "SourceCodePro-Regular.ttf")
|
||||
if err := dc.LoadFontFace(fontPath, fontSize); err != nil {
|
||||
return fmt.Errorf("load font %w", err)
|
||||
@@ -90,6 +92,9 @@ func generateBadge(client api.Client, c *gin.Context) error {
|
||||
dc.SetColor(query.Color)
|
||||
|
||||
labelContainerWidth := labelWidth + textMarginX*2
|
||||
if labelContainerWidth < badgeWidth*0.5 {
|
||||
labelContainerWidth = badgeWidth * 0.5
|
||||
}
|
||||
|
||||
dc.DrawRectangle(0, 0, labelContainerWidth, float64(dc.Height()))
|
||||
dc.Fill()
|
||||
|
||||
Reference in New Issue
Block a user