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

Remove cy.load() from docs & deprecate #822

Closed
maxkfranz opened this issue Feb 5, 2015 · 7 comments
Closed

Remove cy.load() from docs & deprecate #822

maxkfranz opened this issue Feb 5, 2015 · 7 comments
Milestone

Comments

@maxkfranz
Copy link
Member

No description provided.

@bertomaniac
Copy link

Any reason for deprecation? I currently use this as a "reset" of sorts so that I can persist existing data and load old, saved sets.

@maxkfranz maxkfranz modified the milestones: 2.4.0, 2.3.10 Feb 5, 2015
@maxkfranz
Copy link
Member Author

Too many complaints and too much confusion over this function.

If the old data has positions defined already, cy.add() should be the same for your usecase.

I'll put this off to 2.4, and it will be backwards compatible -- but I don't think anyone new should be using cy.load().

@bertomaniac
Copy link

Perhaps there's a better way to do this, but what I am doing is resetting the core to have 0 data (but to maintain the styles and any additional click handlers I've set up). I don't want to wipe the core, but rather zero it out so that I can call cy.add() and have things work nicely.

I've extended the core with a 'reset' function that internally calls load() with an empty collection. The callback allows me to pass in a function that can be called after load() has finished.

cytoscape('core', 'reset', function( callback ){ 
     var cy = this;
     cy.load(cy.collection(), null, callback);
     return this; // chainability
});

I use this function later when loading in a saved data set:

var savedNetworkData = network.get('data');

// need a detached copy of the elements so changes to the data in the graph
// don't affect the model                   
var elements = $.extend(true, {}, savedNetworkData.elements);

// clears the graph
this._cy.reset(_.bind(function() {

     this._cy.startBatch(); 
     this._cy.add(elements);
     this._cy.endBatch();

     var opts = {
          name: 'preset',
     };

     this._cy.layout(opts);
}, this));

@maxkfranz
Copy link
Member Author

I think a call to cy.elements().remove() could replace your cy.reset() call. Because there's no async layout, you don't need the callback or you could just have:

cytoscape('core', 'reset', function( callback ){ 
     var cy = this;
     cy.elements().remove();
     callback();
     return this; // chainability
});

@nebril
Copy link

nebril commented Feb 6, 2015

I do a similar thing as bertomaniac.

Using add or remove and layout after them tended to mess with node positions, so every time I add/remove nodes I call

    cy.layout(layout);
    cy.load( cy.elements('*').jsons(), function() { cy.center(node)} );

And it does the trick.

@MissChocoe
Copy link
Contributor

So if we set up cyto but have the data later on, should we used the "add" and then run a layout?

@maxkfranz
Copy link
Member Author

@MissChocoe Yes. You can always use that manual workflow, even at init if you want (i.e. start with empty graph in init options).

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

No branches or pull requests

4 participants