graph

package
v0.0.0-...-e50112c Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Combo

type Combo struct {
	Id      string                  `json:"id,omitempty"`       // 组合 ID,在一个图中唯一
	Type    string                  `json:"type,omitempty"`     // 组合类型(可选,可以用于指示 Data 的结构)
	ComboId string                  `json:"combo_id,omitempty"` // 父级 Combo 的 ID
	Data    mapUtil.StringObjectMap `json:"data,omitempty"`     // 节点数据
}

Combo 组合

type Direction

type Direction int

Direction 连线方向

const (
	LeftToRight Direction = 0 // -->
	RightToLeft Direction = 1 // <--
	BothWay     Direction = 2 // <->
)

func (Direction) String

func (i Direction) String() string

type Graph

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

Graph 图结构

func New

func New() *Graph

New 创建一个图

func (*Graph) AddCombo

func (this *Graph) AddCombo(combo ...*Combo) error

AddCombo 添加组合框

注意:在变更数据之后,需要调用 Update 更新图。

返回值:

error: 如果要添加的组合框已经存在,则会报 “combo 'xxx' already exists” 错误。

func (*Graph) AddLine

func (this *Graph) AddLine(line ...*Line) error

AddLine 添加连线

注意:在变更数据之后,需要调用 Update 更新图。

返回值:

error: 如果要添加的连线已经存在,则会报 “line 'xxx' already exists” 错误。

func (*Graph) AddNode

func (this *Graph) AddNode(node ...*Node) error

AddNode 添加节点

注意:在变更数据之后,需要调用 Update 更新图。

返回值:

error: 如果要添加的节点已经存在,则会报 “node 'xxx' already exists” 错误。

func (*Graph) ComboCount

func (this *Graph) ComboCount() int

ComboCount 获取组合数量

func (*Graph) DeleteCombo

func (this *Graph) DeleteCombo(ids ...string)

DeleteCombo 删除指定的组合

注意:在变更数据之后,需要调用 Update 更新图。

func (*Graph) DeleteLine

func (this *Graph) DeleteLine(ids ...string)

DeleteLine 删除指定的连线

注意:在变更数据之后,需要调用 Update 更新图。

func (*Graph) DeleteNode

func (this *Graph) DeleteNode(ids ...string)

DeleteNode 删除指定的节点

注意:在变更数据之后,需要调用 Update 更新图。

func (*Graph) FindCombo

func (this *Graph) FindCombo(f ...func(combo *Combo) bool) []*Combo

func (*Graph) FindLine

func (this *Graph) FindLine(f ...func(line *Line, left, right *Node) bool) []*Line

func (*Graph) FindNode

func (this *Graph) FindNode(f ...func(node *Node) bool) []*Node

func (*Graph) GetCombo

func (this *Graph) GetCombo(id string) *Combo

根据 ‘组合 ID’ 获取组合信息

func (*Graph) GetLine

func (this *Graph) GetLine(id string) *Line

根据 ‘连线 ID’ 获取连线信息

func (*Graph) GetNode

func (this *Graph) GetNode(id string) *Node

根据 ‘节点 ID’ 获取节点信息

func (*Graph) GetNodeLines

func (this *Graph) GetNodeLines(id string) []*Line

根据 ‘节点 ID’,获取与该节点直接关联的连线

func (*Graph) GetNodeNeighbours

func (this *Graph) GetNodeNeighbours(id string) []*Node

根据 ‘节点 ID’,获取与该节点直接关联的邻居节点。

func (*Graph) LineCount

func (this *Graph) LineCount() int

LineCount 获取连线数量

func (*Graph) NodeCount

func (this *Graph) NodeCount() int

NodeCount 获取节点数量

func (*Graph) Traversal

func (this *Graph) Traversal(from, to string, f ...func(path *Path, ended bool) bool) []*Path

路径搜索:

搜索能够联通起止的节点的所有路径。

参数:

from: 起始节点 ID
to:   截至节点 ID
f:    回调函数,如果该函数返回 false 则会停止在当前路径上的搜索。
      参数:
        path: 当前路径,包含路径上的所有节点和连线(节点数等于连线数+1,因为包含一个起始节点)。
              比如:可以通过 return len(path.Line) < maxDepth 限制搜索路径的最大深度。

func (*Graph) Update

func (this *Graph) Update() (err error)

Update 更新图结构,并校验数据,确认数据格式正确。

当变更了节点、连线、组合时调用。

返回:

err: 当校验失败时返回对应的错误:
  * 节点的 ComboId 非空、但不存在对应的 Combo;
  * 节点的 ComboId 非空、但不存在对应的 Combo;

type Line

type Line struct {
	Id        string                  `json:"id,omitempty"`        // 连线 ID,在一个图中唯一
	Left      string                  `json:"left,omitempty"`      // 左侧节点 ID
	Right     string                  `json:"right,omitempty"`     // 右侧节点 ID
	Direction Direction               `json:"direction,omitempty"` // 连线方向
	Type      string                  `json:"type,omitempty"`      // 连线类型(可选,可以用于指示 Data 的结构)
	Data      mapUtil.StringObjectMap `json:"data,omitempty"`      // 节点数据
}

Line 节点间的连线

type Node

type Node struct {
	Id      string                  `json:"id,omitempty"`       // 节点 ID,在一个图中唯一
	Level   int                     `json:"level,omitempty"`    // 节点层级(可选,可以用于树状布局时指定 节点 的层级)
	Type    string                  `json:"type,omitempty"`     // 节点类型(可选,可以用于指示 Data 的结构)
	ComboId string                  `json:"combo_id,omitempty"` // 节点所属的 Combo 的 ID
	Data    mapUtil.StringObjectMap `json:"data,omitempty"`     // 节点数据
}

Node 节点

type Path

type Path struct {
	Node []*Node `json:"node,omitempty"` // 该路径上的节点列表
	Line []*Line `json:"line,omitempty"` // 该路径上的连线列表
}

Path 路径

func (*Path) NodeIndex

func (this *Path) NodeIndex(id string) int

func (*Path) String

func (this *Path) String() string

func (*Path) ToString

func (this *Path) ToString(sep ...string) string

拼接路径上所有的 ‘节点 ID’,参数可以指定分隔符。

Jump to

Keyboard shortcuts

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