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
9ad149cf
Commit
9ad149cf
authored
Nov 07, 2019
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Graph] fix useEffectOnce', add dummy state to test graph refresh
parent
99c71876
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
92 deletions
+91
-92
Graph.purs
src/Gargantext/Components/Graph.purs
+3
-3
GraphExplorer.purs
src/Gargantext/Components/GraphExplorer.purs
+6
-2
Sigmax.purs
src/Gargantext/Hooks/Sigmax.purs
+82
-87
No files found.
src/Gargantext/Components/Graph.purs
View file @
9ad149cf
...
@@ -4,7 +4,7 @@ module Gargantext.Components.Graph
...
@@ -4,7 +4,7 @@ module Gargantext.Components.Graph
-- , forceAtlas2Settings, ForceAtlas2Settings, ForceAtlas2OptionalSettings
-- , forceAtlas2Settings, ForceAtlas2Settings, ForceAtlas2OptionalSettings
-- )
-- )
where
where
import Prelude (bind, discard, pure, ($))
import Prelude (bind, discard, pure, ($)
, unit
)
import Data.Maybe (Maybe)
import Data.Maybe (Maybe)
import Data.Nullable (null)
import Data.Nullable (null)
import Data.Sequence as Seq
import Data.Sequence as Seq
...
@@ -47,9 +47,9 @@ graphCpt = R.hooksComponent "Graph" cpt
...
@@ -47,9 +47,9 @@ graphCpt = R.hooksComponent "Graph" cpt
ref <- R.useRef null
ref <- R.useRef null
--startSigma ref props.sigmaRef props.sigmaSettings props.forceAtlas2Settings props.graph
--startSigma ref props.sigmaRef props.sigmaSettings props.forceAtlas2Settings props.graph
R.useEffectOnce $ do
R.useEffectOnce
'
$ do
log "[graphCpt] calling startSigmaEff"
log "[graphCpt] calling startSigmaEff"
pure $
startSigmaEff ref props.sigmaRef props.sigmaSettings props.forceAtlas2Settings props.graph
startSigmaEff ref props.sigmaRef props.sigmaSettings props.forceAtlas2Settings props.graph
pure $ RH.div { ref, style: {height: "95%"} } []
pure $ RH.div { ref, style: {height: "95%"} } []
...
...
src/Gargantext/Components/GraphExplorer.purs
View file @
9ad149cf
...
@@ -63,6 +63,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
...
@@ -63,6 +63,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
cpt {sessions, session, graphId, mCurrentRoute, treeId, graph, frontends} _ = do
cpt {sessions, session, graphId, mCurrentRoute, treeId, graph, frontends} _ = do
controls <- Controls.useGraphControls
controls <- Controls.useGraphControls
state <- useExplorerState
state <- useExplorerState
x /\ setX <- R.useState' 0
showLogin <- snd <$> R.useState' true
showLogin <- snd <$> R.useState' true
pure $
pure $
RH.div
RH.div
...
@@ -75,11 +76,14 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
...
@@ -75,11 +76,14 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
, col [ Toggle.controlsToggleButton controls.showControls ]
, col [ Toggle.controlsToggleButton controls.showControls ]
, col [ pullRight [ Toggle.sidebarToggleButton controls.showSidePanel ] ]
, col [ pullRight [ Toggle.sidebarToggleButton controls.showSidePanel ] ]
]
]
, row [ Controls.controls controls ]
, row [ Controls.controls controls
, RH.div {on: {click: \e -> setX $ \x_ -> x_ + 1}} [ RH.text ("Counter: " <> (show x)) ]
]
, row [ tree {mCurrentRoute, treeId} controls showLogin
, row [ tree {mCurrentRoute, treeId} controls showLogin
, mGraph controls.sigmaRef {graphId, graph}
, mGraph controls.sigmaRef {graphId, graph}
, Sidebar.sidebar {showSidePanel: fst controls.showSidePanel} ]
, Sidebar.sidebar {showSidePanel: fst controls.showSidePanel} ]
, row [ ]
, row [
]
]
]
]
]
]
]
...
...
src/Gargantext/Hooks/Sigmax.purs
View file @
9ad149cf
...
@@ -107,54 +107,6 @@ useSigma settings sigmaRef = do
...
@@ -107,54 +107,6 @@ useSigma settings sigmaRef = do
--pure $ cleanupSigma sigma "useSigma"
--pure $ cleanupSigma sigma "useSigma"
pure $ R.nothing
pure $ R.nothing
startSigmaEff :: forall settings faSettings n e. R.Ref (Nullable Element) -> R.Ref Sigma -> settings -> faSettings -> Graph n e -> Effect Unit
startSigmaEff ref sigmaRef settings forceAtlas2Settings graph = do
log "[startSigmaEff] calling useSigmaEff"
sigma <- useSigmaEff settings sigmaRef
log "[startSigmaEff] calling useCanvasRendererEff"
useCanvasRendererEff ref sigma
log "[startSigmaEff] calling useDataEff"
useDataEff sigma graph
log "[startSigmaEff] calling useForceAtlas2Eff"
useForceAtlas2Eff sigma forceAtlas2Settings
--handleRefresh sigma
where
handleRefresh :: Sigma -> Effect Unit
handleRefresh sigma = do
let rSigma = readSigma sigma
_ <- case rSigma of
Nothing -> log2 "[handleRefresh] can't refresh" sigma
Just s -> do
Sigma.refreshForceAtlas s
pure unit
useSigmaEff :: forall settings. settings -> R.Ref Sigma -> Effect Sigma
useSigmaEff settings sigmaRef = do
--sigma <- newSigma
--delay unit $ handleSigma sigma (readSigma sigma)
let sigma = R.readRef sigmaRef
handleSigma sigma (readSigma sigma)
pure sigma
where
--newSigma = do
-- s <- R2.nothingRef
-- c <- R.useRef Seq.empty
-- pure { sigma: s, cleanup: c }
handleSigma :: Sigma -> (Maybe Sigma.Sigma) -> Effect Unit
handleSigma sigma (Just _) = do
pure unit
handleSigma sigma Nothing = do
ret <- createSigma settings
traverse_ (writeSigma sigma <<< Just) ret
R.setRef sigmaRef sigma
--pure $ cleanupSigma sigma "useSigma"
pure unit
-- | Manages a renderer for the sigma
-- | Manages a renderer for the sigma
useCanvasRenderer :: R.Ref (Nullable Element) -> Sigma -> R.Hooks Unit
useCanvasRenderer :: R.Ref (Nullable Element) -> Sigma -> R.Hooks Unit
...
@@ -179,27 +131,6 @@ useCanvasRenderer container sigma =
...
@@ -179,27 +131,6 @@ useCanvasRenderer container sigma =
errorKillingMsg = "[useCanvasRenderer] Error killing renderer:"
errorKillingMsg = "[useCanvasRenderer] Error killing renderer:"
killedMsg = "[useCanvasRenderer] Killed renderer"
killedMsg = "[useCanvasRenderer] Killed renderer"
useCanvasRendererEff :: R.Ref (Nullable Element) -> Sigma -> Effect Unit
useCanvasRendererEff container sigma =
delay unit $ \_ ->
dependOnContainer container containerNotFoundMsg withContainer
where
withContainer c = dependOnSigma sigma sigmaNotFoundMsg withSigma
where -- close over c
withSigma sig = addRenderer sig renderer >>= handle
where -- close over sig
renderer = { "type": "canvas", container: c }
handle (Right _) = cleanupFirst sigma (Sigma.killRenderer sig renderer >>= logCleanup)
handle (Left e) =
log2 errorAddingMsg e *> cleanupSigma sigma "useCanvasRenderer"
logCleanup (Left e) = log2 errorKillingMsg e
logCleanup _ = log killedMsg
containerNotFoundMsg = "[useCanvasRenderer] Container not found, not adding renderer"
sigmaNotFoundMsg = "[useCanvasRenderer] Sigma not found, not adding renderer"
errorAddingMsg = "[useCanvasRenderer] Error adding canvas renderer: "
errorKillingMsg = "[useCanvasRenderer] Error killing renderer:"
killedMsg = "[useCanvasRenderer] Killed renderer"
createSigma :: forall settings err. settings -> Effect (Either err Sigma.Sigma)
createSigma :: forall settings err. settings -> Effect (Either err Sigma.Sigma)
createSigma settings = do
createSigma settings = do
log2 "[useSigma] Initializing sigma with settings" settings
log2 "[useSigma] Initializing sigma with settings" settings
...
@@ -239,12 +170,6 @@ useData sigma graph =
...
@@ -239,12 +170,6 @@ useData sigma graph =
withSigma sig = refreshData sig (sigmafy graph)
withSigma sig = refreshData sig (sigmafy graph)
sigmaNotFoundMsg = "[useData] Sigma not found, not adding data"
sigmaNotFoundMsg = "[useData] Sigma not found, not adding data"
useDataEff :: forall n e. Sigma -> Graph n e -> Effect Unit
useDataEff sigma graph = dependOnSigma sigma sigmaNotFoundMsg withSigma
where
withSigma sig = refreshData sig (sigmafy graph)
sigmaNotFoundMsg = "[useData] Sigma not found, not adding data"
refreshData :: forall n e. Sigma.Sigma -> Sigma.Graph n e -> Effect Unit
refreshData :: forall n e. Sigma.Sigma -> Sigma.Graph n e -> Effect Unit
refreshData sigma graph
refreshData sigma graph
= log clearingMsg
= log clearingMsg
...
@@ -278,18 +203,6 @@ useForceAtlas2 sigma settings =
...
@@ -278,18 +203,6 @@ useForceAtlas2 sigma settings =
startingMsg = "[Graph] Starting ForceAtlas2"
startingMsg = "[Graph] Starting ForceAtlas2"
sigmaNotFoundMsg = "[Graph] Sigma not found, not initialising"
sigmaNotFoundMsg = "[Graph] Sigma not found, not initialising"
useForceAtlas2Eff :: forall settings. Sigma -> settings -> Effect Unit
useForceAtlas2Eff sigma settings = effect
where
effect = dependOnSigma sigma sigmaNotFoundMsg withSigma
withSigma sig = do
log startingMsg
log sigma
Sigma.startForceAtlas2 sig settings
cleanupFirst sigma (Sigma.killForceAtlas2 sig)
startingMsg = "[Graph] Starting ForceAtlas2"
sigmaNotFoundMsg = "[Graph] Sigma not found, not initialising"
dependOnSigma :: Sigma -> String -> (Sigma.Sigma -> Effect Unit) -> Effect Unit
dependOnSigma :: Sigma -> String -> (Sigma.Sigma -> Effect Unit) -> Effect Unit
dependOnSigma sigma notFoundMsg f = do
dependOnSigma sigma notFoundMsg f = do
case readSigma sigma of
case readSigma sigma of
...
@@ -302,3 +215,85 @@ dependOnContainer container notFoundMsg f = do
...
@@ -302,3 +215,85 @@ dependOnContainer container notFoundMsg f = do
Nothing -> log notFoundMsg
Nothing -> log notFoundMsg
Just c -> f c
Just c -> f c
-- Effectful versions of the above code
startSigmaEff :: forall settings faSettings n e. R.Ref (Nullable Element) -> R.Ref Sigma -> settings -> faSettings -> Graph n e -> Effect Unit
startSigmaEff ref sigmaRef settings forceAtlas2Settings graph = do
log "[startSigmaEff] calling useSigmaEff"
sigma <- useSigmaEff settings sigmaRef
log "[startSigmaEff] calling useCanvasRendererEff"
useCanvasRendererEff ref sigma
log "[startSigmaEff] calling useDataEff"
useDataEff sigma graph
log "[startSigmaEff] calling useForceAtlas2Eff"
useForceAtlas2Eff sigma forceAtlas2Settings
--handleRefresh sigma
where
handleRefresh :: Sigma -> Effect Unit
handleRefresh sigma = do
let rSigma = readSigma sigma
_ <- case rSigma of
Nothing -> log2 "[handleRefresh] can't refresh" sigma
Just s -> do
Sigma.refreshForceAtlas s
pure unit
useSigmaEff :: forall settings. settings -> R.Ref Sigma -> Effect Sigma
useSigmaEff settings sigmaRef = do
let sigma = R.readRef sigmaRef
handleSigma sigma (readSigma sigma)
pure sigma
where
handleSigma :: Sigma -> (Maybe Sigma.Sigma) -> Effect Unit
handleSigma sigma (Just _) = do
pure unit
handleSigma sigma Nothing = do
ret <- createSigma settings
traverse_ (writeSigma sigma <<< Just) ret
R.setRef sigmaRef sigma
pure unit
useDataEff :: forall n e. Sigma -> Graph n e -> Effect Unit
useDataEff sigma graph = dependOnSigma sigma sigmaNotFoundMsg withSigma
where
withSigma sig = refreshData sig (sigmafy graph)
sigmaNotFoundMsg = "[useData] Sigma not found, not adding data"
useCanvasRendererEff :: R.Ref (Nullable Element) -> Sigma -> Effect Unit
useCanvasRendererEff container sigma =
delay unit $ \_ ->
dependOnContainer container containerNotFoundMsg withContainer
where
withContainer c = dependOnSigma sigma sigmaNotFoundMsg withSigma
where -- close over c
withSigma sig = addRenderer sig renderer >>= handle
where -- close over sig
renderer = { "type": "canvas", container: c }
handle (Right _) = cleanupFirst sigma (Sigma.killRenderer sig renderer >>= logCleanup)
handle (Left e) =
log2 errorAddingMsg e *> cleanupSigma sigma "useCanvasRenderer"
logCleanup (Left e) = log2 errorKillingMsg e
logCleanup _ = log killedMsg
containerNotFoundMsg = "[useCanvasRenderer] Container not found, not adding renderer"
sigmaNotFoundMsg = "[useCanvasRenderer] Sigma not found, not adding renderer"
errorAddingMsg = "[useCanvasRenderer] Error adding canvas renderer: "
errorKillingMsg = "[useCanvasRenderer] Error killing renderer:"
killedMsg = "[useCanvasRenderer] Killed renderer"
useForceAtlas2Eff :: forall settings. Sigma -> settings -> Effect Unit
useForceAtlas2Eff sigma settings = effect
where
effect = dependOnSigma sigma sigmaNotFoundMsg withSigma
withSigma sig = do
log startingMsg
log sigma
Sigma.startForceAtlas2 sig settings
cleanupFirst sigma (Sigma.killForceAtlas2 sig)
startingMsg = "[Graph] Starting ForceAtlas2"
sigmaNotFoundMsg = "[Graph] Sigma not found, not initialising"
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