Commit e77d53ff authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] some refactoring of graph explorer code

Eg. unnecessary Maybe types removed.
parent a411ad1d
...@@ -47,7 +47,7 @@ type LayoutProps = ...@@ -47,7 +47,7 @@ type LayoutProps =
) )
type Props = ( type Props = (
graph :: Maybe Graph.Graph graph :: Graph.Graph
, mMetaData :: Maybe GET.MetaData , mMetaData :: Maybe GET.MetaData
| LayoutProps | LayoutProps
) )
...@@ -64,7 +64,7 @@ explorerLayoutCpt = R.hooksComponent "G.C.GraphExplorer.explorerLayout" cpt ...@@ -64,7 +64,7 @@ explorerLayoutCpt = R.hooksComponent "G.C.GraphExplorer.explorerLayout" cpt
where where
handler loaded = handler loaded =
explorer { graphId, mCurrentRoute, mMetaData explorer { graphId, mCurrentRoute, mMetaData
, session, sessions, graph: Just graph, frontends, showLogin} , session, sessions, graph, frontends, showLogin}
where (Tuple mMetaData graph) = convert loaded where (Tuple mMetaData graph) = convert loaded
-------------------------------------------------------------- --------------------------------------------------------------
...@@ -77,19 +77,19 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -77,19 +77,19 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
cpt {frontends, graph, graphId, mCurrentRoute, mMetaData, session, sessions, showLogin} _ = do cpt {frontends, graph, graphId, mCurrentRoute, mMetaData, session, sessions, showLogin} _ = do
dataRef <- R.useRef graph dataRef <- R.useRef graph
graphRef <- R.useRef null graphRef <- R.useRef null
controls <- Controls.useGraphControls controls <- Controls.useGraphControls graph
R.useEffect' $ do R.useEffect' $ do
case Tuple (R.readRef dataRef) graph of let readData = R.readRef dataRef
Tuple Nothing Nothing -> pure unit if SigmaxTypes.eqGraph readData graph then
Tuple (Just g1) (Just g2) | SigmaxTypes.eqGraph g1 g2 -> pure unit pure unit
_ -> do else do
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
snd controls.selectedEdgeIds $ const Set.empty snd controls.selectedEdgeIds $ const Set.empty
snd controls.selectedNodeIds $ const Set.empty snd controls.selectedNodeIds $ const Set.empty
snd controls.graphStage $ const Graph.Init snd controls.graphStage $ const Graph.Init
pure $ pure $
RH.div RH.div
...@@ -105,15 +105,15 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -105,15 +105,15 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
, row [ Controls.controls controls ] , row [ 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: graphClassName controls, style: {height: "95%"} } [] -- graph container
, mGraph { controls , graphView { controls
, elRef: graphRef , elRef: graphRef
, graphId , graphId
, graph , graph
, graphStage: controls.graphStage , graphStage: controls.graphStage
, selectedEdgeIds: controls.selectedEdgeIds , selectedEdgeIds: controls.selectedEdgeIds
, selectedNodeIds: controls.selectedNodeIds , selectedNodeIds: controls.selectedNodeIds
, sigmaRef: controls.sigmaRef , sigmaRef: controls.sigmaRef
} }
, mSidebar graph mMetaData { frontends , mSidebar graph mMetaData { frontends
, session , session
, selectedNodeIds: controls.selectedNodeIds , selectedNodeIds: controls.selectedNodeIds
...@@ -150,29 +150,15 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -150,29 +150,15 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
RH.div {className: "col-md-2", style: {paddingTop: "60px"}} RH.div {className: "col-md-2", style: {paddingTop: "60px"}}
[forest {sessions, route, frontends, showLogin}] [forest {sessions, route, frontends, showLogin}]
mGraph :: { controls :: Record Controls.Controls mSidebar :: Graph.Graph
, elRef :: R.Ref (Nullable Element)
, graphId :: GraphId
, graph :: Maybe Graph.Graph
, graphStage :: R.State Graph.Stage
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
, selectedEdgeIds :: R.State SigmaxTypes.SelectedEdgeIds
, sigmaRef :: R.Ref Sigmax.Sigma
}
-> R.Element
mGraph {graph: Nothing} = RH.div {} []
mGraph r@{graph: Just graph} = graphView $ r { graph = graph }
mSidebar :: Maybe Graph.Graph
-> Maybe GET.MetaData -> Maybe GET.MetaData
-> { frontends :: Frontends -> { frontends :: Frontends
, 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 _ Nothing _ = RH.div {} []
mSidebar (Just graph) (Just metaData) {frontends, session, selectedNodeIds, showSidePanel} = mSidebar graph (Just metaData) {frontends, session, selectedNodeIds, showSidePanel} =
Sidebar.sidebar { frontends Sidebar.sidebar { frontends
, graph , graph
, metaData , metaData
......
...@@ -23,6 +23,7 @@ import Reactix.DOM.HTML as RH ...@@ -23,6 +23,7 @@ import Reactix.DOM.HTML as RH
import Gargantext.Components.Graph as Graph import Gargantext.Components.Graph as Graph
import Gargantext.Components.GraphExplorer.Button (centerButton) import Gargantext.Components.GraphExplorer.Button (centerButton)
import Gargantext.Components.GraphExplorer.RangeControl (edgeSizeControl, nodeSizeControl) import Gargantext.Components.GraphExplorer.RangeControl (edgeSizeControl, nodeSizeControl)
import Gargantext.Components.GraphExplorer.Search (nodeSearchControl)
import Gargantext.Components.GraphExplorer.SlideButton (cursorSizeButton, labelSizeButton) import Gargantext.Components.GraphExplorer.SlideButton (cursorSizeButton, labelSizeButton)
import Gargantext.Components.GraphExplorer.ToggleButton (edgesToggleButton, pauseForceAtlasButton) import Gargantext.Components.GraphExplorer.ToggleButton (edgesToggleButton, pauseForceAtlasButton)
import Gargantext.Components.GraphExplorer.Types as GET import Gargantext.Components.GraphExplorer.Types as GET
...@@ -33,11 +34,12 @@ import Gargantext.Utils.Reactix as R2 ...@@ -33,11 +34,12 @@ import Gargantext.Utils.Reactix as R2
type Controls = type Controls =
( cursorSize :: R.State Number ( cursorSize :: R.State Number
, graph :: Graph.Graph
, graphStage :: R.State Graph.Stage , graphStage :: R.State Graph.Stage
, multiNodeSelect :: R.Ref Boolean , multiNodeSelect :: R.Ref Boolean
, nodeSize :: R.State Range.NumberRange , nodeSize :: R.State Range.NumberRange
, selectedEdgeIds :: R.State (Set.Set String) , selectedEdgeIds :: R.State SigmaxTypes.SelectedEdgeIds
, selectedNodeIds :: R.State (Set.Set String) , selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
, showControls :: R.State Boolean , showControls :: R.State Boolean
, showSidePanel :: R.State GET.SidePanelState , showSidePanel :: R.State GET.SidePanelState
, showTree :: R.State Boolean , showTree :: R.State Boolean
...@@ -60,6 +62,7 @@ initialLocalControls = do ...@@ -60,6 +62,7 @@ initialLocalControls = do
labelSize <- R.useState' 14.0 labelSize <- R.useState' 14.0
--nodeSize <- R.useState' $ Range.Closed { min: 0.0, max: 10.0 } --nodeSize <- R.useState' $ Range.Closed { min: 0.0, max: 10.0 }
pauseForceAtlas <- R.useState' true pauseForceAtlas <- R.useState' true
search <- R.useState' ""
showEdges <- R.useState' true showEdges <- R.useState' true
pure $ { pure $ {
...@@ -128,12 +131,13 @@ controlsCpt = R.hooksComponent "GraphControls" cpt ...@@ -128,12 +131,13 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
-- zoom: 0 -100 - calculate ratio -- zoom: 0 -100 - calculate ratio
-- toggle multi node selection -- toggle multi node selection
-- save button -- save button
, RH.li {} [ nodeSearchControl { selectedNodeIds: props.selectedNodeIds } ]
] ]
] ]
] ]
useGraphControls :: R.Hooks (Record Controls) useGraphControls :: Graph.Graph -> R.Hooks (Record Controls)
useGraphControls = do useGraphControls graph = do
cursorSize <- R.useState' 10.0 cursorSize <- R.useState' 10.0
graphStage <- R.useState' Graph.Init graphStage <- R.useState' Graph.Init
multiNodeSelect <- R.useRef false multiNodeSelect <- R.useRef false
...@@ -147,6 +151,7 @@ useGraphControls = do ...@@ -147,6 +151,7 @@ useGraphControls = do
sigmaRef <- R.useRef sigma sigmaRef <- R.useRef sigma
pure { cursorSize pure { cursorSize
, graph
, graphStage , graphStage
, multiNodeSelect , multiNodeSelect
, nodeSize , nodeSize
......
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