Commit b9719ad8 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] proper FA pausing works now, even across state refreshes

parent 9c4af297
...@@ -81,18 +81,18 @@ controlsCpt = R.hooksComponent "GraphControls" cpt ...@@ -81,18 +81,18 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
--mFAPauseRef <- R.useRef Nothing --mFAPauseRef <- R.useRef Nothing
--R.useEffect $ handleForceAtlasPause props.sigmaRef localControls.pauseForceAtlas mFAPauseRef --R.useEffect $ handleForceAtlasPause props.sigmaRef localControls.pauseForceAtlas mFAPauseRef
R.useEffect $ handleForceAtlasPause props.sigmaRef localControls.pauseForceAtlas R.useEffect' $ Sigmax.handleForceAtlas2Pause props.sigmaRef localControls.pauseForceAtlas
--R.useEffectOnce' $ do R.useEffectOnce' $ do
-- timeoutId <- setTimeout 2000 $ do timeoutId <- setTimeout 2000 $ do
-- --R.setRef mFAPauseRef Nothing --R.setRef mFAPauseRef Nothing
-- let (toggled /\ setToggled) = localControls.pauseForceAtlas let (toggled /\ setToggled) = localControls.pauseForceAtlas
-- if toggled then if toggled then
-- setToggled $ const false setToggled $ const false
-- else else
-- pure unit pure unit
-- --R.setRef mFAPauseRef $ Just timeoutId --R.setRef mFAPauseRef $ Just timeoutId
-- pure unit pure unit
pure $ case getShowControls props of pure $ case getShowControls props of
false -> RH.div {} [] false -> RH.div {} []
...@@ -118,23 +118,6 @@ controlsCpt = R.hooksComponent "GraphControls" cpt ...@@ -118,23 +118,6 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
] ]
] ]
] ]
where
--handleForceAtlasPause sigmaRef (toggled /\ setToggled) mFAPauseRef = do
handleForceAtlasPause sigmaRef (toggled /\ setToggled) = do
let sigma = R.readRef sigmaRef
pure $ Sigmax.dependOnSigma sigma "[handleForceAtlasPause] sigma: Nothing" $ \s -> do
log2 "[handleForceAtlasPause] mSigma: Just " s
log2 "[handleForceAtlasPause] toggled: " toggled
if toggled then
Sigma.stopForceAtlas2 s
else
Sigma.restartForceAtlas2 s
-- handle case when user pressed pause/start fa button before timeout fired
--case R.readRef mFAPauseRef of
-- Nothing -> pure unit
-- Just timeoutId -> do
-- R.setRef mFAPauseRef Nothing
-- clearTimeout timeoutId
useGraphControls :: R.Hooks (Record Controls) useGraphControls :: R.Hooks (Record Controls)
useGraphControls = do useGraphControls = do
......
...@@ -13,6 +13,7 @@ import Data.Nullable (Nullable) ...@@ -13,6 +13,7 @@ import Data.Nullable (Nullable)
import Data.Sequence (Seq) import Data.Sequence (Seq)
import Data.Sequence as Seq import Data.Sequence as Seq
import Data.Traversable (traverse_) import Data.Traversable (traverse_)
import Data.Tuple.Nested((/\))
import Effect (Effect) import Effect (Effect)
import FFI.Simple (delay) import FFI.Simple (delay)
import Gargantext.Hooks.Sigmax.Sigma as Sigma import Gargantext.Hooks.Sigmax.Sigma as Sigma
...@@ -305,3 +306,20 @@ useForceAtlas2Eff sigma settings = effect ...@@ -305,3 +306,20 @@ useForceAtlas2Eff sigma settings = effect
--cleanupFirst sigma (Sigma.killForceAtlas2 sig) --cleanupFirst sigma (Sigma.killForceAtlas2 sig)
startingMsg = "[useForceAtlas2Eff] Starting ForceAtlas2" startingMsg = "[useForceAtlas2Eff] Starting ForceAtlas2"
sigmaNotFoundMsg = "[useForceAtlas2Eff] Sigma not found, not initialising" sigmaNotFoundMsg = "[useForceAtlas2Eff] Sigma not found, not initialising"
--handleForceAtlasPause sigmaRef (toggled /\ setToggled) mFAPauseRef = do
handleForceAtlas2Pause :: R.Ref Sigma -> R.State Boolean -> Effect Unit
handleForceAtlas2Pause sigmaRef (toggled /\ setToggled) = do
let sigma = R.readRef sigmaRef
dependOnSigma sigma "[handleForceAtlas2Pause] sigma: Nothing" $ \s -> do
log2 "[handleForceAtlas2Pause] mSigma: Just " s
log2 "[handleForceAtlas2Pause] toggled: " toggled
case toggled of
true -> Sigma.restartForceAtlas2 s
_ -> Sigma.stopForceAtlas2 s
-- handle case when user pressed pause/start fa button before timeout fired
--case R.readRef mFAPauseRef of
-- Nothing -> pure unit
-- Just timeoutId -> do
-- R.setRef mFAPauseRef Nothing
-- clearTimeout timeoutId
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