Documentation ¶
Overview ¶
Package bitreevis implements tool whichs help visualize binary tree structure in golang.
Index ¶
- Constants
- func BiNodeIsNil(node BiNode) bool
- func CalHeight(root BiNode) int
- func CollectNodeByLevelOrder(root BiNode) [][]BiNode
- func VisAsSvg(root BiNode, filename string, opt *RenderOption) error
- type BiNode
- type FieldHolder
- type PaintableBiNode
- type PlaceableNode
- func (p *PlaceableNode) CollectNodes() []*PlaceableNode
- func (p *PlaceableNode) CollectNodesWithStat() (nodes []*PlaceableNode, limit *SizeLimitStat)
- func (p *PlaceableNode) GetField() string
- func (p *PlaceableNode) GetLeftChild() BiNode
- func (p *PlaceableNode) GetRightChild() BiNode
- func (p *PlaceableNode) IsLeaf() bool
- type RenderOption
- type RenderResult
- type Renderer
- type SizeLimitStat
- type SvgRenderResult
- type SvgRenderer
Constants ¶
const ( DefaultBackgroundColor = "white" DefaultNodeColor = "#868383" DefaultNodeStrokeWidth = 1 DefaultNodeFieldTextSize = 16 DefaultNodeFieldTextColor = "black" DefaultEdegLineWidth = 2 DefaultEdgeColor = "black" DefaultEdgeArrowSize = 2 DefaultEdgeLineWidth = 2 )
Default settings for the graphic
Variables ¶
This section is empty.
Functions ¶
func BiNodeIsNil ¶
BiNodeIsNil reports whether the BiNode interface is nil.
If BiNode interface itself is nil, BiNodeIsNil returns true. If BiNode interface itself is not nil, but the data of interface is nil, BiNodeIsNil returns true
func CalHeight ¶
CalHeight calculates the height of a binary tree in a recursive manner.
If root does not have any children, CalHeight returns 1. If root is nil, returns 0.
func CollectNodeByLevelOrder ¶
CollectNodeByLevelOrder collects all nodes in a binary tree in level order.
CollectNodeByLevelOrder returns nodes from top to down, from left to right, in the form of [][]BiNode
Types ¶
type BiNode ¶
type BiNode interface { FieldHolder GetLeftChild() BiNode GetRightChild() BiNode }
A BiNode represents a node in binary tree.
BiNode specify the minumum elements of a node in binary tree, which are left child, right child and content of node.
type FieldHolder ¶
type FieldHolder interface {
GetField() string
}
A FieldHolder is an interface for storing content of a node in binary tree.
GetField() should return a string .
type PaintableBiNode ¶ added in v1.1.0
type PaintableBiNode interface { BiNode // GetColor returns a color string for this node. GetColor() string }
PaintableBiNode represents a node whose color is private. You can implement this interface if you want each of your node to have different colors.
type PlaceableNode ¶
type PlaceableNode struct { Parent *PlaceableNode Left *PlaceableNode Right *PlaceableNode X float32 Y float32 Offset float32 Thread bool Field string Color string }
PlaceableNode represents a node which can be placed and rendered.
PlaceableNode's attributes follow the definition in algorithm of Tidier Drawings of Trees by Edward M. Reingold and John S. Tilford.
func NewPlaceableNode ¶
func NewPlaceableNode(field string) *PlaceableNode
NewPlaceableNode returns a new *PlaceableNode with spefified field value.
func NewPlaceableTreeFromBiNode ¶
func NewPlaceableTreeFromBiNode(root BiNode) *PlaceableNode
NewPlaceableTreeFromBiNode builds a tree made of placeableNode from a tree made of BiNode
func PerformLayout ¶
func PerformLayout(root *PlaceableNode, siblingSeparation, nodeWidth, levelSeparation int) *PlaceableNode
func (*PlaceableNode) CollectNodes ¶
func (p *PlaceableNode) CollectNodes() []*PlaceableNode
func (*PlaceableNode) CollectNodesWithStat ¶
func (p *PlaceableNode) CollectNodesWithStat() (nodes []*PlaceableNode, limit *SizeLimitStat)
func (*PlaceableNode) GetField ¶
func (p *PlaceableNode) GetField() string
func (*PlaceableNode) GetLeftChild ¶
func (p *PlaceableNode) GetLeftChild() BiNode
Implement interface BiNode for placeableNode
func (*PlaceableNode) GetRightChild ¶
func (p *PlaceableNode) GetRightChild() BiNode
func (*PlaceableNode) IsLeaf ¶
func (p *PlaceableNode) IsLeaf() bool
type RenderOption ¶
type RenderOption struct { // BackgroundColor specifies the global background color of the whole graphic. BackgroundColor string // BackgroundColor specifies the horizontal padding of the graphic on one size. HorizontalPadding int // BackgroundColor specifies the vertical padding of the graphic on one size. VerticalPadding int // SiblingSeparation specifies the minimum gap between two sibling nodes. SiblingSeparation int // LevelSeparation specifies the gap between two different levels. LevelSeparation int // NodeRadius specifies the radius of node. NodeRadius int // NodeColor specifies the color of nodes. NodeColor string // NodeColor specifies the color of leaf nodes, if not specified, NodeColor is used. NodeLeafColor string // NodeStrokeColor specifies the stroke color of nodes. NodeStrokeColor string // NodeStrokeWidth specifies the stroke-width of nodes. NodeStrokeWidth int // NodeFieldTextSize specifies the font size inside of node. NodeFieldTextSize int // NodeFieldTextColor specifies the color of font inside of node. NodeFieldTextColor string // EdgeLineWidth specifies the width of edges which connects nodes. EdgeLineWidth int // EdgeLineWidth specifies the color of edges which connects nodes. EdgeLineColor string // EdgeWithArrow specifies whether to use arrow at the end of edge EdgeWithArrow bool // EdgeArrowSize specifies the arrow size of edge EdgeArrowSize int }
RenderOption is the options of graphics when rendering.
All units related to position and size are pixel(px).
type RenderResult ¶
type RenderResult interface { // GetContent return an io.Reader which can be used to access the rendered data. GetContent() io.Reader // Save helps save the rendered data into a given file. Save(string) error // Error returns the error occurred during rendering. If no error occurs, it returns nil. Error() error }
RenderResult contains rendered output from renderer.
RenderResult should contain a reader which can be read (for example, bytes, string, etc.) from the outsize. GetContent() method returns an io.Reader which provides access to the rendered data.
Save method can save the rendered result to the given filepath.
Error method provides a way for the user to check the error occurred during the rendering process. If no error occurs during rendering, Error should return nil.
type Renderer ¶
type Renderer interface {
Render(*PlaceableNode, RenderOption) RenderResult
}
Render is the interface which defines how to render the binary tree.
type SizeLimitStat ¶
type SvgRenderResult ¶
type SvgRenderResult struct {
// contains filtered or unexported fields
}
SvgRenderResult implements the RenderResult interface. It is the render result for SvgRenderer
func (*SvgRenderResult) Error ¶
func (r *SvgRenderResult) Error() error
func (*SvgRenderResult) GetContent ¶
func (r *SvgRenderResult) GetContent() io.Reader
GetContent returns the inner buffer of the rendered result The actual type of the returned io.Reader is strings.Reader.
func (*SvgRenderResult) Save ¶
func (r *SvgRenderResult) Save(filename string) error
Save save the svg graphic into the given file.
type SvgRenderer ¶
SvgRenderer is a renderer which can render the binary tree into svg format.
func (*SvgRenderer) Render ¶
func (sr *SvgRenderer) Render(root *PlaceableNode, option *RenderOption) RenderResult
Render performs rendering process for specified binary tree.