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
13 {-# LANGUAGE NoImplicitPrelude #-}
14 {-# LANGUAGE FlexibleContexts #-}
15 {-# LANGUAGE OverloadedStrings #-}
17 module Gargantext.Viz.Phylo.View.Sort
20 import Control.Lens hiding (makeLenses, both, Level)
22 import Data.List (notElem,last,head,union,concat,null,nub,(++),init,tail,elemIndex,groupBy,(!!),sortOn,sort,(\\))
23 import Data.Map (Map,elems,adjust,unionWith,intersectionWith,fromList,mapKeys,insert)
24 import Data.Maybe (isNothing)
26 import Data.Text (Text,unwords)
27 import Data.Tuple (fst, snd)
28 import Data.Vector (Vector)
30 import Gargantext.Prelude hiding (head)
31 import Gargantext.Viz.Phylo
32 import Gargantext.Viz.Phylo.Tools
34 import qualified Data.List as List
35 import qualified Data.Map as Map
36 import qualified Data.Set as Set
37 import qualified Data.Vector as Vector
40 -- | To sort a PhyloView by Age
41 sortBranchByAge :: Order -> PhyloView -> PhyloView
42 sortBranchByAge o v = v & phylo_viewBranches %~ f
44 --------------------------------------
45 f :: [PhyloBranch] -> [PhyloBranch]
47 Asc -> sortOn (getBranchMeta "age") xs
48 Desc -> reverse $ sortOn (getBranchMeta "age") xs
49 --------------------------------------
51 -- | To process a Sort to a PhyloView
52 processSort :: Maybe (Sort,Order) -> Phylo -> PhyloView -> PhyloView
53 processSort s p v = case s of
55 Just s -> case fst s of
56 ByBranchAge -> sortBranchByAge (snd s) v
57 _ -> panic "[ERR][Viz.Phylo.View.Sort.processSort] sort not found"