Commit 26de4b9d authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] forceAtlast start/stop works now

parent 3268a4c7
......@@ -8,7 +8,6 @@ import Prelude
import Data.Maybe (Maybe(..))
import Data.Nullable (Nullable, null)
import DOM.Simple.Console (log2)
import FFI.Simple (delay)
import Reactix as R
import Reactix.DOM.HTML as RH
import Gargantext.Hooks.Sigmax
......@@ -43,25 +42,12 @@ graphCpt = R.hooksComponent "Graph" cpt
where
cpt props _ = do
ref <- R.useRef null
let mSigma = R.readRef props.sigmaRef
sigma <- useSigma ref props.sigmaSettings
sigma <- useSigma ref props.sigmaSettings props.sigmaRef
useCanvasRenderer ref sigma
useData sigma props.graph
useForceAtlas2 sigma props.forceAtlas2Settings
R.useLayoutEffect $
delay unit $ \_ -> do
log2 "[graphCpt] mSigma" mSigma
pure $ case mSigma of
Just s -> do
log2 "[graphCpt] mSigma is Just" s
pure unit
Nothing -> do
log2 "[graphCpt] setting sigmaRef" $ Just sigma
log2 "[graphCpt] readSigma" $ readSigma sigma
R.setRef props.sigmaRef $ Just sigma
pure $ RH.div { ref, style: {height: "95%"} } []
type SigmaSettings =
......
......@@ -121,7 +121,8 @@ graphView controls props = R.createElement el props []
where
el = R.hooksComponent "GraphView" cpt
cpt {graphId, graph} _children = do
pure $ RH.div { className: colSize controls }
pure $
RH.div { className: colSize controls }
[
Graph.graph {
forceAtlas2Settings: Graph.forceAtlas2Settings
......
......@@ -37,7 +37,6 @@ type Controls =
, labelSize :: R.State Number
, nodeSize :: R.State Range.NumberRange
, multiNodeSelect :: R.Ref Boolean
, pauseForceAtlas :: R.State Boolean
, showControls :: R.State Boolean
, showEdges :: R.State Boolean
, showSidePanel :: R.State Boolean
......@@ -61,21 +60,34 @@ controlsToSigmaSettings { cursorSize: (cursorSize /\ _)
, maxNodeSize = nodeSizeMax
}
type LocalControls =
( pauseForceAtlas :: R.State Boolean
)
initialLocalControls :: R.Hooks (Record LocalControls)
initialLocalControls = do
pauseForceAtlas <- R.useState' true
pure $ {
pauseForceAtlas
}
controls :: Record Controls -> R.Element
controls props = R.createElement controlsCpt props []
controlsCpt :: R.Component Controls
controlsCpt = R.hooksComponent "GraphControls" cpt
where
cpt props _ =
case getShowControls props of
false -> pure $ RH.div {} []
true -> do
pure $ RH.div { className: "col-md-12", style: { paddingBottom: "10px" } }
cpt props _ = do
localControls <- initialLocalControls
pure $ case getShowControls props of
false -> RH.div {} []
true -> RH.div { className: "col-md-12", style: { paddingBottom: "10px" } }
[ R2.menu { id: "toolbar" }
[ RH.ul {}
[ -- change type button (?)
RH.li {} [ pauseForceAtlasButton props.sigmaRef props.pauseForceAtlas ] -- spatialization (pause ForceAtlas2)
RH.li {} [ pauseForceAtlasButton props.sigmaRef localControls.pauseForceAtlas ] -- spatialization (pause ForceAtlas2)
, RH.li {} [ edgesToggleButton props.showEdges ]
, RH.li {} [ edgeSizeControl props.edgeSize ] -- edge size : 0-3
-- change level
......@@ -100,7 +112,6 @@ useGraphControls = do
labelSize <- R.useState' 3.0
nodeSize <- R.useState' $ Range.Closed { min: 5.0, max: 10.0 }
multiNodeSelect <- R.useRef false
pauseForceAtlas <- R.useState' true
showControls <- R.useState' false
showEdges <- R.useState' true
showSidePanel <- R.useState' false
......@@ -113,7 +124,6 @@ useGraphControls = do
, labelSize
, multiNodeSelect
, nodeSize
, pauseForceAtlas
, showControls
, showEdges
, showSidePanel
......@@ -121,15 +131,15 @@ useGraphControls = do
, sigmaRef
}
getShowTree :: Record Controls -> Boolean
getShowTree { showTree: ( should /\ _ ) } = should
getShowControls :: Record Controls -> Boolean
getShowControls { showControls: ( should /\ _ ) } = should
getShowSidePanel :: Record Controls -> Boolean
getShowSidePanel { showSidePanel: ( should /\ _ ) } = should
getShowTree :: Record Controls -> Boolean
getShowTree { showTree: ( should /\ _ ) } = should
getShowEdges :: Record Controls -> Boolean
getShowEdges { showEdges: ( should /\ _ ) } = should
......@@ -145,15 +155,15 @@ getNodeSize { nodeSize: ( size /\ _ ) } = size
getMultiNodeSelect :: Record Controls -> Boolean
getMultiNodeSelect { multiNodeSelect } = R.readRef multiNodeSelect
setShowTree :: Record Controls -> Boolean -> Effect Unit
setShowTree { showTree: ( _ /\ set ) } v = set $ const v
setShowControls :: Record Controls -> Boolean -> Effect Unit
setShowControls { showControls: ( _ /\ set ) } v = set $ const v
setShowSidePanel :: Record Controls -> Boolean -> Effect Unit
setShowSidePanel { showSidePanel: ( _ /\ set ) } v = set $ const v
setShowTree :: Record Controls -> Boolean -> Effect Unit
setShowTree { showTree: ( _ /\ set ) } v = set $ const v
setShowEdges :: Record Controls -> Boolean -> Effect Unit
setShowEdges { showEdges: ( _ /\ set ) } v = set $ const v
......
......@@ -17,7 +17,7 @@ import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Hooks.Sigmax as Sigmax
import Gargantext.Hooks.Sigmax.Sigma (startForceAtlas2, stopForceAtlas2)
import Gargantext.Hooks.Sigmax.Sigma (restartForceAtlas2, stopForceAtlas2)
import Gargantext.Utils.Reactix as R2
type Props = (
......@@ -78,22 +78,17 @@ pauseForceAtlasButton sigmaRef state = R.createElement el props []
{ className: "btn btn-primary"
, on: {click: \_ -> do
let mSigma = R.readRef sigmaRef
log2 "[pauseForceAtlasButton] mSigma" mSigma
case mSigma of
Nothing -> pure unit
Just sigma -> do
log2 "[pauseForceAtlasButton] sigma" sigma
log2 "[pauseForceAtlasButton] toggled" toggled
let rSigma = Sigmax.readSigma sigma
log2 "[pauseForceAtlasButton] rSigma" rSigma
if toggled then
case rSigma of
Nothing -> pure unit
Just s -> stopForceAtlas2 s
Just s -> if toggled then
stopForceAtlas2 s
else
--startForceAtlas2 $ graph.sigma
pure unit
--setToggled not
restartForceAtlas2 s
setToggled not
}
}
[ H.text (text onMessage offMessage toggled) ]
......
......@@ -51,8 +51,8 @@ cleanupFirst sigma =
R.setRef sigma.cleanup <<< (flip Seq.cons) (R.readRef sigma.cleanup)
-- | Manages a sigma with the given settings
useSigma :: forall settings. R.Ref (Nullable Element) -> settings -> R.Hooks Sigma
useSigma container settings = do
useSigma :: forall settings. R.Ref (Nullable Element) -> settings -> R.Ref (Maybe Sigma) -> R.Hooks Sigma
useSigma container settings sigmaRef = do
sigma <- newSigma <$> R2.nothingRef <*> R.useRef Seq.empty
R.useEffect2 container sigma.sigma $
delay unit $ handleSigma sigma (readSigma sigma)
......@@ -63,7 +63,8 @@ useSigma container settings = do
handleSigma sigma Nothing _ = do
ret <- createSigma settings
traverse_ (writeSigma sigma <<< Just) ret
pure (cleanupSigma sigma "useSigma")
R.setRef sigmaRef $ Just sigma
pure $ cleanupSigma sigma "useSigma"
-- | Manages a renderer for the sigma
useCanvasRenderer :: R.Ref (Nullable Element) -> Sigma -> R.Hooks Unit
......
......@@ -3,6 +3,7 @@ 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 Effect (Effect)
import FFI.Simple.Objects (named)
......@@ -98,6 +99,9 @@ foreign import _bind :: forall e. EffectFn3 Sigma String (EffectFn1 e Unit) Unit
startForceAtlas2 :: forall settings. Sigma -> settings -> Effect Unit
startForceAtlas2 = runEffectFn2 _startForceAtlas2
restartForceAtlas2 :: Sigma -> Effect Unit
restartForceAtlas2 sigma = runEffectFn2 _startForceAtlas2 sigma null
stopForceAtlas2 :: Sigma -> Effect Unit
stopForceAtlas2 = runEffectFn1 _stopForceAtlas2
......
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