Documentation
¶
Index ¶
- Variables
- func DefaultSerifFontNames() []string
- func MeasureBlurb(b *Blurb)
- func SVG(lay Layout, ps *PaperSize) (string, error)
- func ScaleBlurb(b *Blurb, factor float64)
- func ScaleStyle(t *TextStyle, factor float64)
- type AlignedNode
- type Alignment
- type AncestorChart
- type AncestorLayout
- func (l *AncestorLayout) Background() string
- func (l *AncestorLayout) BackgroundColor() string
- func (l *AncestorLayout) Blurbs() []*Blurb
- func (l *AncestorLayout) Connectors() []*Connector
- func (l *AncestorLayout) Debug() bool
- func (l *AncestorLayout) Height() Pixel
- func (l *AncestorLayout) Legend() *Blurb
- func (l *AncestorLayout) Margin() Pixel
- func (l *AncestorLayout) Width() Pixel
- type AncestorLayoutOptions
- type AncestorPerson
- type Blurb
- func CenterAlignedLegend(topCenter Point, title string, titleStyle TextStyle, notes []string, ...) *Blurb
- func CenterAlignedTitle(topCenter Point, title string, preTitle string, postTitle string, ...) *Blurb
- func LeftAlignedLegend(topLeft Point, title string, titleStyle TextStyle, notes []string, ...) *Blurb
- func RightAlignedNotes(topRight Point, notes []string, noteStyle TextStyle) *Blurb
- type ButterflyChart
- type ButterflyLayoutOptions
- type ButterflyPerson
- type Connector
- type DescendantChart
- type DescendantFamily
- type DescendantLayout
- func (l *DescendantLayout) Background() string
- func (l *DescendantLayout) BackgroundColor() string
- func (l *DescendantLayout) Blurbs() []*Blurb
- func (l *DescendantLayout) Connectors() []*Connector
- func (l *DescendantLayout) Debug() bool
- func (l *DescendantLayout) Height() Pixel
- func (l *DescendantLayout) Legend() *Blurb
- func (l *DescendantLayout) Margin() Pixel
- func (l *DescendantLayout) Width() Pixel
- type DescendantPerson
- type Extent
- type FanChart
- type FanLayout
- func (f *FanLayout) Background() string
- func (f *FanLayout) BackgroundColor() string
- func (f *FanLayout) Blurbs() []*Blurb
- func (f *FanLayout) Connectors() []*Connector
- func (f *FanLayout) Debug() bool
- func (f *FanLayout) Height() Pixel
- func (f *FanLayout) Legend() *Blurb
- func (f *FanLayout) Margin() Pixel
- func (f *FanLayout) Width() Pixel
- type FanLayoutOptions
- type FanPerson
- type Font
- type FontData
- type Layout
- type LayoutOptions
- type Millimetre
- type PaperSize
- type Parser
- type Pixel
- type Point
- type SpreadingDescendantArranger
- type TextSection
- type TextStyle
- type TextStyleOption
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ScaleStyle ¶ added in v0.0.5
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 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 ¶
func (ch *AncestorChart) Layout(opts *AncestorLayoutOptions) (*AncestorLayout, error)
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 CenterAlignedTitle ¶ added in v0.0.5
func LeftAlignedLegend ¶ added in v0.0.5
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
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 (*FanLayout) BackgroundColor ¶ added in v0.0.5
func (*FanLayout) Connectors ¶ added in v0.0.5
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
func (*Font) MeasureWidth ¶ added in v0.0.5
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
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.
type Pixel ¶
type Pixel int
Pixel represents a unit of measurement used for digital dimensions, such as font sizes, margins, and positions.
type Point ¶
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
func (a *SpreadingDescendantArranger) Arrange(l *DescendantLayout)
type TextSection ¶ added in v0.0.2
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)