graphs

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package graphs provides the graphs tree component for displaying Zabbix items.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractCategory

func ExtractCategory(key string, categories []string) string

ExtractCategory determines the category for an item based on its key. Returns the matching category prefix or "Other" if no match.

func FormatCategoryName

func FormatCategoryName(prefix string) string

FormatCategoryName formats a category key prefix into a display name.

Types

type HostExpandedMsg

type HostExpandedMsg struct {
	HostID string
}

HostExpandedMsg is sent when a host node is expanded and needs history loading.

type Model

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

Model represents the graphs tree component.

func New

func New(styles *theme.Styles) Model

New creates a new graphs tree model.

func (*Model) ClickNode

func (m *Model) ClickNode(visibleIndex int) tea.Cmd

ClickNode handles a click on a tree node at the given visible index. It selects the node and toggles expansion if it's a parent node. Returns a command if history needs to be loaded.

func (*Model) CollapseAll

func (m *Model) CollapseAll()

CollapseAll collapses all nodes.

func (Model) Count

func (m Model) Count() (total, visible int)

Count returns the total item count and visible node count.

func (*Model) ExpandAll

func (m *Model) ExpandAll()

ExpandAll expands all nodes.

func (Model) GetHistory

func (m Model) GetHistory(itemID string) []zabbix.History

GetHistory returns the history data for an item.

func (Model) GetHostItems

func (m Model) GetHostItems(hostID string) []zabbix.Item

GetHostItems returns all items belonging to a specific host.

func (*Model) GoToBottom

func (m *Model) GoToBottom()

GoToBottom moves the cursor to the last item.

func (*Model) GoToTop

func (m *Model) GoToTop()

GoToTop moves the cursor to the first item.

func (Model) HasHostHistory

func (m Model) HasHostHistory(hostID string) bool

HasHostHistory returns true if history has been loaded for any item of the host.

func (Model) Init

func (m Model) Init() tea.Cmd

Init implements tea.Model.

func (Model) IsHostLoading

func (m Model) IsHostLoading(hostID string) bool

IsHostLoading returns true if the host is currently loading history.

func (*Model) MergeHistory

func (m *Model) MergeHistory(history map[string][]zabbix.History)

MergeHistory adds history data for items without clearing existing data.

func (*Model) MoveDown

func (m *Model) MoveDown()

MoveDown moves the cursor down.

func (*Model) MoveUp

func (m *Model) MoveUp()

MoveUp moves the cursor up.

func (*Model) PageDown

func (m *Model) PageDown()

PageDown moves the cursor down by one page.

func (*Model) PageUp

func (m *Model) PageUp()

PageUp moves the cursor up by one page.

func (*Model) Scroll

func (m *Model) Scroll(delta int)

Scroll scrolls the list by delta lines (positive = down, negative = up).

func (Model) Selected

func (m Model) Selected() *TreeNode

Selected returns the currently selected node.

func (Model) SelectedItem

func (m Model) SelectedItem() *zabbix.Item

SelectedItem returns the currently selected item (if the selection is an item node).

func (*Model) SetFocused

func (m *Model) SetFocused(focused bool)

SetFocused sets the focus state.

func (*Model) SetHistory

func (m *Model) SetHistory(history map[string][]zabbix.History)

SetHistory updates history data for items and regenerates sparklines.

func (*Model) SetHostLoading

func (m *Model) SetHostLoading(hostID string, loading bool)

SetHostLoading sets the loading state for a host.

func (*Model) SetItems

func (m *Model) SetItems(items []zabbix.Item, categories []string)

SetItems updates the items and rebuilds the tree, preserving expanded state.

func (*Model) SetSize

func (m *Model) SetSize(width, height int)

SetSize sets the component dimensions.

func (*Model) SetStyles added in v0.5.0

func (m *Model) SetStyles(styles *theme.Styles)

SetStyles updates the component's styles (for runtime theme changes).

func (*Model) SetTextFilter

func (m *Model) SetTextFilter(filter string)

SetTextFilter sets the text filter (not implemented for tree yet).

func (*Model) Toggle

func (m *Model) Toggle() string

Toggle toggles expand/collapse of the current node. Returns the host ID if a host was expanded and needs history loading, empty string otherwise.

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update implements tea.Model.

func (Model) View

func (m Model) View() string

View implements tea.Model.

func (Model) VisibleNodeCount

func (m Model) VisibleNodeCount() int

VisibleNodeCount returns the number of currently visible nodes.

type NodeType

type NodeType int

NodeType represents the type of tree node.

const (
	NodeTypeHost NodeType = iota
	NodeTypeCategory
	NodeTypeItem
)

Node type constants.

type Tree

type Tree struct {
	Roots       []*TreeNode          // Top-level host nodes
	FlatList    []*TreeNode          // Flattened visible nodes (for rendering)
	AllNodes    map[string]*TreeNode // All nodes by ID
	ItemsByHost map[string][]zabbix.Item
}

Tree represents a collapsible tree of hosts, categories, and items.

func BuildTree

func BuildTree(items []zabbix.Item, categories []string) *Tree

BuildTree constructs a tree from items grouped by host and category. Items are organized as: Host -> Category -> Item

func NewTree

func NewTree() *Tree

NewTree creates an empty tree.

func (*Tree) CollapseAll

func (t *Tree) CollapseAll()

CollapseAll collapses all nodes.

func (*Tree) ExpandAll

func (t *Tree) ExpandAll()

ExpandAll expands all nodes.

func (*Tree) FindNodeIndex

func (t *Tree) FindNodeIndex(id string) int

FindNodeIndex returns the visible index of a node by ID.

func (*Tree) GetNode

func (t *Tree) GetNode(id string) *TreeNode

GetNode returns a node by ID.

func (*Tree) GetVisibleNode

func (t *Tree) GetVisibleNode(index int) *TreeNode

GetVisibleNode returns the node at the given visible index.

func (*Tree) ItemCount

func (t *Tree) ItemCount() int

ItemCount returns the total number of items in the tree.

func (*Tree) RebuildFlatList

func (t *Tree) RebuildFlatList()

RebuildFlatList regenerates the flattened list of visible nodes.

func (*Tree) ToggleNode

func (t *Tree) ToggleNode(id string)

ToggleNode toggles the collapsed state of a node.

func (*Tree) VisibleCount

func (t *Tree) VisibleCount() int

VisibleCount returns the number of visible nodes.

type TreeNode

type TreeNode struct {
	ID        string       // Unique identifier
	Name      string       // Display name
	Type      NodeType     // Type of node
	Collapsed bool         // Whether children are hidden
	Children  []*TreeNode  // Child nodes
	Depth     int          // Nesting depth
	Item      *zabbix.Item // For item nodes, the actual item
	HostID    string       // Host ID for category/item nodes
	Category  string       // Category name for item nodes
}

TreeNode represents a node in the tree structure.

Jump to

Keyboard shortcuts

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