Commit 8f6cbb5e authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] forceAtlas refresh on controls change

parent f8e96c7d
......@@ -60,9 +60,19 @@ startSigma ref sigmaRef settings forceAtlas2Settings graph = do
useData sigma graph
useForceAtlas2 sigma forceAtlas2Settings
else
R.useEffect' $ do
log2 "refreshing" $ readSigma sigma
delay unit $ \_ -> pure $ Sigma.refresh <$> readSigma sigma
pure unit
R.useEffect $ do
delay unit $ handleRefresh sigma
where
handleRefresh sigma _ = do
let rSigma = readSigma sigma
_ <- case rSigma of
Nothing -> log2 "[handleRefresh] can't refresh" sigma
Just s -> do
Sigma.refreshForceAtlas s
pure $ pure unit
-- | Manages a sigma with the given settings
useSigma :: forall settings. R.Ref (Nullable Element) -> settings -> R.Ref (Maybe Sigma) -> R.Hooks {sigma :: Sigma, isNew :: Boolean}
......
module Gargantext.Hooks.Sigmax.Sigma where
import Prelude
import Type.Row (class Union)
import Data.Either (Either(..))
import Data.Nullable (null)
import Data.Unit (Unit)
import DOM.Simple.Console (log, log2)
import Effect (Effect)
import FFI.Simple.Objects (named)
import Effect.Timer (setTimeout)
import Effect.Uncurried (EffectFn1, mkEffectFn1, runEffectFn1, EffectFn2, runEffectFn2, EffectFn3, runEffectFn3, EffectFn4, runEffectFn4)
import FFI.Simple.Objects (named)
import Type.Row (class Union)
foreign import data Sigma :: Type
......@@ -54,6 +57,19 @@ refresh = runEffectFn1 _refresh
foreign import _refresh :: EffectFn1 Sigma Unit
refreshForceAtlas :: Sigma -> Effect Unit
refreshForceAtlas sigma = do
isRunning <- isForceAtlas2Running sigma
if isRunning then
pure unit
else do
_ <- setTimeout 100 $ do
restartForceAtlas2 sigma
_ <- setTimeout 100 $
stopForceAtlas2 sigma
pure unit
pure unit
addRenderer :: forall r err. Sigma -> r -> Effect (Either err Unit)
addRenderer = runEffectFn4 _addRenderer Left Right
......
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