Commit 83c9beeb authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] fix sigma node click event binding

parent 71d3be64
......@@ -9,7 +9,7 @@ import Data.Map as Map
import Data.Maybe (Maybe(..))
import Data.Nullable (notNull, null, Nullable)
import Data.Set as Set
import Data.Tuple (Tuple(..))
import Data.Tuple (fst, snd, Tuple(..))
import Data.Tuple.Nested ((/\))
import DOM.Simple (createElement, setAttr)
import DOM.Simple.Console (log, log2)
......@@ -45,23 +45,21 @@ graphCpt = R.hooksComponent "Graph" cpt
where
cpt props _ = do
let nodesMap = SigmaxTypes.nodesMap props.graph
let (selectedNodeIds /\ setSelectedNodeIds) = props.selectedNodeIds
let selectedNodeIds = props.selectedNodeIds
R.useEffect' $ do
Sigmax.dependOnSigma (R.readRef props.sigmaRef) "[graphCpt] no sigma" $ \sigma ->
Sigmax.markSelectedNodes sigma selectedNodeIds nodesMap
Sigmax.markSelectedNodes sigma (fst selectedNodeIds) nodesMap
R.useEffectOnce $ do
let mSigma = Sigmax.readSigma $ R.readRef props.sigmaRef
Sigmax.startSigmaEff props.elRef props.sigmaRef props.sigmaSettings props.forceAtlas2Settings props.graph
Sigmax.dependOnSigma (R.readRef props.sigmaRef) "[graphCpt] no sigma" $ \sigma ->
Sigma.bindClickNode sigma $ \node -> do
log2 "[graphCpt] clickNode" node
setSelectedNodeIds \nids ->
if Set.member node.id nids then
Set.delete node.id nids
else
Set.insert node.id nids
-- bind the click event only initially, when ref was empty
case mSigma of
Nothing -> Sigmax.bindSelectedNodesClick props.sigmaRef selectedNodeIds
Just _ -> pure unit
delay unit $ \_ -> do
log "[GraphCpt] cleanup"
......
......@@ -345,3 +345,15 @@ markSelectedNodes sigma selectedNodeIds graphNodes = do
_ <- pure $ (n .= "color") newColor
pure unit
Sigma.refresh sigma
bindSelectedNodesClick :: R.Ref Sigma -> R.State SelectedNodeIds -> Effect Unit
bindSelectedNodesClick sigmaRef (_ /\ setSelectedNodeIds) =
dependOnSigma (R.readRef sigmaRef) "[graphCpt] no sigma" $ \sigma ->
Sigma.bindClickNode sigma $ \node -> do
log2 "[graphCpt] clickNode" node
setSelectedNodeIds \nids ->
if Set.member node.id nids then
Set.delete node.id nids
else
Set.insert node.id nids
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