Commit 71d3be64 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] implement crude node search on sidebar

parent 4b13b0ff
...@@ -56,6 +56,7 @@ graphCpt = R.hooksComponent "Graph" cpt ...@@ -56,6 +56,7 @@ graphCpt = R.hooksComponent "Graph" cpt
Sigmax.dependOnSigma (R.readRef props.sigmaRef) "[graphCpt] no sigma" $ \sigma -> Sigmax.dependOnSigma (R.readRef props.sigmaRef) "[graphCpt] no sigma" $ \sigma ->
Sigma.bindClickNode sigma $ \node -> do Sigma.bindClickNode sigma $ \node -> do
log2 "[graphCpt] clickNode" node
setSelectedNodeIds \nids -> setSelectedNodeIds \nids ->
if Set.member node.id nids then if Set.member node.id nids then
Set.delete node.id nids Set.delete node.id nids
......
...@@ -35,15 +35,17 @@ type GraphId = Int ...@@ -35,15 +35,17 @@ type GraphId = Int
type LayoutProps = type LayoutProps =
( graphId :: GraphId ( graphId :: GraphId
, frontends :: Frontends
, mCurrentRoute :: AppRoute , mCurrentRoute :: AppRoute
, treeId :: Maybe Int
, session :: Session , session :: Session
, sessions :: Sessions , sessions :: Sessions
, frontends :: Frontends , treeId :: Maybe Int
) )
type Props = ( type Props = (
graph :: Maybe Graph.Graph | LayoutProps graph :: Maybe Graph.Graph
, mMetaData :: Maybe GET.MetaData
| LayoutProps
) )
-------------------------------------------------------------- --------------------------------------------------------------
...@@ -57,8 +59,8 @@ explorerLayoutCpt = R.hooksComponent "G.C.GraphExplorer.explorerLayout" cpt ...@@ -57,8 +59,8 @@ explorerLayoutCpt = R.hooksComponent "G.C.GraphExplorer.explorerLayout" cpt
useLoader graphId (getNodes session) handler useLoader graphId (getNodes session) handler
where where
handler loaded = handler loaded =
explorer {graphId, mCurrentRoute, treeId, session, sessions, graph, frontends} explorer {graphId, mCurrentRoute, mMetaData, treeId, session, sessions, graph: Just graph, frontends}
where graph = Just (convert loaded) where (Tuple mMetaData graph) = convert loaded
-------------------------------------------------------------- --------------------------------------------------------------
explorer :: Record Props -> R.Element explorer :: Record Props -> R.Element
...@@ -67,7 +69,7 @@ explorer props = R.createElement explorerCpt props [] ...@@ -67,7 +69,7 @@ explorer props = R.createElement explorerCpt props []
explorerCpt :: R.Component Props explorerCpt :: R.Component Props
explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
where where
cpt {sessions, session, graphId, mCurrentRoute, treeId, graph, frontends} _ = do cpt {frontends, graph, graphId, mCurrentRoute, mMetaData, session, sessions, treeId} _ = do
graphRef <- R.useRef null graphRef <- R.useRef null
controls <- Controls.useGraphControls controls <- Controls.useGraphControls
state <- useExplorerState state <- useExplorerState
...@@ -89,7 +91,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -89,7 +91,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
, 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, selectedNodeIds} , mGraph graphRef controls.sigmaRef {graphId, graph, selectedNodeIds}
, mSidebar graph {session, selectedNodeIds, showSidePanel: fst controls.showSidePanel} , mSidebar graph mMetaData {session, selectedNodeIds, showSidePanel: fst controls.showSidePanel}
] ]
, row [ , row [
] ]
...@@ -122,13 +124,16 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -122,13 +124,16 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
mGraph graphRef sigmaRef {graphId, graph: Just graph, selectedNodeIds} = graphView graphRef sigmaRef {graphId, graph, selectedNodeIds} mGraph graphRef sigmaRef {graphId, graph: Just graph, selectedNodeIds} = graphView graphRef sigmaRef {graphId, graph, selectedNodeIds}
mSidebar :: Maybe Graph.Graph mSidebar :: Maybe Graph.Graph
-> Maybe GET.MetaData
-> { showSidePanel :: Boolean -> { showSidePanel :: Boolean
, 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 (Just graph) {session, selectedNodeIds, showSidePanel} = mSidebar _ Nothing _ = RH.div {} []
mSidebar (Just graph) (Just metaData) {session, selectedNodeIds, showSidePanel} =
Sidebar.sidebar { graph Sidebar.sidebar { graph
, metaData
, session , session
, selectedNodeIds , selectedNodeIds
, showSidePanel , showSidePanel
...@@ -174,8 +179,8 @@ graphView elRef sigmaRef props = R.createElement el props [] ...@@ -174,8 +179,8 @@ graphView elRef sigmaRef props = R.createElement el props []
, sigmaRef: sigmaRef , sigmaRef: sigmaRef
} }
convert :: GET.GraphData -> Graph.Graph convert :: GET.GraphData -> Tuple (Maybe GET.MetaData) Graph.Graph
convert (GET.GraphData r) = SigmaxTypes.Graph {nodes, edges} convert (GET.GraphData r) = Tuple r.metaData $ 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) =
...@@ -196,7 +201,7 @@ defaultPalette :: Array String ...@@ -196,7 +201,7 @@ defaultPalette :: Array String
defaultPalette = ["#5fa571","#ab9ba2","#da876d","#bdd3ff","#b399df","#ffdfed","#33c8f3","#739e9a","#caeca3","#f6f7e5","#f9bcca","#ccb069","#c9ffde","#c58683","#6c9eb0","#ffd3cf","#ccffc7","#52a1b0","#d2ecff","#99fffe","#9295ae","#5ea38b","#fff0b3","#d99e68"] defaultPalette = ["#5fa571","#ab9ba2","#da876d","#bdd3ff","#b399df","#ffdfed","#33c8f3","#739e9a","#caeca3","#f6f7e5","#f9bcca","#ccb069","#c9ffde","#c58683","#6c9eb0","#ffd3cf","#ccffc7","#52a1b0","#d2ecff","#99fffe","#9295ae","#5ea38b","#fff0b3","#d99e68"]
-- clusterColor :: Cluster -> Color -- clusterColor :: Cluster -> Color
-- clusterColor (Cluster {clustDefault}) = unsafePartial $ fromJust $ defaultPalette !! (clustDefault `mod` length defaultPalette) -- clusterColor (Cluster {clustDefault}) = unsafePartial $ fromJust $ defaultPalette !! (clustDefault `molength defrultPalette)
-- div [className "col-md-12", style {"padding-bottom" : "10px"}] -- div [className "col-md-12", style {"padding-bottom" : "10px"}]
-- [ menu [_id "toolbar"] -- [ menu [_id "toolbar"]
......
...@@ -3,6 +3,7 @@ module Gargantext.Components.GraphExplorer.Sidebar ...@@ -3,6 +3,7 @@ module Gargantext.Components.GraphExplorer.Sidebar
where where
import Prelude import Prelude
import Data.Array (head)
import Data.Map as Map import Data.Map as Map
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Set as Set import Data.Set as Set
...@@ -13,11 +14,13 @@ import Reactix.DOM.HTML as RH ...@@ -13,11 +14,13 @@ import Reactix.DOM.HTML as RH
import Gargantext.Components.RandomText (words) import Gargantext.Components.RandomText (words)
import Gargantext.Components.Nodes.Corpus.Graph.Tabs as GT import Gargantext.Components.Nodes.Corpus.Graph.Tabs as GT
import Gargantext.Components.Graph as Graph import Gargantext.Components.Graph as Graph
import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Hooks.Sigmax.Types as SigmaxTypes import Gargantext.Hooks.Sigmax.Types as SigmaxTypes
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
type Props = type Props =
( graph :: Graph.Graph ( graph :: Graph.Graph
, metaData :: GET.MetaData
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds , selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
, session :: Session , session :: Session
, showSidePanel :: Boolean , showSidePanel :: Boolean
...@@ -61,7 +64,7 @@ sidebarCpt = R.hooksComponent "Sidebar" cpt ...@@ -61,7 +64,7 @@ sidebarCpt = R.hooksComponent "Sidebar" cpt
] ]
, RH.div { className: "col-md-12", id: "query" } , RH.div { className: "col-md-12", id: "query" }
[ [
query props.session nodesMap props.selectedNodeIds query props.metaData props.session nodesMap props.selectedNodeIds
] ]
] ]
] ]
...@@ -86,9 +89,18 @@ sidebarCpt = R.hooksComponent "Sidebar" cpt ...@@ -86,9 +89,18 @@ sidebarCpt = R.hooksComponent "Sidebar" cpt
, "complex systems" , "complex systems"
, "wireless communications" ] , "wireless communications" ]
query session nodesMap (selectedNodeIds /\ _) = query _ _ _ (selectedNodeIds /\ _) | Set.isEmpty selectedNodeIds = RH.div {} []
GT.tabs {session, query: q <$> Set.toUnfoldable selectedNodeIds, sides: []} query (GET.MetaData metaData) session nodesMap (selectedNodeIds /\ _) =
query' (head metaData.corpusId)
where where
query' Nothing = RH.div {} []
query' (Just corpusId) =
GT.tabs {session, query: q <$> Set.toUnfoldable selectedNodeIds, sides: [side corpusId]}
q id = case Map.lookup id nodesMap of q id = case Map.lookup id nodesMap of
Nothing -> [] Nothing -> []
Just n -> words n.label Just n -> words n.label
side corpusId = GET.GraphSideCorpus {
corpusId
, listId: metaData.listId
, corpusLabel: metaData.title
}
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