]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Viz/Phylo/View/Sort.hs
change export
[gargantext.git] / src / Gargantext / Viz / Phylo / View / Sort.hs
1 {-|
2 Module : Gargantext.Viz.Phylo.Tools
3 Description : Phylomemy Tools to build/manage it
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10
11 -}
12
13
14 module Gargantext.Viz.Phylo.View.Sort
15 where
16
17 import Control.Lens hiding (makeLenses, both, Level)
18 import Data.List (sortOn)
19 import Data.Tuple (fst, snd)
20 import Gargantext.Prelude
21 import Gargantext.Viz.Phylo
22 import Gargantext.Viz.Phylo.Tools
23
24
25 -- | To sort a PhyloView by Age
26 sortBranchByAge :: Order -> PhyloView -> PhyloView
27 sortBranchByAge o v = v & pv_branches %~ f
28 where
29 --------------------------------------
30 f :: [PhyloBranch] -> [PhyloBranch]
31 f xs = case o of
32 Asc -> sortOn (getBranchMeta "age") xs
33 Desc -> reverse $ sortOn (getBranchMeta "age") xs
34 --------------------------------------
35
36 -- | To sort a PhyloView by Birth date of a branch
37 sortBranchByBirth :: Order -> PhyloView -> PhyloView
38 sortBranchByBirth o v = v & pv_branches %~ f
39 where
40 --------------------------------------
41 f :: [PhyloBranch] -> [PhyloBranch]
42 f xs = case o of
43 Asc -> sortOn (getBranchMeta "birth") xs
44 Desc -> reverse $ sortOn (getBranchMeta "birth") xs
45 --------------------------------------
46
47 -- | To process a Sort to a PhyloView
48 processSort :: Maybe (Sort,Order) -> Phylo -> PhyloView -> PhyloView
49 processSort s _p v = case s of
50 Nothing -> v
51 Just s' -> case fst s' of
52 ByBranchAge -> sortBranchByAge (snd s') v
53 ByBranchBirth -> sortBranchByBirth (snd s') v
54 --_ -> panic "[ERR][Viz.Phylo.View.Sort.processSort] sort not found"