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
0
Issues
0
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
Grégoire Locqueville
purescript-gargantext
Commits
98d0e992
Commit
98d0e992
authored
Jan 08, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Graph] refresh graph after nodes are removed
parent
34352a7e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
32 deletions
+66
-32
GraphExplorer.purs
src/Gargantext/Components/GraphExplorer.purs
+38
-13
Sidebar.purs
src/Gargantext/Components/GraphExplorer/Sidebar.purs
+19
-15
Core.purs
src/Gargantext/Components/NgramsTable/Core.purs
+8
-1
Tabs.purs
src/Gargantext/Components/Nodes/Lists/Tabs.purs
+1
-3
No files found.
src/Gargantext/Components/GraphExplorer.purs
View file @
98d0e992
...
...
@@ -12,7 +12,13 @@ import Data.Nullable (null, Nullable)
import Data.Sequence as Seq
import Data.Set as Set
import Data.Tuple (fst, snd, Tuple(..))
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
import Math (log)
import Partial.Unsafe (unsafePartial)
import Reactix as R
import Reactix.DOM.HTML as RH
import Gargantext.Components.Forest (forest)
import Gargantext.Components.Graph as Graph
import Gargantext.Components.GraphExplorer.Controls as Controls
...
...
@@ -29,10 +35,6 @@ import Gargantext.Sessions (Session, Sessions, get)
import Gargantext.Types as Types
import Gargantext.Utils.Range as Range
import Gargantext.Utils.Reactix as R2
import Math (log)
import Partial.Unsafe (unsafePartial)
import Reactix as R
import Reactix.DOM.HTML as RH
type GraphId = Int
...
...
@@ -47,6 +49,7 @@ type LayoutProps =
type Props = (
graph :: SigmaxTypes.SGraph
, graphVersion :: R.State Int
, mMetaData :: Maybe GET.MetaData
| LayoutProps
)
...
...
@@ -58,12 +61,28 @@ explorerLayout props = R.createElement explorerLayoutCpt props []
explorerLayoutCpt :: R.Component LayoutProps
explorerLayoutCpt = R.hooksComponent "G.C.GraphExplorer.explorerLayout" cpt
where
cpt {graphId, mCurrentRoute, session, sessions, frontends, showLogin} _ = do
useLoader graphId (getNodes session) handler
cpt props _ = do
graphVersion <- R.useState' 0
pure $ explorerLayoutView graphVersion props
explorerLayoutView :: R.State Int -> Record LayoutProps -> R.Element
explorerLayoutView graphVersion p = R.createElement el p []
where
el = R.hooksComponent "G.C.GE.explorerLayoutView" cpt
cpt {frontends, graphId, mCurrentRoute, session, sessions, showLogin} _ = do
useLoader graphId (getNodes session graphVersion) handler
where
handler loaded =
explorer { graphId, mCurrentRoute, mMetaData
, session, sessions, graph, frontends, showLogin}
explorer { frontends
, graph
, graphId
, graphVersion
, mCurrentRoute
, mMetaData
, session
, sessions
, showLogin}
where (Tuple mMetaData graph) = convert loaded
--------------------------------------------------------------
...
...
@@ -73,21 +92,24 @@ explorer props = R.createElement explorerCpt props []
explorerCpt :: R.Component Props
explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
where
cpt {frontends, graph, graphId, mCurrentRoute, mMetaData, session, sessions, showLogin} _ = do
cpt {frontends, graph, graphId,
graphVersion,
mCurrentRoute, mMetaData, session, sessions, showLogin} _ = do
dataRef <- R.useRef graph
graphRef <- R.useRef null
graphVersionRef <- R.useRef (fst graphVersion)
controls <- Controls.useGraphControls graph
multiSelectEnabledRef <- R.useRef $ fst controls.multiSelectEnabled
R.useEffect' $ do
let readData = R.readRef dataRef
if SigmaxTypes.eqGraph readData graph then
let gv = R.readRef graphVersionRef
if (SigmaxTypes.eqGraph readData graph) || (gv == fst graphVersion) then
pure unit
else do
-- Graph data changed, reinitialize sigma.
let rSigma = R.readRef controls.sigmaRef
Sigmax.cleanupSigma rSigma "explorerCpt"
R.setRef dataRef graph
R.setRef graphVersionRef (fst graphVersion)
-- Reinitialize bunch of state as well.
snd controls.selectedNodeIds $ const Set.empty
snd controls.showEdges $ const SigmaxTypes.EShow
...
...
@@ -118,6 +140,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
}
, mSidebar mMetaData { frontends
, graph
, graphVersion
, session
, selectedNodeIds: controls.selectedNodeIds
, showSidePanel: fst controls.showSidePanel
...
...
@@ -147,14 +170,16 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
mSidebar :: Maybe GET.MetaData
-> { frontends :: Frontends
, graph :: SigmaxTypes.SGraph
, graphVersion :: R.State Int
, showSidePanel :: GET.SidePanelState
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
, session :: Session }
-> R.Element
mSidebar Nothing _ = RH.div {} []
mSidebar (Just metaData) {frontends, graph, session, selectedNodeIds, showSidePanel} =
mSidebar (Just metaData) {frontends, graph,
graphVersion,
session, selectedNodeIds, showSidePanel} =
Sidebar.sidebar { frontends
, graph
, graphVersion
, metaData
, session
, selectedNodeIds
...
...
@@ -250,8 +275,8 @@ modeGraphType Types.Sources = "star"
modeGraphType Types.Terms = "def"
getNodes :: Session -> GraphId -> Aff GET.GraphData
getNodes session
graphId = get session $ NodeAPI Types.Graph (Just graphId) ""
getNodes :: Session ->
R.State Int ->
GraphId -> Aff GET.GraphData
getNodes session
(graphVersion /\ _) graphId = get session $ NodeAPI Types.Graph (Just graphId) ("?version=" <> show graphVersion)
transformGraph :: Record Controls.Controls -> SigmaxTypes.SGraph -> SigmaxTypes.SGraph
...
...
src/Gargantext/Components/GraphExplorer/Sidebar.purs
View file @
98d0e992
...
...
@@ -4,17 +4,17 @@ module Gargantext.Components.GraphExplorer.Sidebar
import Prelude
import
DOM.Simple.Console (log2
)
import Data.Array (head)
import
Control.Parallel (parTraverse
)
import Data.Array (head
, last
)
import Data.Int (fromString)
import Data.Map as Map
import Data.Maybe (Maybe(..), fromJust)
import Data.Sequence as Seq
import Data.Set as Set
import Data.Traversable (traverse_)
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
import Partial.Unsafe (unsafePartial)
import Reactix as R
import Reactix.DOM.HTML as RH
...
...
@@ -26,14 +26,14 @@ import Gargantext.Components.RandomText (words)
import Gargantext.Data.Array (mapMaybe)
import Gargantext.Ends (Frontends)
import Gargantext.Hooks.Sigmax.Types as SigmaxTypes
import Gargantext.Routes (SessionRoute(NodeAPI))
import Gargantext.Sessions (Session, delete)
import Gargantext.Types (CTabNgramType(..), NodeType(..), TabSubType(..), TabType(..), TermList(..), modeTabType)
import Gargantext.Sessions (Session)
import Gargantext.Types (CTabNgramType, TabSubType(..), TabType(..), TermList(..), modeTabType)
import Gargantext.Utils.Reactix as R2
type Props =
( frontends :: Frontends
, graph :: SigmaxTypes.SGraph
, graphVersion :: R.State Int
, metaData :: GET.MetaData
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
, session :: Session
...
...
@@ -66,10 +66,10 @@ sidebarCpt = R.hooksComponent "Sidebar" cpt
, RH.div { className: "tab-content" }
[
RH.button { className: "btn btn-danger"
, on: { click: onClickRemove CandidateTerm props.session props.metaData nodesMap props.selectedNodeIds }}
, on: { click: onClickRemove CandidateTerm props.session props.metaData nodesMap props.selectedNodeIds
props.graphVersion
}}
[ RH.text "Remove candidate" ]
, RH.button { className: "btn btn-danger"
, on: { click: onClickRemove StopTerm props.session props.metaData nodesMap props.selectedNodeIds }}
, on: { click: onClickRemove StopTerm props.session props.metaData nodesMap props.selectedNodeIds
props.graphVersion
}}
[ RH.text "Remove stop" ]
]
, RH.li { className: "nav-item" }
...
...
@@ -112,11 +112,9 @@ sidebarCpt = R.hooksComponent "Sidebar" cpt
, checked: true
, title: "Mark as completed" } ]
onClickRemove rType session metaData nodesMap (selectedNodeIds /\ _) e = do
log2 "[onClickRemove] selectedNodeIds" selectedNodeIds
onClickRemove rType session metaData nodesMap (selectedNodeIds /\ _) graphVersion e = do
let nodes = mapMaybe (\id -> Map.lookup id nodesMap) $ Set.toUnfoldable selectedNodeIds
deleteNodes rType session metaData nodes
deleteNodes rType session metaData graphVersion nodes
badge :: R.State SigmaxTypes.SelectedNodeIds -> Record SigmaxTypes.Node -> R.Element
...
...
@@ -136,9 +134,15 @@ neighbourBadges graph (selectedNodeIds /\ _) = SigmaxTypes.neighbours graph sele
where
selectedNodes = SigmaxTypes.graphNodes $ SigmaxTypes.nodesById graph selectedNodeIds
deleteNodes :: TermList -> Session -> GET.MetaData -> Array (Record SigmaxTypes.Node) -> Effect Unit
deleteNodes termList session metaData nodes = do
traverse_ (launchAff_ <<< deleteNode termList session metaData) nodes
deleteNodes :: TermList -> Session -> GET.MetaData -> R.State Int -> Array (Record SigmaxTypes.Node) -> Effect Unit
deleteNodes termList session metaData (_ /\ setGraphVersion) nodes = do
launchAff_ do
patches <- (parTraverse (deleteNode termList session metaData) nodes) :: Aff (Array NTC.VersionedNgramsPatches)
let mPatch = last patches
case mPatch of
Nothing -> pure unit
Just (NTC.Versioned patch) -> liftEffect do
setGraphVersion $ const $ patch.version
deleteNode :: TermList -> Session -> GET.MetaData -> Record SigmaxTypes.Node -> Aff NTC.VersionedNgramsPatches
deleteNode termList session (GET.MetaData metaData) node = NTC.putNgramsPatches coreParams versioned
...
...
src/Gargantext/Components/NgramsTable/Core.purs
View file @
98d0e992
...
...
@@ -180,7 +180,14 @@ _list = prop (SProxy :: SProxy "list")
derive instance newtypeNgramsElement :: Newtype NgramsElement _
_NgramsElement :: Iso' NgramsElement _
_NgramsElement :: Iso' NgramsElement {
children :: Set NgramsTerm
, list :: TermList
, ngrams :: NgramsTerm
, occurrences :: Int
, parent :: Maybe NgramsTerm
, root :: Maybe NgramsTerm
}
_NgramsElement = _Newtype
instance decodeJsonNgramsElement :: DecodeJson NgramsElement where
...
...
src/Gargantext/Components/Nodes/Lists/Tabs.purs
View file @
98d0e992
module Gargantext.Components.Nodes.Lists.Tabs where
import Prelude
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\))
import Reactix as R
...
...
@@ -13,7 +11,7 @@ import Gargantext.Components.Nodes.Corpus.Chart.Metrics (metrics)
import Gargantext.Components.Nodes.Corpus.Chart.Pie (pie, bar)
import Gargantext.Components.Nodes.Corpus.Chart.Tree (tree)
import Gargantext.Sessions (Session)
import Gargantext.Types (Mode(..),
modeTabType, CTabNgramType(..), TabType(..), TabSubType(..)
)
import Gargantext.Types (Mode(..),
TabSubType(..), TabType(..), modeTabType
)
type Props =
( session :: Session
...
...
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