Commit 57f6fa5c authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] edge filtering

By edge.weight and edge.confluence.
parent 990eaab3
...@@ -216,7 +216,14 @@ convert (GET.GraphData r) = Tuple r.metaData $ SigmaxTypes.Graph {nodes, edges} ...@@ -216,7 +216,14 @@ convert (GET.GraphData r) = Tuple r.metaData $ SigmaxTypes.Graph {nodes, edges}
cDef (GET.Cluster {clustDefault}) = clustDefault cDef (GET.Cluster {clustDefault}) = clustDefault
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_, color, size: 1.0, source : e.source, target : e.target} edgeFn (GET.Edge e) = Seq.singleton { id : e.id_
, color
, confluence : e.confluence
, hidden : false
, size: 1.0
, source : e.source
, target : e.target
, weight : e.weight }
where where
color = case Map.lookup e.source nodesMap of color = case Map.lookup e.source nodesMap of
Nothing -> "#000000" Nothing -> "#000000"
...@@ -370,14 +377,26 @@ transformGraph controls graph = SigmaxTypes.Graph {nodes: newNodes, edges: newEd ...@@ -370,14 +377,26 @@ transformGraph controls graph = SigmaxTypes.Graph {nodes: newNodes, edges: newEd
$ Seq.filter (\e -> Set.member e.source (fst controls.selectedNodeIds)) edges $ Seq.filter (\e -> Set.member e.source (fst controls.selectedNodeIds)) edges
hasSelection = not $ Set.isEmpty (fst controls.selectedNodeIds) hasSelection = not $ Set.isEmpty (fst controls.selectedNodeIds)
newNodes = nodeSizes <$> nodeMarked <$> nodes newNodes = nodeSizeFilter <$> nodeMarked <$> nodes
newEdges = edgeMarked <$> edges newEdges = edgeConfluenceFilter <$> edgeWeightFilter <$> edgeMarked <$> edges
nodeSizes node@{ size } = nodeSizeFilter node@{ size } =
if Range.within (fst controls.nodeSize) size then if Range.within (fst controls.nodeSize) size then
node node
else else
node { hidden = true } node { hidden = true }
edgeConfluenceFilter edge@{ confluence } =
if Range.within (fst controls.edgeConfluence) confluence then
edge
else
edge { hidden = true }
edgeWeightFilter edge@{ weight } =
if Range.within (fst controls.edgeWeight) weight then
edge
else
edge { hidden = true }
edgeMarked edge@{ id } = do edgeMarked edge@{ id } = do
let isSelected = Set.member id selectedEdgeIds let isSelected = Set.member id selectedEdgeIds
let sourceNode = Map.lookup edge.source graphNodesMap let sourceNode = Map.lookup edge.source graphNodesMap
......
...@@ -23,7 +23,7 @@ import Reactix.DOM.HTML as RH ...@@ -23,7 +23,7 @@ import Reactix.DOM.HTML as RH
import Gargantext.Components.Graph as Graph import Gargantext.Components.Graph as Graph
import Gargantext.Components.GraphExplorer.Button (centerButton) import Gargantext.Components.GraphExplorer.Button (centerButton)
import Gargantext.Components.GraphExplorer.RangeControl (edgeSizeControl, nodeSizeControl) import Gargantext.Components.GraphExplorer.RangeControl (edgeConfluenceControl, edgeWeightControl, nodeSizeControl)
import Gargantext.Components.GraphExplorer.Search (nodeSearchControl) import Gargantext.Components.GraphExplorer.Search (nodeSearchControl)
import Gargantext.Components.GraphExplorer.SlideButton (cursorSizeButton, labelSizeButton) import Gargantext.Components.GraphExplorer.SlideButton (cursorSizeButton, labelSizeButton)
import Gargantext.Components.GraphExplorer.ToggleButton (multiSelectEnabledButton, edgesToggleButton, pauseForceAtlasButton) import Gargantext.Components.GraphExplorer.ToggleButton (multiSelectEnabledButton, edgesToggleButton, pauseForceAtlasButton)
...@@ -35,6 +35,8 @@ import Gargantext.Utils.Reactix as R2 ...@@ -35,6 +35,8 @@ import Gargantext.Utils.Reactix as R2
type Controls = type Controls =
( cursorSize :: R.State Number ( cursorSize :: R.State Number
, edgeConfluence :: R.State Range.NumberRange
, edgeWeight :: R.State Range.NumberRange
, graph :: SigmaxTypes.SGraph , graph :: SigmaxTypes.SGraph
, graphStage :: R.State Graph.Stage , graphStage :: R.State Graph.Stage
, multiSelectEnabled :: R.State Boolean , multiSelectEnabled :: R.State Boolean
...@@ -50,15 +52,13 @@ controlsToSigmaSettings :: Record Controls -> Record Graph.SigmaSettings ...@@ -50,15 +52,13 @@ controlsToSigmaSettings :: Record Controls -> Record Graph.SigmaSettings
controlsToSigmaSettings { cursorSize: (cursorSize /\ _)} = Graph.sigmaSettings controlsToSigmaSettings { cursorSize: (cursorSize /\ _)} = Graph.sigmaSettings
type LocalControls = type LocalControls =
( edgeSize :: R.State Range.NumberRange ( labelSize :: R.State Number
, labelSize :: R.State Number
, pauseForceAtlas :: R.State Boolean , pauseForceAtlas :: R.State Boolean
, showEdges :: R.State Boolean , showEdges :: R.State Boolean
) )
initialLocalControls :: R.Hooks (Record LocalControls) initialLocalControls :: R.Hooks (Record LocalControls)
initialLocalControls = do initialLocalControls = do
edgeSize <- R.useState' $ Range.Closed { min: 0.5, max: 1.0 }
labelSize <- R.useState' 14.0 labelSize <- R.useState' 14.0
--nodeSize <- R.useState' $ Range.Closed { min: 0.0, max: 10.0 } --nodeSize <- R.useState' $ Range.Closed { min: 0.0, max: 10.0 }
pauseForceAtlas <- R.useState' true pauseForceAtlas <- R.useState' true
...@@ -66,8 +66,7 @@ initialLocalControls = do ...@@ -66,8 +66,7 @@ initialLocalControls = do
showEdges <- R.useState' true showEdges <- R.useState' true
pure $ { pure $ {
edgeSize labelSize
, labelSize
--, nodeSize --, nodeSize
, pauseForceAtlas , pauseForceAtlas
, showEdges , showEdges
...@@ -124,7 +123,8 @@ controlsCpt = R.hooksComponent "GraphControls" cpt ...@@ -124,7 +123,8 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
RH.li {} [ centerButton props.sigmaRef ] RH.li {} [ centerButton props.sigmaRef ]
, RH.li {} [ pauseForceAtlasButton props.sigmaRef localControls.pauseForceAtlas ] -- spatialization (pause ForceAtlas2) , RH.li {} [ pauseForceAtlasButton props.sigmaRef localControls.pauseForceAtlas ] -- spatialization (pause ForceAtlas2)
, RH.li {} [ edgesToggleButton props.sigmaRef localControls.showEdges ] , RH.li {} [ edgesToggleButton props.sigmaRef localControls.showEdges ]
, RH.li {} [ edgeSizeControl props.sigmaRef localControls.edgeSize ] -- edge size : 0-3 , RH.li {} [ edgeConfluenceControl props.sigmaRef props.edgeConfluence ]
, RH.li {} [ edgeWeightControl props.sigmaRef props.edgeWeight ]
-- change level -- change level
-- file upload -- file upload
-- run demo -- run demo
...@@ -147,6 +147,8 @@ useGraphControls graph = do ...@@ -147,6 +147,8 @@ useGraphControls graph = do
let nodes = SigmaxTypes.graphNodes graph let nodes = SigmaxTypes.graphNodes graph
cursorSize <- R.useState' 10.0 cursorSize <- R.useState' 10.0
edgeConfluence <- R.useState' $ Range.Closed { min: 0.0, max: 1.0 }
edgeWeight <- R.useState' $ Range.Closed { min: 0.0, max: 1.0 }
graphStage <- R.useState' Graph.Init graphStage <- R.useState' Graph.Init
multiSelectEnabled <- R.useState' false multiSelectEnabled <- R.useState' false
nodeSize <- R.useState' $ Range.Closed { min: 0.0, max: 100.0 } nodeSize <- R.useState' $ Range.Closed { min: 0.0, max: 100.0 }
...@@ -158,6 +160,8 @@ useGraphControls graph = do ...@@ -158,6 +160,8 @@ useGraphControls graph = do
sigmaRef <- R.useRef sigma sigmaRef <- R.useRef sigma
pure { cursorSize pure { cursorSize
, edgeConfluence
, edgeWeight
, graph , graph
, graphStage , graphStage
, multiSelectEnabled , multiSelectEnabled
......
module Gargantext.Components.GraphExplorer.RangeControl module Gargantext.Components.GraphExplorer.RangeControl
( Props ( Props
, rangeControl , rangeControl
, edgeSizeControl , edgeConfluenceControl
, edgeWeightControl
, nodeSizeControl , nodeSizeControl
) where ) where
...@@ -33,25 +34,41 @@ rangeControlCpt = R.hooksComponent "RangeButton" cpt ...@@ -33,25 +34,41 @@ rangeControlCpt = R.hooksComponent "RangeButton" cpt
, RS.rangeSlider sliderProps , RS.rangeSlider sliderProps
] ]
edgeSizeControl :: R.Ref Sigmax.Sigma -> R.State Range.NumberRange -> R.Element edgeConfluenceControl :: R.Ref Sigmax.Sigma -> R.State Range.NumberRange -> R.Element
edgeSizeControl sigmaRef (state /\ setState) = edgeConfluenceControl sigmaRef (state /\ setState) =
rangeControl { rangeControl {
caption: "Edge Size" caption: "Edge Confluence Weight"
, sliderProps: {
bounds: Range.Closed { min: 0.0, max: 1.0 }
, initialValue: state
, epsilon: 0.01
, step: 1.0
, width: 10.0
, height: 5.0
, onChange: setState <<< const
}
}
edgeWeightControl :: R.Ref Sigmax.Sigma -> R.State Range.NumberRange -> R.Element
edgeWeightControl sigmaRef (state /\ setState) =
rangeControl {
caption: "Edge Weight"
, sliderProps: { , sliderProps: {
bounds: Range.Closed { min: 0.0, max: 3.0 } bounds: Range.Closed { min: 0.0, max: 3.0 }
, initialValue: state , initialValue: state
, epsilon: 0.1 , epsilon: 0.01
, step: 1.0 , step: 1.0
, width: 10.0 , width: 10.0
, height: 5.0 , height: 5.0
, onChange: \range@(Range.Closed {min, max}) -> do , onChange: setState <<< const
let sigma = R.readRef sigmaRef -- , onChange: \range@(Range.Closed {min, max}) -> do
Sigmax.dependOnSigma sigma "[edgeSizeControl] sigma: Nothing" $ \s -> do -- let sigma = R.readRef sigmaRef
Sigma.setSettings s { -- Sigmax.dependOnSigma sigma "[edgeWeightControl] sigma: Nothing" $ \s -> do
minEdgeSize: min -- Sigma.setSettings s {
, maxEdgeSize: max -- minEdgeSize: min
} -- , maxEdgeSize: max
setState $ const range -- }
-- setState $ const range
} }
} }
......
...@@ -191,8 +191,9 @@ updateEdges sigma edgesMap = do ...@@ -191,8 +191,9 @@ updateEdges sigma edgesMap = do
let mTEdge = Map.lookup e.id edgesMap let mTEdge = Map.lookup e.id edgesMap
case mTEdge of case mTEdge of
Nothing -> error $ "Edge id " <> e.id <> " not found in edgesMap" Nothing -> error $ "Edge id " <> e.id <> " not found in edgesMap"
(Just tEdge@{color: tColor}) -> do (Just {color: tColor, hidden: tHidden}) -> do
_ <- pure $ (e .= "color") tColor _ <- pure $ (e .= "color") tColor
_ <- pure $ (e .= "hidden") tHidden
pure unit pure unit
Sigma.refresh sigma Sigma.refresh sigma
...@@ -203,7 +204,7 @@ updateNodes sigma nodesMap = do ...@@ -203,7 +204,7 @@ 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 tNode@{color: tColor, hidden: tHidden}) -> do (Just {color: tColor, hidden: tHidden}) -> do
_ <- pure $ (n .= "color") tColor _ <- pure $ (n .= "color") tColor
_ <- pure $ (n .= "hidden") tHidden _ <- pure $ (n .= "hidden") tHidden
pure unit pure unit
...@@ -224,9 +225,7 @@ multiSelectUpdate new selected = foldl fld selected new ...@@ -224,9 +225,7 @@ multiSelectUpdate new selected = foldl fld selected new
bindSelectedNodesClick :: Sigma.Sigma -> R.State SelectedNodeIds -> R.Ref Boolean -> Effect Unit bindSelectedNodesClick :: Sigma.Sigma -> R.State SelectedNodeIds -> R.Ref Boolean -> Effect Unit
bindSelectedNodesClick sigma (_ /\ setSelectedNodeIds) multiSelectEnabledRef = bindSelectedNodesClick sigma (_ /\ setSelectedNodeIds) multiSelectEnabledRef =
Sigma.bindClickNodes sigma $ \nodes -> do Sigma.bindClickNodes sigma $ \nodes -> do
log2 "[bindSelectedNodesClick] nodes" nodes
let multiSelectEnabled = R.readRef multiSelectEnabledRef let multiSelectEnabled = R.readRef multiSelectEnabledRef
log2 "[bindSelectedNodesClick] multiSelectEnabled" multiSelectEnabled
let nodeIds = Set.fromFoldable $ map _.id nodes let nodeIds = Set.fromFoldable $ map _.id nodes
if multiSelectEnabled then if multiSelectEnabled then
setSelectedNodeIds $ multiSelectUpdate nodeIds setSelectedNodeIds $ multiSelectUpdate nodeIds
...@@ -237,7 +236,6 @@ bindSelectedEdgesClick :: R.Ref Sigma -> R.State SelectedEdgeIds -> Effect Unit ...@@ -237,7 +236,6 @@ bindSelectedEdgesClick :: R.Ref Sigma -> R.State SelectedEdgeIds -> Effect Unit
bindSelectedEdgesClick sigmaRef (_ /\ setSelectedEdgeIds) = bindSelectedEdgesClick sigmaRef (_ /\ setSelectedEdgeIds) =
dependOnSigma (R.readRef sigmaRef) "[graphCpt] no sigma" $ \sigma -> do dependOnSigma (R.readRef sigmaRef) "[graphCpt] no sigma" $ \sigma -> do
Sigma.bindClickEdge sigma $ \edge -> do Sigma.bindClickEdge sigma $ \edge -> do
log2 "[bindClickEdge] edge" edge
setSelectedEdgeIds \eids -> setSelectedEdgeIds \eids ->
if Set.member edge.id eids then if Set.member edge.id eids then
Set.delete edge.id eids Set.delete edge.id eids
......
...@@ -30,9 +30,12 @@ type Node = ...@@ -30,9 +30,12 @@ type Node =
type Edge = type Edge =
( id :: String ( id :: String
, color :: String , color :: String
, confluence :: Number
, hidden :: Boolean
, size :: Number , size :: Number
, source :: String , source :: String
, target :: String ) , target :: String
, weight :: Number )
type SelectedNodeIds = Set.Set String type SelectedNodeIds = Set.Set String
type SelectedEdgeIds = Set.Set String type SelectedEdgeIds = Set.Set 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