packages feed

hierarchical-clustering-diagrams 0.1.0.1 → 0.2

raw patch · 2 files changed

+17/−28 lines, 2 filesdep ~diagrams-cairodep ~diagrams-lib

Dependency ranges changed: diagrams-cairo, diagrams-lib

Files

hierarchical-clustering-diagrams.cabal view
@@ -1,5 +1,5 @@ Name:                hierarchical-clustering-diagrams-Version:             0.1.0.1+Version:             0.2 Synopsis:            Draw diagrams of dendrograms made by hierarchical-clustering. License:             BSD3 License-file:        LICENSE@@ -33,7 +33,7 @@      , hierarchical-clustering == 0.4.* -    , diagrams-lib            == 0.4.*+    , diagrams-lib            == 0.5.*   GHC-options: -Wall  Test-suite runtests@@ -45,8 +45,8 @@      , hierarchical-clustering == 0.4.* -    , diagrams-lib            == 0.4.*-    , diagrams-cairo          == 0.4.*+    , diagrams-lib            == 0.5.*+    , diagrams-cairo          == 0.5.*      , hspec                   == 0.9.*     , HUnit                   == 1.2.*
src/Diagrams/Dendrogram.hs view
@@ -12,7 +12,6 @@     , fixedWidth     , variableWidth     , X-    , hcatB     ) where  -- from base@@ -68,11 +67,11 @@ -- 'Width'). -- -- Note: you should probably use 'alignT' to align your items.-dendrogram :: (Monoid m, Renderable (Path R2) b) =>+dendrogram :: (Monoid m, Semigroup m, Renderable (Path R2) b) =>               Width-           -> (a -> AnnDiagram b R2 m)+           -> (a -> QDiagram b R2 m)            -> Dendrogram a-           -> AnnDiagram b R2 m+           -> QDiagram b R2 m dendrogram width_ drawItem dendro = (stroke path_ # value mempty)                                                ===                                          (items # alignL)@@ -82,7 +81,7 @@           Fixed -> let drawnItems = map drawItem (elements dendro)                        w = width (head drawnItems)                        (dendro', _) = fixedWidth w dendro-                   in (dendrogramPath dendro', hcatB drawnItems)+                   in (dendrogramPath dendro', hcat drawnItems)           Variable -> first dendrogramPath $ variableWidth drawItem dendro  @@ -112,11 +111,11 @@           (acc',  (!xL, !yL)) = go acc  l           (acc'', (!xR, !yR)) = go acc' r -          path = fromVertices [ P (xL, yL)-                              , P (xL, d)-                              , P (xR, d)-                              , P (xR, yR)]-          pos  = ((xL + xR) / 2, d)+          path = fromVertices [ p2 (xL, yL)+                              , p2 (xL, d)+                              , p2 (xR, d)+                              , p2 (xR, yR)]+          pos  = (xL + (xR - xL) / 2, d)   -- | The horizontal position of a dendrogram Leaf.@@ -143,10 +142,10 @@ -- resulting diagram having all 'Leaf'@s@ drawn side-by-side. -- -- Note: you should probably use 'alignT' to align your items.-variableWidth :: (Monoid m) =>-                 (a -> AnnDiagram b R2 m)+variableWidth :: (Semigroup m, Monoid m) =>+                 (a -> QDiagram b R2 m)               -> Dendrogram a-              -> (Dendrogram X, AnnDiagram b R2 m)+              -> (Dendrogram X, QDiagram b R2 m) variableWidth draw = finish . go 0 []     where       go !y acc (Leaf a) = (Leaf y', y'', dia : acc)@@ -159,18 +158,8 @@           where             (l', !y',  acc'') = go y  acc' l -- yes, this is acc'             (r', !y'', acc')  = go y' acc r-      finish (dendro, _, dias) = (dendro, hcatB dias)+      finish (dendro, _, dias) = (dendro, hcat dias)       -- We used to concatenate diagrams inside 'go' using (|||).       -- However, pathological dendrograms (such as those created       -- using single linkage) may be highly unbalanced, creating       -- a performance problem for 'variableWidth'.----- | Like 'hcat', but balanced.  Much better performance.  Use it--- for concatenating the items of your dendrogram.-hcatB :: Monoid m => [AnnDiagram b R2 m] -> AnnDiagram b R2 m-hcatB [y] = y-hcatB ys  = hcatB $ dubs ys-  where dubs (x1:x2:xs) = x1 ||| x2 : dubs xs-        dubs [x]        = [x]-        dubs []         = []