svg

package
v0.0.27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer handles SVG generation

func NewRenderer

func NewRenderer(config *decision_tree.Config) *Renderer

NewRenderer creates a new SVG renderer

func (*Renderer) RenderTree

func (r *Renderer) RenderTree(root *decision_tree.Node) string

RenderTree generates SVG for the entire tree

func (*Renderer) SetCenterParent

func (r *Renderer) SetCenterParent(center bool)

SetCenterParent sets whether parent nodes should be centered over their children

type Server added in v0.0.18

type Server struct {
	// contains filtered or unexported fields
}

Server serves SVG content dynamically

func NewServer added in v0.0.18

func NewServer(renderer *Renderer) *Server

NewServer creates a new SVG server with the given renderer

func (*Server) Serve added in v0.0.18

func (s *Server) Serve(tree *decision_tree.Node) error

Serve starts serving the SVG content for the given tree. It automatically selects an available port starting from 12137, and prints the URL to console. The server runs until Stop is called or the process receives SIGINT/SIGTERM.

Example
// Create a simple tree
tree := &decision_tree.Node{
	ID:    "root",
	Label: "Root",
	Children: []*decision_tree.Node{
		{
			ID:    "child",
			Label: "Child",
		},
	},
}

// Create and start server
server := NewServer(nil)
go func() {
	if err := server.Serve(tree); err != http.ErrServerClosed {
		fmt.Printf("server error: %v\n", err)
	}
}()

// Wait a bit for server to start
time.Sleep(100 * time.Millisecond)

// Stop server after demonstration
server.Stop()

// Output will be something like:
// SVG server running at: http://localhost:12137
// Server stop requested...

func (*Server) ServeFile added in v0.0.18

func (s *Server) ServeFile(filename string) error

ServeFile starts serving SVG content from the given JSON file. The file should contain a JSON representation of a decision_tree.Node. The server will read the file on each request to ensure latest content.

func (*Server) SetPortNotifier added in v0.0.18

func (s *Server) SetPortNotifier(ch chan<- int)

SetPortNotifier sets a channel to receive the port number when the server starts. This is primarily used for testing.

func (*Server) Stop added in v0.0.18

func (s *Server) Stop() error

Stop stops the server gracefully

func (*Server) UpdateFile added in v0.0.18

func (s *Server) UpdateFile(filename string) error

UpdateFile updates the file path being served (when in file mode)

func (*Server) UpdateTree added in v0.0.18

func (s *Server) UpdateTree(tree *decision_tree.Node)

UpdateTree updates the tree being served (when in memory mode)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL