1
0
Fork 0

Merge branch 'devel' into multiple_databases

This commit is contained in:
a-brandt 2013-06-04 14:59:48 +02:00
commit 7a476e9a13
8 changed files with 187 additions and 39 deletions

View File

@ -38,34 +38,37 @@ function ColourMapper() {
self = this, self = this,
nextColour = 0; nextColour = 0;
colours.push("navy"); colours.push({back: "navy", front: "white"});
colours.push("green"); colours.push({back: "green", front: "white"});
colours.push("gold"); colours.push({back: "gold", front: "black"});
colours.push("red"); colours.push({back: "red", front: "black"});
colours.push("saddlebrown"); colours.push({back: "saddlebrown", front: "white"});
colours.push("skyblue"); colours.push({back: "skyblue", front: "black"});
colours.push("olive"); colours.push({back: "olive", front: "black"});
colours.push("deeppink"); colours.push({back: "deeppink", front: "black"});
colours.push("orange"); colours.push({back: "orange", front: "black"});
colours.push("silver"); colours.push({back: "silver", front: "black"});
colours.push("blue"); colours.push({back: "blue", front: "white"});
colours.push("yellowgreen"); colours.push({back: "yellowgreen", front: "black"});
colours.push("firebrick"); colours.push({back: "firebrick", front: "black"});
colours.push("rosybrown"); colours.push({back: "rosybrown", front: "black"});
colours.push("hotpink"); colours.push({back: "hotpink", front: "black"});
colours.push("purple"); colours.push({back: "purple", front: "white"});
colours.push("cyan"); colours.push({back: "cyan", front: "black"});
colours.push("teal"); colours.push({back: "teal", front: "black"});
colours.push("peru"); colours.push({back: "peru", front: "black"});
colours.push("maroon"); colours.push({back: "maroon", front: "white"});
this.getColour = function(value) { this.getColour = function(value) {
if (mapping[value] === undefined) { if (mapping[value] === undefined) {
mapping[value] = colours[nextColour]; mapping[value] = colours[nextColour];
if (reverseMapping[colours[nextColour]] === undefined) { if (reverseMapping[colours[nextColour].back] === undefined) {
reverseMapping[colours[nextColour]] = []; reverseMapping[colours[nextColour].back] = {
front: colours[nextColour].front,
list: []
};
} }
reverseMapping[colours[nextColour]].push(value); reverseMapping[colours[nextColour].back].list.push(value);
nextColour++; nextColour++;
if (nextColour === colours.length) { if (nextColour === colours.length) {
nextColour = 0; nextColour = 0;
@ -74,9 +77,29 @@ function ColourMapper() {
if (listener !== undefined) { if (listener !== undefined) {
listener(self.getList()); listener(self.getList());
} }
return mapping[value]; return mapping[value].back;
}; };
this.getForegroundColour = function(value) {
if (mapping[value] === undefined) {
mapping[value] = colours[nextColour];
if (reverseMapping[colours[nextColour].back] === undefined) {
reverseMapping[colours[nextColour].back] = {
front: colours[nextColour].front,
list: []
};
}
reverseMapping[colours[nextColour].back].list.push(value);
nextColour++;
if (nextColour === colours.length) {
nextColour = 0;
}
}
if (listener !== undefined) {
listener(self.getList());
}
return mapping[value].front;
};
this.reset = function() { this.reset = function() {

View File

@ -110,6 +110,7 @@ function NodeShaper(parent, flags, idfunc) {
addColor = noop, addColor = noop,
addShape = noop, addShape = noop,
addLabel = noop, addLabel = noop,
addLabelColor = function() {return "black";},
addCommunityShape = function(g) { addCommunityShape = function(g) {
g.append("polygon") g.append("polygon")
.attr("points", "0,-25 -16,20 23,-10 -23,-10 16,20"); .attr("points", "0,-25 -16,20 23,-10 -23,-10 16,20");
@ -248,7 +249,9 @@ function NodeShaper(parent, flags, idfunc) {
.attr("width", width) // Set width .attr("width", width) // Set width
.attr("height", height) // Set height .attr("height", height) // Set height
.attr("x", translateX) .attr("x", translateX)
.attr("y", translateY); .attr("y", translateY)
.attr("rx", "8")
.attr("ry", "8");
}; };
break; break;
case undefined: case undefined:
@ -263,7 +266,7 @@ function NodeShaper(parent, flags, idfunc) {
addLabel = function (node) { addLabel = function (node) {
var textN = node.append("text") // Append a label for the node var textN = node.append("text") // Append a label for the node
.attr("text-anchor", "middle") // Define text-anchor .attr("text-anchor", "middle") // Define text-anchor
.attr("fill", "black") // Force a black color .attr("fill", addLabelColor) // Force a black color
.attr("stroke", "none"); // Make it readable .attr("stroke", "none"); // Make it readable
textN.each(function(d) { textN.each(function(d) {
var chunks = splitLabel(label(d)); var chunks = splitLabel(label(d));
@ -283,7 +286,7 @@ function NodeShaper(parent, flags, idfunc) {
addLabel = function (node) { addLabel = function (node) {
var textN = node.append("text") // Append a label for the node var textN = node.append("text") // Append a label for the node
.attr("text-anchor", "middle") // Define text-anchor .attr("text-anchor", "middle") // Define text-anchor
.attr("fill", "black") // Force a black color .attr("fill", addLabelColor) // Force a black color
.attr("stroke", "none"); // Make it readable .attr("stroke", "none"); // Make it readable
textN.each(function(d) { textN.each(function(d) {
var chunks = splitLabel(d._data[label]); var chunks = splitLabel(d._data[label]);
@ -320,6 +323,9 @@ function NodeShaper(parent, flags, idfunc) {
g.attr("stroke", color.stroke); g.attr("stroke", color.stroke);
g.attr("fill", color.fill); g.attr("fill", color.fill);
}; };
addLabelColor = function (d) {
return color.stroke;
};
break; break;
case "expand": case "expand":
addColor = function (g) { addColor = function (g) {
@ -336,6 +342,9 @@ function NodeShaper(parent, flags, idfunc) {
return color.collapsed; return color.collapsed;
}); });
}; };
addLabelColor = function (d) {
return "black";
};
break; break;
case "attribute": case "attribute":
addColor = function (g) { addColor = function (g) {
@ -352,6 +361,13 @@ function NodeShaper(parent, flags, idfunc) {
return colourMapper.getColour(n._data[color.key]); return colourMapper.getColour(n._data[color.key]);
}); });
}; };
addLabelColor = function (n) {
if (n._data === undefined) {
return colourMapper.getForegroundColour(undefined);
}
return colourMapper.getForegroundColour(n._data[color.key]);
};
break; break;
default: default:
throw "Sorry given colour-scheme not known"; throw "Sorry given colour-scheme not known";

View File

@ -125,8 +125,8 @@
expect(_.keys(colorList).length).toEqual(3); expect(_.keys(colorList).length).toEqual(3);
_.each(_.values(colorList), function(v) { _.each(_.values(colorList), function(v) {
expect(v).toEqual(jasmine.any(Array)); expect(v.list).toEqual(jasmine.any(Array));
expect(v.length).toEqual(1); expect(v.list.length).toEqual(1);
}); });
}); });

View File

@ -39,7 +39,7 @@
"use strict"; "use strict";
describe('Event Dispatcher UI', function () { describe('Event Dispatcher UI', function () {
var svg, dispatcher, dispatcherUI, list, var svg, dispatcherUI, list,
nodeShaper, edgeShaper, layouter, nodeShaper, edgeShaper, layouter,
nodes, edges, adapter, nodes, edges, adapter,
mousePointerbox, mousePointerbox,
@ -149,6 +149,7 @@
spyOn(nodeShaper, "changeTo").andCallThrough(); spyOn(nodeShaper, "changeTo").andCallThrough();
spyOn(edgeShaper, "changeTo").andCallThrough(); spyOn(edgeShaper, "changeTo").andCallThrough();
this.addMatchers({ this.addMatchers({
toBeTag: function(name) { toBeTag: function(name) {
var item = this.actual; var item = this.actual;
@ -207,6 +208,57 @@
}).toThrow("The EdgeShaper has to be given."); }).toThrow("The EdgeShaper has to be given.");
}); });
it('should be able to add a new node control to the list', function() {
runs(function() {
dispatcherUI.addControlNewNode();
expect($("#control_event_list #control_event_newnode").length).toEqual(1);
helper.simulateMouseEvent("click", "control_event_newnode");
expect(nodeShaper.changeTo).toHaveBeenCalledWith({
actions: {
reset: true
}
});
expect(edgeShaper.changeTo).toHaveBeenCalledWith({
actions: {
reset: true
}
});
expect(mousePointerbox.className).toEqual("mousepointer icon-plus-sign");
helper.simulateMouseEvent("click", "svg");
expect($("#control_event_new_node_modal").length).toEqual(1);
//$("#control_event_node_edit_name_value").val("Bob");
helper.simulateMouseEvent("click", "control_event_new_node_submit");
expect(adapter.createNode).toHaveBeenCalledWith(
{},
jasmine.any(Function)
);
/*
expect(adapter.createNode).toHaveBeenCalledWith(
{
name: "Bob"
},
jasmine.any(Function)
);
*/
});
waitsFor(function() {
return $("#control_event_node_edit_modal").length === 0;
}, 2000, "The modal dialog should disappear.");
});
it('should be able to add a drag control to the list', function() { it('should be able to add a drag control to the list', function() {
runs(function() { runs(function() {
dispatcherUI.addControlDrag(); dispatcherUI.addControlDrag();
@ -476,6 +528,7 @@
expect($("#control_event_list #control_event_expand").length).toEqual(1); expect($("#control_event_list #control_event_expand").length).toEqual(1);
expect($("#control_event_list #control_event_delete").length).toEqual(1); expect($("#control_event_list #control_event_delete").length).toEqual(1);
expect($("#control_event_list #control_event_connect").length).toEqual(1); expect($("#control_event_list #control_event_connect").length).toEqual(1);
expect($("#control_event_list #control_event_newnode").length).toEqual(1);
}); });
}); });

View File

@ -315,8 +315,8 @@
expect(_.keys(colorList).length).toEqual(3); expect(_.keys(colorList).length).toEqual(3);
_.each(_.values(colorList), function(v) { _.each(_.values(colorList), function(v) {
expect(v).toEqual(jasmine.any(Array)); expect(v.list).toEqual(jasmine.any(Array));
expect(v.length).toEqual(1); expect(v.list.length).toEqual(1);
}); });
}); });
@ -736,6 +736,26 @@
}); });
it('should add rounded corners', function() {
var nodes = [
{_id: 1},
{_id: 2}
];
shaper = new NodeShaper(d3.select("svg"),
{
shape: {
type: NodeShaper.shapes.RECT
}
});
shaper.drawNodes(nodes);
expect($("svg #1 rect").attr("rx")).toEqual("8");
expect($("svg #2 rect").attr("rx")).toEqual("8");
expect($("svg #1 rect").attr("ry")).toEqual("8");
expect($("svg #2 rect").attr("ry")).toEqual("8");
});
}); });
describe('configured for label', function () { describe('configured for label', function () {
@ -775,7 +795,7 @@
textEl; textEl;
shaper.drawNodes(node); shaper.drawNodes(node);
textEl = $("svg .node text"); textEl = $("svg .node text");
expect(textEl.attr("fill")).toEqual("black"); expect(textEl.attr("fill")).toEqual("#8AA051");
expect(textEl.attr("stroke")).toEqual("none"); expect(textEl.attr("stroke")).toEqual("none");
}); });

View File

@ -52,8 +52,14 @@
spyOn(shaper, 'changeTo'); spyOn(shaper, 'changeTo');
spyOn(shaper, 'getColourMapping').andCallFake(function() { spyOn(shaper, 'getColourMapping').andCallFake(function() {
return { return {
"blue": ["bl", "ue"], blue: {
"green": ["gr", "een"] list: ["bl", "ue"],
front: "white"
},
green: {
list: ["gr", "een"],
front: "black"
}
}; };
}); });
spyOn(shaper, "setColourMappingListener"); spyOn(shaper, "setColourMappingListener");

View File

@ -135,6 +135,32 @@ function EventDispatcherControls(list, cursorIconBox, nodeShaper, edgeShaper, di
cursorIconBox.style.display = "block"; cursorIconBox.style.display = "block";
}); });
this.addControlNewNode = function() {
var prefix = "control_event_newnode",
idprefix = prefix + "_",
icon = "plus-sign",
createCallback = function(n) {
modalDialogHelper.createModalEditDialog(
"Create New Node",
"control_event_new_node_",
{},
function(data) {
dispatcher.events.CREATENODE(data, function() {
$("#control_event_new_node_modal").modal('hide');
})();
}
);
},
callback = function() {
setCursorIcon(icon);
rebindNodes();
rebindEdges();
rebindSVG({click: createCallback});
};
createIcon(icon, "newnode", callback);
};
this.addControlDrag = function() { this.addControlDrag = function() {
var prefix = "control_event_drag", var prefix = "control_event_drag",
idprefix = prefix + "_", idprefix = prefix + "_",
@ -256,6 +282,7 @@ function EventDispatcherControls(list, cursorIconBox, nodeShaper, edgeShaper, di
self.addControlExpand(); self.addControlExpand();
self.addControlDelete(); self.addControlDelete();
self.addControlConnect(); self.addControlConnect();
self.addControlNewNode();
}; };
} }

View File

@ -47,9 +47,12 @@ function NodeShaperControls(list, shaper) {
} }
var list = document.createElement("ul"); var list = document.createElement("ul");
colourDiv.appendChild(list); colourDiv.appendChild(list);
_.each(mapping, function(els, col) { _.each(mapping, function(obj, col) {
var li = document.createElement("li"); var li = document.createElement("li"),
els = obj.list,
fore = obj.front;
li.style.backgroundColor = col; li.style.backgroundColor = col;
li.style.color = fore;
li.appendChild(document.createTextNode(els.join(", "))); li.appendChild(document.createTextNode(els.join(", ")));
list.appendChild(li); list.appendChild(li);
}); });