]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Viz/Graph/FGL.hs
Merge branch 'dev' into dev-phylo
[gargantext.git] / src / Gargantext / Viz / Graph / FGL.hs
1 {-| Module : Gargantext.Viz.Graph.FGL
2 Description : FGL main functions used in Garg
3 Copyright : (c) CNRS, 2017-Present
4 License : AGPL + CECILL v3
5 Maintainer : team@gargantext.org
6 Stability : experimental
7 Portability : POSIX
8
9 Main FGL funs/types to ease portability with IGraph.
10
11 -}
12
13 {-# LANGUAGE NoImplicitPrelude #-}
14 {-# LANGUAGE ConstraintKinds #-}
15
16 module Gargantext.Viz.Graph.FGL where
17
18 import Gargantext.Prelude
19 import qualified Data.Graph.Inductive as FGL
20 import Data.List as List
21 ------------------------------------------------------------------
22 -- | Main Types
23
24 type Graph_Undirected = FGL.Gr () ()
25 type Graph_Directed = FGL.Gr () ()
26
27 type Graph = FGL.Graph
28 type Node = FGL.Node
29 type Edge = FGL.Edge
30
31 ------------------------------------------------------------------
32 -- | Main Functions
33
34 mkGraph :: [Node] -> [Edge] -> Graph_Undirected
35 mkGraph = FGL.mkUGraph
36
37 neighbors :: Graph gr => gr a b -> Node -> [Node]
38 neighbors = FGL.neighbors
39
40 -- | TODO bug: if graph is undirected, we need to filter
41 -- nub . (map (\(n1,n2) -> if n1 < n2 then (n1,n2) else (n2,n1))) . FGL.edges
42 edges :: Graph gr => gr a b -> [Edge]
43 edges = FGL.edges
44
45 nodes :: Graph gr => gr a b -> [Node]
46 nodes = FGL.nodes
47
48 ------------------------------------------------------------------
49 -- | Main sugared functions
50
51 mkGraphUfromEdges :: [(Int, Int)] -> Graph_Undirected
52 mkGraphUfromEdges es = mkGraph ns es
53 where
54 ns = List.nub (a <> b)
55 where
56 (a, b) = List.unzip es
57