From 73be6f5eb4ca7293a7569c84d2638fd058b86c2d Mon Sep 17 00:00:00 2001 From: Junwei Zhao Date: Sat, 11 Jul 2020 00:06:24 +1000 Subject: [PATCH] Optimize the style --- Readme.md | 2 ++ main.go | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 1287558..08362f2 100644 --- a/Readme.md +++ b/Readme.md @@ -9,5 +9,7 @@ Create badge from your prometheus metrics ![Github Star](https://badge.home.toozhao.com/png/github) ![Air Index](https://badge.home.toozhao.com/svg/mel) +![Dockerhub Pull](https://badge.home.toozhao.com/svg/dockerhub) +![Github Star](https://badge.home.toozhao.com/svg/github) [![](https://images.microbadger.com/badges/image/wahyd4/aria2-ui.svg)](https://microbadger.com/images/wahyd4/aria2-ui "Get your own image badge on microbadger.com") diff --git a/main.go b/main.go index 2731cbf..d1a42b4 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,7 @@ const ( 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;" ) var ( @@ -95,10 +96,10 @@ func geneateSvg(client api.Client, c *gin.Context) error { // labelContainerWidth = badgeWidth * 0.5 // } canvas.Rect(0, 0, int(labelContainerWidth), badgeHeight, "fill-opacity:1.00; fill:rgb(49, 197, 83)") - canvas.Text(textMarginX, 15, metric.Label, "text-anchor:left;font-size:12px;fill:white;") + canvas.Text(textMarginX, 15, metric.Label, textStyle) valueText := strconv.Itoa(int(metric.Value)) - canvas.Text(badgeWidth-textMarginX-len(valueText)*fontSize, 15, valueText, "text-anchor:right;font-size:12px;fill:white;") + canvas.Text(badgeWidth-textMarginX-len(valueText)*fontSize, 15, valueText, textStyle) canvas.End() return nil }