Closed xhluca closed 5 years ago
The preset layout is a null-op, unless you specify the positions
field in the layout options.
See http://js.cytoscape.org/#layouts/preset
At init, a preset layout means that you would just use the positions specified in the elements JSON directly -- i.e. a null-op doesn't change the initial positions. Normally, a layout would overwrite the positions at init.
Example of post-init preset layout:
let elesJson = [
{ data: { id: 'a' }, position: { x: 0, y: 100 } },
{ data: { id: 'b' }, position: { x: 0, y: 200 } },
{ data: { id: 'c' }, position: { x: 0, y: 300 } }
];
// map of id => position obj (this example uses the initial positions)
// NB you must copy the position b/c cytoscape owns the objects you pass to it
let presetPositions = elesJson.reduce((positions, eleJson) => {
positions[eleJson.data.id] = _.clone(eleJson.position);
return positions;
}, {});
let cy = cytoscape({
elements: elesJson
// more options...
});
// some time after init restore the initial positions...
cy.layout({ name: 'preset', positions: presetPositions }).run();
Very clearly explain, thank you! I'll explore this further.
@xhlulu Can this be closed?
Hello yes, this can be closed. Sorry.
Description
Whenever the layout is changed to something else (random, grid, etc.), the component is rendered correctly. however, whenever it is changed back to
preset
, nothing happens (it stays stuck in the previous layout).Files
App.js
is written as such:Reproducing Error
Steps toward reproducing the error in command line: