Commit faf6c03f authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[sigma] node selector works now

parent 0548858f
...@@ -196,8 +196,9 @@ multiSelectUpdate new selected = foldl fld selected new ...@@ -196,8 +196,9 @@ multiSelectUpdate new selected = foldl fld selected new
bindSelectedNodesClick :: Sigma.Sigma -> T.Box ST.NodeIds -> T.Box Boolean -> Effect Unit bindSelectedNodesClick :: Sigma.Sigma -> T.Box ST.NodeIds -> T.Box Boolean -> Effect Unit
bindSelectedNodesClick sigma selectedNodeIds multiSelectEnabled = bindSelectedNodesClick sigma selectedNodeIds multiSelectEnabled =
Sigma.bindClickNodes sigma $ \nodes -> do Sigma.bindClickNodes sigma $ \nodeIds' -> do
let nodeIds = Set.fromFoldable $ map _.id nodes console.log2 "[bindSelectedNodesClick] nodeIds'" nodeIds'
let nodeIds = Set.fromFoldable nodeIds'
multiSelectEnabled' <- T.read multiSelectEnabled multiSelectEnabled' <- T.read multiSelectEnabled
if multiSelectEnabled' then if multiSelectEnabled' then
T.modify_ (multiSelectUpdate nodeIds) selectedNodeIds T.modify_ (multiSelectUpdate nodeIds) selectedNodeIds
......
...@@ -140,7 +140,9 @@ let sigmaMouseSelector = function(sigma, options) { ...@@ -140,7 +140,9 @@ let sigmaMouseSelector = function(sigma, options) {
} }
const onClick = (e) => { const onClick = (e) => {
if(!_isValidClick) { // TODO For some reason this event is sent again, with
// _clickPositionX/Y empty
if(!_isValidClick || !_clickPositionX || !_clickPositionY) {
return; return;
} }
const size = sigma.settings['mouseSelectorSize'] || 3; const size = sigma.settings['mouseSelectorSize'] || 3;
...@@ -148,12 +150,12 @@ let sigmaMouseSelector = function(sigma, options) { ...@@ -148,12 +150,12 @@ let sigmaMouseSelector = function(sigma, options) {
//const y = e.data.clientY + document.body.scrollTop - _offset.top - size/2; //const y = e.data.clientY + document.body.scrollTop - _offset.top - size/2;
//const prefix = _renderer.options.prefix; //const prefix = _renderer.options.prefix;
//console.log('[sigmaMouseSelector] clicked', e, x, y, size); //console.log('[sigmaMouseSelector] clicked', e, x, y, size);
let nodes = []; let nodeIds = [];
for(let node in sigma.nodeDataCache) { for(let nodeId in sigma.nodeDataCache) {
let data = sigma.nodeDataCache[node]; let data = sigma.nodeDataCache[nodeId];
let position = sigma.framedGraphToViewport(data); let position = sigma.framedGraphToViewport(data);
if(distance(e.x, e.y, position.x, position.y) <= size) { if(distance(e.x, e.y, position.x, position.y) <= size) {
nodes.push(node); nodeIds.push(nodeId);
} }
} }
/* /*
...@@ -163,10 +165,12 @@ let sigmaMouseSelector = function(sigma, options) { ...@@ -163,10 +165,12 @@ let sigmaMouseSelector = function(sigma, options) {
} }
}); });
*/ */
console.log('clicked node ids', nodes);
//console.log('[sigmaMouseSelector] nodes', nodes); //console.log('[sigmaMouseSelector] nodes', nodes);
sigma.emit('clickNode', { // nodes.forEach((n) => {
node: nodes // sigma.emit('clickNode', { node: n });
// })
sigma.emit('clickNodes', {
nodeIds: nodeIds
//captor: e.data //captor: e.data
}) })
_clickPositionX = null; _clickPositionX = null;
...@@ -194,6 +198,10 @@ let sigmaMouseSelector = function(sigma, options) { ...@@ -194,6 +198,10 @@ let sigmaMouseSelector = function(sigma, options) {
} }
mouseSelector(); mouseSelector();
// sigma.on('clickNode', (e) => {
// console.log('clickNode', e);
// })
} }
//sigmaMouseSelector(sigma); //sigmaMouseSelector(sigma);
...@@ -266,7 +274,6 @@ let _setSettings = function(g, settings) { ...@@ -266,7 +274,6 @@ let _setSettings = function(g, settings) {
} }
let _refresh = function(g) { let _refresh = function(g) {
console.log('[refresh], g', g);
return g.refresh(); return g.refresh();
} }
......
...@@ -129,9 +129,9 @@ unbindClickNode :: Sigma -> Effect Unit ...@@ -129,9 +129,9 @@ unbindClickNode :: Sigma -> Effect Unit
unbindClickNode s = unbind_ s "clickNode" unbindClickNode s = unbind_ s "clickNode"
-- | Bind a `clickNodes` event. -- | Bind a `clickNodes` event.
bindClickNodes :: Sigma -> (Array (Record Types.Node) -> Effect Unit) -> Effect Unit bindClickNodes :: Sigma -> (Array Types.NodeId -> Effect Unit) -> Effect Unit
bindClickNodes s f = on_ s "clickNodes" $ \e -> do bindClickNodes s f = on_ s "clickNodes" $ \e -> do
let ns = e .. "data" .. "node" :: Array (Record Types.Node) let ns = e .. "nodeIds" :: Array Types.NodeId
f ns f ns
-- | Unbind a `clickNodes` event. -- | Unbind a `clickNodes` event.
unbindClickNodes :: Sigma -> Effect Unit unbindClickNodes :: Sigma -> Effect Unit
......
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