Commit 9ad149cf authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] fix useEffectOnce', add dummy state to test graph refresh

parent 99c71876
...@@ -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%"} } []
......
...@@ -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 [
]
] ]
] ]
] ]
......
...@@ -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"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment