Commit 9e296c86 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] implemented node hover for selected nodes

Also, preliminary work done for selectorSize control.
parent 2a9ccf59
...@@ -32,6 +32,7 @@ type Props sigma forceatlas2 = ...@@ -32,6 +32,7 @@ type Props sigma forceatlas2 =
, graph :: SigmaxTypes.SGraph , graph :: SigmaxTypes.SGraph
, multiSelectEnabledRef :: R.Ref Boolean , multiSelectEnabledRef :: R.Ref Boolean
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds , selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
, selectorSize :: R.State Int
, showEdges :: R.State SigmaxTypes.ShowEdgesState , showEdges :: R.State SigmaxTypes.ShowEdgesState
, sigmaRef :: R.Ref Sigmax.Sigma , sigmaRef :: R.Ref Sigmax.Sigma
, sigmaSettings :: sigma , sigmaSettings :: sigma
...@@ -102,6 +103,10 @@ graphCpt = R.hooksComponent "Graph" cpt ...@@ -102,6 +103,10 @@ graphCpt = R.hooksComponent "Graph" cpt
Sigmax.updateNodes sigma tNodesMap Sigmax.updateNodes sigma tNodesMap
Sigmax.setEdges sigma (not $ SigmaxTypes.edgeStateHidden showEdges) Sigmax.setEdges sigma (not $ SigmaxTypes.edgeStateHidden showEdges)
-- R.useEffect1' (fst props.selectorSize) $ do
-- Sigmax.dependOnSigma (R.readRef sigmaRef) "[graphCpt (Ready)] no sigma" $ \sigma -> do
-- Sigmax.selectorWithSize sigma $ fst props.selectorSize
stageHooks _ = pure unit stageHooks _ = pure unit
......
...@@ -189,6 +189,7 @@ graphViewCpt = R.hooksComponent "GraphView" cpt ...@@ -189,6 +189,7 @@ graphViewCpt = R.hooksComponent "GraphView" cpt
, graph , graph
, multiSelectEnabledRef , multiSelectEnabledRef
, selectedNodeIds: controls.selectedNodeIds , selectedNodeIds: controls.selectedNodeIds
, selectorSize: controls.selectorSize
, showEdges: controls.showEdges , showEdges: controls.showEdges
, sigmaRef: controls.sigmaRef , sigmaRef: controls.sigmaRef
, sigmaSettings: Graph.sigmaSettings , sigmaSettings: Graph.sigmaSettings
...@@ -202,16 +203,19 @@ convert (GET.GraphData r) = Tuple r.metaData $ SigmaxTypes.Graph {nodes, edges} ...@@ -202,16 +203,19 @@ convert (GET.GraphData r) = Tuple r.metaData $ SigmaxTypes.Graph {nodes, edges}
nodes = foldMapWithIndex nodeFn r.nodes nodes = foldMapWithIndex nodeFn r.nodes
nodeFn i (GET.Node n) = nodeFn i (GET.Node n) =
Seq.singleton Seq.singleton
{ id : n.id_ { borderColor: color
, size : log (toNumber n.size + 1.0) , color : color
, hidden : false , hidden : false
, id : n.id_
, label : n.label , label : n.label
, size : log (toNumber n.size + 1.0)
, type : "def" -- default type
, x : n.x -- cos (toNumber i) , x : n.x -- cos (toNumber i)
, y : n.y -- sin (toNumber i) , y : n.y -- sin (toNumber i)
, color : GET.intColor (cDef n.attributes)
} }
where where
cDef (GET.Cluster {clustDefault}) = clustDefault cDef (GET.Cluster {clustDefault}) = clustDefault
color = GET.intColor (cDef n.attributes)
nodesMap = SigmaxTypes.nodesMap nodes nodesMap = SigmaxTypes.nodesMap nodes
edges = foldMap edgeFn r.edges edges = foldMap edgeFn r.edges
edgeFn (GET.Edge e) = Seq.singleton { id : e.id_ edgeFn (GET.Edge e) = Seq.singleton { id : e.id_
...@@ -410,6 +414,6 @@ transformGraph controls graph = SigmaxTypes.Graph {nodes: newNodes, edges: newEd ...@@ -410,6 +414,6 @@ transformGraph controls graph = SigmaxTypes.Graph {nodes: newNodes, edges: newEd
_ -> edge _ -> edge
nodeMarked node@{ id } = nodeMarked node@{ id } =
if Set.member id (fst controls.selectedNodeIds) then if Set.member id (fst controls.selectedNodeIds) then
node { color = "#ff0000" } node { borderColor = "#000", type = "hovered" }
else else
node node
...@@ -43,6 +43,7 @@ type Controls = ...@@ -43,6 +43,7 @@ type Controls =
, multiSelectEnabled :: R.State Boolean , multiSelectEnabled :: R.State Boolean
, nodeSize :: R.State Range.NumberRange , nodeSize :: R.State Range.NumberRange
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds , selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
, selectorSize :: R.State Int
, showControls :: R.State Boolean , showControls :: R.State Boolean
, showEdges :: R.State SigmaxTypes.ShowEdgesState , showEdges :: R.State SigmaxTypes.ShowEdgesState
, showSidePanel :: R.State GET.SidePanelState , showSidePanel :: R.State GET.SidePanelState
...@@ -167,6 +168,7 @@ useGraphControls graph = do ...@@ -167,6 +168,7 @@ useGraphControls graph = do
nodeSize <- R.useState' $ Range.Closed { min: 0.0, max: 100.0 } nodeSize <- R.useState' $ Range.Closed { min: 0.0, max: 100.0 }
showTree <- R.useState' false showTree <- R.useState' false
selectedNodeIds <- R.useState' $ Set.empty selectedNodeIds <- R.useState' $ Set.empty
selectorSize <- R.useState' 5
showControls <- R.useState' false showControls <- R.useState' false
showEdges <- R.useState' SigmaxTypes.EShow showEdges <- R.useState' SigmaxTypes.EShow
showSidePanel <- R.useState' GET.InitialClosed showSidePanel <- R.useState' GET.InitialClosed
...@@ -182,6 +184,7 @@ useGraphControls graph = do ...@@ -182,6 +184,7 @@ useGraphControls graph = do
, multiSelectEnabled , multiSelectEnabled
, nodeSize , nodeSize
, selectedNodeIds , selectedNodeIds
, selectorSize
, showControls , showControls
, showEdges , showEdges
, showSidePanel , showSidePanel
......
...@@ -132,12 +132,6 @@ handleForceAtlas2Pause sigmaRef (toggled /\ setToggled) mFAPauseRef = do ...@@ -132,12 +132,6 @@ handleForceAtlas2Pause sigmaRef (toggled /\ setToggled) mFAPauseRef = do
-- restore edges state -- restore edges state
Sigma.stopForceAtlas2 s Sigma.stopForceAtlas2 s
_ -> pure unit _ -> pure unit
-- handle case when user pressed pause/start fa button before timeout fired
--case R.readRef mFAPauseRef of
-- Nothing -> pure unit
-- Just timeoutId -> do
-- R.setRef mFAPauseRef Nothing
-- clearTimeout timeoutId
setEdges :: Sigma.Sigma -> Boolean -> Effect Unit setEdges :: Sigma.Sigma -> Boolean -> Effect Unit
setEdges sigma val = do setEdges sigma val = do
...@@ -148,45 +142,6 @@ setEdges sigma val = do ...@@ -148,45 +142,6 @@ setEdges sigma val = do
} }
Sigma.setSettings sigma settings Sigma.setSettings sigma settings
-- -- prevent showing edges (via show edges button) when FA is running (flickering)
-- isFARunning <- Sigma.isForceAtlas2Running sigma
-- case Tuple val isFARunning of
-- Tuple false _ ->
-- Sigma.setSettings sigma settings
-- Tuple true false ->
-- Sigma.setSettings sigma settings
-- _ -> pure unit
markSelectedEdges :: Sigma.Sigma -> ST.SelectedEdgeIds -> ST.EdgesMap -> Effect Unit
markSelectedEdges sigma selectedEdgeIds graphEdges = do
Sigma.forEachEdge sigma \e -> do
case Map.lookup e.id graphEdges of
Nothing -> error $ "Edge id " <> e.id <> " not found in graphEdges map"
Just {color} -> do
let newColor =
if Set.member e.id selectedEdgeIds then
"#ff0000"
else
color
_ <- pure $ (e .= "color") newColor
pure unit
Sigma.refresh sigma
markSelectedNodes :: Sigma.Sigma -> ST.SelectedNodeIds -> ST.NodesMap -> Effect Unit
markSelectedNodes sigma selectedNodeIds graphNodes = do
Sigma.forEachNode sigma \n -> do
case Map.lookup n.id graphNodes of
Nothing -> error $ "Node id " <> n.id <> " not found in graphNodes map"
Just {color} -> do
let newColor =
if Set.member n.id selectedNodeIds then
"#ff0000"
else
color
_ <- pure $ (n .= "color") newColor
pure unit
Sigma.refresh sigma
updateEdges :: Sigma.Sigma -> ST.EdgesMap -> Effect Unit updateEdges :: Sigma.Sigma -> ST.EdgesMap -> Effect Unit
updateEdges sigma edgesMap = do updateEdges sigma edgesMap = do
...@@ -207,9 +162,14 @@ updateNodes sigma nodesMap = do ...@@ -207,9 +162,14 @@ updateNodes sigma nodesMap = do
let mTNode = Map.lookup n.id nodesMap let mTNode = Map.lookup n.id nodesMap
case mTNode of case mTNode of
Nothing -> error $ "Node id " <> n.id <> " not found in nodesMap" Nothing -> error $ "Node id " <> n.id <> " not found in nodesMap"
(Just {color: tColor, hidden: tHidden}) -> do (Just { borderColor: tBorderColor
, color: tColor
, hidden: tHidden
, type: tType}) -> do
_ <- pure $ (n .= "borderColor") tBorderColor
_ <- pure $ (n .= "color") tColor _ <- pure $ (n .= "color") tColor
_ <- pure $ (n .= "hidden") tHidden _ <- pure $ (n .= "hidden") tHidden
_ <- pure $ (n .= "type") tType
pure unit pure unit
--Sigma.refresh sigma --Sigma.refresh sigma
...@@ -244,3 +204,39 @@ bindSelectedEdgesClick sigmaRef (_ /\ setSelectedEdgeIds) = ...@@ -244,3 +204,39 @@ bindSelectedEdgesClick sigmaRef (_ /\ setSelectedEdgeIds) =
Set.delete edge.id eids Set.delete edge.id eids
else else
Set.insert edge.id eids Set.insert edge.id eids
selectorWithSize :: Sigma.Sigma -> Int -> Effect Unit
selectorWithSize sigma size = do
pure unit
-- DEPRECATED
markSelectedEdges :: Sigma.Sigma -> ST.SelectedEdgeIds -> ST.EdgesMap -> Effect Unit
markSelectedEdges sigma selectedEdgeIds graphEdges = do
Sigma.forEachEdge sigma \e -> do
case Map.lookup e.id graphEdges of
Nothing -> error $ "Edge id " <> e.id <> " not found in graphEdges map"
Just {color} -> do
let newColor =
if Set.member e.id selectedEdgeIds then
"#ff0000"
else
color
_ <- pure $ (e .= "color") newColor
pure unit
Sigma.refresh sigma
markSelectedNodes :: Sigma.Sigma -> ST.SelectedNodeIds -> ST.NodesMap -> Effect Unit
markSelectedNodes sigma selectedNodeIds graphNodes = do
Sigma.forEachNode sigma \n -> do
case Map.lookup n.id graphNodes of
Nothing -> error $ "Node id " <> n.id <> " not found in graphNodes map"
Just {color} -> do
let newColor =
if Set.member n.id selectedNodeIds then
"#ff0000"
else
color
_ <- pure $ (n .= "color") newColor
pure unit
Sigma.refresh sigma
...@@ -6,7 +6,21 @@ if (typeof window !== 'undefined') { ...@@ -6,7 +6,21 @@ if (typeof window !== 'undefined') {
window.sigma = sigma; window.sigma = sigma;
} }
require('sigma/plugins/garg.js').init(sigma, window); const CustomShapes = require('sigma/plugins/garg.js').init(sigma, window).customShapes;
require('sigma/src/utils/sigma.utils.js').init(sigma);
sigma.canvas.nodes.hovered = (node, context, settings) => {
// hack
// We need to temporarily set node.type to 'def'. This is for 2 reasons
// 1. Make it render as a normal node
// 2. Avoid infinite recursion (hovers.def calls node renderer and we would end up here back
// again with node.type = 'hovered')
node.type = 'def';
sigma.canvas.hovers.def(node, context, settings);
node.type = 'hovered';
};
CustomShapes.init();
function _sigma(left, right, opts) { function _sigma(left, right, opts) {
try { try {
......
...@@ -22,18 +22,21 @@ type Renderer = { "type" :: String, container :: Element } ...@@ -22,18 +22,21 @@ type Renderer = { "type" :: String, container :: Element }
type Node = type Node =
( id :: String ( borderColor :: String
, label :: String , color :: String
, hidden :: Boolean , hidden :: Boolean
, id :: String
, label :: String
, size :: Number
, type :: String -- available types: circle, cross, def, diamond, equilateral, pacman, square, star
, x :: Number , x :: Number
, y :: Number , y :: Number
, size :: Number )
, color :: String )
type Edge = type Edge =
( id :: String ( color :: String
, color :: String
, confluence :: Number , confluence :: Number
, id :: String
, hidden :: Boolean , hidden :: Boolean
, size :: Number , size :: Number
, source :: String , source :: String
......
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