1
0
Fork 0

GraphViewer: EventDispatchion for edge-creation finished

This commit is contained in:
Michael Hackstein 2013-04-08 13:11:43 +02:00
parent 33abdae1f0
commit 9cb974531b
2 changed files with 68 additions and 24 deletions

View File

@ -71,14 +71,38 @@ function EventDispatcher(nodeShaper, edgeShaper, config) {
if (eventlib.checkEdgeEditorConfig(config)) {
var insert = new eventlib.InsertEdge(config),
patch = new eventlib.PatchEdge(config),
del = new eventlib.DeleteEdge(config);
/*
self.events.CREATEEDGE = function(callback) {
return function() {
insert(callback);
del = new eventlib.DeleteEdge(config),
edgeStart = null,
didInsert = false;
self.events.STARTCREATEEDGE = function(callback) {
return function(node) {
edgeStart = node;
didInsert = false;
if (callback !== undefined) {
callback();
}
}
};
*/
self.events.CANCELCREATEEDGE = function(callback) {
return function() {
edgeStart = null;
if (callback !== undefined && !didInsert) {
callback();
}
}
};
self.events.FINISHCREATEEDGE = function(callback) {
return function(node) {
if (edgeStart !== null && node !== edgeStart) {
insert(edgeStart, node, callback);
didInsert = true;
}
}
};
self.events.PATCHEDGE = function(edge, getNewData, callback) {
if (!_.isFunction(getNewData)) {
throw "Please give a function to extract the new node data";
@ -93,20 +117,6 @@ function EventDispatcher(nodeShaper, edgeShaper, config) {
del(edge, callback);
}
};
/*
var insert = new eventlib.InsertEdge(config.edgeEditor);
self.events.CREATEEDGE = function(callback) {
return function() {
insert(callback);
}
};
*/
self.events.CREATEEDGE = new eventlib.InsertEdge(config);
/*
self.events.PATCHEDGE = new eventlib.PatchEdge(config.edgeEditor);
self.events.DELETEEDGE = new eventlib.DeleteEdge(config.edgeEditor);
*/
}
};

View File

@ -521,16 +521,44 @@
});
});
it('should be able to bind the create edge event', function() {
it('should be able to bind the events to create an edge', function() {
nodes = [{_id: 1}, {_id: 2}, {_id: 3}];
edges = [{source: nodes[0], target: nodes[2]}];
nodeShaper.drawNodes(nodes);
edgeShaper.drawEdges(edges);
var started = 0,
canceled = 0;
runs(function() {
dispatcher.bind($("svg"), "click", dispatcher.events.CREATEEDGE(
dispatcher.bind("nodes", "mousedown", dispatcher.events.STARTCREATEEDGE(
function() {
started++;
}
));
dispatcher.bind("nodes", "mouseup", dispatcher.events.FINISHCREATEEDGE(
function() {
// Never reached as the spy stops propagation
return 0;
}
));
dispatcher.bind($("svg"), "mouseup", dispatcher.events.CANCELCREATEEDGE(
function() {
return canceled++;
}
));
helper.simulateMouseEvent("mousedown", "1");
helper.simulateMouseEvent("mouseup", "svg");
helper.simulateMouseEvent("mousedown", "1");
helper.simulateMouseEvent("mouseup", "1-3");
helper.simulateMouseEvent("mousedown", "1");
helper.simulateMouseEvent("mouseup", "1");
helper.simulateMouseEvent("mousedown", "1");
helper.simulateMouseEvent("mouseup", "2");
helper.simulateMouseEvent("click", "svg");
});
waitsFor(function() {
@ -538,7 +566,13 @@
}, 1000, "The event should have been triggered.");
runs(function() {
expect(true).toBeTruthy();
expect(started).toEqual(4);
expect(canceled).toEqual(3);
expect(adapter.createEdge.calls.length).toEqual(1);
expect(adapter.createEdge).toHaveBeenCalledWith({
source: nodes[0],
target: nodes[1]
}, jasmine.any(Function));
});
});