Help us shape the future of Go! Take the 2026 Go Developer Survey

gtree

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Unlicense Imports: 21 Imported by: 2

README

gtree

A Go package for generating family tree diagrams as SVG.

Test Status Go Report Card go.dev reference

Chart Types

  • Descendant Chart -- root person at the top, successive generations in horizontal rows below.
  • Ancestor Chart -- root person on the left, ancestors expanding to the right.
  • Fan Chart -- root person at the centre, ancestors radiating outward in concentric arcs.
  • Butterfly Chart -- root person in the middle, paternal ancestors to one side and maternal to the other.

All chart types output SVG.

Getting Started

go get github.com/iand/gtree@latest

Usage

Build a chart data structure, compute its layout, then render to SVG:

ch := &gtree.DescendantChart{
    Title: "The Smith Family",
    Root: &gtree.DescendantPerson{
        ID:       1,
        Headings: []string{"John Smith"},
        Details:  []string{"b. 1850", "d. 1914"},
        Families: []*gtree.DescendantFamily{
            {
                Other: &gtree.DescendantPerson{
                    ID:       2,
                    Headings: []string{"Jane Doe"},
                },
                Children: []*gtree.DescendantPerson{
                    {ID: 3, Headings: []string{"Alice Smith"}},
                    {ID: 4, Headings: []string{"Bob Smith"}},
                },
            },
        },
    },
}

layout, err := ch.Layout(nil) // nil uses default options
if err != nil {
    log.Fatal(err)
}

svg, err := gtree.SVG(layout, nil) // nil omits fixed paper size
if err != nil {
    log.Fatal(err)
}
fmt.Println(svg)

Ancestor charts follow the same pattern with AncestorChart and AncestorPerson:

ch := &gtree.AncestorChart{
    Title: "Ancestors of John Smith",
    Root: &gtree.AncestorPerson{
        ID:      1,
        Details: []string{"John Smith", "b. 1850"},
        Father:  &gtree.AncestorPerson{ID: 2, Details: []string{"Father Smith"}},
        Mother:  &gtree.AncestorPerson{ID: 3, Details: []string{"Mother Brown"}},
    },
}

layout, err := ch.Layout(nil)
Parsing a Descendant List

The Parser reads an indented text format into a DescendantChart:

1. John Smith (b. 1850, d. 1914)
  sp. Jane Doe (m. 1875)
    2. Alice Smith (b. 1876)
    2. Bob Smith (b. 1878)
      sp. Carol Jones (m. 1900)
        3. Eve Smith (b. 1901)
parser := new(gtree.Parser)
chart, err := parser.Parse(ctx, strings.NewReader(input))

Lines prefixed with a generation number (1, 2, 3...) are people. Lines prefixed with sp or + are spouses. Detail text goes in parentheses. See the Parser documentation for the full format.

Layout Options

Each chart type has its own options struct with defaults:

opts := gtree.DefaultLayoutOptions()       // descendant charts
opts := gtree.DefaultAncestorLayoutOptions() // ancestor charts

Options include font styles, spacing, margins, line widths, and background colour. Pass nil to Layout() to use defaults.

Examples

Runnable examples are in the repository root:

go run descendant_example.go > chart.svg
go run ancestor_example.go > chart.svg
go run butterfly_example.go > chart.svg
go run fan_example.go > chart.svg
go run parse_example.go > chart.svg

Documentation

Full API documentation is at pkg.go.dev/github.com/iand/gtree.

License

This is free and unencumbered software released into the public domain. For more information, see http://unlicense.org/ or the accompanying UNLICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ISO A Series Sizes
	PaperSizeA0Portrait  = PaperSize{Width: 841, Height: 1189}
	PaperSizeA0Landscape = PaperSize{Width: 1189, Height: 841}

	PaperSizeA1Portrait  = PaperSize{Width: 594, Height: 841}
	PaperSizeA1Landscape = PaperSize{Width: 841, Height: 594}

	PaperSizeA2Portrait  = PaperSize{Width: 420, Height: 594}
	PaperSizeA2Landscape = PaperSize{Width: 594, Height: 420}

	PaperSizeA3Portrait  = PaperSize{Width: 297, Height: 420}
	PaperSizeA3Landscape = PaperSize{Width: 420, Height: 297}

	PaperSizeA4Portrait  = PaperSize{Width: 210, Height: 297}
	PaperSizeA4Landscape = PaperSize{Width: 297, Height: 210}

	// North American Letter (8.5 × 11 inches)
	PaperSizeLetterPortrait  = PaperSize{Width: 215.9, Height: 279.4} // 8.5 × 11 inches
	PaperSizeLetterLandscape = PaperSize{Width: 279.4, Height: 215.9}
)

