1
0
Fork 0

GraphViewer: Now edges are connected to the correct nodels inside the community

This commit is contained in:
Michael Hackstein 2013-07-19 16:17:36 +02:00
parent d9cc1f0a18
commit 9937736929
3 changed files with 88 additions and 18 deletions

View File

@ -58,12 +58,18 @@ function CommunityNode(parent, initial) {
// Private functions // // Private functions //
//////////////////////////////////// ////////////////////////////////////
getDistance = function() { getDistance = function(def) {
return 160; if (self._expanded) {
return 2 * def;
}
return def;
}, },
getCharge = function() { getCharge = function(def) {
return -5000; if (self._expanded) {
return 8 * def;
}
return def;
}, },
@ -406,4 +412,37 @@ function CommunityNode(parent, initial) {
this.expand = expand; this.expand = expand;
this.shape = shapeAll; this.shape = shapeAll;
// TMP
this.getSourcePosition = function(e) {
if (self._expanded) {
var p = self.position;
var diff = e._source;
var x = p.x + diff.x;
var y = p.y + diff.y;
var z = p.z + diff.z;
return {
x: x,
y: y,
z: z
}
}
return self.position;
};
this.getTargetPosition = function(e) {
if (self._expanded) {
var p = self.position;
var diff = e._target;
var x = p.x + diff.x;
var y = p.y + diff.y;
var z = p.z + diff.z;
return {
x: x,
y: y,
z: z
}
}
return self.position;
};
} }

View File

@ -53,7 +53,7 @@ function EdgeShaper(parent, flags, idfunc) {
followEdge = {}, followEdge = {},
followEdgeG, followEdgeG,
idFunction = function(d) { idFunction = function(d) {
return d.source._id + "-" + d.target._id; return d._id;
}, },
noop = function (line, g) { noop = function (line, g) {
@ -109,13 +109,35 @@ function EdgeShaper(parent, flags, idfunc) {
} }
}, },
calculateNodePositions = function (e) {
var sp, tp, s, t;
s = e.source;
t = e.target;
if (s._isCommunity) {
sp = s.getSourcePosition(e);
} else {
sp = s.position;
}
if (t._isCommunity) {
tp = t.getTargetPosition(e);
} else {
tp = t.position;
}
return {
s: sp,
t: tp
};
},
addPosition = function (line, g) { addPosition = function (line, g) {
g.attr("transform", function(d) { g.attr("transform", function(d) {
var p = calculateNodePositions(d);
return "translate(" return "translate("
+ d.source.position.x + ", " + p.s.x + ", "
+ d.source.position.y + ")" + p.s.y + ")"
+ "rotate(" + "rotate("
+ getCorner(d.source.position, d.target.position) + getCorner(p.s, p.t)
+ ")"; + ")";
}); });
line.attr("x2", function(d) { line.attr("x2", function(d) {
@ -127,7 +149,8 @@ function EdgeShaper(parent, flags, idfunc) {
console.log(d.target); console.log(d.target);
} }
*/ */
return getDistance(d.source.position, d.target.position); var p = calculateNodePositions(d);
return getDistance(p.s, p.t);
}); });
}, },

View File

@ -52,15 +52,23 @@ function ForceLayouter(config) {
gravity = config.gravity || 0.01, // 0.08 gravity = config.gravity || 0.01, // 0.08
charge = config.charge || -1000, // -240 charge = config.charge || -1000, // -240
*/ */
distance = config.distance || 160, defaultCharge = config.charge || -600,
defaultDistance = config.distance || 160,
gravity = config.gravity || 0.08, gravity = config.gravity || 0.08,
//charge = config.charge || -600, distance = function(d) {
if (d.source._isCommunity) {
charge = config.charge || function(d) { return d.source.getDistance(defaultDistance);
if (d._isCommunity && d._expanded) {
return -5000;
} }
return -600; if (d.target._isCommunity) {
return d.target.getDistance(defaultDistance);
}
return defaultDistance;
},
charge = function(d) {
if (d._isCommunity) {
return d.getCharge(defaultCharge);
}
return defaultCharge;
}, },
onUpdate = config.onUpdate || function () {}, onUpdate = config.onUpdate || function () {},
@ -68,13 +76,13 @@ function ForceLayouter(config) {
height = config.height || 680, height = config.height || 680,
parseConfig = function(config) { parseConfig = function(config) {
if (config.distance) { if (config.distance) {
force.linkDistance(config.distance); defaultDistance = config.distance;
} }
if (config.gravity) { if (config.gravity) {
force.gravity(config.gravity); force.gravity(config.gravity);
} }
if (config.charge) { if (config.charge) {
force.charge(config.charge); defaultCharge = config.charge;
} }
}; };