gauge.gno
2.54 Kb · 100 lines
1package charts
2
3import (
4 "gno.land/p/samcrew/gauge"
5)
6
7// RenderGaugeExample creates a simple gauge bar example
8func RenderGaugeExample() string {
9 return gauge.Render(75, 100, "Progress", "#2ecc71", gauge.DefaultConfig)
10}
11
12// Render renders the gauge documentation page
13func RenderGauge() string {
14 // Multiple gauge examples
15 basicExample := RenderGaugeExample()
16
17 // Custom config example
18 customConfig := gauge.Config{
19 PercentOnly: true,
20 Width: 400,
21 CanvasHeight: 35,
22 FontSize: 14,
23 PaddingH: 8,
24 }
25 customExample := gauge.Render(90, 100, "Loading", "#3498db", customConfig)
26
27 // Different progress example
28 progressExample := gauge.Render(33, 50, "Health", "#e74c3c", gauge.DefaultConfig)
29
30 return `
31# [Gauge](/p/samcrew/gauge) Documentation
32
33Generate progress bars and gauges as SVG images with customizable styling and labels.
34
35## Basic Usage
36
37` + "```go" + `
38import "gno.land/p/samcrew/gauge"
39
40// Basic gauge with default config
41gauge := gauge.Render(75, 100, "Progress", "#2ecc71", gauge.DefaultConfig)
42` + "```" + `
43
44` + basicExample + `
45
46## Custom Configuration Example
47
48` + "```go" + `
49config := gauge.Config{
50 PercentOnly: true, // Show only percentage
51 Width: 400, // Custom width in pixels
52 CanvasHeight: 35, // Custom height in pixels
53 FontSize: 14, // Font size in pixels
54 PaddingH: 8, // Horizontal padding in pixels
55}
56gauge := gauge.Render(90, 100, "Loading", "#3498db", config)
57` + "```" + `
58
59` + customExample + `
60
61## Different Progress Example
62
63` + "```go" + `
64healthGauge := gauge.Render(33, 50, "Health", "#e74c3c", gauge.DefaultConfig)
65` + "```" + `
66
67` + progressExample + `
68
69## API Reference
70
71` + "```go" + `
72type Config struct {
73 PercentOnly bool // Only display the percentage on the right side
74 Width int // Width of the gauge in pixels
75 CanvasHeight int // Height of the gauge in pixels
76 FontSize int // Font size of the text in pixels
77 PaddingH int // Horizontal padding (for the text) in pixels
78}
79
80var DefaultConfig = Config{
81 PercentOnly: false,
82 Width: 300,
83 CanvasHeight: 30,
84 FontSize: 16,
85 PaddingH: 6,
86}
87
88// value: Current value (must be ≤ total)
89// total: Maximum value (must be > 0)
90// label: Text label displayed on the left
91// color: Fill color (hex format, e.g., "#4caf50")
92// config: Configuration options
93// Returns: SVG string as markdown image
94func Render(value int, total int, label string, color string, config Config) string
95` + "```" + `
96---
97
98[← Back to Charts](/r/docs/charts) | [View Package](/p/samcrew/gauge)
99`
100}