Skip to content

Commit

Permalink
more work on network visualisations
Browse files Browse the repository at this point in the history
  • Loading branch information
kdickson93 committed Jun 27, 2018
1 parent 58bc8bb commit f9ac209
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
Expand Up @@ -86,6 +86,7 @@ function initSigma(config) {
a.active = !1;
a.neighbors = {};
a.detail = !1;
// a.activateFishEye();


dataReady = function() {//This is called as soon as data is loaded
Expand Down
@@ -0,0 +1,94 @@
sigma.classes.FishEye = function(sig) {
sigma.classes.Cascade.call(this);

var self = this;
var isActivated = false;

this.p = {
radius: 200,
power: 2
};

function applyFishEye(mouseX, mouseY) {
var newDist, newSize, xDist, yDist, dist,
radius = self.p.radius,
power = self.p.power,
powerExp = Math.exp(power);

sig.graph.nodes.forEach(function(node) {
xDist = node.displayX - mouseX;
yDist = node.displayY - mouseY;
dist = Math.sqrt(xDist*xDist + yDist*yDist);

if(dist < radius){
newDist = powerExp/(powerExp-1)*radius*(1-Math.exp(-dist/radius*power));
newSize = powerExp/(powerExp-1)*radius*(1-Math.exp(-dist/radius*power));

if(!node.isFixed){
node.displayX = mouseX + xDist*(newDist/dist*3/4 + 1/4);
node.displayY = mouseY + yDist*(newDist/dist*3/4 + 1/4);
}

node.displaySize = Math.min(node.displaySize*newSize/dist,10*node.displaySize);
}
});
};

function handler() {
applyFishEye(
sig.mousecaptor.mouseX,
sig.mousecaptor.mouseY
);
}

this.handler = handler;
this.activated = function(v) {
if(v==undefined){
return isActivated;
}else{
isActivated = v;
return this;
}
};

this.refresh = function(){};
};

sigma.publicPrototype.activateFishEye = function() {
if(!this.fisheye) {
var sigmaInstance = this;
var fe = new sigma.classes.FishEye(sigmaInstance._core);
sigmaInstance.fisheye = fe;

fe.refresh = function refresh() {
sigmaInstance.draw(2,2,2);
};
}

if(!this.fisheye.activated()){
this.fisheye.activated(true);
this._core.bind('graphscaled', this.fisheye.handler);
document.getElementById(
'sigma_mouse_'+this.getID()
).addEventListener('mousemove',this.fisheye.refresh,true);
}

return this;
};

sigma.publicPrototype.desactivateFishEye = function() {
if(this.fisheye && this.fisheye.activated()){
this.fisheye.activated(false);
this._core.unbind('graphscaled', this.fisheye.handler);
document.getElementById(
'sigma_mouse_'+this.getID()
).removeEventListener('mousemove',this.fisheye.refresh,true);
}

return this;
};

sigma.publicPrototype.fishEyeProperties = function(a1, a2) {
var res = this.fisheye.config(a1, a2);
return res == s ? this.fisheye : res;
};

0 comments on commit f9ac209

Please sign in to comment.