Functions

func DefaultSerifFontNames added in v0.0.5

func DefaultSerifFontNames() []string

func MeasureBlurb added in v0.0.5

func MeasureBlurb(b *Blurb)

func SVG

func SVG(lay Layout, ps *PaperSize) (string, error)

SVG generates an SVG (Scalable Vector Graphics) representation of the provided layout. It takes a Layout interface as input and returns a string containing the SVG markup, or an error if the generation fails.

The SVG output includes: - The XML declaration and SVG root element with specified width and height based on the layout dimensions. - A white background covering the entire SVG canvas. - The title of the chart, if provided, rendered at the top of the SVG. - Any notes, rendered below the title, with appropriate spacing. - Blurbs representing individuals or family members, each with their associated text and optional background rectangle if debug mode is enabled. - Connectors, represented as paths, connecting blurbs according to their relationships.

The function iterates over the layout elements (title, notes, blurbs, connectors), converts their properties to SVG-compatible attributes, and appends them to an internal buffer. Finally, it returns the complete SVG as a string.

func ScaleBlurb added in v0.0.5

func ScaleBlurb(b *Blurb, factor float64)

func ScaleStyle added in v0.0.5

func ScaleStyle(t *TextStyle, factor float64)

Types

type AlignedNode added in v0.0.5

type AlignedNode struct {
	ID           int
	HeadingTexts TextSection
	DetailTexts  TextSection
	Tags         []string

	// Text          []string
	CentreText          bool         // true if the text for this blurb is better presented as centred
	Width               Pixel        // Width is the horizontal extent of the Blurb
	AbsolutePositioning bool         // when true, the position of the blurb is controlled by TopPos and LeftPos, otherwise it is calculated relative to neighbours
	TopPos              Pixel        // TopPos is the absolute vertical position of the upper edge of the Blurb
	LeftPos             Pixel        // LeftPos is the absolute horizontal position of the left edge of the Blurb
	Height              Pixel        // Height is the vertical extent of the Blurb
	Col                 int          // column the blurb appears in for layouts that use columns
	Row                 int          // row the blurb appears in for layouts that use rows
	LeftPad             Pixel        // required padding to left of blurb to separate families
	NoShift             bool         // when true the left shift will not be changed
	KeepTightRight      *AlignedNode // the blurb to the right that this blurb should keep as close as possible to
	LeftNeighbour       *AlignedNode // the blurb to the left of this one, when non-nil will be used for horizontal positioning
	Parent              *AlignedNode
	TopHookOffset       Pixel // TopHookOffset is the offset from the left of the blurb where any dropped connecting line should finish (ensures it is within the bounds of the name, even if subsequent detail lines are longer)
	SideHookOffset      Pixel // SideHookOffset is the offset from the top of the blurb where any connecting line should finish

	FirstChild *AlignedNode
	LastChild  *AlignedNode
}

AlignedNode represents a visual element in the layout, typically used to display information about a person in a chart. It includes various properties to control its positioning, text content, and relationships with other blurbs.

func (*AlignedNode) Blurb added in v0.0.5

func (n *AlignedNode) Blurb() *Blurb

func (*AlignedNode) Bottom added in v0.0.5

func (b *AlignedNode) Bottom() Pixel

Bottom returns the vertical position of the lower edge of the Node

func (*AlignedNode) Left added in v0.0.5

func (b *AlignedNode) Left() Pixel

Left returns the horizontal position of the leftmost edge of the Blurb

func (*AlignedNode) Right added in v0.0.5

func (b *AlignedNode) Right() Pixel

Right returns the horizontal position of the rightmost edge of the Node

func (*AlignedNode) SideHookY added in v0.0.5

func (b *AlignedNode) SideHookY() Pixel

func (*AlignedNode) TopHookX added in v0.0.5

func (b *AlignedNode) TopHookX() Pixel

func (*AlignedNode) X added in v0.0.5

func (b *AlignedNode) X() Pixel

X returns the horizontal position of the centre of the Blurb

func (*AlignedNode) Y added in v0.0.5

func (b *AlignedNode) Y() Pixel

Y returns the vertical position of the centre of the Blurb

type Alignment added in v0.0.5

type Alignment int
const (
	AlignmentLeft   Alignment = 0
	AlignmentCenter Alignment = 1
	AlignmentRight  Alignment = 2
)

type AncestorChart

type AncestorChart struct {
	Title string
	Notes []string
	Root  *AncestorPerson
}

AncestorChart represents a horizontal ancestor chart, where the root person is positioned on the left, and successive generations extend to the right. Ancestors in each generation are aligned vertically, visually depicting the lineage from the root person to their ancestors.

func (*AncestorChart) Layout

Layout generates the layout for the ancestor chart based on the provided options.

type AncestorLayout

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

AncestorLayout represents the layout of an ancestor chart, including dimensions and layout options.

func (*AncestorLayout) Background added in v0.0.5

func (l *AncestorLayout) Background() string

func (*AncestorLayout) BackgroundColor added in v0.0.5

func (l *AncestorLayout) BackgroundColor() string

func (*AncestorLayout) Blurbs

func (l *AncestorLayout) Blurbs() []*Blurb

Blurbs returns all the blurbs in the layout.

func (*AncestorLayout) Connectors

func (l *AncestorLayout) Connectors() []*Connector

Connectors returns all the connectors in the layout.

func (*AncestorLayout) Debug

func (l *AncestorLayout) Debug() bool

Debug reports whether the layout is in debug mode.

func (*AncestorLayout) Height

func (l *AncestorLayout) Height() Pixel

Height returns the height of the layout.

func (*AncestorLayout) Legend added in v0.0.5

func (l *AncestorLayout) Legend() *Blurb

Legend returns the legend element of the layout.

func (*AncestorLayout) Margin

func (l *AncestorLayout) Margin() Pixel

Margin returns the margin of the layout.

func (*AncestorLayout) Width

func (l *AncestorLayout) Width() Pixel

Width returns the width of the layout.

type AncestorLayoutOptions

type AncestorLayoutOptions struct {
	Debug bool

	LineWidth Pixel // width of any drawn lines
	Margin    Pixel // margin to add to entire drawing
	Hspace    Pixel // the horizontal space to leave between nodes in different generations
	Vspace    Pixel // the vertical space to leave between nodes in the same generation
	LineGap   Pixel // the distance to leave between a connecting line and any text

	HookLength Pixel // the length of the line drawn from the parent or a child to the vertical line that joins them

	TitleStyle   TextStyleOption // TitleStyle is the style of the font to use for the title of the chart.
	NoteStyle    TextStyleOption // NoteStyle is the style of the font to use for the notes of the chart.
	HeadingStyle TextStyleOption // HeadingStyle is the style of the font to use for the first line of each node.
	DetailStyle  TextStyleOption // DetailStyle is the style of the font to use for the subsequent lines of each node after the first.

	DetailWrapWidth Pixel // DetailWrapWidth is the maximum width of detail text before wrapping to a new line.

	BackgroundColor string // BackgroundColor is the color of the background, empty for transparent/no-background fill
}

AncestorLayoutOptions defines various layout parameters for rendering the ancestor chart.

func DefaultAncestorLayoutOptions

func DefaultAncestorLayoutOptions() *AncestorLayoutOptions

DefaultAncestorLayoutOptions returns the default layout options for rendering the ancestor chart.

type AncestorPerson

type AncestorPerson struct {
	ID       int
	Headings []string
	Details  []string
	Father   *AncestorPerson
	Mother   *AncestorPerson
}

