README.md
1.43 Kb · 56 lines
gauge
- SVG progress bars
Generate progress bars and gauges as SVG images with customizable styling and labels.
Usage
1// Basic gauge with default config
2gauge := gauge.Render(75, 100, "Progress", "#4caf50", gauge.DefaultConfig)
3
4// Custom configuration
5config := gauge.Config{
6 PercentOnly: true,
7 Width: 400,
8 CanvasHeight: 40,
9 FontSize: 18,
10 PaddingH: 10,
11}
12gauge := gauge.Render(33, 50, "Loading", "#2196f3", config)
13
14// Different styles
15progress := gauge.Render(8, 10, "Health", "#f44336", gauge.DefaultConfig)
API Reference
1type Config struct {
2 PercentOnly bool // Only display the percentage on the right side
3 Width int // Width of the gauge in pixels
4 CanvasHeight int // Height of the gauge in pixels
5 FontSize int // Font size of the text in pixels
6 PaddingH int // Horizontal padding (for the text) in pixels
7}
8
9var DefaultConfig = Config{
10 PercentOnly: false,
11 Width: 300,
12 CanvasHeight: 30,
13 FontSize: 16,
14 PaddingH: 6,
15}
16
17// value: Current value (must be ≤ total)
18// total: Maximum value (must be > 0)
19// label: Text label displayed on the left
20// color: Fill color (hex format, e.g., "#4caf50")
21// config: Configuration options
22// Returns: SVG string as markdown image
23func Render(value int, total int, label string, color string, config Config) string