1
0
Fork 0

GraphViewer: CommunityNodes now tell the outer world how many nodes are inside

This commit is contained in:
Michael Hackstein 2013-05-22 14:08:13 +02:00
parent d81d136cb5
commit e627714763
2 changed files with 46 additions and 14 deletions

View File

@ -92,7 +92,17 @@ function NodeShaper(parent, flags, idfunc) {
addColor = noop,
addShape = noop,
addLabel = noop,
addCommunityShape = function(g) {
g.append("polygon")
.attr("points", "0,-25 -16,20 23,-10 -23,-10 16,20");
},
addCommunityLabel = function(g) {
g.append("text") // Append a label for the node
.attr("text-anchor", "middle") // Define text-anchor
.text(function(d) {
return d._size;
});
},
unbindEvents = function() {
// Hard unbind the dragging
self.parent
@ -121,9 +131,18 @@ function NodeShaper(parent, flags, idfunc) {
},
addQue = function (g) {
addShape(g);
var community = g.filter(function(n) {
return communityRegEx.test(n._id);
}),
normal = g.filter(function(n) {
return !communityRegEx.test(n._id);
});
addCommunityShape(community);
addShape(normal);
if (visibleLabels) {
addLabel(g);
addCommunityLabel(community);
addLabel(normal);
}
addColor(g);
addEvents(g);
@ -182,17 +201,9 @@ function NodeShaper(parent, flags, idfunc) {
case NodeShaper.shapes.CIRCLE:
radius = shape.radius || 25;
addShape = function (node) {
node.filter(function(n) {
return communityRegEx.test(n._id);
})
.append("polygon")
.attr("points", "0,-25 -16,20 23,-10 -23,-10 16,20");
node.filter(function(n) {
return !communityRegEx.test(n._id);
})
.append("circle") // Display nodes as circles
.attr("r", radius); // Set radius
node
.append("circle") // Display nodes as circles
.attr("r", radius); // Set radius
};
break;
case NodeShaper.shapes.RECT:

View File

@ -1018,6 +1018,7 @@
var nodes = helper.createSimpleNodes([0, 1, 2]),
commNode = {
_id: "*community_42",
_size: 4,
_inboundCounter: 0,
_outboundCounter: 0,
position: {
@ -1036,6 +1037,26 @@
expect(star.attr("points")).toEqual("0,-25 -16,20 23,-10 -23,-10 16,20");
});
it('should print the size of the capsulated community', function() {
var nodes = helper.createSimpleNodes([0, 1, 2]),
commNode = {
_id: "*community_42",
_size: 4,
_inboundCounter: 0,
_outboundCounter: 0,
position: {
x: 1,
y: 1,
z: 1
}
},
text;
nodes.push(commNode);
shaper.drawNodes(nodes);
text = $("svg #\\*community_42 text")[0].textContent;
expect(text).toEqual("4");
});
});
});