AncestorPerson represents an individual in the ancestor chart, including their ID, details, and their parents.

type Blurb

type Blurb struct {
	Texts     []TextSection
	Alignment Alignment

	X        Pixel   // the vertical position of the centre of the Blurb
	Y        Pixel   // the horizontal position of the centre of the Blurb
	Width    Pixel   // the horizontal extent of the Blurb
	Height   Pixel   // the vertical extent of the Blurb
	Rotation float64 //
}

Blurb represents a visual element in the layout, typically used to display information about a person in a chart.

func CenterAlignedLegend added in v0.0.5

func CenterAlignedLegend(topCenter Point, title string, titleStyle TextStyle, notes []string, noteStyle TextStyle) *Blurb

func CenterAlignedTitle added in v0.0.5

func CenterAlignedTitle(topCenter Point, title string, preTitle string, postTitle string, titleStyle TextStyle, subTitleStyle TextStyle) *Blurb

func LeftAlignedLegend added in v0.0.5

func LeftAlignedLegend(topLeft Point, title string, titleStyle TextStyle, notes []string, noteStyle TextStyle) *Blurb

func RightAlignedNotes added in v0.0.5

func RightAlignedNotes(topRight Point, notes []string, noteStyle TextStyle) *Blurb

type ButterflyChart added in v0.0.5

type ButterflyChart struct {
	TitleLine1 string
	TitleLine2 string
	Note       string
	Root       *ButterflyPerson
}

ButterflyChart represents a horizontal butterfly chart, where the parents of the root person are positioned in the centre. Successive paternal generations extend to the left and maternal generations extend to the right. Ancestors in each generation are aligned vertically, visually depicting the lineage from the root person to their ancestors.

func (*ButterflyChart) RenderSVG added in v0.0.5

func (ch *ButterflyChart) RenderSVG(opts *ButterflyLayoutOptions) (string, error)

RenderSVG renders butterfly chart as SVG based on the provided options.

type ButterflyLayoutOptions added in v0.0.5

type ButterflyLayoutOptions struct {
	Debug bool

	// Horizontals are x coordinates by generation
	// if paternal then use 5-gen to find coord
	// if maternal then use 6+gen to find coord
	Horizontals [12]float64

	// Verticals are y coordinates by generation, 6 generations
	Verticals [6][]float64

	// BoxWidths are widths of each box, by generation
	BoxWidths [6]float64

	// BoxHeights are heights of each box, by generation
	BoxHeights [6]float64

	// AscenderHorizontals are the horizontal positions of each ascender, by generation
	// if paternal then use 4-gen to find coord
	// if maternal then use 5+gen to find coord
	AscenderHorizontals [10]float64

	// AscenderVerticals are the vertical psotions of each ascender by generation, 5 generations
	AscenderVerticals       [5][]float64
	AscenderVerticalOffset  [5]float64
	AscenderVerticalSpacing [5]float64
}

ButterflyLayoutOptions defines various layout parameters for rendering the butterfly chart.

func DefaultButterflyLayoutOptions added in v0.0.5

func DefaultButterflyLayoutOptions() *ButterflyLayoutOptions

DefaultButterflyLayoutOptions returns the default layout options for rendering the butterfly chart.

type ButterflyPerson added in v0.0.5

type ButterflyPerson struct {
	ID            int
	Forenames     string
	Surname       string
	DetailLine1   string
	DetailLine2   string
	MarriageLine1 string // only used for male
	MarriageLine2 string
	Father        *ButterflyPerson
	Mother        *ButterflyPerson
}

ButterflyPerson represents an individual in the butterfly chart, including their ID, details, and their parents.

type Connector

type Connector struct {
	Points []Point
}

Connector represents a connection between two or more points in the layout, typically used to draw lines between blurbs.

type DescendantChart

type DescendantChart struct {
	Title string
	Notes []string
	Root  *DescendantPerson
}

DescendantChart represents a chart of descendants, with the earliest ancestor (root person) at the top. Each successive generation is arranged in horizontal rows, with the next generation placed directly below the previous one. This layout visually depicts the lineage, with descendants expanding downward from the root person.

