Browse Source

Fixed #1575: fixed selection events

codeClimate
Alex de Mulder 8 years ago
parent
commit
1cb16f64ee
3 changed files with 38 additions and 35 deletions
  1. +1
    -0
      HISTORY.md
  2. +19
    -19
      dist/vis.js
  3. +18
    -16
      lib/network/modules/InteractionHandler.js

+ 1
- 0
HISTORY.md View File

@ -22,6 +22,7 @@ http://visjs.org
- Fixed #1635: edges are now referring to the correct points. - Fixed #1635: edges are now referring to the correct points.
- Fixed #1644, #1631: overlapping nodes in hierarchical layout should no longer occur. - Fixed #1644, #1631: overlapping nodes in hierarchical layout should no longer occur.
- Added parentCentralization option for hierarchical layout. - Added parentCentralization option for hierarchical layout.
- Fixed #1575: fixed selection events
## 2016-02-04, version 4.14.0 ## 2016-02-04, version 4.14.0

+ 19
- 19
dist/vis.js View File

@ -38286,8 +38286,8 @@ return /******/ (function(modules) { // webpackBootstrap
var _determineIfDifferent2 = this._determineIfDifferent(previousSelection, currentSelection); var _determineIfDifferent2 = this._determineIfDifferent(previousSelection, currentSelection);
var nodesChanges = _determineIfDifferent2.nodesChanges;
var edgesChanges = _determineIfDifferent2.edgesChanges;
var nodesChanged = _determineIfDifferent2.nodesChanged;
var edgesChanged = _determineIfDifferent2.edgesChanged;
var nodeSelected = false; var nodeSelected = false;
@ -38296,15 +38296,15 @@ return /******/ (function(modules) { // webpackBootstrap
this.selectionHandler._generateClickEvent('selectNode', event, pointer); this.selectionHandler._generateClickEvent('selectNode', event, pointer);
selected = true; selected = true;
nodeSelected = true; nodeSelected = true;
} else if (selectedNodesCount - previouslySelectedNodeCount < 0) {
// node was deselected
this.selectionHandler._generateClickEvent('deselectNode', event, pointer, previousSelection);
selected = true;
} else if (selectedNodesCount === previouslySelectedNodeCount && nodesChanges === true) {
} else if (nodesChanged === true && selectedNodesCount > 0) {
this.selectionHandler._generateClickEvent('deselectNode', event, pointer, previousSelection); this.selectionHandler._generateClickEvent('deselectNode', event, pointer, previousSelection);
this.selectionHandler._generateClickEvent('selectNode', event, pointer); this.selectionHandler._generateClickEvent('selectNode', event, pointer);
nodeSelected = true; nodeSelected = true;
selected = true; selected = true;
} else if (selectedNodesCount - previouslySelectedNodeCount < 0) {
// node was deselected
this.selectionHandler._generateClickEvent('deselectNode', event, pointer, previousSelection);
selected = true;
} }
// handle the selected edges // handle the selected edges
@ -38312,13 +38312,13 @@ return /******/ (function(modules) { // webpackBootstrap
// edge was selected // edge was selected
this.selectionHandler._generateClickEvent('selectEdge', event, pointer); this.selectionHandler._generateClickEvent('selectEdge', event, pointer);
selected = true; selected = true;
} else if (selectedEdgesCount - previouslySelectedEdgeCount < 0) {
// edge was deselected
} else if (selectedEdgesCount > 0 && edgesChanged === true) {
this.selectionHandler._generateClickEvent('deselectEdge', event, pointer, previousSelection); this.selectionHandler._generateClickEvent('deselectEdge', event, pointer, previousSelection);
this.selectionHandler._generateClickEvent('selectEdge', event, pointer);
selected = true; selected = true;
} else if (selectedEdgesCount === previouslySelectedEdgeCount && edgesChanges === true) {
} else if (selectedEdgesCount - previouslySelectedEdgeCount < 0) {
// edge was deselected
this.selectionHandler._generateClickEvent('deselectEdge', event, pointer, previousSelection); this.selectionHandler._generateClickEvent('deselectEdge', event, pointer, previousSelection);
this.selectionHandler._generateClickEvent('selectEdge', event, pointer);
selected = true; selected = true;
} }
@ -38333,37 +38333,37 @@ return /******/ (function(modules) { // webpackBootstrap
* This function checks if the nodes and edges previously selected have changed. * This function checks if the nodes and edges previously selected have changed.
* @param previousSelection * @param previousSelection
* @param currentSelection * @param currentSelection
* @returns {{nodesChanges: boolean, edgesChanges: boolean}}
* @returns {{nodesChanged: boolean, edgesChanged: boolean}}
* @private * @private
*/ */
}, { }, {
key: '_determineIfDifferent', key: '_determineIfDifferent',
value: function _determineIfDifferent(previousSelection, currentSelection) { value: function _determineIfDifferent(previousSelection, currentSelection) {
var nodesChanges = false;
var edgesChanges = false;
var nodesChanged = false;
var edgesChanged = false;
for (var i = 0; i < previousSelection.nodes.length; i++) { for (var i = 0; i < previousSelection.nodes.length; i++) {
if (currentSelection.nodes.indexOf(previousSelection.nodes[i]) === -1) { if (currentSelection.nodes.indexOf(previousSelection.nodes[i]) === -1) {
nodesChanges = true;
nodesChanged = true;
} }
} }
for (var i = 0; i < currentSelection.nodes.length; i++) { for (var i = 0; i < currentSelection.nodes.length; i++) {
if (previousSelection.nodes.indexOf(previousSelection.nodes[i]) === -1) { if (previousSelection.nodes.indexOf(previousSelection.nodes[i]) === -1) {
nodesChanges = true;
nodesChanged = true;
} }
} }
for (var i = 0; i < previousSelection.edges.length; i++) { for (var i = 0; i < previousSelection.edges.length; i++) {
if (currentSelection.edges.indexOf(previousSelection.edges[i]) === -1) { if (currentSelection.edges.indexOf(previousSelection.edges[i]) === -1) {
edgesChanges = true;
edgesChanged = true;
} }
} }
for (var i = 0; i < currentSelection.edges.length; i++) { for (var i = 0; i < currentSelection.edges.length; i++) {
if (previousSelection.edges.indexOf(previousSelection.edges[i]) === -1) { if (previousSelection.edges.indexOf(previousSelection.edges[i]) === -1) {
edgesChanges = true;
edgesChanged = true;
} }
} }
return { nodesChanges: nodesChanges, edgesChanges: edgesChanges };
return { nodesChanged: nodesChanged, edgesChanged: edgesChanged };
} }
/** /**

+ 18
- 16
lib/network/modules/InteractionHandler.js View File

@ -189,7 +189,7 @@ class InteractionHandler {
let selectedNodesCount = this.selectionHandler._getSelectedNodeCount(); let selectedNodesCount = this.selectionHandler._getSelectedNodeCount();
let currentSelection = this.selectionHandler.getSelection(); let currentSelection = this.selectionHandler.getSelection();
let {nodesChanges, edgesChanges} = this._determineIfDifferent(previousSelection, currentSelection);
let {nodesChanged, edgesChanged} = this._determineIfDifferent(previousSelection, currentSelection);
let nodeSelected = false; let nodeSelected = false;
if (selectedNodesCount - previouslySelectedNodeCount > 0) { // node was selected if (selectedNodesCount - previouslySelectedNodeCount > 0) { // node was selected
@ -197,32 +197,34 @@ class InteractionHandler {
selected = true; selected = true;
nodeSelected = true; nodeSelected = true;
} }
else if (selectedNodesCount - previouslySelectedNodeCount < 0) { // node was deselected
else if (nodesChanged === true && selectedNodesCount > 0) {
this.selectionHandler._generateClickEvent('deselectNode', event, pointer, previousSelection); this.selectionHandler._generateClickEvent('deselectNode', event, pointer, previousSelection);
this.selectionHandler._generateClickEvent('selectNode', event, pointer);
nodeSelected = true;
selected = true; selected = true;
} }
else if (selectedNodesCount === previouslySelectedNodeCount && nodesChanges === true) {
else if (selectedNodesCount - previouslySelectedNodeCount < 0) { // node was deselected
this.selectionHandler._generateClickEvent('deselectNode', event, pointer, previousSelection); this.selectionHandler._generateClickEvent('deselectNode', event, pointer, previousSelection);
this.selectionHandler._generateClickEvent('selectNode', event, pointer);
nodeSelected = true;
selected = true; selected = true;
} }
// handle the selected edges // handle the selected edges
if (selectedEdgesCount - previouslySelectedEdgeCount > 0 && nodeSelected === false) { // edge was selected if (selectedEdgesCount - previouslySelectedEdgeCount > 0 && nodeSelected === false) { // edge was selected
this.selectionHandler._generateClickEvent('selectEdge', event, pointer); this.selectionHandler._generateClickEvent('selectEdge', event, pointer);
selected = true; selected = true;
} }
else if (selectedEdgesCount - previouslySelectedEdgeCount < 0) { // edge was deselected
else if (selectedEdgesCount > 0 && edgesChanged === true) {
this.selectionHandler._generateClickEvent('deselectEdge', event, pointer, previousSelection); this.selectionHandler._generateClickEvent('deselectEdge', event, pointer, previousSelection);
this.selectionHandler._generateClickEvent('selectEdge', event, pointer);
selected = true; selected = true;
} }
else if (selectedEdgesCount === previouslySelectedEdgeCount && edgesChanges === true) {
else if (selectedEdgesCount - previouslySelectedEdgeCount < 0) { // edge was deselected
this.selectionHandler._generateClickEvent('deselectEdge', event, pointer, previousSelection); this.selectionHandler._generateClickEvent('deselectEdge', event, pointer, previousSelection);
this.selectionHandler._generateClickEvent('selectEdge', event, pointer);
selected = true; selected = true;
} }
// fire the select event if anything has been selected or deselected // fire the select event if anything has been selected or deselected
if (selected === true) { // select or unselect if (selected === true) { // select or unselect
this.selectionHandler._generateClickEvent('select', event, pointer); this.selectionHandler._generateClickEvent('select', event, pointer);
@ -234,35 +236,35 @@ class InteractionHandler {
* This function checks if the nodes and edges previously selected have changed. * This function checks if the nodes and edges previously selected have changed.
* @param previousSelection * @param previousSelection
* @param currentSelection * @param currentSelection
* @returns {{nodesChanges: boolean, edgesChanges: boolean}}
* @returns {{nodesChanged: boolean, edgesChanged: boolean}}
* @private * @private
*/ */
_determineIfDifferent(previousSelection,currentSelection) { _determineIfDifferent(previousSelection,currentSelection) {
let nodesChanges = false;
let edgesChanges = false;
let nodesChanged = false;
let edgesChanged = false;
for (let i = 0; i < previousSelection.nodes.length; i++) { for (let i = 0; i < previousSelection.nodes.length; i++) {
if (currentSelection.nodes.indexOf(previousSelection.nodes[i]) === -1) { if (currentSelection.nodes.indexOf(previousSelection.nodes[i]) === -1) {
nodesChanges = true;
nodesChanged = true;
} }
} }
for (let i = 0; i < currentSelection.nodes.length; i++) { for (let i = 0; i < currentSelection.nodes.length; i++) {
if (previousSelection.nodes.indexOf(previousSelection.nodes[i]) === -1) { if (previousSelection.nodes.indexOf(previousSelection.nodes[i]) === -1) {
nodesChanges = true;
nodesChanged = true;
} }
} }
for (let i = 0; i < previousSelection.edges.length; i++) { for (let i = 0; i < previousSelection.edges.length; i++) {
if (currentSelection.edges.indexOf(previousSelection.edges[i]) === -1) { if (currentSelection.edges.indexOf(previousSelection.edges[i]) === -1) {
edgesChanges = true;
edgesChanged = true;
} }
} }
for (let i = 0; i < currentSelection.edges.length; i++) { for (let i = 0; i < currentSelection.edges.length; i++) {
if (previousSelection.edges.indexOf(previousSelection.edges[i]) === -1) { if (previousSelection.edges.indexOf(previousSelection.edges[i]) === -1) {
edgesChanges = true;
edgesChanged = true;
} }
} }
return {nodesChanges, edgesChanges};
return {nodesChanged, edgesChanged};
} }

Loading…
Cancel
Save