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