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.Display
20 import Control.Lens hiding (makeLenses, both, Level)
22 import Data.List (head,null,(++),sortOn)
23 import Gargantext.Prelude hiding (head)
24 import Gargantext.Viz.Phylo
25 import Gargantext.Viz.Phylo.Tools
27 -- | To transform a flat Phyloview into a nested Phyloview
28 toNestedView :: [PhyloNode] -> [PhyloNode] -> [PhyloNode]
31 | otherwise = toNestedView (filter (\n -> lvl' == getNodeLevel n) nested)
32 (filter (\n -> lvl' < getNodeLevel n) nested)
34 --------------------------------------
36 lvl' = getNodeLevel $ head $ nested
37 --------------------------------------
39 nested = foldl (\ns'' n -> let nIds' = getNodeParentsId n
40 in map (\n' -> if elem (getNodeId n') nIds'
41 then n' & pn_childs %~ (++ [n])
43 --------------------------------------
46 -- | To process a DisplayMode to a PhyloView
47 processDisplay :: DisplayMode -> PhyloView -> PhyloView
48 processDisplay d v = case d of
50 Nested -> let ns = sortOn getNodeLevel $ v ^. pv_nodes
51 lvl = getNodeLevel $ head ns
52 in v & pv_nodes .~ toNestedView (filter (\n -> lvl == getNodeLevel n) ns)
53 (filter (\n -> lvl < getNodeLevel n) ns)
54 --_ -> panic "[ERR][Viz.Phylo.Example.processDisplay] display not found"