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

[Graph] forceAtlas refresh on controls change

parent f8e96c7d
...@@ -131,7 +131,7 @@ graphView sigmaRef props = R.createElement el props [] ...@@ -131,7 +131,7 @@ graphView sigmaRef props = R.createElement el props []
RH.div { id: "graph-view", className: "col-md-12" } RH.div { id: "graph-view", className: "col-md-12" }
[ [
Graph.graph { Graph.graph {
forceAtlas2Settings: Graph.forceAtlas2Settings forceAtlas2Settings: Graph.forceAtlas2Settings
, graph , graph
, sigmaSettings: Graph.sigmaSettings , sigmaSettings: Graph.sigmaSettings
, sigmaRef: sigmaRef , sigmaRef: sigmaRef
......
...@@ -60,9 +60,19 @@ startSigma ref sigmaRef settings forceAtlas2Settings graph = do ...@@ -60,9 +60,19 @@ startSigma ref sigmaRef settings forceAtlas2Settings graph = do
useData sigma graph useData sigma graph
useForceAtlas2 sigma forceAtlas2Settings useForceAtlas2 sigma forceAtlas2Settings
else else
R.useEffect' $ do pure unit
log2 "refreshing" $ readSigma sigma
delay unit $ \_ -> pure $ Sigma.refresh <$> readSigma sigma 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 -- | 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} useSigma :: forall settings. R.Ref (Nullable Element) -> settings -> R.Ref (Maybe Sigma) -> R.Hooks {sigma :: Sigma, isNew :: Boolean}
......
module Gargantext.Hooks.Sigmax.Sigma where module Gargantext.Hooks.Sigmax.Sigma where
import Prelude import Prelude
import Type.Row (class Union)
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Nullable (null) import Data.Nullable (null)
import Data.Unit (Unit) import Data.Unit (Unit)
import DOM.Simple.Console (log, log2)
import Effect (Effect) 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 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 foreign import data Sigma :: Type
...@@ -54,6 +57,19 @@ refresh = runEffectFn1 _refresh ...@@ -54,6 +57,19 @@ refresh = runEffectFn1 _refresh
foreign import _refresh :: EffectFn1 Sigma Unit 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 :: forall r err. Sigma -> r -> Effect (Either err Unit)
addRenderer = runEffectFn4 _addRenderer Left Right 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