Skip to content

Conversation

nickchomey
Copy link

@nickchomey nickchomey commented Mar 25, 2022

Fixes #1688

previousSelection was returning the entire node and edge objects rather than just an array of ids. This fixes it. I only tested it via modifying the vis-network.min.js file directly, but have translated it back to this format. Please check and improve as necessary. - I am brand new to javascript, so assume there are more efficient ways of extracting the ids.

value: function (g, A) {
    var t = !1,
        e = this._selectionAccumulator.commit(),
        C = {},
        nodes = [], 
        edges = [];    
    for (let i = 0; i < e.nodes.previous.length; i++ ){
        nodes.push(e.nodes.previous[i].id);
    };
    for (let i = 0; i < e.edges.previous.length; i++ ){
        edges.push(e.edges.previous[i].id);
    };    
    C = {
        nodes: nodes,
        edges: edges
    };

Previous selection was returning the entire node and edge objects rather than just an array of ids. This fixes it. I only tested it via modifying the vis-network.min.js file directly, but have translated it back to this format. Please check and improve as necessary. 
`
  value: function (g, A) {
                    var t = !1,
                        e = this._selectionAccumulator.commit(),
                        C = {},
                        nodes = [], 
                        edges = [];
                    
                    for (let i = 0; i < e.nodes.previous.length; i++ ){
                        nodes.push(e.nodes.previous[i].id);
                    };
                    for (let i = 0; i < e.edges.previous.length; i++ ){
                        edges.push(e.edges.previous[i].id);
                    };
                    
                    C = {
                        nodes: nodes,
                        edges: edges
                    };
`
@nickchomey nickchomey changed the title previous selection returned entire object vs ids previousSelection returned entire object vs ids Mar 25, 2022
@micrology
Copy link

The following might be neater:

Replace lines 18179 - 18182 in vis-network/esnext/esm/vis-network.js :

const previousSelection = {
      nodes: selectionChanges.nodes.previous,
      edges: selectionChanges.edges.previous,
    };

with

const previousSelection = {
    nodes: selectionChanges.nodes.previous.map(node => node.id),
    edges: selectionChanges.edges.previous.map(edge => edge.id),
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deselectNode event reports nodes, not nodeIds, in previousSelection

2 participants