Commit b370c63c authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] add preliminary node selection query on sidebar

This still doesn't show up because I need GraphSideCorpus array from
somewhere, apparently.
parent 3e3ccc7a
...@@ -32,6 +32,7 @@ type Props sigma forceatlas2 = ...@@ -32,6 +32,7 @@ type Props sigma forceatlas2 =
( elRef :: R.Ref (Nullable Element) ( elRef :: R.Ref (Nullable Element)
, forceAtlas2Settings :: forceatlas2 , forceAtlas2Settings :: forceatlas2
, graph :: Graph , graph :: Graph
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
, sigmaSettings :: sigma , sigmaSettings :: sigma
, sigmaRef :: R.Ref Sigmax.Sigma , sigmaRef :: R.Ref Sigmax.Sigma
) )
...@@ -43,10 +44,8 @@ graphCpt :: forall s fa2. R.Component (Props s fa2) ...@@ -43,10 +44,8 @@ graphCpt :: forall s fa2. R.Component (Props s fa2)
graphCpt = R.hooksComponent "Graph" cpt graphCpt = R.hooksComponent "Graph" cpt
where where
cpt props _ = do cpt props _ = do
(selectedNodeIds /\ setSelectedNodeIds) <- R.useState' $ Set.empty let nodesMap = SigmaxTypes.nodesMap props.graph
let (selectedNodeIds /\ setSelectedNodeIds) = props.selectedNodeIds
let (SigmaxTypes.Graph {nodes: nodes}) = props.graph
let nodesMap = Map.fromFoldable $ map (\n -> Tuple n.id {color: n.color}) nodes
R.useEffect' $ do R.useEffect' $ do
Sigmax.dependOnSigma (R.readRef props.sigmaRef) "[graphCpt] no sigma" $ \sigma -> Sigmax.dependOnSigma (R.readRef props.sigmaRef) "[graphCpt] no sigma" $ \sigma ->
......
...@@ -5,10 +5,12 @@ import Gargantext.Prelude hiding (max,min) ...@@ -5,10 +5,12 @@ import Gargantext.Prelude hiding (max,min)
import Data.FoldableWithIndex (foldMapWithIndex) import Data.FoldableWithIndex (foldMapWithIndex)
import Data.Foldable (foldMap) import Data.Foldable (foldMap)
import Data.Int (toNumber) import Data.Int (toNumber)
import Data.Map as Map
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Nullable (null, Nullable) import Data.Nullable (null, Nullable)
import Data.Sequence as Seq import Data.Sequence as Seq
import Data.Tuple (fst,snd) import Data.Set as Set
import Data.Tuple (fst, snd, Tuple(..))
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Types (Element) import DOM.Simple.Types (Element)
import Effect.Aff (Aff) import Effect.Aff (Aff)
...@@ -17,7 +19,7 @@ import Reactix.DOM.HTML as RH ...@@ -17,7 +19,7 @@ import Reactix.DOM.HTML as RH
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.Sigmax (Sigma) import Gargantext.Hooks.Sigmax (Sigma)
import Gargantext.Hooks.Sigmax.Types as Sigmax import Gargantext.Hooks.Sigmax.Types as SigmaxTypes
import Gargantext.Components.GraphExplorer.Controls as Controls import Gargantext.Components.GraphExplorer.Controls as Controls
import Gargantext.Components.GraphExplorer.Sidebar as Sidebar import Gargantext.Components.GraphExplorer.Sidebar as Sidebar
import Gargantext.Components.GraphExplorer.ToggleButton as Toggle import Gargantext.Components.GraphExplorer.ToggleButton as Toggle
...@@ -70,6 +72,8 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -70,6 +72,8 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
controls <- Controls.useGraphControls controls <- Controls.useGraphControls
state <- useExplorerState state <- useExplorerState
showLogin <- snd <$> R.useState' true showLogin <- snd <$> R.useState' true
selectedNodeIds <- R.useState' $ Set.empty
pure $ pure $
RH.div RH.div
{ id: "graph-explorer" } { id: "graph-explorer" }
...@@ -84,8 +88,9 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -84,8 +88,9 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
, row [ Controls.controls controls ] , row [ Controls.controls controls ]
, row [ tree {mCurrentRoute, treeId} controls showLogin , row [ tree {mCurrentRoute, treeId} controls showLogin
, RH.div { ref: graphRef, id: "graph-view", className: "col-md-12", style: {height: "95%"} } [] -- graph container , RH.div { ref: graphRef, id: "graph-view", className: "col-md-12", style: {height: "95%"} } [] -- graph container
, mGraph graphRef controls.sigmaRef {graphId, graph} , mGraph graphRef controls.sigmaRef {graphId, graph, selectedNodeIds}
, Sidebar.sidebar {showSidePanel: fst controls.showSidePanel} ] , mSidebar graph {session, selectedNodeIds, showSidePanel: fst controls.showSidePanel}
]
, row [ , row [
] ]
] ]
...@@ -107,9 +112,27 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -107,9 +112,27 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
pullLeft = RH.div { className: "pull-left" } pullLeft = RH.div { className: "pull-left" }
pullRight = RH.div { className: "pull-right" } pullRight = RH.div { className: "pull-right" }
mGraph :: R.Ref (Nullable Element) -> R.Ref Sigma -> {graphId :: GraphId, graph :: Maybe Graph.Graph} -> R.Element mGraph :: R.Ref (Nullable Element)
-> R.Ref Sigma
-> { graphId :: GraphId
, graph :: Maybe Graph.Graph
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds}
-> R.Element
mGraph _ _ {graph: Nothing} = RH.div {} [] mGraph _ _ {graph: Nothing} = RH.div {} []
mGraph graphRef sigmaRef {graphId, graph: Just graph} = graphView graphRef sigmaRef {graphId, graph} mGraph graphRef sigmaRef {graphId, graph: Just graph, selectedNodeIds} = graphView graphRef sigmaRef {graphId, graph, selectedNodeIds}
mSidebar :: Maybe Graph.Graph
-> { showSidePanel :: Boolean
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
, session :: Session }
-> R.Element
mSidebar Nothing _ = RH.div {} []
mSidebar (Just graph) {session, selectedNodeIds, showSidePanel} =
Sidebar.sidebar { graph
, session
, selectedNodeIds
, showSidePanel
}
useExplorerState :: R.Hooks (Record GET.State) useExplorerState :: R.Hooks (Record GET.State)
useExplorerState = do pure {} useExplorerState = do pure {}
...@@ -132,6 +155,7 @@ useExplorerState = do pure {} ...@@ -132,6 +155,7 @@ useExplorerState = do pure {}
type GraphProps = ( type GraphProps = (
graphId :: GraphId graphId :: GraphId
, graph :: Graph.Graph , graph :: Graph.Graph
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
) )
graphView :: R.Ref (Nullable Element) -> R.Ref Sigma -> Record GraphProps -> R.Element graphView :: R.Ref (Nullable Element) -> R.Ref Sigma -> Record GraphProps -> R.Element
...@@ -140,17 +164,18 @@ graphView elRef sigmaRef props = R.createElement el props [] ...@@ -140,17 +164,18 @@ graphView elRef sigmaRef props = R.createElement el props []
where where
--memoCmp props1 props2 = props1.graphId == props2.graphId --memoCmp props1 props2 = props1.graphId == props2.graphId
el = R.hooksComponent "GraphView" cpt el = R.hooksComponent "GraphView" cpt
cpt {graphId, graph} _children = do cpt {graphId, graph, selectedNodeIds} _children = do
pure $ Graph.graph { pure $ Graph.graph {
elRef elRef
, forceAtlas2Settings: Graph.forceAtlas2Settings , forceAtlas2Settings: Graph.forceAtlas2Settings
, graph , graph
, selectedNodeIds
, sigmaSettings: Graph.sigmaSettings , sigmaSettings: Graph.sigmaSettings
, sigmaRef: sigmaRef , sigmaRef: sigmaRef
} }
convert :: GET.GraphData -> Graph.Graph convert :: GET.GraphData -> Graph.Graph
convert (GET.GraphData r) = Sigmax.Graph {nodes, edges} convert (GET.GraphData r) = SigmaxTypes.Graph {nodes, edges}
where where
nodes = foldMapWithIndex nodeFn r.nodes nodes = foldMapWithIndex nodeFn r.nodes
nodeFn i (GET.Node n) = nodeFn i (GET.Node n) =
......
...@@ -3,10 +3,25 @@ module Gargantext.Components.GraphExplorer.Sidebar ...@@ -3,10 +3,25 @@ module Gargantext.Components.GraphExplorer.Sidebar
where where
import Prelude import Prelude
import Data.Map as Map
import Data.Maybe (Maybe(..))
import Data.Set as Set
import Data.Tuple.Nested((/\))
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as RH import Reactix.DOM.HTML as RH
type Props = ( showSidePanel :: Boolean ) import Gargantext.Components.RandomText (words)
import Gargantext.Components.Nodes.Corpus.Graph.Tabs as GT
import Gargantext.Components.Graph as Graph
import Gargantext.Hooks.Sigmax.Types as SigmaxTypes
import Gargantext.Sessions (Session)
type Props =
( graph :: Graph.Graph
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
, session :: Session
, showSidePanel :: Boolean
)
sidebar :: Record Props -> R.Element sidebar :: Record Props -> R.Element
sidebar props = R.createElement sidebarCpt props [] sidebar props = R.createElement sidebarCpt props []
...@@ -17,6 +32,8 @@ sidebarCpt = R.hooksComponent "Sidebar" cpt ...@@ -17,6 +32,8 @@ sidebarCpt = R.hooksComponent "Sidebar" cpt
cpt {showSidePanel: false} _children = do cpt {showSidePanel: false} _children = do
pure $ RH.div {} [] pure $ RH.div {} []
cpt props _children = do cpt props _children = do
let nodesMap = SigmaxTypes.nodesMap props.graph
pure $ pure $
RH.div { id: "sp-container", className: "col-md-2" } RH.div { id: "sp-container", className: "col-md-2" }
[ RH.div {} [ RH.div {}
...@@ -39,7 +56,16 @@ sidebarCpt = R.hooksComponent "Sidebar" cpt ...@@ -39,7 +56,16 @@ sidebarCpt = R.hooksComponent "Sidebar" cpt
[ checkbox "Pubs" [ checkbox "Pubs"
, checkbox "Projects" , checkbox "Projects"
, checkbox "Patents" , checkbox "Patents"
, checkbox "Others" ] ] ] ] ] , checkbox "Others"
]
]
, RH.div { className: "col-md-12", id: "query" }
[
query props.session nodesMap props.selectedNodeIds
]
]
]
]
badge text = badge text =
RH.a { className: "badge badge-light" } [ RH.text text ] RH.a { className: "badge badge-light" } [ RH.text text ]
checkbox text = checkbox text =
...@@ -59,3 +85,10 @@ sidebarCpt = R.hooksComponent "Sidebar" cpt ...@@ -59,3 +85,10 @@ sidebarCpt = R.hooksComponent "Sidebar" cpt
, "software engineering" , "software engineering"
, "complex systems" , "complex systems"
, "wireless communications" ] , "wireless communications" ]
query session nodesMap (selectedNodeIds /\ _) =
GT.tabs {session, query: q <$> Set.toUnfoldable selectedNodeIds, sides: []}
where
q id = case Map.lookup id nodesMap of
Nothing -> []
Just n -> words n.label
...@@ -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 (delay, (.=)) import FFI.Simple (delay, (.=))
import Gargantext.Hooks.Sigmax.Sigma as Sigma import Gargantext.Hooks.Sigmax.Sigma as Sigma
import Gargantext.Hooks.Sigmax.Types (Graph(..), Node(..)) import Gargantext.Hooks.Sigmax.Types (Graph(..), Node(..), NodesMap, SelectedNodeIds)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Prelude (Unit, bind, const, discard, flip, pure, unit, ($), (*>), (<$), (<$>), (<<<), (<>), (>>=), not) import Prelude (Unit, bind, const, discard, flip, pure, unit, ($), (*>), (<$), (<$>), (<<<), (<>), (>>=), not)
import Reactix as R import Reactix as R
...@@ -330,7 +330,7 @@ setEdges sigma val = do ...@@ -330,7 +330,7 @@ setEdges sigma val = do
Sigma.setSettings sigma settings Sigma.setSettings sigma settings
_ -> pure unit _ -> pure unit
markSelectedNodes :: Sigma.Sigma -> Set.Set String -> Map.Map String {color :: String} -> Effect Unit markSelectedNodes :: Sigma.Sigma -> SelectedNodeIds -> NodesMap -> Effect Unit
markSelectedNodes sigma selectedNodeIds graphNodes = do markSelectedNodes sigma selectedNodeIds graphNodes = do
log2 "[markSelectedNodes] selectedNodeIds" selectedNodeIds log2 "[markSelectedNodes] selectedNodeIds" selectedNodeIds
Sigma.forEachNode sigma \n -> do Sigma.forEachNode sigma \n -> do
......
...@@ -55,6 +55,7 @@ function killSigma(left, right, sigma) { ...@@ -55,6 +55,7 @@ function killSigma(left, right, sigma) {
} }
function clear(sigma) { sigma.graph.clear(); } function clear(sigma) { sigma.graph.clear(); }
function bind(sigma, event, handler) { sigma.bind(event, handler); } function bind(sigma, event, handler) { sigma.bind(event, handler); }
function unbind(sigma, event) { sigma.unbind(event); }
function forEachNode(sigma, handler) { sigma.graph.nodes().forEach(handler); } function forEachNode(sigma, handler) { sigma.graph.nodes().forEach(handler); }
function forEachEdge(sigma, handler) { sigma.graph.edges().forEach(handler); } function forEachEdge(sigma, handler) { sigma.graph.edges().forEach(handler); }
function setSettings(sigma, settings) { sigma.settings(settings); } function setSettings(sigma, settings) { sigma.settings(settings); }
...@@ -82,6 +83,7 @@ exports._setRendererContainer = setRendererContainer; ...@@ -82,6 +83,7 @@ exports._setRendererContainer = setRendererContainer;
exports._killSigma = killSigma exports._killSigma = killSigma
exports._clear = clear; exports._clear = clear;
exports._bind = bind; exports._bind = bind;
exports._unbind = unbind;
exports._forEachNode = forEachNode; exports._forEachNode = forEachNode;
exports._forEachEdge = forEachEdge; exports._forEachEdge = forEachEdge;
exports._setSettings = setSettings; exports._setSettings = setSettings;
......
...@@ -119,6 +119,11 @@ bind_ s e h = runEffectFn3 _bind s e (mkEffectFn1 h) ...@@ -119,6 +119,11 @@ bind_ s e h = runEffectFn3 _bind s e (mkEffectFn1 h)
foreign import _bind :: forall e. EffectFn3 Sigma String (EffectFn1 e Unit) Unit foreign import _bind :: forall e. EffectFn3 Sigma String (EffectFn1 e Unit) Unit
unbind_ :: forall e. Sigma -> String -> Effect Unit
unbind_ s e = runEffectFn2 _unbind s e
foreign import _unbind :: forall e. EffectFn2 Sigma String Unit
forEachNode :: Sigma -> (Record Types.Node -> Effect Unit) -> Effect Unit forEachNode :: Sigma -> (Record Types.Node -> Effect Unit) -> Effect Unit
forEachNode s f = runEffectFn2 _forEachNode s (mkEffectFn1 f) forEachNode s f = runEffectFn2 _forEachNode s (mkEffectFn1 f)
...@@ -134,6 +139,9 @@ bindClickNode sigma f = bind_ sigma "clickNode" $ \e -> do ...@@ -134,6 +139,9 @@ bindClickNode sigma f = bind_ sigma "clickNode" $ \e -> do
let node = e .. "data" .. "node" :: Record Types.Node let node = e .. "data" .. "node" :: Record Types.Node
f node f node
unbindClickNode :: Sigma -> Effect Unit
unbindClickNode sigma = unbind_ sigma "clickNode"
setSettings :: forall settings. Sigma -> settings -> Effect Unit setSettings :: forall settings. Sigma -> settings -> Effect Unit
setSettings sigma settings = do setSettings sigma settings = do
runEffectFn2 _setSettings sigma settings runEffectFn2 _setSettings sigma settings
......
module Gargantext.Hooks.Sigmax.Types where module Gargantext.Hooks.Sigmax.Types where
import Prelude (map, ($))
import Data.Map as Map
import Data.Sequence (Seq) import Data.Sequence (Seq)
import Data.Set as Set
import Data.Tuple (Tuple(..))
import DOM.Simple.Types (Element) import DOM.Simple.Types (Element)
newtype Graph n e = Graph { nodes :: Seq {|n}, edges :: Seq {|e} } newtype Graph n e = Graph { nodes :: Seq {|n}, edges :: Seq {|e} }
...@@ -23,3 +27,11 @@ type Node = ...@@ -23,3 +27,11 @@ type Node =
, color :: String ) , color :: String )
type Edge = ( id :: String, source :: String, target :: String ) type Edge = ( id :: String, source :: String, target :: String )
type SelectedNodeIds = Set.Set String
type NodesMap = Map.Map String (Record Node)
nodesMap :: Graph Node Edge -> NodesMap
nodesMap graph = do
let (Graph {nodes}) = graph
Map.fromFoldable $ map (\n -> Tuple n.id n) nodes
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