]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Viz/Phylo/View/Display.hs
[PHYLO.API] Adding REST functions.
[gargantext.git] / src / Gargantext / Viz / Phylo / View / Display.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 {-# LANGUAGE NoImplicitPrelude #-}
14 {-# LANGUAGE FlexibleContexts #-}
15 {-# LANGUAGE OverloadedStrings #-}
16
17 module Gargantext.Viz.Phylo.View.Display
18 where
19
20 import Control.Lens hiding (makeLenses, both, Level)
21
22 import Data.List (head,null,(++),sortOn)
23 import Gargantext.Prelude hiding (head)
24 import Gargantext.Viz.Phylo
25 import Gargantext.Viz.Phylo.Tools
26
27 -- | To transform a flat Phyloview into a nested Phyloview
28 toNestedView :: [PhyloNode] -> [PhyloNode] -> [PhyloNode]
29 toNestedView ns ns'
30 | null ns' = ns
31 | otherwise = toNestedView (filter (\n -> lvl' == getNodeLevel n) nested)
32 (filter (\n -> lvl' < getNodeLevel n) nested)
33 where
34 --------------------------------------
35 lvl' :: Level
36 lvl' = getNodeLevel $ head $ nested
37 --------------------------------------
38 nested :: [PhyloNode]
39 nested = foldl (\ns'' n -> let nIds' = getNodeParentsId n
40 in map (\n' -> if elem (getNodeId n') nIds'
41 then n' & pn_childs %~ (++ [n])
42 else n') ns'') ns' ns
43 --------------------------------------
44
45
46 -- | To process a DisplayMode to a PhyloView
47 processDisplay :: DisplayMode -> PhyloView -> PhyloView
48 processDisplay d v = case d of
49 Flat -> v
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"