Search Apps Documentation Source Content File Folder Download Copy Actions Download

piechart.gno

3.01 Kb · 111 lines
  1package charts
  2
  3import (
  4	"gno.land/p/samcrew/piechart"
  5)
  6
  7// RenderPieChartExample creates a simple data distribution pie chart example
  8func RenderPieChartExample() string {
  9	data := []piechart.PieSlice{
 10		{Value: 35, Color: "#e74c3c", Label: "Category A"},
 11		{Value: 25, Color: "#3498db", Label: "Category B"},
 12		{Value: 20, Color: "#2ecc71", Label: "Category C"},
 13		{Value: 15, Color: "#f39c12", Label: "Category D"},
 14		{Value: 5, Color: "#9b59b6", Label: "Category E"},
 15	}
 16	return piechart.Render(data, "Data Distribution Example")
 17}
 18
 19// Render renders the piechart documentation page
 20func RenderPieChart() string {
 21	// Multiple piechart examples
 22	basicExample := RenderPieChartExample()
 23
 24	// Custom example with different data
 25	customData := []piechart.PieSlice{
 26		{Value: 40, Color: "#FF6B6B", Label: "Red Section"},
 27		{Value: 30, Color: "#4ECDC4", Label: "Teal Section"},
 28		{Value: 20, Color: "#45B7D1", Label: "Blue Section"},
 29		{Value: 10, Color: "#96CEB4", Label: "Green Section"},
 30	}
 31	customExample := piechart.Render(customData, "Custom Color Example")
 32
 33	// Small dataset example
 34	smallData := []piechart.PieSlice{
 35		{Value: 70, Color: "#FF9F43", Label: "Majority"},
 36		{Value: 30, Color: "#686DE0", Label: "Minority"},
 37	}
 38	smallExample := piechart.Render(smallData, "Simple Split")
 39
 40	return `
 41# [Piechart](/p/samcrew/piechart) Documentation
 42
 43Generate pie charts with label as SVG images.
 44
 45## Basic Usage
 46
 47` + "```go" + `
 48import "gno.land/p/samcrew/piechart"
 49
 50data := []piechart.PieSlice{
 51    {Value: 35, Color: "#e74c3c", Label: "Category A"},
 52    {Value: 25, Color: "#3498db", Label: "Category B"},
 53    {Value: 20, Color: "#2ecc71", Label: "Category C"},
 54    {Value: 15, Color: "#f39c12", Label: "Category D"},
 55    {Value: 5, Color: "#9b59b6", Label: "Category E"},
 56}
 57chart := piechart.Render(data, "Data Distribution Example")
 58` + "```" + `
 59
 60` + basicExample + `
 61
 62---
 63
 64## Custom Colors Example
 65
 66` + "```go" + `
 67customData := []piechart.PieSlice{
 68    {Value: 40, Color: "#FF6B6B", Label: "Red Section"},
 69    {Value: 30, Color: "#4ECDC4", Label: "Teal Section"},
 70    {Value: 20, Color: "#45B7D1", Label: "Blue Section"},
 71    {Value: 10, Color: "#96CEB4", Label: "Green Section"},
 72}
 73chart := piechart.Render(customData, "Custom Color Example")
 74` + "```" + `
 75
 76` + customExample + `
 77
 78---
 79
 80## Simple Split Example
 81
 82` + "```go" + `
 83simpleData := []piechart.PieSlice{
 84    {Value: 70, Color: "#FF9F43", Label: "Majority"},
 85    {Value: 30, Color: "#686DE0", Label: "Minority"},
 86}
 87chart := piechart.Render(simpleData, "Simple Split")
 88` + "```" + `
 89
 90` + smallExample + `
 91
 92## API Reference
 93
 94` + "```go" + `
 95type PieSlice struct {
 96    Value float64 // Numeric value for the slice
 97    Color string  // Hex color code (e.g., "#ff6b6b")
 98    Label string  // Display label for the slice
 99}
100
101// slices: Array of PieSlice structs containing the data
102// title: Chart title (empty string for no title)
103// Returns: SVG markup as a string
104func Render(slices []PieSlice, title string) string
105` + "```" + `
106
107---
108
109[← Back to Charts](/r/docs/charts) | [View Package](/p/samcrew/piechart)
110`
111}