Browse Source

Added dragStart event for adding edges. (#3141)

revert-3409-performance
wimrijnders 7 years ago
committed by yotamberk
parent
commit
16a639bae5
2 changed files with 24 additions and 4 deletions
  1. +13
    -2
      examples/network/events/interactionEvents.html
  2. +11
    -2
      lib/network/modules/ManipulationSystem.js

+ 13
- 2
examples/network/events/interactionEvents.html View File

@ -48,7 +48,14 @@
nodes: nodes, nodes: nodes,
edges: edges edges: edges
}; };
var options = {interaction:{hover:true}};
var options = {
interaction:{hover:true},
manipulation: {
enabled: true
}
};
var network = new vis.Network(container, data, options); var network = new vis.Network(container, data, options);
network.on("click", function (params) { network.on("click", function (params) {
@ -65,8 +72,10 @@
document.getElementById('eventSpan').innerHTML = '<h2>oncontext (right click) event:</h2>' + JSON.stringify(params, null, 4); document.getElementById('eventSpan').innerHTML = '<h2>oncontext (right click) event:</h2>' + JSON.stringify(params, null, 4);
}); });
network.on("dragStart", function (params) { network.on("dragStart", function (params) {
// There's no point in displaying this event on screen, it gets immediately overwritten
params.event = "[original event]"; params.event = "[original event]";
document.getElementById('eventSpan').innerHTML = '<h2>dragStart event:</h2>' + JSON.stringify(params, null, 4);
console.log('dragStart Event:', params);
console.log('dragStart event, getNodeAt returns: ' + this.getNodeAt(params.pointer.DOM));
}); });
network.on("dragging", function (params) { network.on("dragging", function (params) {
params.event = "[original event]"; params.event = "[original event]";
@ -75,6 +84,8 @@
network.on("dragEnd", function (params) { network.on("dragEnd", function (params) {
params.event = "[original event]"; params.event = "[original event]";
document.getElementById('eventSpan').innerHTML = '<h2>dragEnd event:</h2>' + JSON.stringify(params, null, 4); document.getElementById('eventSpan').innerHTML = '<h2>dragEnd event:</h2>' + JSON.stringify(params, null, 4);
console.log('dragEnd Event:', params);
console.log('dragEnd event, getNodeAt returns: ' + this.getNodeAt(params.pointer.DOM));
}); });
network.on("zoom", function (params) { network.on("zoom", function (params) {
document.getElementById('eventSpan').innerHTML = '<h2>zoom event:</h2>' + JSON.stringify(params, null, 4); document.getElementById('eventSpan').innerHTML = '<h2>zoom event:</h2>' + JSON.stringify(params, null, 4);

+ 11
- 2
lib/network/modules/ManipulationSystem.js View File

@ -322,8 +322,7 @@ class ManipulationSystem {
this._temporaryBindUI('onDragEnd', this._finishConnect.bind(this)); this._temporaryBindUI('onDragEnd', this._finishConnect.bind(this));
this._temporaryBindUI('onDrag', this._dragControlNode.bind(this)); this._temporaryBindUI('onDrag', this._dragControlNode.bind(this));
this._temporaryBindUI('onRelease', this._finishConnect.bind(this)); this._temporaryBindUI('onRelease', this._finishConnect.bind(this));
this._temporaryBindUI('onDragStart', () => {});
this._temporaryBindUI('onDragStart',this._dragStartEdge.bind(this));
this._temporaryBindUI('onHold', () => {}); this._temporaryBindUI('onHold', () => {});
} }
@ -935,6 +934,7 @@ class ManipulationSystem {
edge.updateEdgeType(); edge.updateEdgeType();
this.body.emitter.emit('restorePhysics'); this.body.emitter.emit('restorePhysics');
} }
this.body.emitter.emit('_redraw'); this.body.emitter.emit('_redraw');
} }
@ -1048,9 +1048,18 @@ class ManipulationSystem {
} }
} }
} }
// No need to do _generateclickevent('dragEnd') here, the regular dragEnd event fires.
this.body.emitter.emit('_redraw'); this.body.emitter.emit('_redraw');
} }
_dragStartEdge(event) {
let pointer = this.lastTouch;
this.selectionHandler._generateClickEvent('dragStart', event, pointer, undefined, true);
}
// --------------------------------------- END OF ADD EDGE FUNCTIONS -------------------------------------// // --------------------------------------- END OF ADD EDGE FUNCTIONS -------------------------------------//

Loading…
Cancel
Save