Created
July 2, 2015 05:50
-
-
Save ajihyf/b0d2ead0c97e6f3552fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
if (typeof sigma === 'undefined') | |
throw 'sigma is not declared'; | |
sigma.utils.pkg('sigma.plugins'); | |
var startPosition; | |
var WIDTH; | |
var HEIGHT; | |
var ctx; | |
var gCanvas; | |
var graph; | |
var callback; | |
function mousedown(e){ | |
if (e.which != 3) return; | |
startPosition={x:e.layerX, y:e.layerY}; | |
gCanvas.addEventListener('mousemove',mousemove); | |
} | |
function mouseup(e){ | |
if (e.which != 3) return; | |
gCanvas.removeEventListener('mousemove',mousemove); | |
clear(ctx); | |
callback(null, getNodesInArea(startPosition.x, startPosition.y, e.layerX, e.layerY)); | |
} | |
function getNodesInArea(x1, y1, x2, y2){ | |
var nodesInArea = []; | |
var startX; | |
var endX; | |
var startY; | |
var endY; | |
if (x1 > x2){ | |
startX = x2; | |
endX = x1; | |
}else{ | |
startX = x1; | |
endX = x2; | |
} | |
if (y1 > y2){ | |
startY = y2; | |
endY = y1; | |
}else{ | |
startY = y1; | |
endY = y2; | |
} | |
graph.camera.quadtree._cache.result.forEach(function(node){ | |
var nodeX = node['cam0:x']; | |
var nodeY = node['cam0:y']; | |
if ((nodeX > startX) && (nodeX < endX) && | |
(nodeY > startY) && (nodeY < endY) && !node.hidden){ | |
nodesInArea.push(node); | |
} | |
}); | |
return nodesInArea; | |
} | |
function mousemove(e){ | |
clear(ctx); | |
ctx.beginPath(); | |
ctx.lineWidth='1'; | |
ctx.setLineDash([6]); | |
ctx.strokeStyle='black'; | |
ctx.rect(startPosition.x, startPosition.y, e.layerX - startPosition.x, e.layerY - startPosition.y); | |
ctx.stroke(); | |
} | |
sigma.plugins.multiNodesSelection = function(s, cb) { | |
if (!s){ | |
cb('graph not supplied'); | |
}else{ | |
var renderer = s.renderers[0]; | |
var container = renderer.container; | |
graph = s; | |
callback = cb; | |
gCanvas = container.lastChild; | |
HEIGHT = gCanvas.height; | |
WIDTH = gCanvas.width; | |
ctx = gCanvas.getContext('2d'); | |
gCanvas.addEventListener('mousedown',mousedown); | |
gCanvas.addEventListener('mouseup',mouseup); | |
} | |
}; | |
function clear(c) { | |
c.clearRect(0, 0, WIDTH, HEIGHT); | |
} | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment