mirror of
https://github.com/wahyd4/badger.git
synced 2026-08-09 05:15:58 +10:00
Styling updates
This commit is contained in:
@@ -21,19 +21,20 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/prometheus/common/model"
|
||||
logrus "github.com/sirupsen/logrus"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
// backgroundImageFilename = "images/bg.png"
|
||||
radius = 0
|
||||
fontSize = 12
|
||||
textMarginX = 5.0
|
||||
textMarginX = 6.0
|
||||
textMarginY = -2.0
|
||||
badgeWidth = 180
|
||||
badgeHeight = 20
|
||||
textStyle = "text-anchor:right;font-size:12px;fill:white;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji;"
|
||||
textStyle = "text-anchor:start;font-size:12px;fill:white;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji;"
|
||||
badgeExpireSeconds = 120
|
||||
labelWidthPortion = 0.65
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -134,11 +135,12 @@ func generateSVG(client api.Client, c *gin.Context) error {
|
||||
canvas.Rect(0, 0, badgeWidth, badgeHeight, "fill-opacity:1.00; fill:rgb(90,90,90); padding: 2px 5px;")
|
||||
|
||||
//labelContainerWidth := len(metric.Label)*fontSize + textMarginX
|
||||
labelContainerWidth := badgeWidth * 0.6
|
||||
|
||||
labelContainerWidth := badgeWidth * labelWidthPortion
|
||||
// if labelContainerWidth < badgeWidth*0.5 {
|
||||
// labelContainerWidth = badgeWidth * 0.5
|
||||
// }
|
||||
canvas.Rect(0, 0, int(labelContainerWidth), badgeHeight, "fill-opacity:1.00; fill:rgb(49, 197, 83); padding: 2px 5px; float: right")
|
||||
canvas.Rect(0, 0, int(labelContainerWidth), badgeHeight, "fill-opacity:1.00; fill:rgb(49, 197, 83); padding: 2px 5px;")
|
||||
|
||||
label := metric.Label
|
||||
//when there is metric label then use default label
|
||||
@@ -148,7 +150,7 @@ func generateSVG(client api.Client, c *gin.Context) error {
|
||||
canvas.Text(textMarginX, 15, label, textStyle)
|
||||
|
||||
valueText := strconv.Itoa(int(metric.Value))
|
||||
canvas.Text(badgeWidth*0.7, 15, valueText, textStyle)
|
||||
canvas.Text(badgeWidth*labelWidthPortion+textMarginX, 15, valueText, textStyle)
|
||||
canvas.End()
|
||||
badgeGenerationTime.Observe(float64(time.Now().Sub(startTime).Microseconds()))
|
||||
badgeRequested.With(map[string]string{"badge": queryName}).Inc()
|
||||
|
||||
Reference in New Issue
Block a user