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
14 module Gargantext.Viz.Phylo.View.Sort
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
25 -- | To sort a PhyloView by Age
26 sortBranchByAge :: Order -> PhyloView -> PhyloView
27 sortBranchByAge o v = v & pv_branches %~ f
29 --------------------------------------
30 f :: [PhyloBranch] -> [PhyloBranch]
32 Asc -> sortOn (getBranchMeta "age") xs
33 Desc -> reverse $ sortOn (getBranchMeta "age") xs
34 --------------------------------------
36 -- | To sort a PhyloView by Birth date of a branch
37 sortBranchByBirth :: Order -> PhyloView -> PhyloView
38 sortBranchByBirth o v = v & pv_branches %~ f
40 --------------------------------------
41 f :: [PhyloBranch] -> [PhyloBranch]
43 Asc -> sortOn (getBranchMeta "birth") xs
44 Desc -> reverse $ sortOn (getBranchMeta "birth") xs
45 --------------------------------------
47 -- | To process a Sort to a PhyloView
48 processSort :: Maybe (Sort,Order) -> Phylo -> PhyloView -> PhyloView
49 processSort s _p v = case s of
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"