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