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)
21 import Data.List (sortOn)
22 import Data.Tuple (fst, snd)
23 import Gargantext.Prelude hiding (head)
24 import Gargantext.Viz.Phylo
25 import Gargantext.Viz.Phylo.Tools
28 -- | To sort a PhyloView by Age
29 sortBranchByAge :: Order -> PhyloView -> PhyloView
30 sortBranchByAge o v = v & pv_branches %~ f
32 --------------------------------------
33 f :: [PhyloBranch] -> [PhyloBranch]
35 Asc -> sortOn (getBranchMeta "age") xs
36 Desc -> reverse $ sortOn (getBranchMeta "age") xs
37 --------------------------------------
39 -- | To process a Sort to a PhyloView
40 processSort :: Maybe (Sort,Order) -> Phylo -> PhyloView -> PhyloView
41 processSort s _p v = case s of
43 Just s' -> case fst s' of
44 ByBranchAge -> sortBranchByAge (snd s') v
45 --_ -> panic "[ERR][Viz.Phylo.View.Sort.processSort] sort not found"