treemap

package module
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 1 Imported by: 7

README

🍬 Pretty Treemaps

Looking to run this for Go coverage? Check https://github.com/nikolaydubina/go-cover-treemap

Go Reference codecov Go Report Card OpenSSF Scorecard

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

$ go install github.com/nikolaydubina/treemap/cmd/treemap@latest 
$ echo '
Africa/Algeria,33333216,72
Africa/Angola,12420476,42
Africa/Benin,8078314,56
...
' | treemap > out.svg

example

Adjusting size

$ ... | treemap -w 1080 -h 360 > out.svg

example-narrow

$ ... | treemap -w 1080 -h 1080 > out.svg

example-square

Imputing heat

$ ... | treemap -impute-heat > out.svg

example-narrow

Different colorscheme

$ ... | treemap -color RdYlGn > out.svg

example-RdYlGn

Tree-Hue coloring when there is no heat

$ ... | treemap -color balanced > out.svg

example-balanced

Without color

$ ... | treemap -color none > out.svg

example-no-color

Format

Size and heat is optional.

</ delimitered path>,<size>,<heat>

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

Welcomed!

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: Less Illustrative Examples

Large dimensions and large tree (e.g. github.com/golang/go)

$ ... | treemap -w 4096 -h 4096 > out.svg

example-large

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollapseLongPaths added in v1.2.0

func CollapseLongPaths(t *Tree)

CollapseLongPaths will collapse all long chains in tree.

func CollapseLongPathsFromNode added in v1.2.0

func CollapseLongPathsFromNode(t *Tree, nodeName string)

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 and heat to this child's size and heat. Expecting Name containing either single value for current node.

func SetNamesFromPaths added in v1.1.0

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
	Heat    float64
	HasHeat bool
}

type SumSizeImputer added in v1.0.2

type SumSizeImputer struct {
	EmptyLeafSize float64
}

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

func (SumSizeImputer) ImputeSize added in v1.0.2

func (s SumSizeImputer) ImputeSize(t Tree)

func (SumSizeImputer) ImputeSizeNode added in v1.0.2

func (s SumSizeImputer) ImputeSizeNode(t Tree, node string)

type Tree

type Tree struct {
	Nodes map[string]Node
	To    map[string][]string
	Root  string
}

func (Tree) HasHeat

func (t Tree) HasHeat() bool

func (Tree) HeatRange

func (t Tree) HeatRange() (minHeat float64, maxHeat float64)

func (Tree) NormalizeHeat

func (t Tree) NormalizeHeat()

type WeightedHeatImputer added in v1.0.2

type WeightedHeatImputer struct {
	EmptyLeafHeat float64
}

WeightedHeatImputer will make color of parent to weighted sum of colors of its children.

func (WeightedHeatImputer) ImputeHeat added in v1.0.2

func (s WeightedHeatImputer) ImputeHeat(t Tree)

func (WeightedHeatImputer) ImputeHeatNode added in v1.0.2

func (s WeightedHeatImputer) ImputeHeatNode(t Tree, node string)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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