Commit a6636be4 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[sigma] forceatlas pause/resume is working

parent 399e3b00
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -27,6 +27,7 @@ import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Config (defaultFrontends)
import Gargantext.Data.Louvain as Louvain
import Gargantext.Hooks.Session (useSession)
import Gargantext.Hooks.Sigmax.ForceAtlas2 as ForceAtlas
import Gargantext.Hooks.Sigmax as Sigmax
import Gargantext.Hooks.Sigmax.Types as SigmaxT
import Gargantext.Types as GT
......@@ -43,15 +44,16 @@ here :: R2.Here
here = R2.here "Gargantext.Components.GraphExplorer.Layout"
type Props =
( sigmaRef :: R.Ref Sigmax.Sigma
( fa2Ref :: R.Ref (Maybe ForceAtlas.FA2Layout)
, sigmaRef :: R.Ref Sigmax.Sigma
)
layout :: R2.Leaf Props
layout = R2.leaf layoutCpt
layoutCpt :: R.Memo Props
layoutCpt = R.memo' $ here.component "explorerWriteGraph" cpt where
cpt { sigmaRef
cpt { fa2Ref
, sigmaRef
} _ = do
-- | States
-- |
......@@ -187,7 +189,8 @@ layoutCpt = R.memo' $ here.component "explorerWriteGraph" cpt where
}
[
Controls.controls
{ reloadForest: reloadForest
{ fa2Ref
, reloadForest: reloadForest
, sigmaRef
}
]
......@@ -200,6 +203,7 @@ layoutCpt = R.memo' $ here.component "explorerWriteGraph" cpt where
[
graphView
{ elRef: graphRef
, fa2Ref
, sigmaRef
}
]
......@@ -208,8 +212,9 @@ layoutCpt = R.memo' $ here.component "explorerWriteGraph" cpt where
--------------------------------------------------------------
type GraphProps =
( elRef :: R.Ref (Nullable Element)
, sigmaRef :: R.Ref Sigmax.Sigma
( elRef :: R.Ref (Nullable Element)
, fa2Ref :: R.Ref (Maybe ForceAtlas.FA2Layout)
, sigmaRef :: R.Ref Sigmax.Sigma
)
graphView :: R2.Leaf GraphProps
......@@ -217,6 +222,7 @@ graphView = R2.leaf graphViewCpt
graphViewCpt :: R.Memo GraphProps
graphViewCpt = R.memo' $ here.component "graphView" cpt where
cpt { elRef
, fa2Ref
, sigmaRef
} _ = do
-- | States
......@@ -265,6 +271,7 @@ graphViewCpt = R.memo' $ here.component "graphView" cpt where
Graph.drawGraph
{ elRef
, fa2Ref
, forceAtlas2Settings: Graph.forceAtlas2Settings
, sigmaRef
, sigmaSettings: Graph.sigmaSettings
......
......@@ -30,10 +30,11 @@ import Record (merge)
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.Graph"
here = R2.here "Gargantext.Components.GraphExplorer.Resources"
type Props sigma forceatlas2 =
( elRef :: R.Ref (Nullable Element)
, fa2Ref :: R.Ref (Maybe ForceAtlas2.FA2Layout)
, forceAtlas2Settings :: forceatlas2
, sigmaRef :: R.Ref Sigmax.Sigma
, sigmaSettings :: sigma
......@@ -49,6 +50,7 @@ drawGraphCpt = R.memo' $ here.component "graph" cpt where
-- | Component
-- |
cpt { elRef
, fa2Ref
, sigmaRef
, forceAtlas2Settings: fa2
, transformedGraph
......@@ -56,8 +58,6 @@ drawGraphCpt = R.memo' $ here.component "graph" cpt where
boxes <- AppStore.use
fa2Ref <- R.useRef (Nothing :: Maybe ForceAtlas2.FA2Layout)
{ showEdges
, graphStage
, graph
......@@ -85,10 +85,9 @@ drawGraphCpt = R.memo' $ here.component "graph" cpt where
Just fa2 -> do
ForceAtlas2.stop fa2
ForceAtlas2.kill fa2
here.log2 "[graphCpt (Cleanup)] forceAtlas stopped for" fa2
R.setRef fa2Ref Nothing
Sigmax.dependOnSigma (R.readRef sigmaRef) "[graphCpt (Cleanup)] no sigma" $ \sigma -> do
--Sigma.stopForceAtlas2 sigma
here.log2 "[graphCpt (Cleanup)] forceAtlas stopped for" sigma
Sigma.kill sigma
here.log "[graphCpt (Cleanup)] sigma killed"
......
......@@ -12,6 +12,7 @@ import Gargantext.Prelude
import Data.Maybe (Maybe(..))
import Data.Set as Set
import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Hooks.Sigmax.ForceAtlas2 as ForceAtlas
import Gargantext.Hooks.Sigmax.Types as SigmaxT
import Gargantext.Types as GT
import Gargantext.Utils (getter)
......
......@@ -19,6 +19,7 @@ import Gargantext.Components.GraphExplorer.Toolbar.RangeControl (edgeConfluenceC
import Gargantext.Components.GraphExplorer.Toolbar.SlideButton (labelSizeButton, mouseSelectorSizeButton)
import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Hooks.Session (useSession)
import Gargantext.Hooks.Sigmax.ForceAtlas2 as ForceAtlas
import Gargantext.Hooks.Sigmax as Sigmax
import Gargantext.Hooks.Sigmax.Types as SigmaxT
import Gargantext.Types as GT
......@@ -33,16 +34,17 @@ here :: R2.Here
here = R2.here "Gargantext.Components.GraphExplorer.Toolbar.Controls"
type Controls =
( reloadForest :: T2.ReloadS
, sigmaRef :: R.Ref Sigmax.Sigma
( fa2Ref :: R.Ref (Maybe ForceAtlas.FA2Layout)
, reloadForest :: T2.ReloadS
, sigmaRef :: R.Ref Sigmax.Sigma
)
controls :: R2.Leaf Controls
controls = R2.leaf controlsCpt
controlsCpt :: R.Memo Controls
controlsCpt = R.memo' $ here.component "controls" cpt where
cpt { reloadForest
cpt { fa2Ref
, reloadForest
, sigmaRef
} _ = do
-- | States
......@@ -91,7 +93,7 @@ controlsCpt = R.memo' $ here.component "controls" cpt where
_ -> pure unit
-- Handle case when FA is paused from outside events, eg. the automatic timer.
R.useEffect' $ Sigmax.handleForceAtlas2Pause sigmaRef forceAtlasState mFAPauseRef Graph.forceAtlas2Settings
R.useEffect' $ Sigmax.handleForceAtlas2Pause fa2Ref forceAtlasState mFAPauseRef Graph.forceAtlas2Settings
-- Handle automatic edge hiding when FA is running (to prevent flickering).
-- TODO Commented temporarily: this breaks forceatlas rendering after reset
......
......@@ -20,6 +20,7 @@ import Gargantext.Config.REST (logRESTError)
import Gargantext.Hooks.FirstEffect (useFirstEffect')
import Gargantext.Hooks.Loader (useLoaderEffect)
import Gargantext.Hooks.Session (useSession)
import Gargantext.Hooks.Sigmax.ForceAtlas2 as ForceAtlas
import Gargantext.Hooks.Sigmax as Sigmax
import Gargantext.Hooks.Sigmax.Types as SigmaxT
import Gargantext.Utils (getter)
......@@ -29,7 +30,7 @@ import Reactix as R
import Record as Record
type Props =
( graphId :: GET.GraphId
( graphId :: GET.GraphId
)
here :: R2.Here
......@@ -37,7 +38,6 @@ here = R2.here "Gargantext.Components.Nodes.Corpus.Graph"
node :: R2.Leaf ( key :: String | Props )
node = R2.leaf nodeCpt
nodeCpt :: R.Component ( key :: String | Props )
nodeCpt = here.component "node" cpt where
cpt { graphId } _ = do
......@@ -118,7 +118,6 @@ type HydrateStoreProps =
hydrateStore:: R2.Leaf HydrateStoreProps
hydrateStore = R2.leaf hydrateStoreCpt
hydrateStoreCpt :: R.Component HydrateStoreProps
hydrateStoreCpt = here.component "hydrateStore" cpt where
cpt { mMetaData
......@@ -142,6 +141,7 @@ hydrateStoreCpt = here.component "hydrateStore" cpt where
-- |
sigmaRef <- Sigmax.initSigma >>= R.useRef
fa2Ref <- R.useRef (Nothing :: Maybe ForceAtlas.FA2Layout)
-- Hydrate GraphStore
(state :: Record GraphStore.State) <- pure $
......@@ -171,5 +171,6 @@ hydrateStoreCpt = here.component "hydrateStore" cpt where
state
[
layout
{ sigmaRef }
{ fa2Ref
, sigmaRef }
]
......@@ -18,6 +18,7 @@ import Effect (Effect)
import Effect.Class.Console (error)
import Effect.Timer (TimeoutId, clearTimeout)
import FFI.Simple ((.=))
import Gargantext.Hooks.Sigmax.ForceAtlas2 as ForceAtlas
import Gargantext.Hooks.Sigmax.Graphology as Graphology
import Gargantext.Hooks.Sigmax.Sigma as Sigma
import Gargantext.Hooks.Sigmax.Types as ST
......@@ -115,28 +116,29 @@ dependOnContainer container notFoundMsg f = do
-- | Effect for handling pausing FA via state changes. We need this because
-- | pausing can be done not only via buttons but also from the initial
-- | setTimer.
handleForceAtlas2Pause :: forall settings. R.Ref Sigma -> T.Box ST.ForceAtlasState -> R.Ref (Maybe TimeoutId) -> settings -> Effect Unit
handleForceAtlas2Pause sigmaRef forceAtlasState mFAPauseRef settings = do
let sigma = R.readRef sigmaRef
handleForceAtlas2Pause :: forall settings. R.Ref (Maybe ForceAtlas.FA2Layout)
-> T.Box ST.ForceAtlasState
-> R.Ref (Maybe TimeoutId)
-> settings
-> Effect Unit
handleForceAtlas2Pause fa2Ref forceAtlasState mFAPauseRef settings = do
let fa2_ = R.readRef fa2Ref
toggled <- T.read forceAtlasState
dependOnSigma sigma "[handleForceAtlas2Pause] sigma: Nothing" $ \s -> do
-- TODO Rewrite using R.Ref FA2Layout instead of a Sigma ref
--let isFARunning = Sigma.isForceAtlas2Running s
let isFARunning = false
case Tuple toggled isFARunning of
Tuple ST.InitialRunning false -> do
--Sigma.restartForceAtlas2 s settings
pure unit
Tuple ST.Running false -> do
--Sigma.restartForceAtlas2 s settings
pure unit
case R.readRef mFAPauseRef of
Nothing -> pure unit
Just timeoutId -> clearTimeout timeoutId
Tuple ST.Paused true -> do
--Sigma.stopForceAtlas2 s
pure unit
_ -> pure unit
case fa2_ of
Nothing -> pure unit
Just fa2 -> do
isFARunning <- ForceAtlas.isRunning fa2
case Tuple toggled isFARunning of
Tuple ST.InitialRunning false -> do
ForceAtlas.restart fa2
Tuple ST.Running false -> do
ForceAtlas.restart fa2
case R.readRef mFAPauseRef of
Nothing -> pure unit
Just timeoutId -> clearTimeout timeoutId
Tuple ST.Paused true -> do
ForceAtlas.stop fa2
_ -> pure unit
setEdges :: Sigma.Sigma -> Boolean -> Effect Unit
setEdges sigma val = do
......
......@@ -44,7 +44,11 @@ isRunning = runEffectFn1 _isRunning
-- TODO?
restart :: FA2Layout -> Effect Unit
restart = start
restart fa2 = do
stop fa2
_ <- setTimeout 100 $ do
start fa2
pure unit
refresh :: FA2Layout -> Effect Unit
refresh f = do
......
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