// Package examples demonstrates diagram export functionality package main import ( "fmt" "log" "os" "mermaid-go/pkg/exporter" "mermaid-go/pkg/parser" ) func main() { fmt.Println("=== Mermaid-Go Export Examples ===") // Create exporter exp := exporter.NewDiagramExporter() mermaidParser := parser.NewMermaidParser() // Test different diagram types examples := []struct { name string input string filename string }{ { name: "Pie Chart", input: `pie showData title Market Share 2024 "Company A" : 45 "Company B" : 30 "Company C" : 15 "Others" : 10`, filename: "pie_chart", }, { name: "Organization Chart", input: `organization title Company Structure CEO[Chief Executive Officer] CEO --> CTO[Chief Technology Officer] CEO --> CFO[Chief Financial Officer] CTO --> DevManager[Development Manager] DevManager --> Developer[Senior Developer]`, filename: "org_chart", }, { name: "Flowchart", input: `flowchart TD A[Start] --> B{Decision} B -->|Yes| C[Process] B -->|No| D[End] C --> D`, filename: "flowchart", }, { name: "Sequence Diagram", input: `sequenceDiagram participant User participant System User ->> System: Login Request System -->> User: Login Response User ->> System: Data Request System -->> User: Data Response`, filename: "sequence", }, { name: "Gantt Chart", input: `gantt title Project Timeline dateFormat YYYY-MM-DD section Planning Requirements : 2024-01-01, 5d Design : 2024-01-06, 3d section Development Backend : 2024-01-09, 10d Frontend : 2024-01-15, 8d`, filename: "gantt", }, } // Create output directory outputDir := "output" if err := os.MkdirAll(outputDir, 0755); err != nil { log.Fatalf("Failed to create output directory: %v", err) } // Export each example for i, example := range examples { fmt.Printf("\n--- Example %d: %s ---\n", i+1, example.name) // Parse diagram diagram, err := mermaidParser.Parse(example.input) if err != nil { log.Printf("Failed to parse %s: %v", example.name, err) continue } // Export to SVG svgOptions := &exporter.ExportOptions{ Format: exporter.FormatSVG, Width: 800, Height: 600, Theme: "default", } svgFile := fmt.Sprintf("%s/%s.svg", outputDir, example.filename) err = exp.ExportToFile(diagram, svgFile, svgOptions) if err != nil { log.Printf("Failed to export %s to SVG: %v", example.name, err) } else { fmt.Printf("✅ Exported SVG: %s\n", svgFile) } // Show file size if svgInfo, err := os.Stat(svgFile); err == nil { fmt.Printf(" SVG size: %d bytes\n", svgInfo.Size()) } } // Demonstrate different export options fmt.Printf("\n--- Custom Export Options ---\n") // Large size export pieInput := `pie showData title Large Size Export "Data A" : 40 "Data B" : 35 "Data C" : 25` diagram, err := mermaidParser.Parse(pieInput) if err != nil { log.Printf("Failed to parse pie chart: %v", err) } else { // Large SVG largeOptions := &exporter.ExportOptions{ Format: exporter.FormatSVG, Width: 1600, Height: 1200, Theme: "default", } largeFile := fmt.Sprintf("%s/large_pie.svg", outputDir) err = exp.ExportToFile(diagram, largeFile, largeOptions) if err != nil { log.Printf("Failed to export large SVG: %v", err) } else { fmt.Printf("✅ Exported large SVG: %s\n", largeFile) if info, err := os.Stat(largeFile); err == nil { fmt.Printf(" Size: %d bytes (1600x1200)\n", info.Size()) } } } // Show supported formats and diagram types fmt.Printf("\n--- Export Capabilities ---\n") fmt.Printf("Supported formats: %v\n", exp.GetSupportedFormats()) fmt.Printf("Supported diagram types: %v\n", exp.GetSupportedDiagramTypes()) fmt.Printf("\n=== Export Examples Complete ===\n") fmt.Printf("Check the '%s' directory for exported files!\n", outputDir) }