Diagrams.Dendrogram
Description
This module contain functions for drawing diagrams of dendrograms.
- dendrogram :: (Monoid m, Renderable (Path R2) b) => Width -> (a -> AnnDiagram b R2 m) -> Dendrogram a -> AnnDiagram b R2 m
- data Width
- dendrogramPath :: Dendrogram X -> Path R2
- fixedWidth :: Double -> Dendrogram a -> (Dendrogram X, Double)
- variableWidth :: Monoid m => (a -> AnnDiagram b R2 m) -> Dendrogram a -> (Dendrogram X, AnnDiagram b R2 m)
- type X = Double
- hcatB :: Monoid m => [AnnDiagram b R2 m] -> AnnDiagram b R2 m
High-level interface
Given a dendrogram dendro :: and a function Dendrogram adrawItem :: a -> Diagram b R2 for drawing the items on the leaves of dendro, just use to draw a diagram of dendrogram Variable drawItem dendro :: Diagram b R2dendro.
Runnable example which produces something like https://patch-tag.com/r/felipe/hierarchical-clustering-diagrams/snapshot/current/content/pretty/example.png:
import Data.Clustering.Hierarchical (Dendrogram(..)) import Diagrams.Prelude (Diagram, R2, atop, lw, pad, roundedRect, text, (#)) import Diagrams.Backend.Cairo.CmdLine (Cairo, defaultMain) import qualified Diagrams.Dendrogram as D main :: IO () main = defaultMain diagram diagram :: Diagram Cairo R2 diagram = D.dendrogramFixedchar test # lw 0.1 # pad 1.1 char :: Char -> Diagram Cairo R2 char c = pad 1.3 $ roundedRect (1,1) 0.1 `atop` text [c] test :: Dendrogram Char test = Branch 5 (Branch 2 (Branch 1 (Leaf 'A') (Leaf 'B')) (Leaf 'C')) (Leaf 'D')
dendrogram :: (Monoid m, Renderable (Path R2) b) => Width -> (a -> AnnDiagram b R2 m) -> Dendrogram a -> AnnDiagram b R2 mSource
The width of the items on the leafs of a dendrogram.
Constructors
| Fixed |
|
| Variable |
|
Low-level interface
dendrogramPath :: Dendrogram X -> Path R2Source
A dendrogram path that can be stroked later. This function assumes that the Leafs of your Dendrogram are already in the right position.
fixedWidth :: Double -> Dendrogram a -> (Dendrogram X, Double)Source
fixedWidth w positions the Leafs of a Dendrogram assuming that they have the same width w. Also returns the total width.
variableWidth :: Monoid m => (a -> AnnDiagram b R2 m) -> Dendrogram a -> (Dendrogram X, AnnDiagram b R2 m)Source
variableWidth draw positions the Leafs of a Dendrogram according to the diagram generated by draw. Each Leaf may have a different width. Also returns the resulting diagram having all Leafs drawn side-by-side.
Note: you should probably use alignT to align your items.
hcatB :: Monoid m => [AnnDiagram b R2 m] -> AnnDiagram b R2 mSource
Like hcat, but balanced. Much better performance. Use it for concatenating the items of your dendrogram.