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

addLink batch function #46

Closed
toqueteos opened this issue Jul 18, 2013 · 2 comments
Closed

addLink batch function #46

toqueteos opened this issue Jul 18, 2013 · 2 comments

Comments

@toqueteos
Copy link

Is there any way of adding a list of links? Right now one must call addLink N times.

Instead of:

graph.addLink(0, 1);
graph.addLink(0, 2);
graph.addLink(1, 3);
graph.addLink(2, 1);
graph.addLink(2, 4);
graph.addLink(3, 2);
graph.addLink(4, 0);

This:

graph.addLinkBatch([[0, 1], [0, 2], [1, 3], [2, 1], [2, 4], [3, 2], [4, 0]])
@anvaka
Copy link
Owner

anvaka commented Jul 20, 2013

@toqueteos I see how batch operations could be useful, but I'm trying to keep core graph object API as small as possible. It exposes two primitives to implement all sort of batch updates in helper methods: graph.beginUpdate() and graph.endUpdate().

Here is an example:

function addLinkBatch(graph, linksArray) {
  // enter into batch modification block. Nothing will be updated on UI
  // or layout until we call endUpdate();
  graph.beginUpdate();
  for (var i = 0; i < linksArray.length; ++i) {
    var linkPair = linksArray[i];
    graph.addLink(linkPair[0], linkPair[1]);
  }
  // Now let the world know the graph was changed.
  graph.endUpdate(); 
}

@toqueteos
Copy link
Author

@anvaka Well, maybe I issued this too fast; just using that for loop of yours should be fine.

Of course not updating UI each time if lots of adds are expected is a nice thing, so thanks for your proposed solution 👍.

Feel free to close this whenever you want.

@anvaka anvaka closed this as completed Nov 11, 2013
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

No branches or pull requests

2 participants