func (*DescendantChart) Layout

func (ch *DescendantChart) Layout(opts *LayoutOptions) (*DescendantLayout, error)

Layout generates the layout for the descendant chart based on the provided options.

type DescendantFamily

type DescendantFamily struct {
	Other    *DescendantPerson
	Details  []string
	Children []*DescendantPerson
}

DescendantFamily represents a family unit, including the spouse and their children.

type DescendantLayout

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

DescendantLayout represents the layout of a descendant chart, including dimensions and layout options.

func (*DescendantLayout) Background added in v0.0.5

func (l *DescendantLayout) Background() string

func (*DescendantLayout) BackgroundColor added in v0.0.5

func (l *DescendantLayout) BackgroundColor() string

func (*DescendantLayout) Blurbs

func (l *DescendantLayout) Blurbs() []*Blurb

Blurbs returns all the blurbs in the layout.

func (*DescendantLayout) Connectors

func (l *DescendantLayout) Connectors() []*Connector

Connectors returns all the connectors in the layout.

func (*DescendantLayout) Debug

func (l *DescendantLayout) Debug() bool

Debug reports whether the layout is in debug mode.

func (*DescendantLayout) Height

func (l *DescendantLayout) Height() Pixel

Height returns the height of the layout.

func (*DescendantLayout) Legend added in v0.0.5

func (l *DescendantLayout) Legend() *Blurb

Title returns the legend element of the layout.

func (*DescendantLayout) Margin

func (l *DescendantLayout) Margin() Pixel

Margin returns the margin of the layout.

func (*DescendantLayout) Width

func (l *DescendantLayout) Width() Pixel

Width returns the width of the layout.

type DescendantPerson

type DescendantPerson struct {
	ID       int
	Headings []string
	Details  []string
	Families []*DescendantFamily
	Tags     []string
}

DescendantPerson represents an individual in the descendant chart, including their ID, details, and families.

type Extent added in v0.0.5

type Extent struct {
	Width  Pixel
	Height Pixel
}

Extent represents a size in the layout, defined by its width and height

type FanChart added in v0.0.5

type FanChart struct {
	Title     string     // Title displayed on the diagram.
	PreTitle  string     // A line of text to place above the title, uses subtitle style
	PostTitle string     // A line of text to place below the title, uses subtitle style
	Notes     []string   // Optional lines of annotation, shown at the edge of the layout.
	Root      *FanPerson // The subject of the chart (generation 0). All ancestors trace back from this person.
}

FanChart defines the top-level structure for a radial ancestor chart. It represents a single subject (Root) and their lineage going backward. The chart includes a title, optional notes, and a recursive ancestry tree.

type FanLayout added in v0.0.5

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

FanLayout implements the gtree.Layout interface, representing the output of a radial ancestor layout.

func GenerateFanLayout added in v0.0.5

func GenerateFanLayout(chart *FanChart, opts *FanLayoutOptions) (*FanLayout, error)

func (*FanLayout) Background added in v0.0.5

func (f *FanLayout) Background() string

func (*FanLayout) BackgroundColor added in v0.0.5

func (f *FanLayout) BackgroundColor() string

func (*FanLayout) Blurbs added in v0.0.5

func (f *FanLayout) Blurbs() []*Blurb

func (*FanLayout) Connectors added in v0.0.5

func (f *FanLayout) Connectors() []*Connector

func (*FanLayout) Debug added in v0.0.5

func (f *FanLayout) Debug() bool

func (*FanLayout) Height added in v0.0.5

func (f *FanLayout) Height() Pixel

func (*FanLayout) Legend added in v0.0.5

func (f *FanLayout) Legend() *Blurb

func (*FanLayout) Margin added in v0.0.5

func (f *FanLayout) Margin() Pixel

func (*FanLayout) Width added in v0.0.5

func (f *FanLayout) Width() Pixel

type FanLayoutOptions added in v0.0.5

