Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

previousSelection returned entire object vs ids #1734

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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