squarify

package module
v0.0.0-...-f38712e Latest Latest
Warning

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

Go to latest
Published: May 17, 2015 License: MIT Imports: 1 Imported by: 3

README

squarify

GoDoc

Go implementation of the Squarified Treemaps algorithm of Bruls, Huizing, and Van Wijk:

http://www.win.tue.nl/~vanwijk/stm.pdf

The basic idea is to generate a tiling of items of various sizes, each of which may have children which are tiled nested inside their parent.

Sample TreeMap

Documentation

Overview

Package squarify implements the Squarified Treemap algorithm of Bruls, Huizing, and Van Wijk:

http://www.win.tue.nl/~vanwijk/stm.pdf

The basic idea is to generate a tiling of items of various sizes, each of which may have children which are tiled nested inside their parent.

Tiling is performed by calling the Squarify() function.

Index

Constants

View Source
const (
	// Vertical lays out the row vertically
	Vertical direction = iota
	// Horizontal lays out the row horizontally
	Horizontal
)
View Source
const (
	// DoSort may be used in the Options struct to request sorting
	DoSort = true
	// DontSort may be used in the Options struct to decline sorting
	DontSort = false
)

Variables

This section is empty.

Functions

func Squarify

func Squarify(root TreeSizer, rect Rect, options Options) (blocks []Block, meta []Meta)

Squarify implements the Squarified Treemap algorithm. It lays out the children of root inside the area represented by rect with areas proportional to the Size() of the children. Squarify returns a slice of Blocks for rendering and a slice of Metas which contain metadata corresponding to the Blocks. Element block[i] has metadata in meta[i].

Types

type Block

type Block struct {
	// Position and size of the layed-out TreeSizer
	Rect
	// The TreeSizer represented by this Block
	TreeSizer TreeSizer
}

Block represents the output for a single TreeSizer node from Squarify(). It's the layed-out position and size of the TreeSizer node and the associated TreeSizer that it represents.

type Margins

type Margins struct {
	L, R, T, B float64
}

Margins defines the empty space that should exist between a parent Block and it's internal children Blocks when layed out. Similar to how the margins of a page separate the content from the page edges. The left (L), right (R), top (T) and bottom (B) margins are specified separately.

type Meta

type Meta struct {
	// Depth is the depth of the Block in the TreeSizer tree, starting from 0.
	// This is useful when coloring the blocks, for example.
	Depth int
}

Meta is metadata that is returned by Squarify() for each Block it lays out.

type Options

type Options struct {
	// Maximum depth in the tree to descend to. Blocks at depth <= MaxDepth are layed out,
	// and > MaxDepth are ignored. Depth is counted starting at the children of the root node being 1.
	// If MaxDepth is left as the zero value then a MaxDepth of 20 is used.
	MaxDepth int
	// Margins between a parent and it's children.
	Margins *Margins
	// Sort the blocks by size within their parent. This pushes larger blocks to the left/above
	// smaller blocks.
	Sort bool
	// MinW and MinH limit the smallness of Blocks that are output. Blocks who's width is < MinW
	// or who's height is < MinH are not output, nor are their children processed.
	MinW, MinH float64
}

Options controls how Squarify() behaves.

type Rect

type Rect struct {
	X, Y, W, H float64
}

Rect represents a two-dimensional rectangle having the upper-left corner at coordinate (X,Y) and having width W and height H.

type TreeSizer

type TreeSizer interface {
	// Size is the logical size of the item and will be used to compute it's area. The size of
	// a node must be greater than or equal to the sum of the sizes of it's children.
	Size() float64
	// NumChildren is the number of children that this tree node has.
	NumChildren() int
	// Child returns the child of this node at the specified index.
	Child(i int) TreeSizer
}

The TreeSizer interface must be implemented by any tree that will be Squarified. Each node in the tree implements TreeSizer.

Directories

Path Synopsis
examples
svg

Jump to

Keyboard shortcuts

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