treemap

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: MIT Imports: 3 Imported by: 0

README

Memory efficient Treemaps

Uses "Squarified Treemaps" (Mark Bruls, Kees Huizing, and Jarke J. van Wijk., 2000) algorithm.

The original code was copied from Nikolay Dubina's treemap repo (Check resources)

$ go install github.com/MazenAlKhatib/treemap/cmd/treemap@latest
$ treemap -input your_csv_file -output-path your/output/path -w 1024 -h 1024

example

Different colorscheme

$ treemap -color RdYlGn

example-RdYlGn

Tree-Hue coloring

$ treemap -color balanced

example-balanced

Without color

$ treemap -color none

example-no-color

Format

</ delimitered path>,<size>

Algorithms

  • Squarified algorithm for treemap layout problem. This is very common algorithm used in Plotly and most of visualization packages. "Squarified Treemaps", Mark Bruls, Kees Huizing, and Jarke J. van Wijk, 2000
  • Tree-Hue Color algorithm for generating colors for nodes in treemap. The idea is to represent hierarchical structure by recursively painting similar hue to subtrees. Nikolay Dubina, 2021

Contributions

Are much appreciated!

References

Appendix A: Long Roots

When roots have one child multiple times it takes extra vertical space, which is very useful for narrow final dimensions.

example-long-roots

Can collapse them into one node example-long-roots-collapse

Long roots without collapsing somewhere deep inside

Long roots with collapsing somewhere deep inside

Appendix B: Known Issues

The entire treemap is a black box when viewed from Jenkins

It's convenient to create treemap svg reports in a Jenkins jobs, because you can browse the job's "artifacts" from your browser. However, out of the box, Jenkin's Content Security Policy prevents inline styles from being applied. Instead of your treemap, you'll see a giant black rectangle.

If you look at the javascript console in the developer tools, you will see:

Refused to apply inline style because it violates the following
Content Security Policy directive: "style-src 'self'".

You can relax Jenkin's CSP rules by following the examples at:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollapseLongPaths

func CollapseLongPaths(t *Tree)

CollapseLongPaths will collapse all long chains in tree.

func CollapseLongPathsFromNode

func CollapseLongPathsFromNode(t *Tree, nodeName string, bar *progressbar.ProgressBar)

CollapseLongPathsFromNode will collapse current node into children as long as it has single child. Will set name of this node to joined path from roots. Will set size to this child's size. Expecting Name containing either single value for current node.

func SetNamesFromPaths

func SetNamesFromPaths(t *Tree)

SetNamesFromPaths will update each node to its path leaf as name.

Types

type Node

type Node struct {
	Path string
	Name string
	Size float64
}

type SumSizeImputer

type SumSizeImputer struct {
	EmptyLeafSize float64
}

SumSizeImputer will set sum of children into empty parents and fill children with contant.

func (SumSizeImputer) ImputeSize

func (s SumSizeImputer) ImputeSize(t Tree)

func (SumSizeImputer) ImputeSizeNode

func (s SumSizeImputer) ImputeSizeNode(t Tree, node string, bar *progressbar.ProgressBar)

type Tree

type Tree struct {
	Nodes map[string]Node     // node identifier (path) -> Node
	To    map[string][]string // node identifier (path) -> list of node identifiers (paths) for edges from it (to children)
	Root  string
}

Directories

Path Synopsis
cmd
treemap command

Jump to

Keyboard shortcuts

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