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
142
Issues
142
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
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
10dace7c
Commit
10dace7c
authored
Jun 07, 2019
by
James Laver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add filtering to graph explorer - no ui
parent
802ce118
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
11 deletions
+66
-11
Types.purs
src/Gargantext/Components/GraphExplorer/Types.purs
+3
-0
Graph.purs
src/Gargantext/Pages/Corpus/Graph.purs
+63
-11
No files found.
src/Gargantext/Components/GraphExplorer/Types.purs
View file @
10dace7c
...
...
@@ -32,6 +32,9 @@ newtype Edge = Edge
derive instance newtypeEdge :: Newtype Edge _
-- | A 'fully closed interval' in CS parlance
type InclusiveRange t = { min :: t, max :: t }
type CorpusId = Int
type CorpusLabel = String
...
...
src/Gargantext/Pages/Corpus/Graph.purs
View file @
10dace7c
...
...
@@ -9,7 +9,7 @@ import Affjax.ResponseFormat as ResponseFormat
import Control.Monad.Cont.Trans (lift)
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.?), (.??), (:=), (~>))
import Data.Argonaut (decodeJson)
import Data.Array (fold, length, mapWithIndex, (!!), null)
import Data.Array (f
ilter, f
old, length, mapWithIndex, (!!), null)
import Data.Either (Either(..))
import Data.HTTP.Method (Method(..))
import Data.Int (fromString, toNumber)
...
...
@@ -41,6 +41,7 @@ import Gargantext.Pages.Corpus.Graph.Tabs as GT
import Gargantext.Prelude (flip)
import Gargantext.Types (class Optional)
import Gargantext.Utils (getter, toggleSet)
import Gargantext.Utils.Range as Range
import Math (cos, sin)
import Partial.Unsafe (unsafePartial)
import React (ReactElement)
...
...
@@ -115,7 +116,10 @@ numberTargetValue e =
-- TODO remove newtype here
newtype State = State
{ graphData :: GraphData
{ rawGraphData :: GraphData
, graphData :: GraphData
, edgeFilters :: EdgeFilters
, nodeFilters :: NodeFilters
, filePath :: String
, sigmaGraphData :: Maybe SigmaGraphData
, legendData :: Array Legend
...
...
@@ -132,9 +136,16 @@ newtype State = State
derive instance newtypeState :: Newtype State _
emptyGraphData :: GraphData
emptyGraphData = GraphData { nodes: [], edges: [], sides: [], metaData }
where metaData = Just $ MetaData { title : "", legend : [], corpusId : [] }
initialState :: State
initialState = State
{ graphData : GraphData {nodes: [], edges: [], sides: [], metaData : Just $ MetaData{title : "", legend : [], corpusId : []}}
{ rawGraphData : emptyGraphData
, graphData : emptyGraphData
, edgeFilters : defaultEdgeFilters
, nodeFilters : defaultNodeFilters
, filePath : ""
, sigmaGraphData : Nothing
, legendData : []
...
...
@@ -156,27 +167,68 @@ graphSpec :: Spec State {} Action
graphSpec = simpleSpec performAction render
-}
type ControlsData = { }
type EdgeFilters =
{ confluence :: Range.Closed Number }
defaultEdgeFilters :: EdgeFilters
defaultEdgeFilters = { confluence: Range.closedProbability }
type NodeFilters = {}
defaultNodeFilters :: NodeFilters
defaultNodeFilters = {}
filterNode :: NodeFilters -> Node -> Boolean
filterNode _ n = true
filterNodes :: NodeFilters -> Array Node -> Array Node
filterNodes f = filter (filterNode f)
filterEdge :: EdgeFilters -> Edge -> Boolean
filterEdge f (Edge e) = Range.within f.confluence e.confluence
filterEdges :: EdgeFilters -> Array Edge -> Array Edge
filterEdges f = filter (filterEdge f)
filterGraphData :: State -> GraphData -> GraphData
filterGraphData (State s) (GraphData g) = GraphData $
g { nodes = filterNodes s.nodeFilters g.nodes
, edges = filterEdges s.edgeFilters g.edges }
performAction :: PerformAction State {} Action
performAction (LoadGraph fp) _ _ = void do
_ <- logs fp
_ <- modifyState \(State s) -> State s {corpusId = fp, sigmaGraphData = Nothing}
r
esp
<- lift $ getNodes fp
r
awGraphData
<- lift $ getNodes fp
treeResp <- liftEffect $ getAuthData
case treeResp of
Just (AuthData {token,tree_id }) ->
modifyState \(State s) -> State s {graphData = resp, sigmaGraphData = Just $ convert resp, legendData = getLegendData resp, treeId = Just tree_id}
modifyState \(State s) ->
State $
s { rawGraphData = rawGraphData
, graphData = filterGraphData (State s) rawGraphData
, sigmaGraphData = Just $ sigmafy rawGraphData
, legendData = getLegendData rawGraphData
, treeId = Just tree_id}
Nothing ->
modifyState \(State s) -> State s { graphData = resp, sigmaGraphData = Just $ convert resp, legendData = getLegendData resp, treeId = Nothing}
-- TODO: here one might `catchError getNodes` to visually empty the
modifyState \(State s) ->
State $
s { rawGraphData = rawGraphData
, graphData = filterGraphData (State s) rawGraphData
, sigmaGraphData = Just $ sigmafy rawGraphData
, legendData = getLegendData rawGraphData
, treeId = Nothing}
-- TODO: here one might `catchError getNodes` to visually empty the
-- graph.
--modifyState \(State s) -> State s {
graphData = resp, sigmaGraphData = Just $ convert resp, legendData = getLegendData resp
}
--modifyState \(State s) -> State s {
rawGraphData, graphData=filterGraphData (State s) rawGraphData, sigmaGraphData = Just $ sigmafy rawGraphData, legendData = getLegendData rawGraphData
}
performAction (SelectNode selectedNode@(SelectedNode node)) _ (State state) =
modifyState_ $ \(State s) ->
State s {selectedNodes = toggleSet selectedNode
(if s.multiNodeSelection then s.selectedNodes
else Set.empty) }
performAction (ShowSidePanel b) _ (State state) = void do
modifyState $ \(State s) -> State s {showSidePanel = b }
...
...
@@ -214,8 +266,8 @@ performAction (ChangeCursorSize size) _ _ =
-- modifyState_ $ \() -> do
-- State $
convert
:: GraphData -> SigmaGraphData
convert
(GraphData r) = SigmaGraphData {nodes, edges}
sigmafy
:: GraphData -> SigmaGraphData
sigmafy
(GraphData r) = SigmaGraphData {nodes, edges}
where
nodes = mapWithIndex nodeFn r.nodes
nodeFn i (Node n) =
...
...
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