1
0
Fork 0

GraphViewer: The communityNode now can render its bounding box.

This commit is contained in:
Michael Hackstein 2013-07-18 08:34:31 +02:00
parent 045f53c648
commit 71a48ea13a
2 changed files with 67 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true */
/*global _ */
/*global _, document*/
////////////////////////////////////////////////////////////////////////////////
/// @brief Graph functionality
///
@ -36,6 +36,8 @@ function CommunityNode(initial) {
var
myRect,
////////////////////////////////////
// Private variables //
////////////////////////////////////
@ -204,8 +206,26 @@ function CommunityNode(initial) {
},
shapeAll = function(g, shapeFunc, colourMapper) {
/*
myRect = g.append(testee)
.attr("rx", "8")
.attr("ry", "8")
.attr("fill", "none")
.attr("stroke", "black");
*/
myRect = g.append("rect");
addShape(g, shapeFunc, colourMapper);
addLabel(g, colourMapper);
var bbox = document.getElementById(self._id).getBBox();
myRect.attr("width", bbox.width + 10) // Set width
.attr("height", bbox.height + 10) // Set height
.attr("x", bbox.x - 5)
.attr("y", bbox.y - 5)
.attr("rx", "8")
.attr("ry", "8")
.attr("fill", "none")
.attr("stroke", "black");
};
////////////////////////////////////

View File

@ -2,6 +2,7 @@
/*global beforeEach, afterEach */
/*global describe, it, expect, spyOn */
/*global helper*/
/*global document*/
/*global CommunityNode*/
////////////////////////////////////////////////////////////////////////////////
@ -246,11 +247,16 @@
describe('shaping functionality', function() {
var tSpan1, tSpan2, text, g, shaper, colourMapper;
var tSpan1, tSpan2, text, g, shaper, colourMapper, box, boxRect;
beforeEach(function() {
var first = true;
box = {
x: -10,
y: -10,
width: 20,
height: 20
};
tSpan1 = {
attr: function() {
return this;
@ -267,6 +273,11 @@
return this;
}
};
boxRect = {
attr: function() {
return this;
}
};
text = {
attr: function() {
return this;
@ -287,8 +298,13 @@
attr: function() {
return this;
},
append: function() {
return text;
append: function(type) {
if (type === "text") {
return text;
}
if (type === "rect") {
return boxRect;
}
}
};
shaper = {
@ -299,6 +315,14 @@
return "black";
}
};
spyOn(document, "getElementById").andCallFake(function() {
return {
getBBox: function() {
return box;
}
};
});
});
it('should initially contain the required attributes for shaping', function() {
@ -394,6 +418,24 @@
expect(tSpan2.text).wasCalledWith("label");
});
it('should print the bounding box correctly', function() {
var c = new CommunityNode(nodes.slice(0, 2));
spyOn(g, "append").andCallThrough();
spyOn(boxRect, "attr").andCallThrough();
c.shape(g, shaper.shapeFunc, colourMapper);
expect(g.append).wasCalledWith("rect");
expect(boxRect.attr).wasCalledWith("width", box.width + 10);
expect(boxRect.attr).wasCalledWith("height", box.height + 10);
expect(boxRect.attr).wasCalledWith("x", box.x - 5);
expect(boxRect.attr).wasCalledWith("y", box.y - 5);
expect(boxRect.attr).wasCalledWith("rx", "8");
expect(boxRect.attr).wasCalledWith("ry", "8");
expect(boxRect.attr).wasCalledWith("fill", "none");
expect(boxRect.attr).wasCalledWith("stroke", "black");
});
});
describe('edge functionality', function() {