Commit ad1ada7e authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski Committed by Alexandre Delanoë

[graph explorer] some drafts on handling hidden edges

parent 27db9304
......@@ -302,22 +302,24 @@ sigmaSettings =
}
type ForceAtlas2Settings =
( adjustSizes :: Boolean
, barnesHutOptimize :: Boolean
-- , barnesHutTheta :: Number
, edgeWeightInfluence :: Number
-- , fixedY :: Boolean
, gravity :: Number
, iterationsPerRender :: Number
, linLogMode :: Boolean
( adjustSizes :: Boolean
, barnesHutOptimize :: Boolean
-- , barnesHutTheta :: Number
, edgeWeightInfluence :: Number
-- , fixedY :: Boolean
, gravity :: Number
, includeHiddenEdges :: Boolean
, includeHiddenNodes :: Boolean
, iterationsPerRender :: Number
, linLogMode :: Boolean
, outboundAttractionDistribution :: Boolean
, scalingRatio :: Number
, skipHidden :: Boolean
, slowDown :: Number
, startingIterations :: Number
, strongGravityMode :: Boolean
-- , timeout :: Number
-- , worker :: Boolean
, scalingRatio :: Number
, skipHidden :: Boolean
, slowDown :: Number
, startingIterations :: Number
, strongGravityMode :: Boolean
-- , timeout :: Number
-- , worker :: Boolean
)
forceAtlas2Settings :: {|ForceAtlas2Settings}
......@@ -327,6 +329,8 @@ forceAtlas2Settings =
, edgeWeightInfluence : 1.0
-- fixedY : false
, gravity : 0.01
, includeHiddenEdges: false
, includeHiddenNodes: true
, iterationsPerRender : 50.0 -- 10.0
, linLogMode : false -- false
, outboundAttractionDistribution: false
......
......@@ -20,7 +20,7 @@ import Gargantext.Components.Graph as Graph
import Gargantext.Components.GraphExplorer.Button (centerButton, cameraButton)
import Gargantext.Components.GraphExplorer.RangeControl (edgeConfluenceControl, edgeWeightControl, nodeSizeControl)
import Gargantext.Components.GraphExplorer.SlideButton (labelSizeButton, mouseSelectorSizeButton)
import Gargantext.Components.GraphExplorer.ToggleButton (multiSelectEnabledButton, edgesToggleButton, louvainToggleButton, pauseForceAtlasButton)
import Gargantext.Components.GraphExplorer.ToggleButton (multiSelectEnabledButton, edgesToggleButton, louvainToggleButton, pauseForceAtlasButton, resetForceAtlasButton)
import Gargantext.Components.GraphExplorer.Sidebar.Types as GEST
import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Hooks.Sigmax as Sigmax
......@@ -108,7 +108,7 @@ controlsCpt = here.component "controls" cpt
_ -> pure unit
-- Handle case when FA is paused from outside events, eg. the automatic timer.
R.useEffect' $ Sigmax.handleForceAtlas2Pause sigmaRef forceAtlasState mFAPauseRef
R.useEffect' $ Sigmax.handleForceAtlas2Pause sigmaRef forceAtlasState mFAPauseRef Graph.forceAtlas2Settings
-- Handle automatic edge hiding when FA is running (to prevent flickering).
R.useEffect2' sigmaRef forceAtlasState' $ do
......@@ -162,6 +162,7 @@ controlsCpt = here.component "controls" cpt
[ RH.ul { className: "navbar-nav mx-auto" }
[ -- change type button (?)
navItem [ centerButton sigmaRef ]
, navItem [ resetForceAtlasButton { forceAtlasState, sigmaRef } [] ]
, navItem [ pauseForceAtlasButton { state: forceAtlasState } [] ]
, navItem [ edgesToggleButton { state: showEdges } [] ]
, navItem [ louvainToggleButton { state: showLouvain } [] ]
......
......@@ -8,6 +8,7 @@ module Gargantext.Components.GraphExplorer.ToggleButton
, multiSelectEnabledButton
, sidebarToggleButton
, pauseForceAtlasButton
, resetForceAtlasButton
, treeToggleButton
) where
......@@ -18,6 +19,9 @@ import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Components.Graph as Graph
import Gargantext.Hooks.Sigmax as Sigmax
import Gargantext.Hooks.Sigmax.Sigma as Sigma
import Gargantext.Hooks.Sigmax.Types as SigmaxTypes
import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2
......@@ -156,9 +160,32 @@ pauseForceAtlasButtonCpt = here.component "forceAtlasToggleButton" cpt
text SigmaxTypes.InitialStopped = "Start Force Atlas"
text SigmaxTypes.Running = "Pause Force Atlas"
text SigmaxTypes.Paused = "Start Force Atlas"
text SigmaxTypes.Killed = "Start Force Atlas"
onClick state _ = T.modify_ SigmaxTypes.toggleForceAtlasState state
type ResetForceAtlasProps = (
forceAtlasState :: T.Box SigmaxTypes.ForceAtlasState
, sigmaRef :: R.Ref Sigmax.Sigma
)
resetForceAtlasButton :: R2.Component ResetForceAtlasProps
resetForceAtlasButton = R.createElement resetForceAtlasButtonCpt
resetForceAtlasButtonCpt :: R.Component ResetForceAtlasProps
resetForceAtlasButtonCpt = here.component "resetForceAtlasToggleButton" cpt
where
cpt { forceAtlasState, sigmaRef } _ = do
pure $ H.button { className: "btn btn-outline-primary"
, on: { click: onClick forceAtlasState sigmaRef }
} [ R2.small {} [ H.text "Reset Force Atlas" ] ]
onClick forceAtlasState sigmaRef _ = do
-- TODO Sigma.killForceAtlas2 sigma
-- startForceAtlas2 sigma
Sigmax.dependOnSigma (R.readRef sigmaRef) "[resetForceAtlasButton] no sigma" $ \sigma -> do
Sigma.killForceAtlas2 sigma
T.write_ SigmaxTypes.Killed forceAtlasState
type TreeToggleButtonProps = (
state :: T.Box Boolean
)
......
......@@ -113,28 +113,21 @@ 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.
--handleForceAtlasPause sigmaRef (toggled /\ setToggled) mFAPauseRef = do
handleForceAtlas2Pause :: R.Ref Sigma -> T.Box ST.ForceAtlasState -> R.Ref (Maybe TimeoutId) -> Effect Unit
handleForceAtlas2Pause sigmaRef forceAtlasState mFAPauseRef = do
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
toggled <- T.read forceAtlasState
dependOnSigma sigma "[handleForceAtlas2Pause] sigma: Nothing" $ \s -> do
--log2 "[handleForceAtlas2Pause] mSigma: Just " s
--log2 "[handleForceAtlas2Pause] toggled: " toggled
let isFARunning = Sigma.isForceAtlas2Running s
--log2 "[handleForceAtlas2Pause] isFARunning: " isFARunning
case Tuple toggled isFARunning of
Tuple ST.InitialRunning false -> do
-- hide edges during forceAtlas rendering, this prevents flickering
Sigma.restartForceAtlas2 s
Sigma.restartForceAtlas2 s settings
Tuple ST.Running false -> do
-- hide edges during forceAtlas rendering, this prevents flickering
Sigma.restartForceAtlas2 s
Sigma.restartForceAtlas2 s settings
case R.readRef mFAPauseRef of
Nothing -> pure unit
Just timeoutId -> clearTimeout timeoutId
Tuple ST.Paused true -> do
-- restore edges state
Sigma.stopForceAtlas2 s
_ -> pure unit
......
......@@ -222,8 +222,8 @@ startForceAtlas2 :: forall settings. Sigma -> settings -> Effect Unit
startForceAtlas2 s settings = pure $ s ... "startForceAtlas2" $ [ settings ]
-- | Restart forceAtlas2 on a sigmajs instance.
restartForceAtlas2 :: Sigma -> Effect Unit
restartForceAtlas2 s = startForceAtlas2 s null
restartForceAtlas2 :: forall settings. Sigma -> settings -> Effect Unit
restartForceAtlas2 s settings = startForceAtlas2 s settings
-- | Stop forceAtlas2 on a sigmajs instance.
stopForceAtlas2 :: Sigma -> Effect Unit
......@@ -239,14 +239,14 @@ isForceAtlas2Running s = s ... "isForceAtlas2Running" $ [] :: Boolean
-- | Refresh forceAtlas2 (with a `setTimeout` hack as it seems it doesn't work
-- | otherwise).
refreshForceAtlas :: Sigma -> Effect Unit
refreshForceAtlas s = do
refreshForceAtlas :: forall settings. Sigma -> settings -> Effect Unit
refreshForceAtlas s settings = do
let isRunning = isForceAtlas2Running s
if isRunning then
pure unit
else do
_ <- setTimeout 100 $ do
restartForceAtlas2 s
restartForceAtlas2 s settings
_ <- setTimeout 100 $
stopForceAtlas2 s
pure unit
......
......@@ -4,14 +4,3 @@ exports.goToImpl = function(cam) {
return cam.goTo(props);
};
};
exports.pauseForceAtlas2 = function() {
var s = window.sigmaGargInstance;
if (s) {
if (s.isForceAtlas2Running()) {
s.stopForceAtlas2()
}
else {
s.startForceAtlas2()
}
}
};
......@@ -103,8 +103,6 @@ foreign import goToImpl :: forall o. CameraInstance -> EffectFn1 { | o } CameraI
goTo :: forall o. Optional o CameraProps => CameraInstance -> { | o } -> Effect CameraInstance
goTo cam = runEffectFn1 (goToImpl cam)
foreign import pauseForceAtlas2 :: Effect Unit
type SigmaProps =
( renderer :: String
, settings :: SigmaSettings
......
......@@ -157,7 +157,7 @@ eqGraph (Graph {nodes: n1, edges: e1}) (Graph {nodes: n2, edges: e2}) = (n1 == n
-- however when graph is loaded initially, forceAtlas is running for a couple of
-- seconds and then stops (unless the user alters this by clicking the toggle
-- button).
data ForceAtlasState = InitialRunning | InitialStopped | Running | Paused
data ForceAtlasState = InitialRunning | InitialStopped | Running | Paused | Killed
derive instance genericForceAtlasState :: Generic ForceAtlasState _
instance eqForceAtlasState :: Eq ForceAtlasState where
......@@ -168,6 +168,7 @@ toggleForceAtlasState InitialRunning = Paused
toggleForceAtlasState InitialStopped = InitialRunning
toggleForceAtlasState Running = Paused
toggleForceAtlasState Paused = Running
toggleForceAtlasState Killed = Running
-- | Custom state for show edges. Normally it is EShow or EHide (show/hide
-- | edges). However, edges are temporarily turned off when forceAtlas is
......@@ -218,6 +219,7 @@ forceAtlasEdgeState Running EShow = ETempHiddenThenShow
forceAtlasEdgeState Running es = es
forceAtlasEdgeState Paused ETempHiddenThenShow = EShow
forceAtlasEdgeState Paused es = es
forceAtlasEdgeState Killed es = es
louvainEdges :: SGraph -> Array (Record Louvain.Edge)
......
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