graph

package
v0.1.4-0...-8b98d0b Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNodeNotFound is returned when a node is not found.
	ErrNodeNotFound = errors.New("node not found")
	// ErrPartialTemplate is returned when root node template is missing or
	// partial.
	ErrPartialTemplate = errors.New("partial or missing template")
)
View Source
var (
	// RootNodeID is empty UUDI, filled with zeros, id of the root node.
	RootNodeID = uuid.Nil //nolint:gochecknoglobals // constant.
	// RootNodePath is empty path, root node path.
	RootNodePath = pathutil.NodePath("") //nolint:gochecknoglobals // constant.
)

Functions

This section is empty.

Types

type Metrics

type Metrics struct {
	Nodes      int    `json:"nodes"`
	FinalNodes int    `json:"finalNodes"`
	Depth      metric `json:"depth"`
	Leafs      metric `json:"leafs"`
}

Metrics groups all nodes metrics.

type Node

type Node struct {
	Path    pathutil.NodePath `json:"path"`
	Header  NodeHeader        `json:"header"`
	Content string            `json:"content"`
}

Node describes a single node.

func (*Node) AddSub

func (n *Node) AddSub(p Provider, name string) (*Node, error)

AddSub new node as child with name.

func (*Node) ChildNodes

func (n *Node) ChildNodes(p Provider) ([]*Node, error)

ChildNodes returns all child nodes of node.

func (*Node) FillID

func (n *Node) FillID() (uuid.UUID, error)

FillID fills nodes id if it is empty.

func (*Node) GetLeafs

func (n *Node) GetLeafs(r Reader) ([]*Node, error)

GetLeafs returns all leafs of node.

func (*Node) GetTemplate

func (n *Node) GetTemplate(p Provider) (*NodeTemplate, error)

GetTemplate returns the first template encountered when walking up the tree.

func (*Node) Metrics

func (n *Node) Metrics(p Provider) (*Metrics, error)

Metrics calculates metrics for node.

func (*Node) Name

func (n *Node) Name() string

Name returns the name of a node. That being either the defined name in node header or first element of nodes path.

func (*Node) Parent

func (n *Node) Parent(p Provider) (*Node, error)

Parent returns parent of node.

func (*Node) Template

func (n *Node) Template(
	p Provider,
	rawName string,
) (*NodeTemplate, *TemplateData, error)

Template prepares n nodes template. Walking up the graph tree to find a base template and setting template data to be used to fill template fields.

func (*Node) Walk

func (n *Node) Walk(
	r Reader,
	callback func(depth int, node *Node) (shouldWalkLeafs bool, err error),
) error

Walk to every child node recursively starting from n. callback is called for every child node. callback is called for n with depth 0.

type NodeHeader

type NodeHeader struct {
	ID          uuid.UUID      `yaml:"id"`
	DisplayName string         `yaml:"displayName,omitempty"`
	Weight      int            `yaml:"weight,omitempty"`
	Template    *NodeTemplate  `yaml:"template,omitempty"`
	Any         map[string]any `yaml:",inline"`
}

NodeHeader describes info stored in nodes header.

type NodeTemplate

type NodeTemplate struct {
	DisplayName string        `yaml:"displayName,omitempty"`
	PathName    string        `yaml:"pathName,omitempty"`
	Weight      string        `yaml:"weight,omitempty"`
	Content     string        `yaml:"content,omitempty"`
	Template    *NodeTemplate `yaml:"template,omitempty"`
}

NodeTemplate describes a template data of a node.

func (*NodeTemplate) FillContent

func (nt *NodeTemplate) FillContent(td *TemplateData) (string, error)

FillContent fills templated node content.

func (*NodeTemplate) FillNames

func (nt *NodeTemplate) FillNames(td *RawTemplateData) (string, string, error)

FillNames returns templated nodes display name and path name.

func (*NodeTemplate) FillWeight

func (nt *NodeTemplate) FillWeight(td *TemplateData) (int, error)

FillWeight fills templated node weight.

type Provider

type Provider interface {
	Reader
	Writer
}

Provider describes graph node manipulations.

type RawTemplateData

type RawTemplateData struct {
	RawName   string // name that user provided.
	Day       int    // day of the month   1,2,..31
	Month     int    // month of the year 1,2,3...12
	MonthName string // month name in English
	Year      int

	Week        int    // week number of the year
	Weekday     int    // number of the weekday 1,2...7
	WeekdayName string // monday (1), tuesday(2)...sunday
	YearDay     int    // day of the year 1,2,...365

	// next ++ increment of weight of largest sibling node
	WeightAutoincrement int

	Smile string // random gyph smile
}

RawTemplateData describes the template fields available to unprocessed template fillers, like FillName.

type Reader

type Reader interface {
	GetByID(id uuid.UUID) (*Node, error)
	GetByPath(path pathutil.NodePath) (*Node, error)
	GetLeafs(path pathutil.NodePath) ([]*Node, error)
}

Reader describes graph read operations.

type RootsProvider

type RootsProvider interface {
	Roots() ([]*Node, error)
	Reader
	Writer
}

RootsProvider describes a provider implementation with an additional Roots method that can retrieve root nodes separately.

type TemplateData

type TemplateData struct {
	RawTemplateData
	// fields populated when template is executed.
	DisplayName string
	PathName    string
}

TemplateData describes data that can be used in node templates.

type Writer

type Writer interface {
	Move(id uuid.UUID, path pathutil.NodePath) error
	Write(node *Node) error
	Delete(node *Node) error
}

Writer describes graph write operations.

Jump to

Keyboard shortcuts

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