type FanLayoutOptions struct {
	MaxGenerations int // Maximum number of generations to layout.
	Margin         Millimetre
	RadiusStep     float64 // Radial distance (in pixels) between generations.
	BaseFontSize   float64 // Font size for the closest generation (generation 0).
	GenScaleFactor float64 // Scaling factor applied to font size per generation (e.g. 0.85).
	AngularSpanDeg float64 // Total angular spread of the fan in degrees (e.g. 120 for 120°).
	Debug          bool
	TitleStyle     TextStyleOption // TitleStyle is the style of the font to use for the title of the chart.
	SubTitleStyle  TextStyleOption // SubTitleStyle is the style of the font to use for the pre and post titles of the chart.
	NoteStyle      TextStyleOption // NoteStyle is the style of the font to use for the notes of the chart.
	HeadingStyle   TextStyleOption // HeadingStyle is the style of the font to use for the heading lines of each node.
	DetailStyle    TextStyleOption // DetailStyle is the style of the font to use for the subsequent lines of each node after the first.
	DPI            int

	BackgroundColor string // BackgroundColor is the color of the background, empty for transparent/no-background fill
	// contains filtered or unexported fields
}

FanLayoutOptions optsures the geometric and stylistic aspects of the fan chart layout.

func DefaultFanLayoutOptions added in v0.0.5

func DefaultFanLayoutOptions() *FanLayoutOptions

DefaultAncestorLayoutOptions returns the default layout options for rendering the ancestor chart.

type FanPerson added in v0.0.5

type FanPerson struct {
	ID       int        // Unique ID used to identify this person within the chart.
	Headings []string   // Main lines of text (e.g. name), usually rendered in larger or bolder type.
	Details  []string   // Secondary lines (e.g. birth/death years, occupation).
	Father   *FanPerson // Pointer to the father, if known. nil if unknown.
	Mother   *FanPerson // Pointer to the mother, if known. nil if unknown.
}

FanPerson represents an individual in the fan chart, including their ID, details, and their parents. Information is provided as freeform lines of text, for headings and details.

type Font added in v0.0.5

type Font struct {
	Name  string
	Bytes []byte
	// contains filtered or unexported fields
}

func (*Font) MeasureWidth added in v0.0.5

func (f *Font) MeasureWidth(s string) Pixel

type FontData added in v0.0.5

type FontData struct {
	Font  *opentype.Font
	Bytes []byte
}

type Layout

type Layout interface {
	Height() Pixel
	Width() Pixel
	Margin() Pixel
	Legend() *Blurb
	Blurbs() []*Blurb
	Connectors() []*Connector
	Debug() bool
	Background() string // raw svg to use as a background
	BackgroundColor() string
}

Layout defines an interface for chart layouts, providing methods to retrieve dimensions, text elements, and layout components such as blurbs and connectors.

type LayoutOptions

type LayoutOptions struct {
	Debug      bool // Debug indicates whether to emit logging and debug information.
	Iterations int  // Number of iterations of adjustment to run

	Hspace     Pixel // Hspace is the horizontal spacing between nodes within the same family.
	LineWidth  Pixel // LineWidth is the width of the lines connecting nodes.
	Margin     Pixel // Margin is the margin added to the entire drawing.
	FamilyDrop Pixel // FamilyDrop is the length of the line drawn from parents to the children group line.
	ChildDrop  Pixel // ChildDrop is the length of the line drawn from the children group line to a child.
	LineGap    Pixel // LineGap is the distance between a connecting line and any text.

	TitleStyle   TextStyleOption // TitleStyle is the style of the font to use for the title of the chart.
	NoteStyle    TextStyleOption // NoteStyle is the style of the font to use for the notes of the chart.
	HeadingStyle TextStyleOption // HeadingStyle is the style of the font to use for the first line of each node.
	DetailStyle  TextStyleOption // DetailStyle is the style of the font to use for the subsequent lines of each node after the first.

	DetailWrapWidth Pixel // DetailWrapWidth is the maximum width of detail text before wrapping to a new line.

	BackgroundColor string // BackgroundColor is the color of the background, empty for transparent/no-background fill
}

LayoutOptions defines various layout parameters for rendering the descendant chart.

func DefaultLayoutOptions

func DefaultLayoutOptions() *LayoutOptions

DefaultLayoutOptions returns the default layout options for rendering the descendant chart.

