Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
597e9a73
Commit
597e9a73
authored
Sep 22, 2022
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[sigma.js] graph doesn't crash now
parent
84ca8906
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
30 deletions
+46
-30
Sigmax.purs
src/Gargantext/Hooks/Sigmax.purs
+13
-9
Graphology.js
src/Gargantext/Hooks/Sigmax/Graphology.js
+15
-3
Graphology.purs
src/Gargantext/Hooks/Sigmax/Graphology.purs
+18
-18
No files found.
src/Gargantext/Hooks/Sigmax.purs
View file @
597e9a73
...
...
@@ -213,15 +213,19 @@ selectorWithSize _ _ = do
performDiff :: Sigma.Sigma -> ST.SGraph -> Effect Unit
performDiff sigma g = do
if (Seq.null addEdges) && (Seq.null addNodes) && (Set.isEmpty removeEdges) && (Set.isEmpty removeNodes) then
pure unit
else do
traverse_ (Graphology.addNode sigmaGraph) addNodes
traverse_ (Graphology.addEdge sigmaGraph) addEdges
traverse_ (Graphology.removeEdge sigmaGraph) removeEdges
traverse_ (Graphology.removeNode sigmaGraph) removeNodes
Sigma.refresh sigma
Sigma.killForceAtlas2 sigma
-- if (Seq.null addEdges) && (Seq.null addNodes) && (Set.isEmpty removeEdges) && (Set.isEmpty removeNodes) then
-- pure unit
-- else do
console.log2 "[performDiff] addNodes" addNodes
console.log2 "[performDiff] addEdges" $ A.fromFoldable addEdges
console.log2 "[performDiff] removeNodes" removeNodes
console.log2 "[performDiff] removeEdges" removeEdges
traverse_ (Graphology.addNode sigmaGraph) addNodes
traverse_ (Graphology.addEdge sigmaGraph) addEdges
traverse_ (Graphology.removeEdge sigmaGraph) removeEdges
traverse_ (Graphology.removeNode sigmaGraph) removeNodes
Sigma.refresh sigma
Sigma.killForceAtlas2 sigma
where
sigmaGraph = Sigma.graph sigma
sigmaEdgeIds = Graphology.edgeIds sigmaGraph
...
...
src/Gargantext/Hooks/Sigmax/Graphology.js
View file @
597e9a73
...
...
@@ -22,11 +22,23 @@ export function _mapNodes(g, fn) {
});
}
export
function
_forEachEdge
(
g
,
fn
)
{
return
g
.
forEachEdge
(
function
(
name
,
attrs
,
source
,
target
,
sourceAttributes
,
targetAttributes
,
undirected
)
{
return
fn
({
id
:
name
,
source
,
target
,
...
attrs
});
});
}
// Almost the same as graphology.mapNodes but with a change that only
// 1 argument is passed: the whole node structure
//
TODO Add source, target
//
https://graphology.github.io/iteration.html#mapedges
export
function
_mapEdges
(
g
,
fn
)
{
return
g
.
mapEdges
(
function
(
name
,
attrs
)
{
return
fn
({
id
:
name
,
...
attrs
});
return
g
.
mapEdges
(
function
(
name
,
attrs
,
source
,
target
,
sourceAttributes
,
targetAttributes
,
undirected
)
{
return
fn
({
id
:
name
,
source
,
target
,
...
attrs
});
});
}
src/Gargantext/Hooks/Sigmax/Graphology.purs
View file @
597e9a73
...
...
@@ -8,6 +8,7 @@ module Gargantext.Hooks.Sigmax.Graphology where
import Prelude
import Data.Array as A
import Data.Function.Uncurried (Fn2, runFn2)
import Data.Sequence as Seq
import Data.Set as Set
import Data.Traversable (traverse)
...
...
@@ -23,8 +24,9 @@ foreign import data Graph :: Type
foreign import _newGraph :: EffectFn1 Unit Graph
foreign import _addNode :: EffectFn3 Graph String (Record Types.Node) String
foreign import _addEdge :: EffectFn4 Graph String String (Record Types.Edge) String
foreign import _mapNodes :: forall a. EffectFn2 Graph (Record Types.Node -> a) (Array a)
foreign import _mapEdges :: forall a. EffectFn2 Graph (Record Types.Edge -> a) (Array a)
foreign import _mapNodes :: forall a. Fn2 Graph (Record Types.Node -> a) (Array a)
foreign import _forEachEdge :: EffectFn2 Graph (Record Types.Edge -> Effect Unit) Unit
foreign import _mapEdges :: forall a. Fn2 Graph (Record Types.Edge -> a) (Array a)
newGraph :: Unit -> Effect Graph
newGraph = runEffectFn1 _newGraph
...
...
@@ -47,17 +49,18 @@ forEachNode :: Graph -> (Record Types.Node -> Effect Unit) -> Effect Unit
-- TODO Check this: how does FFI translate function of two arguments
-- into PS \x y ?
forEachNode g fn = pure $ g ... "forEachNode" $ [\_ n -> fn n]
mapNodes ::
Graph -> (Record Types.Node -> Record Types.Node) -> Effect (Array (Record Types.Node))
mapNodes = run
Effect
Fn2 _mapNodes
mapNodes ::
forall a. Graph -> (Record Types.Node -> a) -> Array a
mapNodes = runFn2 _mapNodes
addEdge :: Graph -> Record Types.Edge -> Effect String
addEdge g edge@{ source, target } = runEffectFn4 _addEdge g source target edge
removeEdge :: Graph -> String -> Effect Unit
removeEdge g eId = pure $ g ... "dropEdge" $ [eId]
forEachEdge :: Graph -> (Record Types.Edge -> Effect Unit) -> Effect Unit
forEachEdge g fn = pure $ g ... "forEachEdge" $ [\_ e -> fn e]
mapEdges :: Graph -> (Record Types.Edge -> Record Types.Edge) -> Effect (Array (Record Types.Edge))
mapEdges = runEffectFn2 _mapEdges
forEachEdge = runEffectFn2 _forEachEdge
--forEachEdge g fn = pure $ g ... "forEachEdge" $ [\_ e -> fn e]
mapEdges :: forall a. Graph -> (Record Types.Edge -> a) -> Array a
mapEdges = runFn2 _mapEdges
-- TODO Maybe our use of this function (`updateWithGraph`) in code is
-- too much. We convert Types.Graph into Graphology.Graph and then
...
...
@@ -99,20 +102,17 @@ edges_ g = g ... "edges" $ [] :: Array Types.EdgeId
nodes_ :: Graph -> Array Types.NodeId
nodes_ g = g ... "nodes" $ [] :: Array Types.NodeId
-- | Call `sigmaGraph.edges()` on a sigmajs graph instance.
edges :: Graph -> Effect (Seq.Seq (Record Types.Edge))
edges g = do
edges' <- mapEdges g identity
pure $ Seq.fromFoldable edges'
-- | Call `sigmaGraph.nodes()` on a sigmajs graph instance.
nodes :: Graph -> Effect (Seq.Seq (Record Types.Node))
nodes g = do
nodes' <- mapNodes g identity
pure $ Seq.fromFoldable nodes'
-- | `sigma.edges()` returns only edge keys, we need to map to get the full edge
edges :: Graph -> Seq.Seq (Record Types.Edge)
edges g = Seq.fromFoldable $ mapEdges g identity
-- | `sigma.nodes()` returns only node keys, we need to map to get the full node
nodes :: Graph -> Seq.Seq (Record Types.Node)
nodes g = Seq.fromFoldable $ mapNodes g identity
-- | Fetch ids of graph edges in a sigmajs instance.
edgeIds :: Graph -> Types.EdgeIds
edgeIds = Set.fromFoldable <<< edges_
-- auto-assigned edge ids are different from our edge ids
edgeIds g = Set.fromFoldable $ mapEdges g (\{ id } -> id) -- -<<< edges_
-- | Fetch ids of graph nodes in a sigmajs instance.
nodeIds :: Graph -> Types.NodeIds
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment