Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
139
Issues
139
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
purescript-gargantext
Commits
7ecae0f6
Commit
7ecae0f6
authored
Dec 06, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev-graph' into mergeMaster
parents
7d0dfeb9
044be1f5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
26 deletions
+89
-26
Graph.purs
src/Gargantext/Pages/Corpus/Graph.purs
+89
-26
No files found.
src/Gargantext/Pages/Corpus/Graph.purs
View file @
7ecae0f6
module Gargantext.Pages.Corpus.Graph where
module Gargantext.Pages.Corpus.Graph where
import Effect.Unsafe
import Gargantext.Prelude
import Gargantext.Prelude
import Affjax (defaultRequest, request)
import Affjax (defaultRequest, request)
import Affjax.ResponseFormat (printResponseFormatError)
import Affjax.ResponseFormat (
ResponseFormat(..),
printResponseFormatError)
import Affjax.ResponseFormat as ResponseFormat
import Affjax.ResponseFormat as ResponseFormat
import Control.Monad.Cont.Trans (lift)
import Control.Monad.Cont.Trans (lift)
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.?), (.??), (:=), (~>))
import Data.Argonaut (decodeJson)
import Data.Argonaut (decodeJson)
import Data.Array (length, mapWithIndex, (!!))
import Data.Array (length, mapWithIndex, (!!))
import Data.Either (Either(..))
import Data.Either (Either(..))
import Data.HTTP.Method (Method(..))
import Data.HTTP.Method (Method(..))
import Data.Int (toNumber)
import Data.Int (
fromString,
toNumber)
import Data.Maybe (Maybe(..), fromJust)
import Data.Maybe (Maybe(..), fromJust
, fromMaybe
)
import Data.Newtype (class Newtype)
import Data.Newtype (class Newtype)
import Effect.Aff (Aff)
import Data.String (joinWith)
import Effect.Aff (Aff, attempt)
import Effect.Aff.Class (liftAff)
import Effect.Class (liftEffect)
import Effect.Class (liftEffect)
import Effect.Console (log)
import Effect.Console (log)
import Gargantext.Components.GraphExplorer.Sigmajs (Color(Color), SigmaEasing, SigmaGraphData(SigmaGraphData), SigmaNode, SigmaSettings, canvas, edgeShape, edgeShapes, forceAtlas2, sStyle, sigma, sigmaEasing, sigmaEdge, sigmaEnableWebGL, sigmaNode, sigmaSettings)
import Gargantext.Components.GraphExplorer.Sigmajs (Color(Color), SigmaEasing, SigmaGraphData(SigmaGraphData), SigmaNode, SigmaSettings, canvas, edgeShape, edgeShapes, forceAtlas2, sStyle, sigma, sigmaEasing, sigmaEdge, sigmaEnableWebGL, sigmaNode, sigmaSettings)
import Gargantext.Components.GraphExplorer.Types (Cluster(..), Edge(..), GraphData(..), Legend(..), Node(..), getLegendData)
import Gargantext.Components.GraphExplorer.Types (Cluster(..), Edge(..), GraphData(..), Legend(..), Node(..), getLegendData)
import Gargantext.Config as Config
import Gargantext.Config as Config
import Gargantext.Config.REST (get)
import Gargantext.Config.REST (get
, post
)
import Gargantext.Utils (getter)
import Gargantext.Utils (getter)
import Math (cos, sin)
import Math (cos, sin)
import Partial.Unsafe (unsafePartial)
import Partial.Unsafe (unsafePartial)
import React (ReactElement)
import React (ReactElement)
import React.DOM (a, br', button, div, form', input, li, li', menu, option, p, select, span, text, ul, ul')
import React.DOM (a, br', button, div, form', input, li, li', menu, option, p, select, span, text, ul, ul')
import React.DOM.Props (_id, _type, checked, className, href, name, onChange, onClick,placeholder, style, title, value)
import React.DOM.Props (_id, _type, checked, className, href, name, onChange, onClick,
placeholder, style, title, value)
import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec)
import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec)
import Unsafe.Coerce (unsafeCoerce)
import Unsafe.Coerce (unsafeCoerce)
data Action
data Action
= LoadGraph Int
= LoadGraph Int
| SelectNode SelectedNode
| SelectNode SelectedNode
| ShowSidePanel
| ShowSidePanel
Boolean
| ShowControls
| ShowControls
newtype SelectedNode = SelectedNode {id :: String, label :: String}
newtype SelectedNode = SelectedNode {id :: String, label :: String}
...
@@ -50,6 +53,20 @@ newtype State = State
...
@@ -50,6 +53,20 @@ newtype State = State
, selectedNode :: Maybe SelectedNode
, selectedNode :: Maybe SelectedNode
, showSidePanel :: Boolean
, showSidePanel :: Boolean
, showControls :: Boolean
, showControls :: Boolean
, nodeResults :: Array NodeResults
, corpusId :: Int
}
newtype NodeQuery = NodeQuery
{
query :: Array String
, parentId :: Int
}
newtype NodeResults = NodeResults
{
rid :: Int
, title :: String
, authors :: String
}
}
initialState :: State
initialState :: State
...
@@ -61,6 +78,8 @@ initialState = State
...
@@ -61,6 +78,8 @@ initialState = State
, selectedNode : Nothing
, selectedNode : Nothing
, showSidePanel : false
, showSidePanel : false
, showControls : false
, showControls : false
, nodeResults : []
, corpusId : 0
}
}
graphSpec :: Spec State {} Action
graphSpec :: Spec State {} Action
...
@@ -69,17 +88,24 @@ graphSpec = simpleSpec performAction render
...
@@ -69,17 +88,24 @@ graphSpec = simpleSpec performAction render
performAction :: PerformAction State {} Action
performAction :: PerformAction State {} Action
performAction (LoadGraph fp) _ _ = void do
performAction (LoadGraph fp) _ _ = void do
_ <- logs fp
_ <- logs fp
_ <- modifyState \(State s) -> State s { sigmaGraphData = Nothing}
_ <- modifyState \(State s) -> State s {
corpusId = fp,
sigmaGraphData = Nothing}
resp <- lift $ getNodes fp
resp <- lift $ getNodes fp
-- TODO: here one might `catchError getNodes` to visually empty the
-- TODO: here one might `catchError getNodes` to visually empty the
-- graph.
-- graph.
modifyState \(State s) -> State s {graphData = resp, sigmaGraphData = Just $ convert resp, legendData = getLegendData resp}
modifyState \(State s) -> State s {graphData = resp, sigmaGraphData = Just $ convert resp, legendData = getLegendData resp}
performAction (SelectNode node) _ _ = void do
performAction (SelectNode (SelectedNode node)) _ (State state) = void do
modifyState $ \(State s) -> State s {selectedNode = pure node}
_ <- modifyState $ \(State s) -> State s {selectedNode = pure $ SelectedNode node}
response <- lift $ attempt $ selectNodeApi $ NodeQuery {query : [node.label], parentId : state.corpusId}
case response of
Left err -> do
_ <- liftEffect $ log $ show err
modifyState identity
Right resp -> do
modifyState $ \(State s) -> State s {nodeResults = resp}
performAction (ShowSidePanel) _ (State state) = void do
performAction (ShowSidePanel
b
) _ (State state) = void do
modifyState $ \(State s) -> State s {showSidePanel =
not (state.showSidePanel)
}
modifyState $ \(State s) -> State s {showSidePanel =
b
}
performAction (ShowControls) _ (State state) = void do
performAction (ShowControls) _ (State state) = void do
...
@@ -115,10 +141,11 @@ render d p (State s) c =
...
@@ -115,10 +141,11 @@ render d p (State s) c =
, renderer : canvas
, renderer : canvas
, settings : mySettings
, settings : mySettings
, style : sStyle { height : "95%"}
, style : sStyle { height : "95%"}
-- , onClickNode : \e -> do
, onClickNode : \e -> unsafePerformEffect $ do
-- logs $ unsafeCoerce e
_ <- log "hello"
-- d $ SelectNode $ SelectedNode {id : (unsafeCoerce e).data.node.id, label : (unsafeCoerce e).data.node.label}
-- _ <- logs $ unsafeCoerce e
-- pure unit
_ <- d $ SelectNode $ SelectedNode {id : (unsafeCoerce e).data.node.id, label : (unsafeCoerce e).data.node.label}
pure unit
-- TODO: fix this!
-- TODO: fix this!
}
}
[ sigmaEnableWebGL
[ sigmaEnableWebGL
...
@@ -283,8 +310,8 @@ specOld = simpleSpec performAction render'
...
@@ -283,8 +310,8 @@ specOld = simpleSpec performAction render'
[text "Show Controls"]
[text "Show Controls"]
, button [className "btn btn-primary"
, button [className "btn btn-primary"
, style {position:"relative",top:"-25px",left: "1380px"}
, style {position:"relative",top:"-25px",left: "1380px"}
,onClick \_ -> d
S
howSidePanel
,onClick \_ -> d
$ ShowSidePanel $ not st.s
howSidePanel
] [text "
show
SidePanel"]
] [text "
Show
SidePanel"]
]
]
, if (st.showControls) then
, if (st.showControls) then
div [className "col-md-12", style {marginBottom : "21px"}]
div [className "col-md-12", style {marginBottom : "21px"}]
...
@@ -358,7 +385,7 @@ specOld = simpleSpec performAction render'
...
@@ -358,7 +385,7 @@ specOld = simpleSpec performAction render'
]
]
, div [className "row"]
, div [className "row"]
[ div [if (st.showSidePanel) then className "col-md-10" else className "col-md-11"]
[ div [if (st.showSidePanel) then className "col-md-10" else className "col-md-11"]
[ div [style {
border : "1px black solid",
height: "90%"}] $
[ div [style {height: "90%"}] $
[
[
]
]
<>
<>
...
@@ -369,10 +396,13 @@ specOld = simpleSpec performAction render'
...
@@ -369,10 +396,13 @@ specOld = simpleSpec performAction render'
, renderer : canvas
, renderer : canvas
, settings : mySettings
, settings : mySettings
, style : sStyle { height : "95%"}
, style : sStyle { height : "95%"}
-- , onClickNode : \e -> do
, onClickNode : \e -> unsafePerformEffect $ do
-- logs $ unsafeCoerce e
_ <- log " hello 2"
-- d $ SelectNode $ SelectedNode {id : (unsafeCoerce e).data.node.id, label : (unsafeCoerce e).data.node.label}
--_ <- attempt $ selectNodeApi $ NodeQuery {query : [], parentId : 0}
-- pure unit
--logs $ unsafeCoerce e
_ <- d $ ShowSidePanel true
_ <- d $ SelectNode $ SelectedNode {id : (unsafeCoerce e).data.node.id, label : (unsafeCoerce e).data.node.label}
pure unit
}
}
[ sigmaEnableWebGL
[ sigmaEnableWebGL
, forceAtlas2 forceAtlas2Config
, forceAtlas2 forceAtlas2Config
...
@@ -388,8 +418,10 @@ specOld = simpleSpec performAction render'
...
@@ -388,8 +418,10 @@ specOld = simpleSpec performAction render'
[ div [className "row"]
[ div [className "row"]
[ div [_id "sidepanel" , style {borderBottom : "1px solid black"}]
[ div [_id "sidepanel" , style {borderBottom : "1px solid black"}]
[ case st.selectedNode of
[ case st.selectedNode of
Nothing -> span [] []
Nothing -> span [] [ text "dummy text"]
Just selectedNode -> p [] [text $ "selected Node : " <> getter _.label selectedNode
Just selectedNode -> p [] [ text $ "selected Node : " <> getter _.label selectedNode
, text $ (joinWith ", " ( getTitle st.nodeResults))
, text $ (joinWith ", " (getAuthors st.nodeResults))
, br'
, br'
, p [] [button [className "btn btn-primary", style {marginBottom : "18px"}] [text "Remove"]]
, p [] [button [className "btn btn-primary", style {marginBottom : "18px"}] [text "Remove"]]
]
]
...
@@ -487,5 +519,36 @@ specOld = simpleSpec performAction render'
...
@@ -487,5 +519,36 @@ specOld = simpleSpec performAction render'
]
]
]
]
getTitle :: Array NodeResults -> Array String
getTitle ary = map (\(NodeResults s)-> s.title) ary
getAuthors :: Array NodeResults -> Array String
getAuthors ary = map (\(NodeResults s ) -> s.authors) ary
getNodes :: Int -> Aff GraphData
getNodes :: Int -> Aff GraphData
getNodes graphId = get $ Config.toUrl Config.Back Config.Graph $ Just graphId
getNodes graphId = get $ Config.toUrl Config.Back Config.Graph $ Just graphId
selectNodeApi :: NodeQuery -> Aff (Array NodeResults)
selectNodeApi = post $ getUrl <> "search"
instance encodeJsonNQuery :: EncodeJson NodeQuery where
encodeJson (NodeQuery post)
= "query" := post.query
~> "parent_id" := post.parentId
~> jsonEmptyObject
instance decodeJsonNResults :: DecodeJson NodeResults where
decodeJson json = do
obj <- decodeJson json
rid <- obj .? "id"
title <- obj .? "title"
authors <- obj .? "authors"
pure $ NodeResults {rid,title,authors}
getUrl :: String
getUrl = back.baseUrl <> back.prePath
where
back = Config.endConfig.back
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment