Commit bfc60431 authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge branch 'dev-warnings-cleanup' into dev

parents 9b8fde6e ca7160ae
...@@ -10,6 +10,19 @@ ...@@ -10,6 +10,19 @@
display: flex; display: flex;
max-width: 200px; max-width: 200px;
} }
#graph-explorer .row.controls {
height: 79px;
}
#graph-explorer .graph-tree {
position: absolute;
top: 120px;
max-height: 600px;
overflow-y: scroll;
z-index: 1;
}
#graph-explorer #graph-view {
height: 95%;
}
#graph-explorer #sp-container { #graph-explorer #sp-container {
position: absolute; position: absolute;
left: 70%; left: 70%;
...@@ -17,6 +30,8 @@ ...@@ -17,6 +30,8 @@
z-index: 1; z-index: 1;
border: 1px white solid; border: 1px white solid;
background-color: white; background-color: white;
max-height: 600px;
overflow-y: scroll;
} }
#graph-explorer #sp-container #myTab { #graph-explorer #sp-container #myTab {
marginBottom: 18px; marginBottom: 18px;
......
...@@ -10,6 +10,19 @@ ...@@ -10,6 +10,19 @@
display: flex display: flex
max-width: 200px max-width: 200px
.row.controls
height: 79px
.graph-tree
position: absolute
top: 120px
max-height: 600px
overflow-y: scroll
z-index: 1
#graph-view
height: 95%
#sp-container #sp-container
position: absolute position: absolute
left: 70% left: 70%
...@@ -17,6 +30,8 @@ ...@@ -17,6 +30,8 @@
z-index: 1 z-index: 1
border: 1px white solid border: 1px white solid
background-color: white background-color: white
max-height: 600px
overflow-y: scroll
#myTab #myTab
marginBottom: 18px marginBottom: 18px
......
...@@ -4,7 +4,7 @@ module Gargantext.Components.Graph ...@@ -4,7 +4,7 @@ module Gargantext.Components.Graph
-- , forceAtlas2Settings, ForceAtlas2Settings, ForceAtlas2OptionalSettings -- , forceAtlas2Settings, ForceAtlas2Settings, ForceAtlas2OptionalSettings
-- ) -- )
where where
import Prelude (bind, const, discard, pure, ($), unit, map) import Prelude (bind, const, discard, pure, ($), unit, map, not, show)
import Data.Array as A import Data.Array as A
import Data.Either (Either(..)) import Data.Either (Either(..))
...@@ -32,6 +32,7 @@ type Props sigma forceatlas2 = ...@@ -32,6 +32,7 @@ type Props sigma forceatlas2 =
, graph :: SigmaxTypes.SGraph , graph :: SigmaxTypes.SGraph
, multiSelectEnabledRef :: R.Ref Boolean , multiSelectEnabledRef :: R.Ref Boolean
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds , selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
, showEdges :: R.State SigmaxTypes.ShowEdgesState
, sigmaRef :: R.Ref Sigmax.Sigma , sigmaRef :: R.Ref Sigmax.Sigma
, sigmaSettings :: sigma , sigmaSettings :: sigma
, stage :: R.State Stage , stage :: R.State Stage
...@@ -90,7 +91,7 @@ graphCpt = R.hooksComponent "Graph" cpt ...@@ -90,7 +91,7 @@ graphCpt = R.hooksComponent "Graph" cpt
log "[graphCpt] cleanup" log "[graphCpt] cleanup"
pure $ pure unit pure $ pure unit
stageHooks props@{sigmaRef, stage: (Ready /\ setStage), transformedGraph} = do stageHooks props@{showEdges: (showEdges /\ _), sigmaRef, stage: (Ready /\ setStage), transformedGraph} = do
let tEdgesMap = SigmaxTypes.edgesGraphMap transformedGraph let tEdgesMap = SigmaxTypes.edgesGraphMap transformedGraph
let tNodesMap = SigmaxTypes.nodesGraphMap transformedGraph let tNodesMap = SigmaxTypes.nodesGraphMap transformedGraph
...@@ -99,6 +100,7 @@ graphCpt = R.hooksComponent "Graph" cpt ...@@ -99,6 +100,7 @@ graphCpt = R.hooksComponent "Graph" cpt
Sigmax.dependOnSigma (R.readRef sigmaRef) "[graphCpt (Ready)] no sigma" $ \sigma -> do Sigmax.dependOnSigma (R.readRef sigmaRef) "[graphCpt (Ready)] no sigma" $ \sigma -> do
Sigmax.updateEdges sigma tEdgesMap Sigmax.updateEdges sigma tEdgesMap
Sigmax.updateNodes sigma tNodesMap Sigmax.updateNodes sigma tNodesMap
Sigmax.setEdges sigma (not $ SigmaxTypes.edgeStateHidden showEdges)
stageHooks _ = pure unit stageHooks _ = pure unit
......
...@@ -12,6 +12,7 @@ import Data.Sequence as Seq ...@@ -12,6 +12,7 @@ import Data.Sequence as Seq
import Data.Set as Set import Data.Set as Set
import Data.Tuple (fst, snd, Tuple(..)) import Data.Tuple (fst, snd, Tuple(..))
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import DOM.Simple.Types (Element) import DOM.Simple.Types (Element)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Math (log) import Math (log)
...@@ -85,11 +86,16 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -85,11 +86,16 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
if SigmaxTypes.eqGraph readData graph then if SigmaxTypes.eqGraph readData graph then
pure unit pure unit
else do else do
-- Graph data changed, reinitialize sigma.
let rSigma = R.readRef controls.sigmaRef let rSigma = R.readRef controls.sigmaRef
Sigmax.cleanupSigma rSigma "explorerCpt" Sigmax.cleanupSigma rSigma "explorerCpt"
R.setRef dataRef graph R.setRef dataRef graph
-- Reinitialize bunch of state as well.
snd controls.selectedNodeIds $ const Set.empty snd controls.selectedNodeIds $ const Set.empty
snd controls.showEdges $ const SigmaxTypes.EShow
snd controls.forceAtlasState $ const SigmaxTypes.InitialRunning
snd controls.graphStage $ const Graph.Init snd controls.graphStage $ const Graph.Init
snd controls.showSidePanel $ const GET.InitialClosed
pure $ pure $
RH.div RH.div
...@@ -102,38 +108,32 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -102,38 +108,32 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
, col [ Toggle.controlsToggleButton controls.showControls ] , col [ Toggle.controlsToggleButton controls.showControls ]
, col [ pullRight [ Toggle.sidebarToggleButton controls.showSidePanel ] ] , col [ pullRight [ Toggle.sidebarToggleButton controls.showSidePanel ] ]
] ]
, row [ Controls.controls controls ] , rowControls [ Controls.controls controls ]
, row [ tree (fst controls.showTree) {sessions, mCurrentRoute, frontends} (snd showLogin) , row [ tree (fst controls.showTree) {sessions, mCurrentRoute, frontends} (snd showLogin)
, RH.div { ref: graphRef, id: "graph-view", className: graphClassName controls, style: {height: "95%"} } [] -- graph container , RH.div { ref: graphRef, id: "graph-view", className: "col-md-12" } [] -- graph container
, graphView { controls , graphView { controls
, elRef: graphRef , elRef: graphRef
, graphId , graphId
, graph , graph
, multiSelectEnabledRef , multiSelectEnabledRef
} }
, mSidebar graph mMetaData { frontends , mSidebar mMetaData { frontends
, graph
, session , session
, selectedNodeIds: controls.selectedNodeIds , selectedNodeIds: controls.selectedNodeIds
, showSidePanel: fst controls.showSidePanel , showSidePanel: fst controls.showSidePanel
} }
] ]
, row [
]
] ]
] ]
] ]
] ]
graphClassName :: Record Controls.Controls -> String
graphClassName {showSidePanel: (GET.Opened /\ _), showTree: (true /\ _)} = "col-md-8"
graphClassName {showTree: (true /\ _)} = "col-md-10"
graphClassName {showSidePanel: (GET.Opened /\ _)} = "col-md-10"
graphClassName _ = "col-md-12"
outer = RH.div { className: "col-md-12" } outer = RH.div { className: "col-md-12" }
inner = RH.div { className: "container-fluid", style: { paddingTop: "90px" } } inner = RH.div { className: "container-fluid", style: { paddingTop: "90px" } }
row1 = RH.div { className: "row", style: { paddingBottom: "10px", marginTop: "-24px" } } row1 = RH.div { className: "row", style: { paddingBottom: "10px", marginTop: "-24px" } }
row = RH.div { className: "row" } row = RH.div { className: "row" }
rowControls = RH.div { className: "row controls" }
col = RH.div { className: "col-md-4" } col = RH.div { className: "col-md-4" }
pullLeft = RH.div { className: "pull-left" } pullLeft = RH.div { className: "pull-left" }
pullRight = RH.div { className: "pull-right" } pullRight = RH.div { className: "pull-right" }
...@@ -144,18 +144,17 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -144,18 +144,17 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
-> R.Element -> R.Element
tree false _ _ = RH.div { id: "tree" } [] tree false _ _ = RH.div { id: "tree" } []
tree true {sessions, mCurrentRoute: route, frontends} showLogin = tree true {sessions, mCurrentRoute: route, frontends} showLogin =
RH.div {className: "col-md-2", style: {paddingTop: "60px"}} RH.div {className: "col-md-2 graph-tree"} [forest {sessions, route, frontends, showLogin}]
[forest {sessions, route, frontends, showLogin}]
mSidebar :: SigmaxTypes.SGraph mSidebar :: Maybe GET.MetaData
-> Maybe GET.MetaData
-> { frontends :: Frontends -> { frontends :: Frontends
, graph :: SigmaxTypes.SGraph
, showSidePanel :: GET.SidePanelState , showSidePanel :: GET.SidePanelState
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds , selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
, session :: Session } , session :: Session }
-> R.Element -> R.Element
mSidebar _ Nothing _ = RH.div {} [] mSidebar Nothing _ = RH.div {} []
mSidebar graph (Just metaData) {frontends, session, selectedNodeIds, showSidePanel} = mSidebar (Just metaData) {frontends, graph, session, selectedNodeIds, showSidePanel} =
Sidebar.sidebar { frontends Sidebar.sidebar { frontends
, graph , graph
, metaData , metaData
...@@ -192,6 +191,7 @@ graphViewCpt = R.hooksComponent "GraphView" cpt ...@@ -192,6 +191,7 @@ graphViewCpt = R.hooksComponent "GraphView" cpt
, graph , graph
, multiSelectEnabledRef , multiSelectEnabledRef
, selectedNodeIds: controls.selectedNodeIds , selectedNodeIds: controls.selectedNodeIds
, showEdges: controls.showEdges
, sigmaRef: controls.sigmaRef , sigmaRef: controls.sigmaRef
, sigmaSettings: Graph.sigmaSettings , sigmaSettings: Graph.sigmaSettings
, stage: controls.graphStage , stage: controls.graphStage
...@@ -378,7 +378,7 @@ transformGraph controls graph = SigmaxTypes.Graph {nodes: newNodes, edges: newEd ...@@ -378,7 +378,7 @@ transformGraph controls graph = SigmaxTypes.Graph {nodes: newNodes, edges: newEd
hasSelection = not $ Set.isEmpty (fst controls.selectedNodeIds) hasSelection = not $ Set.isEmpty (fst controls.selectedNodeIds)
newNodes = nodeSizeFilter <$> nodeMarked <$> nodes newNodes = nodeSizeFilter <$> nodeMarked <$> nodes
newEdges = edgeConfluenceFilter <$> edgeWeightFilter <$> edgeMarked <$> edges newEdges = edgeConfluenceFilter <$> edgeWeightFilter <$> edgeShowFilter <$> edgeMarked <$> edges
nodeSizeFilter node@{ size } = nodeSizeFilter node@{ size } =
if Range.within (fst controls.nodeSize) size then if Range.within (fst controls.nodeSize) size then
...@@ -391,6 +391,11 @@ transformGraph controls graph = SigmaxTypes.Graph {nodes: newNodes, edges: newEd ...@@ -391,6 +391,11 @@ transformGraph controls graph = SigmaxTypes.Graph {nodes: newNodes, edges: newEd
edge edge
else else
edge { hidden = true } edge { hidden = true }
edgeShowFilter edge =
if (SigmaxTypes.edgeStateHidden $ fst controls.showEdges) then
edge { hidden = true }
else
edge
edgeWeightFilter edge@{ weight } = edgeWeightFilter edge@{ weight } =
if Range.within (fst controls.edgeWeight) weight then if Range.within (fst controls.edgeWeight) weight then
edge edge
......
...@@ -14,7 +14,7 @@ import Data.Maybe (Maybe(..), maybe) ...@@ -14,7 +14,7 @@ import Data.Maybe (Maybe(..), maybe)
import Data.Sequence as Seq 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 ((/\))
import Effect (Effect) import Effect (Effect)
import Effect.Timer (setTimeout) import Effect.Timer (setTimeout)
import Prelude import Prelude
...@@ -37,12 +37,14 @@ type Controls = ...@@ -37,12 +37,14 @@ 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
, nodeSize :: R.State Range.NumberRange , nodeSize :: R.State Range.NumberRange
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds , selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
, showControls :: R.State Boolean , showControls :: R.State Boolean
, showEdges :: R.State SigmaxTypes.ShowEdgesState
, showSidePanel :: R.State GET.SidePanelState , showSidePanel :: R.State GET.SidePanelState
, showTree :: R.State Boolean , showTree :: R.State Boolean
, sigmaRef :: R.Ref Sigmax.Sigma , sigmaRef :: R.Ref Sigmax.Sigma
...@@ -53,23 +55,15 @@ controlsToSigmaSettings { cursorSize: (cursorSize /\ _)} = Graph.sigmaSettings ...@@ -53,23 +55,15 @@ 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
) )
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
pure $ { pure $ {
labelSize labelSize
--, nodeSize
, pauseForceAtlas
, showEdges
} }
controls :: Record Controls -> R.Element controls :: Record Controls -> R.Element
...@@ -84,30 +78,41 @@ controlsCpt = R.hooksComponent "GraphControls" cpt ...@@ -84,30 +78,41 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
-- If user pauses FA before auto is triggered, clear the timeoutId -- If user pauses FA before auto is triggered, clear the timeoutId
mFAPauseRef <- R.useRef Nothing mFAPauseRef <- R.useRef Nothing
-- when graph is changed, cleanup the mFAPauseRef -- When graph is changed, cleanup the mFAPauseRef so that forceAtlas
-- timeout is retriggered.
R.useEffect' $ do R.useEffect' $ do
case fst props.graphStage of case fst props.graphStage of
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 -- Handle case when FA is paused from outside events, eg. the automatic timer.
R.useEffect' $ Sigmax.handleForceAtlas2Pause props.sigmaRef props.forceAtlasState mFAPauseRef
-- Handle automatic edge hiding when FA is running (to prevent flickering).
R.useEffect2' props.sigmaRef props.forceAtlasState $
snd props.showEdges $ SigmaxTypes.forceAtlasEdgeState (fst props.forceAtlasState)
-- Automatic opening of sidebar when a node is selected (but only first time).
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
snd props.showSidePanel $ \_ -> GET.Opened snd props.showSidePanel $ \_ -> GET.Opened
else else
pure unit pure unit
R.useEffectOnce' $ do -- Timer to turn off the initial FA. This is because FA eats up lot of
-- CPU, has memory leaks etc.
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,8 +126,8 @@ controlsCpt = R.hooksComponent "GraphControls" cpt ...@@ -121,8 +126,8 @@ 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 {state: props.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 ]
-- change level -- change level
...@@ -149,12 +154,14 @@ useGraphControls graph = do ...@@ -149,12 +154,14 @@ 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 }
showTree <- R.useState' false showTree <- R.useState' false
selectedNodeIds <- R.useState' $ Set.empty selectedNodeIds <- R.useState' $ Set.empty
showControls <- R.useState' false showControls <- R.useState' false
showEdges <- R.useState' SigmaxTypes.EShow
showSidePanel <- R.useState' GET.InitialClosed showSidePanel <- R.useState' GET.InitialClosed
sigma <- Sigmax.initSigma sigma <- Sigmax.initSigma
sigmaRef <- R.useRef sigma sigmaRef <- R.useRef sigma
...@@ -162,12 +169,14 @@ useGraphControls graph = do ...@@ -162,12 +169,14 @@ useGraphControls graph = do
pure { cursorSize pure { cursorSize
, edgeConfluence , edgeConfluence
, edgeWeight , edgeWeight
, forceAtlasState
, graph , graph
, graphStage , graphStage
, multiSelectEnabled , multiSelectEnabled
, nodeSize , nodeSize
, selectedNodeIds , selectedNodeIds
, showControls , showControls
, showEdges
, showSidePanel , showSidePanel
, showTree , showTree
, sigmaRef , sigmaRef
......
...@@ -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
...@@ -55,19 +56,28 @@ controlsToggleButton state = ...@@ -55,19 +56,28 @@ controlsToggleButton state =
, onClick: \_ -> snd state not , onClick: \_ -> snd state not
} }
edgesToggleButton :: R.Ref Sigmax.Sigma -> R.State Boolean -> R.Element type EdgesButtonProps = (
edgesToggleButton sigmaRef state = state :: R.State SigmaxTypes.ShowEdgesState
toggleButton { )
state: state
, onMessage: "Hide Edges" edgesToggleButton :: Record EdgesButtonProps -> R.Element
, offMessage: "Show Edges" edgesToggleButton props = R.createElement edgesToggleButtonCpt props []
, onClick: \_ -> do
let sigma = R.readRef sigmaRef edgesToggleButtonCpt :: R.Component EdgesButtonProps
let (toggled /\ setToggled) = state edgesToggleButtonCpt = R.hooksComponent "EdgesToggleButton" cpt
Sigmax.dependOnSigma sigma "[edgesToggleButton] sigma: Nothing" $ \s -> do where
Sigmax.setEdges s $ not toggled cpt {state: (state /\ setState)} _ = do
setToggled not pure $
} H.span {}
[
H.button
{ className: "btn btn-primary", on: {click: onClick setState} }
[ H.text (text state) ]
]
text s = if SigmaxTypes.edgeStateHidden s then "Show edges" else "Hide edges"
-- TODO: Move this to Graph.purs to the R.useEffect handler which renders nodes/edges
onClick setState _ = setState SigmaxTypes.toggleShowEdgesState
multiSelectEnabledButton :: R.State Boolean -> R.Element multiSelectEnabledButton :: R.State Boolean -> R.Element
multiSelectEnabledButton state = multiSelectEnabledButton state =
...@@ -78,16 +88,29 @@ multiSelectEnabledButton state = ...@@ -78,16 +88,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,8 +110,8 @@ dependOnContainer container notFoundMsg f = do ...@@ -110,8 +110,8 @@ 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 -> R.Ref (Maybe TimeoutId) -> Effect Unit
handleForceAtlas2Pause sigmaRef (toggled /\ setToggled) showEdges mFAPauseRef = do handleForceAtlas2Pause sigmaRef (toggled /\ setToggled) 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
--log2 "[handleForceAtlas2Pause] mSigma: Just " s --log2 "[handleForceAtlas2Pause] mSigma: Just " s
...@@ -119,17 +119,18 @@ handleForceAtlas2Pause sigmaRef (toggled /\ setToggled) showEdges mFAPauseRef = ...@@ -119,17 +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
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
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
_ -> pure unit _ -> pure unit
-- handle case when user pressed pause/start fa button before timeout fired -- handle case when user pressed pause/start fa button before timeout fired
--case R.readRef mFAPauseRef of --case R.readRef mFAPauseRef of
...@@ -145,16 +146,18 @@ setEdges sigma val = do ...@@ -145,16 +146,18 @@ setEdges sigma val = do
, drawEdgeLabels: val , drawEdgeLabels: val
, hideEdgesOnMove: not val , hideEdgesOnMove: not val
} }
-- prevent showing edges (via show edges button) when FA is running (flickering)
isFARunning <- Sigma.isForceAtlas2Running sigma
case Tuple val isFARunning of
Tuple false _ ->
Sigma.setSettings sigma settings Sigma.setSettings sigma settings
Tuple true false ->
Sigma.setSettings sigma settings
_ -> pure unit
markSelectedEdges :: Sigma.Sigma -> SelectedEdgeIds -> EdgesMap -> Effect Unit -- -- prevent showing edges (via show edges button) when FA is running (flickering)
-- isFARunning <- Sigma.isForceAtlas2Running sigma
-- case Tuple val isFARunning of
-- Tuple false _ ->
-- Sigma.setSettings sigma settings
-- Tuple true false ->
-- Sigma.setSettings sigma settings
-- _ -> pure 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 +172,7 @@ markSelectedEdges sigma selectedEdgeIds graphEdges = do ...@@ -169,7 +172,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 +188,7 @@ markSelectedNodes sigma selectedNodeIds graphNodes = do ...@@ -185,7 +188,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
...@@ -195,10 +198,10 @@ updateEdges sigma edgesMap = do ...@@ -195,10 +198,10 @@ updateEdges sigma edgesMap = do
_ <- pure $ (e .= "color") tColor _ <- pure $ (e .= "color") tColor
_ <- pure $ (e .= "hidden") tHidden _ <- pure $ (e .= "hidden") tHidden
pure unit pure unit
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
...@@ -208,11 +211,11 @@ updateNodes sigma nodesMap = do ...@@ -208,11 +211,11 @@ updateNodes sigma nodesMap = do
_ <- pure $ (n .= "color") tColor _ <- pure $ (n .= "color") tColor
_ <- pure $ (n .= "hidden") tHidden _ <- pure $ (n .= "hidden") tHidden
pure unit pure unit
Sigma.refresh sigma --Sigma.refresh sigma
-- | 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 +225,7 @@ multiSelectUpdate new selected = foldl fld selected new ...@@ -222,7 +225,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 +235,7 @@ bindSelectedNodesClick sigma (_ /\ setSelectedNodeIds) multiSelectEnabledRef = ...@@ -232,7 +235,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 Eq, class Ord, class Show, Ordering, compare)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Data.Generic.Rep.Show (genericShow)
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 +66,68 @@ nodesGraphMap graph = ...@@ -63,3 +66,68 @@ 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)
-- | Custom state for force atlas. Basically, it can be "Running" or "Paused"
-- 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 | Running | Paused
derive instance genericForceAtlasState :: Generic ForceAtlasState _
instance eqForceAtlasState :: Eq ForceAtlasState where
eq = genericEq
toggleForceAtlasState :: ForceAtlasState -> ForceAtlasState
toggleForceAtlasState InitialRunning = Paused
toggleForceAtlasState Running = Paused
toggleForceAtlasState Paused = Running
-- | Custom state for show edges. Normally it is EShow or EHide (show/hide
-- | edges). However, edges are temporarily turned off when forceAtlas is
-- | running.
data ShowEdgesState = EShow | EHide | ETempHiddenThenShow
derive instance genericShowEdgesState :: Generic ShowEdgesState _
instance eqShowEdgesState :: Eq ShowEdgesState where
eq = genericEq
instance showShowEdgesState :: Show ShowEdgesState where
show = genericShow
-- | Whether the edges are hidden now (temp or "stable").
edgeStateHidden :: ShowEdgesState -> Boolean
edgeStateHidden EHide = true
edgeStateHidden ETempHiddenThenShow = true
edgeStateHidden _ = false
-- | Switch from hidden to shown, handling the temp state as well.
toggleShowEdgesState :: ShowEdgesState -> ShowEdgesState
toggleShowEdgesState s =
if edgeStateHidden s then
EShow
else
EHide
-- | Return the temporary hidden state, if applicable.
edgeStateTempHide :: ShowEdgesState -> ShowEdgesState
edgeStateTempHide EHide = EHide
edgeStateTempHide _ = ETempHiddenThenShow
-- | Whether, after disabling the temp state, edges will be shown or hidden.
edgeStateWillBeHidden :: ShowEdgesState -> Boolean
edgeStateWillBeHidden EHide = true
edgeStateWillBeHidden _ = false
-- | Get rid of the temporary transition
edgeStateStabilize :: ShowEdgesState -> ShowEdgesState
edgeStateStabilize ETempHiddenThenShow = EShow
edgeStateStabilize s = s
-- | Return state in which showEdges should be depending on forceAtlasState
forceAtlasEdgeState :: ForceAtlasState -> ShowEdgesState -> ShowEdgesState
forceAtlasEdgeState InitialRunning EShow = ETempHiddenThenShow
forceAtlasEdgeState InitialRunning es = es
forceAtlasEdgeState Running EShow = ETempHiddenThenShow
forceAtlasEdgeState Running es = es
forceAtlasEdgeState Paused ETempHiddenThenShow = EShow
forceAtlasEdgeState Paused es = es
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