type Millimetre added in v0.0.5

type Millimetre float64

Millimetre represents a unit of measurement used for physical dimensions. The digital sizes are determined by scaling by a dpi (dots per inch)

func (Millimetre) Pixel added in v0.0.5

func (m Millimetre) Pixel(dpi int) Pixel

type PaperSize added in v0.0.5

type PaperSize struct {
	Width  Millimetre // width in millimetres
	Height Millimetre // height in millimetres
}

func (PaperSize) ExtentAtDPI added in v0.0.5

func (ps PaperSize) ExtentAtDPI(dpi int) Extent

type Parser

type Parser struct {
	SurnameSeparateLine bool // if true the parser puts the surname on a second header line
}

A Parser parses a textual descendent list.

A descendant list is a list of person entries each consisting of a prefix followed by detail text. Each entry begins on a new line. Leading whitespace is significant (for spouse disambiguation) but trailing is not. Lines consisting only of whitespace are ignored.

The prefix of each entry denotes the relationship of the person to an earlier person. A prefix text may be a generation number followed by a dot (.) which indicates the position of the person in the family tree relative to the root ancestor. A generation number of 1 indicates the root ancestor, 2 indicates their children, and so on.

Alternatively the prefix may be the two characters 'sp' or the single character '+' which indicates that the person is the spouse of the preceding numbered person with equal or lesser indentation.

The entry text may wrap onto subsequent lines until a line with a generation number or spouse prefix is encountered.

The text after the prefix is the person's name followed by optional tags and detail text used for additional information such as birth, death, marriage, and other life events.

If the SurnameSeparateLine field is true then the name will be parsed to detect a surname, which will be placed on a seperate heading line. If the name ends in one or more words delimted by slashes '/' then these will be used as the surname, otherwise the surname will be taken to be the last whole word after a space.

All text up to the first tag delimiter or detail delimiter is to be the name of the person.

Tags may be specified by prefixing words with a hash '#'. Multiple tags may be specified. Any tags must be occur between the name and the detail text delimiter.

Detail text is delimited by parantheses '(' and ')'. All text between the parantheses is assumed to be the detail text.

Any text after the closing detail paranthesis is ignored.

The name and the detail text are trimmed to remove leading and trailing whitespace. Outer matching parantheses are removed from the detail text before trimming.

Any semicolons ';' within the detail text are treated as line breaks, resulting in multiple lines of text.

Identifiers are assigned using the line number of the person's entry. People in a family group are placed in the order the lines are read from the input.

func (*Parser) Parse

func (p *Parser) Parse(ctx context.Context, r io.Reader) (*DescendantChart, error)

type Pixel

type Pixel int

Pixel represents a unit of measurement used for digital dimensions, such as font sizes, margins, and positions.

type Point

type Point struct {
	X Pixel
	Y Pixel
}

Point represents a coordinate in the layout, defined by its X (horizontal) and Y (vertical) position.

type SpreadingDescendantArranger added in v0.0.2

type SpreadingDescendantArranger struct{}

func (*SpreadingDescendantArranger) Arrange added in v0.0.2

type TextSection added in v0.0.2

type TextSection struct {
	Lines []string
	Style TextStyle
}

type TextStyle

type TextStyle struct {
	FontSize   Pixel // FontSize is the size of the font to use for the text of each blurb.
	FontFamily string
	LineHeight Pixel // LineHeight is the vertical distance between lines of text of the same style.
	Font       *Font
	Color      string // Color is the color of the text. The default is black #000000.
}

func NewTextStyle added in v0.0.5

func NewTextStyle(opt TextStyleOption) (TextStyle, error)

func (*TextStyle) MeasureWidth added in v0.0.5

func (ts *TextStyle) MeasureWidth(s string) Pixel

type TextStyleOption added in v0.0.5

type TextStyleOption struct {
	FontNames  []string // list of font names in priority order
	FontSize   Pixel    // FontSize is the size of the font to use for the text of each node.
	Color      string   // Color is the color of the text. The default is black #000000.
	LineHeight Pixel    // TODO: remove
}

Jump to

Keyboard shortcuts

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