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
9 Main FGL funs/types to ease portability with IGraph.
13 {-# LANGUAGE NoImplicitPrelude #-}
14 {-# LANGUAGE ConstraintKinds #-}
16 module Gargantext.Viz.Graph.FGL where
18 import Gargantext.Prelude
19 import qualified Data.Graph.Inductive as FGL
20 import Data.List as List
21 ------------------------------------------------------------------
24 type Graph_Undirected = FGL.Gr () ()
25 type Graph_Directed = FGL.Gr () ()
27 type Graph = FGL.Graph
31 ------------------------------------------------------------------
34 mkGraph :: [Node] -> [Edge] -> Graph_Undirected
35 mkGraph = FGL.mkUGraph
37 neighbors :: Graph gr => gr a b -> Node -> [Node]
38 neighbors = FGL.neighbors
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]
45 nodes :: Graph gr => gr a b -> [Node]
48 ------------------------------------------------------------------
49 -- | Main sugared functions
51 mkGraphUfromEdges :: [(Int, Int)] -> Graph_Undirected
52 mkGraphUfromEdges es = mkGraph ns es
54 ns = List.nub (a <> b)
56 (a, b) = List.unzip es