svgsequence

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: MIT Imports: 9 Imported by: 1

README

svg-sequence

Small go library and CLI tool to generate sequence diagrams in SVG format.

Usage

As a library
package main

import (
	"fmt"

	svgsequence "github.com/aorith/svg-sequence"
)

func main() {
	s := svgsequence.NewSequence()

	s.AddStep(svgsequence.Step{SourceActor: "Bob", TargetActor: "Maria", Description: "Hi! How are you doing?"})
	s.OpenSection("response", "")
	s.AddStep(svgsequence.Step{
		SourceActor: "Maria", TargetActor: "Maria",
		Description: "*Thinks*\nLong time no see...",
		Color:       "#667777",
	})
	s.AddStep(svgsequence.Step{SourceActor: "Maria", TargetActor: "Bob", Description: "Fine!"})
	s.CloseSection()
	svg, err := s.Generate()
	if err != nil {
		panic(err)
	}
	fmt.Println(svg)
}

This will print a basic SVG that you can save and open in the browser.

Using the CLI

Check the command at cmd/cli.

See cmd/cli/examples for config examples.

# Install the CLI tool or run it from cmd/cli
go install github.com/aorith/svg-sequence/cmd/cli@latest

# Generate a sequence from a config file
$ svgsequence -i complete.cfg -o /tmp/sequence.svg

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateFromCFG

func GenerateFromCFG(filename string) (string, error)

GenerateFromCFG generates the sequence by parsing a config file

Types

type Sequence

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

func NewSequence

func NewSequence() *Sequence

func (*Sequence) AddActors

func (s *Sequence) AddActors(actors ...string)

AddActors adds the given actors to the sequence, in order use this to ensure the order of the actors in the sequence

func (*Sequence) AddStep

func (s *Sequence) AddStep(step Step)

AddStep adds a new step to the sequence diagram.

func (*Sequence) CloseSection

func (s *Sequence) CloseSection()

CloseSection closes the open section

func (*Sequence) Generate

func (s *Sequence) Generate() (string, error)

Generate generates a new SVG sequence

func (*Sequence) OpenSection

func (s *Sequence) OpenSection(name, color string)

OpenSection opens a new section to the sequence diagram. An open section must be closed after adding the steps which should be placed in it.

Parameters:

  • name: Required name of the section.
  • color: Optional CSS color value (e.g., "#ff0000", "red"). Pass an empty string to use the default color.

func (*Sequence) SetDistance

func (s *Sequence) SetDistance(d int)

SetDistance sets the distance between actors

func (*Sequence) SetHeight

func (s *Sequence) SetHeight(height string)

SetHeight sets the SVG height.

Any CSS value for size is valid, including pixels or percentages.

func (*Sequence) SetWidth

func (s *Sequence) SetWidth(width string)

SetWidth sets the SVG width.

Any CSS value for size is valid, including pixels or percentages.

type Step

type Step struct {
	// Description: Optional text displayed above the arrow or mark.
	Description string

	// SourceActor: Required name of the actor that initiates the action.
	SourceActor string

	// TargetActor: Required name of the actor that receives the action.
	//
	// It can be the same as sourceActor.
	TargetActor string

	// Color: Optional CSS color value (e.g., "#ff0000", "red").
	//
	// Pass an empty string to use the default color.
	Color string
	// contains filtered or unexported fields
}

Directories

Path Synopsis
cmd
cli command

Jump to

Keyboard shortcuts

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