svgsequence

package module
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: MIT Imports: 10 Imported by: 1

README

svg-sequence

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

Usage

As a library

Check the reference documentation

package main

import (
	"fmt"

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

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

	s.AddStep(svgsequence.Step{Source: "Bob", Target: "Maria", Text: "Hi! How are you doing?"})
	s.OpenSection("response", nil)
	s.AddStep(svgsequence.Step{
		Source: "Maria", Target: "Maria",
		Text: "*Thinks*\nLong time no see...",
		Color:       "#667777",
	})
	s.AddStep(svgsequence.Step{Source: "Maria", Target: "Bob", Text: "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 SectionConfig added in v0.0.16

type SectionConfig struct {
	Color         string // Optional CSS color value (e.g., " #ff0000", "red").
	WithoutBorder bool   // Section is drawn without a border.
}

SectionConfig holds optional configuration for a section.

type Sequence

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

func NewSequence

func NewSequence() *Sequence

func (*Sequence) Actors added in v0.0.13

func (s *Sequence) Actors() []string

Actors returns the current list of actors

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) AppendActors added in v0.0.13

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

AppendActors ensures that an actor exists if it does not, the actor is appended (thus appears the last)

func (*Sequence) CloseAllSections added in v0.0.6

func (s *Sequence) CloseAllSections()

CloseAllSections closes all the sections. Use only if you cannot guarantee an open/close sequence for the sections.

func (*Sequence) CloseSection

func (s *Sequence) CloseSection()

CloseSection closes the last 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 string, cfg *SectionConfig)

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.
  • config: Optional 'SectionConfig' configuration. Pass nil to use defaults.

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) SetStepHeight added in v0.0.7

func (s *Sequence) SetStepHeight(h int)

SetStepHeight sets the height of each step in the sequence.

func (*Sequence) SetVerticalSectionText added in v0.0.11

func (s *Sequence) SetVerticalSectionText(b bool)

SetVerticalSectionText sets the section text vertically on the left

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 {
	// Text: Optional text displayed above the arrow or mark.
	Text string

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

	// Target: Required name of the actor that receives the action.
	//
	// It can be the same as sourceActor.
	Target 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