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