Browse Source

- Fixed #884, selectNode event.

flowchartTest
Alex de Mulder 9 years ago
parent
commit
e8bef2f837
4 changed files with 9146 additions and 9043 deletions
  1. +1
    -0
      HISTORY.md
  2. +9079
    -9036
      dist/vis.js
  3. +21
    -1
      examples/network/events/interactionEvents.html
  4. +45
    -6
      lib/network/modules/InteractionHandler.js

+ 1
- 0
HISTORY.md View File

@ -21,6 +21,7 @@ http://visjs.org
- Fixed bug with the moveTo and getViewPosition methods. - Fixed bug with the moveTo and getViewPosition methods.
- Fixed #861, brokenImage only working for one node if nodes have the same image. - Fixed #861, brokenImage only working for one node if nodes have the same image.
- Fixed hoverNode and blurNode events and added them to the docs. - Fixed hoverNode and blurNode events and added them to the docs.
- Fixed #884, selectNode event.
### Graph2d & Timeline ### Graph2d & Timeline

+ 9079
- 9036
dist/vis.js
File diff suppressed because it is too large
View File


+ 21
- 1
examples/network/events/interactionEvents.html View File

@ -17,11 +17,12 @@
<body> <body>
<p> <p>
Create a simple network with some nodes and edges.
Create a simple network with some nodes and edges. Some of the events are logged in the console in improve readability.
</p> </p>
<div id="mynetwork"></div> <div id="mynetwork"></div>
<pre id="eventSpan"></pre> <pre id="eventSpan"></pre>
<script type="text/javascript"> <script type="text/javascript">
// create an array with nodes // create an array with nodes
var nodes = new vis.DataSet([ var nodes = new vis.DataSet([
@ -79,6 +80,25 @@
network.on("showPopup", function (params) { network.on("showPopup", function (params) {
document.getElementById('eventSpan').innerHTML = '<h2>showPopup event: </h2>' + JSON.stringify(params, null, 4); document.getElementById('eventSpan').innerHTML = '<h2>showPopup event: </h2>' + JSON.stringify(params, null, 4);
}); });
network.on("hidePopup", function (params) {
console.log('hidePopup Event:', params);
});
network.on("select", function (params) {
console.log('select Event:', params);
});
network.on("selectNode", function (params) {
console.log('selectNode Event:', params);
});
network.on("selectEdge", function (params) {
console.log('selectEdge Event:', params);
});
network.on("deselectNode", function (params) {
console.log('deselectNode Event:', params);
});
network.on("deselectEdge", function (params) {
console.log('deselectEdge Event:', params);
});
</script> </script>

+ 45
- 6
lib/network/modules/InteractionHandler.js View File

@ -184,23 +184,26 @@ class InteractionHandler {
else { else {
selected = this.selectionHandler.selectOnPoint(pointer); selected = this.selectionHandler.selectOnPoint(pointer);
} }
let selectedEdges = this.selectionHandler._getSelectedEdgeCount();
let selectedNodes = this.selectionHandler._getSelectedNodeCount();
let selectedEdgesCount = this.selectionHandler._getSelectedEdgeCount();
let selectedNodesCount = this.selectionHandler._getSelectedNodeCount();
let currentSelection = this.selectionHandler.getSelection();
if (selectedNodes - previouslySelectedNodeCount > 0) { // node was selected
let {nodesChanges, edgesChanges} = this._determineIfDifferent(previousSelection, currentSelection);
if (selectedNodesCount - previouslySelectedNodeCount > 0 || (selectedNodesCount === previouslySelectedNodeCount && nodesChanges === true)) { // node was selected
this.selectionHandler._generateClickEvent('selectNode', event, pointer); this.selectionHandler._generateClickEvent('selectNode', event, pointer);
selected = true; selected = true;
} }
else if (selectedNodes - previouslySelectedNodeCount < 0) { // node was deselected
else if (selectedNodesCount - previouslySelectedNodeCount < 0) { // node was deselected
this.selectionHandler._generateClickEvent('deselectNode', event, pointer, previousSelection); this.selectionHandler._generateClickEvent('deselectNode', event, pointer, previousSelection);
selected = true; selected = true;
} }
if (selectedEdges - previouslySelectedEdgeCount > 0) { // node was selected
if (selectedEdgesCount - previouslySelectedEdgeCount > 0|| (selectedEdgesCount === previouslySelectedEdgeCount && edgesChanges === true)) { // node was selected
this.selectionHandler._generateClickEvent('selectEdge', event, pointer); this.selectionHandler._generateClickEvent('selectEdge', event, pointer);
selected = true; selected = true;
} }
else if (selectedEdges - previouslySelectedEdgeCount < 0) { // node was deselected
else if (selectedEdgesCount - previouslySelectedEdgeCount < 0) { // node was deselected
this.selectionHandler._generateClickEvent('deselectEdge', event, pointer, previousSelection); this.selectionHandler._generateClickEvent('deselectEdge', event, pointer, previousSelection);
selected = true; selected = true;
} }
@ -211,6 +214,42 @@ class InteractionHandler {
} }
/**
* This function checks if the nodes and edges previously selected have changed.
* @param previousSelection
* @param currentSelection
* @returns {{nodesChanges: boolean, edgesChanges: boolean}}
* @private
*/
_determineIfDifferent(previousSelection,currentSelection) {
let nodesChanges = false;
let edgesChanges = false;
for (let i = 0; i < previousSelection.nodes.length; i++) {
if (currentSelection.nodes.indexOf(previousSelection.nodes[i]) === -1) {
nodesChanges = true;
}
}
for (let i = 0; i < currentSelection.nodes.length; i++) {
if (previousSelection.nodes.indexOf(previousSelection.nodes[i]) === -1) {
nodesChanges = true;
}
}
for (let i = 0; i < previousSelection.edges.length; i++) {
if (currentSelection.edges.indexOf(previousSelection.edges[i]) === -1) {
edgesChanges = true;
}
}
for (let i = 0; i < currentSelection.edges.length; i++) {
if (previousSelection.edges.indexOf(previousSelection.edges[i]) === -1) {
edgesChanges = true;
}
}
return {nodesChanges, edgesChanges};
}
/** /**
* This function is called by onDragStart. * This function is called by onDragStart.
* It is separated out because we can then overload it for the datamanipulation system. * It is separated out because we can then overload it for the datamanipulation system.

Loading…
Cancel
Save