Commit f32bd31b authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] some refactoring of FA pausing

Also, attempt to make automatic FA pause almost working.
parent 65165d69
......@@ -11,9 +11,11 @@ module Gargantext.Components.GraphExplorer.Controls
, getMultiNodeSelect, setMultiNodeSelect
) where
import Data.Maybe (Maybe)
import Data.Maybe (Maybe(..))
import DOM.Simple.Console (log, log2)
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect.Timer (clearTimeout, setTimeout)
import Prelude
import Reactix as R
import Reactix.DOM.HTML as RH
......@@ -24,6 +26,7 @@ import Gargantext.Components.GraphExplorer.RangeControl (edgeSizeControl, nodeSi
import Gargantext.Components.GraphExplorer.SlideButton (cursorSizeButton, labelSizeButton)
import Gargantext.Components.GraphExplorer.ToggleButton (edgesToggleButton, pauseForceAtlasButton)
import Gargantext.Hooks.Sigmax as Sigmax
import Gargantext.Hooks.Sigmax.Sigma as Sigma
import Gargantext.Utils.Range as Range
import Gargantext.Utils.Reactix as R2
......@@ -72,6 +75,24 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
where
cpt props _ = do
localControls <- initialLocalControls
-- ref to track automatic FA pausing
-- If user pauses FA before auto is triggered, clear the timeoutId
-- TODO: mFAPauseRef needs to be set higher up the tree
--mFAPauseRef <- R.useRef Nothing
--R.useEffect $ handleForceAtlasPause props.sigmaRef localControls.pauseForceAtlas mFAPauseRef
R.useEffect $ handleForceAtlasPause props.sigmaRef localControls.pauseForceAtlas
R.useEffectOnce' $ do
timeoutId <- setTimeout 2000 $ do
--R.setRef mFAPauseRef Nothing
let (toggled /\ setToggled) = localControls.pauseForceAtlas
if toggled then
setToggled $ const false
else
pure unit
--R.setRef mFAPauseRef $ Just timeoutId
pure unit
pure $ case getShowControls props of
false -> RH.div {} []
......@@ -97,6 +118,26 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
]
]
]
where
--handleForceAtlasPause sigmaRef (toggled /\ setToggled) mFAPauseRef = do
handleForceAtlasPause sigmaRef (toggled /\ setToggled) = do
let mSigma = Sigmax.readSigma $ R.readRef sigmaRef
pure $ case mSigma of
Just s -> do
log2 "[handleForceAtlasPause] mSigma: Just " s
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
_ -> do
log "[handleForceAtlasPause] mSigma: Nothing"
pure unit
useGraphControls :: R.Hooks (Record Controls)
useGraphControls = do
......
......@@ -81,14 +81,7 @@ pauseForceAtlasButton sigmaRef state =
, onMessage: "Pause Force Atlas"
, offMessage: "Start Force Atlas"
, onClick: \_ -> do
let mSigma = Sigmax.readSigma $ R.readRef sigmaRef
let (toggled /\ setToggled) = state
case mSigma of
Just s -> if toggled then
Sigma.stopForceAtlas2 s
else
Sigma.restartForceAtlas2 s
_ -> pure unit
let (_ /\ setToggled) = state
setToggled not
}
......
......@@ -14,7 +14,6 @@ import Data.Sequence (Seq)
import Data.Sequence as Seq
import Data.Traversable (traverse_)
import Effect (Effect)
import Effect.Timer (setTimeout)
import FFI.Simple (delay)
import Gargantext.Hooks.Sigmax.Sigma as Sigma
import Gargantext.Hooks.Sigmax.Types (Graph(..))
......@@ -28,8 +27,6 @@ type Sigma =
, cleanup :: R.Ref (Seq (Effect Unit))
}
type ForceAtlas2Timeout = Int
type Data n e = { graph :: R.Ref (Graph n e) }
initSigma :: R.Hooks Sigma
......@@ -234,7 +231,7 @@ startSigmaEff ref sigmaRef settings forceAtlas2Settings graph = do
log "[startSigmaEff] calling useDataEff"
useDataEff sigma graph
log "[startSigmaEff] calling useForceAtlas2Eff"
useForceAtlas2Eff sigma forceAtlas2Settings (Just 2000)
useForceAtlas2Eff sigma forceAtlas2Settings
Just sig -> do
log "[startSigmaEff] sigma initialized already"
useCanvasRendererEff ref rSigma
......@@ -300,8 +297,8 @@ useCanvasRendererEff container sigma =
errorKillingMsg = "[useCanvasRenderer] Error killing renderer:"
killedMsg = "[useCanvasRenderer] Killed renderer"
useForceAtlas2Eff :: forall settings. Sigma -> settings -> Maybe ForceAtlas2Timeout -> Effect Unit
useForceAtlas2Eff sigma settings mFATimeout = effect
useForceAtlas2Eff :: forall settings. Sigma -> settings -> Effect Unit
useForceAtlas2Eff sigma settings = effect
where
effect = dependOnSigma sigma sigmaNotFoundMsg withSigma
withSigma sig = do
......@@ -309,11 +306,5 @@ useForceAtlas2Eff sigma settings mFATimeout = effect
log sigma
Sigma.startForceAtlas2 sig settings
--cleanupFirst sigma (Sigma.killForceAtlas2 sig)
case mFATimeout of
Nothing -> pure unit
Just timeout -> do
_ <- setTimeout timeout $ do
Sigma.stopForceAtlas2 sig
pure unit
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