Commit 3408c4cd authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] fix tree clicking when refreshing graphs

parent 57f6fa5c
...@@ -89,6 +89,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -89,6 +89,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
Sigmax.cleanupSigma rSigma "explorerCpt" Sigmax.cleanupSigma rSigma "explorerCpt"
R.setRef dataRef graph R.setRef dataRef graph
snd controls.selectedNodeIds $ const Set.empty snd controls.selectedNodeIds $ const Set.empty
snd controls.forceAtlasState $ const SigmaxTypes.InitialRunning
snd controls.graphStage $ const Graph.Init snd controls.graphStage $ const Graph.Init
pure $ pure $
......
...@@ -15,6 +15,7 @@ import Data.Sequence as Seq ...@@ -15,6 +15,7 @@ import Data.Sequence as Seq
import Data.Set as Set import Data.Set as Set
import Data.Tuple (fst, snd) import Data.Tuple (fst, snd)
import Data.Tuple.Nested ((/\), get1) import Data.Tuple.Nested ((/\), get1)
import DOM.Simple.Console (log, log2)
import Effect (Effect) import Effect (Effect)
import Effect.Timer (setTimeout) import Effect.Timer (setTimeout)
import Prelude import Prelude
...@@ -37,6 +38,7 @@ type Controls = ...@@ -37,6 +38,7 @@ type Controls =
( cursorSize :: R.State Number ( cursorSize :: R.State Number
, edgeConfluence :: R.State Range.NumberRange , edgeConfluence :: R.State Range.NumberRange
, edgeWeight :: R.State Range.NumberRange , edgeWeight :: R.State Range.NumberRange
, forceAtlasState :: R.State SigmaxTypes.ForceAtlasState
, graph :: SigmaxTypes.SGraph , graph :: SigmaxTypes.SGraph
, graphStage :: R.State Graph.Stage , graphStage :: R.State Graph.Stage
, multiSelectEnabled :: R.State Boolean , multiSelectEnabled :: R.State Boolean
...@@ -53,22 +55,17 @@ controlsToSigmaSettings { cursorSize: (cursorSize /\ _)} = Graph.sigmaSettings ...@@ -53,22 +55,17 @@ controlsToSigmaSettings { cursorSize: (cursorSize /\ _)} = Graph.sigmaSettings
type LocalControls = type LocalControls =
( labelSize :: R.State Number ( labelSize :: R.State Number
, pauseForceAtlas :: R.State Boolean
, showEdges :: R.State Boolean , showEdges :: R.State Boolean
) )
initialLocalControls :: R.Hooks (Record LocalControls) initialLocalControls :: R.Hooks (Record LocalControls)
initialLocalControls = do initialLocalControls = do
labelSize <- R.useState' 14.0 labelSize <- R.useState' 14.0
--nodeSize <- R.useState' $ Range.Closed { min: 0.0, max: 10.0 }
pauseForceAtlas <- R.useState' true
search <- R.useState' "" search <- R.useState' ""
showEdges <- R.useState' true showEdges <- R.useState' true
pure $ { pure $ {
labelSize labelSize
--, nodeSize
, pauseForceAtlas
, showEdges , showEdges
} }
...@@ -90,7 +87,7 @@ controlsCpt = R.hooksComponent "GraphControls" cpt ...@@ -90,7 +87,7 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
Graph.Init -> R.setRef mFAPauseRef Nothing Graph.Init -> R.setRef mFAPauseRef Nothing
_ -> pure unit _ -> pure unit
R.useEffect' $ Sigmax.handleForceAtlas2Pause props.sigmaRef localControls.pauseForceAtlas (get1 localControls.showEdges) mFAPauseRef R.useEffect' $ Sigmax.handleForceAtlas2Pause props.sigmaRef props.forceAtlasState (get1 localControls.showEdges) mFAPauseRef
R.useEffect' $ do R.useEffect' $ do
if fst props.showSidePanel == GET.InitialClosed && (not Set.isEmpty $ fst props.selectedNodeIds) then if fst props.showSidePanel == GET.InitialClosed && (not Set.isEmpty $ fst props.selectedNodeIds) then
...@@ -98,16 +95,18 @@ controlsCpt = R.hooksComponent "GraphControls" cpt ...@@ -98,16 +95,18 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
else else
pure unit pure unit
R.useEffectOnce' $ do R.useEffect1' (fst props.forceAtlasState) $ do
if (fst props.forceAtlasState) == SigmaxTypes.InitialRunning then do
timeoutId <- setTimeout 2000 $ do timeoutId <- setTimeout 2000 $ do
let (toggled /\ setToggled) = localControls.pauseForceAtlas let (toggled /\ setToggled) = props.forceAtlasState
if toggled then case toggled of
setToggled $ const false SigmaxTypes.InitialRunning -> setToggled $ const SigmaxTypes.Paused
else _ -> pure unit
pure unit
R.setRef mFAPauseRef Nothing R.setRef mFAPauseRef Nothing
R.setRef mFAPauseRef $ Just timeoutId R.setRef mFAPauseRef $ Just timeoutId
pure unit pure unit
else
pure unit
let nodesSorted = A.sortWith (_.size) $ Seq.toUnfoldable $ SigmaxTypes.graphNodes props.graph let nodesSorted = A.sortWith (_.size) $ Seq.toUnfoldable $ SigmaxTypes.graphNodes props.graph
let nodeSizeMin = maybe 0.0 _.size $ A.head nodesSorted let nodeSizeMin = maybe 0.0 _.size $ A.head nodesSorted
...@@ -121,7 +120,7 @@ controlsCpt = R.hooksComponent "GraphControls" cpt ...@@ -121,7 +120,7 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
[ RH.ul {} [ RH.ul {}
[ -- change type button (?) [ -- change type button (?)
RH.li {} [ centerButton props.sigmaRef ] RH.li {} [ centerButton props.sigmaRef ]
, RH.li {} [ pauseForceAtlasButton props.sigmaRef localControls.pauseForceAtlas ] -- spatialization (pause ForceAtlas2) , RH.li {} [ pauseForceAtlasButton {state: props.forceAtlasState} ]
, RH.li {} [ edgesToggleButton props.sigmaRef localControls.showEdges ] , RH.li {} [ edgesToggleButton props.sigmaRef localControls.showEdges ]
, RH.li {} [ edgeConfluenceControl props.sigmaRef props.edgeConfluence ] , RH.li {} [ edgeConfluenceControl props.sigmaRef props.edgeConfluence ]
, RH.li {} [ edgeWeightControl props.sigmaRef props.edgeWeight ] , RH.li {} [ edgeWeightControl props.sigmaRef props.edgeWeight ]
...@@ -149,6 +148,7 @@ useGraphControls graph = do ...@@ -149,6 +148,7 @@ useGraphControls graph = do
cursorSize <- R.useState' 10.0 cursorSize <- R.useState' 10.0
edgeConfluence <- R.useState' $ Range.Closed { min: 0.0, max: 1.0 } edgeConfluence <- R.useState' $ Range.Closed { min: 0.0, max: 1.0 }
edgeWeight <- R.useState' $ Range.Closed { min: 0.0, max: 1.0 } edgeWeight <- R.useState' $ Range.Closed { min: 0.0, max: 1.0 }
forceAtlasState <- R.useState' SigmaxTypes.InitialRunning
graphStage <- R.useState' Graph.Init graphStage <- R.useState' Graph.Init
multiSelectEnabled <- R.useState' false multiSelectEnabled <- R.useState' false
nodeSize <- R.useState' $ Range.Closed { min: 0.0, max: 100.0 } nodeSize <- R.useState' $ Range.Closed { min: 0.0, max: 100.0 }
...@@ -162,6 +162,7 @@ useGraphControls graph = do ...@@ -162,6 +162,7 @@ useGraphControls graph = do
pure { cursorSize pure { cursorSize
, edgeConfluence , edgeConfluence
, edgeWeight , edgeWeight
, forceAtlasState
, graph , graph
, graphStage , graphStage
, multiSelectEnabled , multiSelectEnabled
......
...@@ -20,6 +20,7 @@ import Reactix.DOM.HTML as H ...@@ -20,6 +20,7 @@ import Reactix.DOM.HTML as H
import Gargantext.Components.GraphExplorer.Types as GET import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Hooks.Sigmax as Sigmax import Gargantext.Hooks.Sigmax as Sigmax
import Gargantext.Hooks.Sigmax.Types as SigmaxTypes
type Props = ( type Props = (
state :: R.State Boolean state :: R.State Boolean
...@@ -78,16 +79,29 @@ multiSelectEnabledButton state = ...@@ -78,16 +79,29 @@ multiSelectEnabledButton state =
, onClick: \_ -> snd state not , onClick: \_ -> snd state not
} }
pauseForceAtlasButton :: R.Ref Sigmax.Sigma -> R.State Boolean -> R.Element type ForceAtlasProps = (
pauseForceAtlasButton sigmaRef state = state :: R.State SigmaxTypes.ForceAtlasState
toggleButton { )
state: state
, onMessage: "Pause Force Atlas" pauseForceAtlasButton :: Record ForceAtlasProps -> R.Element
, offMessage: "Start Force Atlas" pauseForceAtlasButton props = R.createElement pauseForceAtlasButtonCpt props []
, onClick: \_ -> do
let (_ /\ setToggled) = state pauseForceAtlasButtonCpt :: R.Component ForceAtlasProps
setToggled not pauseForceAtlasButtonCpt = R.hooksComponent "ForceAtlasToggleButton" cpt
} where
cpt {state: (state /\ setState)} _ = do
pure $
H.span {}
[
H.button
{ className: "btn btn-primary", on: {click: onClick setState} }
[ H.text (text state) ]
]
text SigmaxTypes.InitialRunning = "Pause Force Atlas"
text SigmaxTypes.Running = "Pause Force Atlas"
text SigmaxTypes.Paused = "Start Force Atlas"
onClick setState _ = setState SigmaxTypes.toggleForceAtlasState
treeToggleButton :: R.State Boolean -> R.Element treeToggleButton :: R.State Boolean -> R.Element
treeToggleButton state = treeToggleButton state =
......
...@@ -22,7 +22,7 @@ import Effect.Class.Console (error) ...@@ -22,7 +22,7 @@ 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.Sigma as Sigma import Gargantext.Hooks.Sigmax.Sigma as Sigma
import Gargantext.Hooks.Sigmax.Types (Graph(..), SGraph, EdgesMap, NodesMap, SelectedNodeIds, SelectedEdgeIds, graphEdges) import Gargantext.Hooks.Sigmax.Types as ST
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Reactix as R import Reactix as R
...@@ -32,7 +32,7 @@ type Sigma = ...@@ -32,7 +32,7 @@ type Sigma =
, cleanup :: R.Ref (Seq (Effect Unit)) , cleanup :: R.Ref (Seq (Effect Unit))
} }
type Data n e = { graph :: R.Ref (Graph n e) } type Data n e = { graph :: R.Ref (ST.Graph n e) }
initSigma :: R.Hooks Sigma initSigma :: R.Hooks Sigma
initSigma = do initSigma = do
...@@ -85,8 +85,8 @@ refreshData sigma graph ...@@ -85,8 +85,8 @@ refreshData sigma graph
refreshingMsg = "[refreshData] Refreshing graph" refreshingMsg = "[refreshData] Refreshing graph"
errorMsg = "[refreshData] Error reading graph data:" errorMsg = "[refreshData] Error reading graph data:"
sigmafy :: forall n e. Graph n e -> Sigma.Graph n e sigmafy :: forall n e. ST.Graph n e -> Sigma.Graph n e
sigmafy (Graph g) = {nodes,edges} sigmafy (ST.Graph g) = {nodes,edges}
where where
nodes = A.fromFoldable g.nodes nodes = A.fromFoldable g.nodes
edges = A.fromFoldable g.edges edges = A.fromFoldable g.edges
...@@ -110,7 +110,7 @@ dependOnContainer container notFoundMsg f = do ...@@ -110,7 +110,7 @@ dependOnContainer container notFoundMsg f = do
-- | 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.
--handleForceAtlasPause sigmaRef (toggled /\ setToggled) mFAPauseRef = do --handleForceAtlasPause sigmaRef (toggled /\ setToggled) mFAPauseRef = do
handleForceAtlas2Pause :: R.Ref Sigma -> R.State Boolean -> Boolean -> R.Ref (Maybe TimeoutId) -> Effect Unit handleForceAtlas2Pause :: R.Ref Sigma -> R.State ST.ForceAtlasState -> Boolean -> R.Ref (Maybe TimeoutId) -> Effect Unit
handleForceAtlas2Pause sigmaRef (toggled /\ setToggled) showEdges mFAPauseRef = do handleForceAtlas2Pause sigmaRef (toggled /\ setToggled) showEdges mFAPauseRef = do
let sigma = R.readRef sigmaRef let sigma = R.readRef sigmaRef
dependOnSigma sigma "[handleForceAtlas2Pause] sigma: Nothing" $ \s -> do dependOnSigma sigma "[handleForceAtlas2Pause] sigma: Nothing" $ \s -> do
...@@ -119,14 +119,18 @@ handleForceAtlas2Pause sigmaRef (toggled /\ setToggled) showEdges mFAPauseRef = ...@@ -119,14 +119,18 @@ handleForceAtlas2Pause sigmaRef (toggled /\ setToggled) showEdges mFAPauseRef =
isFARunning <- Sigma.isForceAtlas2Running s isFARunning <- Sigma.isForceAtlas2Running s
--log2 "[handleForceAtlas2Pause] isFARunning: " isFARunning --log2 "[handleForceAtlas2Pause] isFARunning: " isFARunning
case Tuple toggled isFARunning of case Tuple toggled isFARunning of
Tuple true false -> do Tuple ST.InitialRunning false -> do
-- hide edges during forceAtlas rendering, this prevents flickering
Sigma.restartForceAtlas2 s
setEdges s false
Tuple ST.Running false -> do
-- hide edges during forceAtlas rendering, this prevents flickering -- hide edges during forceAtlas rendering, this prevents flickering
Sigma.restartForceAtlas2 s Sigma.restartForceAtlas2 s
setEdges s false setEdges s false
case R.readRef mFAPauseRef of case R.readRef mFAPauseRef of
Nothing -> pure unit Nothing -> pure unit
Just timeoutId -> clearTimeout timeoutId Just timeoutId -> clearTimeout timeoutId
Tuple false true -> do Tuple ST.Paused true -> do
-- restore edges state -- restore edges state
Sigma.stopForceAtlas2 s Sigma.stopForceAtlas2 s
setEdges s showEdges setEdges s showEdges
...@@ -154,7 +158,7 @@ setEdges sigma val = do ...@@ -154,7 +158,7 @@ setEdges sigma val = do
Sigma.setSettings sigma settings Sigma.setSettings sigma settings
_ -> pure unit _ -> pure unit
markSelectedEdges :: Sigma.Sigma -> SelectedEdgeIds -> EdgesMap -> Effect Unit markSelectedEdges :: Sigma.Sigma -> ST.SelectedEdgeIds -> ST.EdgesMap -> Effect Unit
markSelectedEdges sigma selectedEdgeIds graphEdges = do markSelectedEdges sigma selectedEdgeIds graphEdges = do
Sigma.forEachEdge sigma \e -> do Sigma.forEachEdge sigma \e -> do
case Map.lookup e.id graphEdges of case Map.lookup e.id graphEdges of
...@@ -169,7 +173,7 @@ markSelectedEdges sigma selectedEdgeIds graphEdges = do ...@@ -169,7 +173,7 @@ markSelectedEdges sigma selectedEdgeIds graphEdges = do
pure unit pure unit
Sigma.refresh sigma Sigma.refresh sigma
markSelectedNodes :: Sigma.Sigma -> SelectedNodeIds -> NodesMap -> Effect Unit markSelectedNodes :: Sigma.Sigma -> ST.SelectedNodeIds -> ST.NodesMap -> Effect Unit
markSelectedNodes sigma selectedNodeIds graphNodes = do markSelectedNodes sigma selectedNodeIds graphNodes = do
Sigma.forEachNode sigma \n -> do Sigma.forEachNode sigma \n -> do
case Map.lookup n.id graphNodes of case Map.lookup n.id graphNodes of
...@@ -185,7 +189,7 @@ markSelectedNodes sigma selectedNodeIds graphNodes = do ...@@ -185,7 +189,7 @@ markSelectedNodes sigma selectedNodeIds graphNodes = do
Sigma.refresh sigma Sigma.refresh sigma
updateEdges :: Sigma.Sigma -> EdgesMap -> Effect Unit updateEdges :: Sigma.Sigma -> ST.EdgesMap -> Effect Unit
updateEdges sigma edgesMap = do updateEdges sigma edgesMap = do
Sigma.forEachEdge sigma \e -> do Sigma.forEachEdge sigma \e -> do
let mTEdge = Map.lookup e.id edgesMap let mTEdge = Map.lookup e.id edgesMap
...@@ -198,7 +202,7 @@ updateEdges sigma edgesMap = do ...@@ -198,7 +202,7 @@ updateEdges sigma edgesMap = do
Sigma.refresh sigma Sigma.refresh sigma
updateNodes :: Sigma.Sigma -> NodesMap -> Effect Unit updateNodes :: Sigma.Sigma -> ST.NodesMap -> Effect Unit
updateNodes sigma nodesMap = do updateNodes sigma nodesMap = do
Sigma.forEachNode sigma \n -> do Sigma.forEachNode sigma \n -> do
let mTNode = Map.lookup n.id nodesMap let mTNode = Map.lookup n.id nodesMap
...@@ -212,7 +216,7 @@ updateNodes sigma nodesMap = do ...@@ -212,7 +216,7 @@ updateNodes sigma nodesMap = do
-- | Toggles item visibility in the selected set -- | Toggles item visibility in the selected set
multiSelectUpdate :: SelectedNodeIds -> SelectedNodeIds -> SelectedNodeIds multiSelectUpdate :: ST.SelectedNodeIds -> ST.SelectedNodeIds -> ST.SelectedNodeIds
multiSelectUpdate new selected = foldl fld selected new multiSelectUpdate new selected = foldl fld selected new
where where
fld selectedAcc item = fld selectedAcc item =
...@@ -222,7 +226,7 @@ multiSelectUpdate new selected = foldl fld selected new ...@@ -222,7 +226,7 @@ multiSelectUpdate new selected = foldl fld selected new
Set.insert item selectedAcc Set.insert item selectedAcc
bindSelectedNodesClick :: Sigma.Sigma -> R.State SelectedNodeIds -> R.Ref Boolean -> Effect Unit bindSelectedNodesClick :: Sigma.Sigma -> R.State ST.SelectedNodeIds -> R.Ref Boolean -> Effect Unit
bindSelectedNodesClick sigma (_ /\ setSelectedNodeIds) multiSelectEnabledRef = bindSelectedNodesClick sigma (_ /\ setSelectedNodeIds) multiSelectEnabledRef =
Sigma.bindClickNodes sigma $ \nodes -> do Sigma.bindClickNodes sigma $ \nodes -> do
let multiSelectEnabled = R.readRef multiSelectEnabledRef let multiSelectEnabled = R.readRef multiSelectEnabledRef
...@@ -232,7 +236,7 @@ bindSelectedNodesClick sigma (_ /\ setSelectedNodeIds) multiSelectEnabledRef = ...@@ -232,7 +236,7 @@ bindSelectedNodesClick sigma (_ /\ setSelectedNodeIds) multiSelectEnabledRef =
else else
setSelectedNodeIds $ const nodeIds setSelectedNodeIds $ const nodeIds
bindSelectedEdgesClick :: R.Ref Sigma -> R.State SelectedEdgeIds -> Effect Unit bindSelectedEdgesClick :: R.Ref Sigma -> R.State ST.SelectedEdgeIds -> Effect Unit
bindSelectedEdgesClick sigmaRef (_ /\ setSelectedEdgeIds) = bindSelectedEdgesClick sigmaRef (_ /\ setSelectedEdgeIds) =
dependOnSigma (R.readRef sigmaRef) "[graphCpt] no sigma" $ \sigma -> do dependOnSigma (R.readRef sigmaRef) "[graphCpt] no sigma" $ \sigma -> do
Sigma.bindClickEdge sigma $ \edge -> do Sigma.bindClickEdge sigma $ \edge -> do
......
module Gargantext.Hooks.Sigmax.Types where module Gargantext.Hooks.Sigmax.Types where
import Prelude (map, ($), (&&), (==), class Ord, Ordering, compare) import Prelude (map, ($), (&&), (==), class Ord, Ordering, compare, class Eq)
import Data.Map as Map import Data.Map as Map
import Data.Sequence (Seq) import Data.Sequence (Seq)
import Data.Set as Set import Data.Set as Set
...@@ -63,3 +63,13 @@ nodesGraphMap graph = ...@@ -63,3 +63,13 @@ nodesGraphMap graph =
eqGraph :: (Graph Node Edge) -> (Graph Node Edge) -> Boolean eqGraph :: (Graph Node Edge) -> (Graph Node Edge) -> Boolean
eqGraph (Graph {nodes: n1, edges: e1}) (Graph {nodes: n2, edges: e2}) = (n1 == n2) && (e1 == e2) eqGraph (Graph {nodes: n1, edges: e1}) (Graph {nodes: n2, edges: e2}) = (n1 == n2) && (e1 == e2)
data ForceAtlasState = InitialRunning | Running | Paused
derive instance eqForceAtlasState :: Eq ForceAtlasState
toggleForceAtlasState :: ForceAtlasState -> ForceAtlasState
toggleForceAtlasState InitialRunning = Paused
toggleForceAtlasState Running = Paused
toggleForceAtlasState Paused = Running
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