Can i disable a defined diagram "layout" at runtime?

Hello,

Here is my scenario;
i have defined a layout something like this;

  public layout: LayoutModel = {
    type: 'HierarchicalTree', orientation: 'LeftToRight',
    horizontalAlignment: 'Center',
    verticalSpacing: 325, margin: {left: 0, right: 0, top: 0, bottom: 0}
  };

That is all well and good, until i try to save the state of the Diagram. 

So i moved my nodes around, to the position/coordinate of my liking, then saved the diagram. When I try to load that saved state, the "layout" supersedes whatever saved state that diagram was on, and it will still implement that automatic "layout" model, not the coordinates of the saved state i wanted.

So i was thinking of a solution wherein, after the diagram was "created", if there is a saved state of that diagram, i will just remove or disable the "layout", and load that particular state I wanted. If there is no "saved state", then it will just adjust according to the "layout" model.

 That is why my question was if i can "disable" (or toggle to enable/disable) the "layout" at runtime.

Thank you for your support.




3 Replies

AR Aravind Ravi Syncfusion Team April 13, 2020 12:03 PM UTC

Hi Vithunan, 
 
We have created a sample to save and load the layout without changing the nodes position. Before load the diagram , set layout type as none in the saveDiagram Json object. So that when you load the diagram nodes and connectors does not gets rearranges. Please find below code snippet for how to set layout type as ‘None’ in the diagram JSON object. 
 
public Save() { 
       
this.save = this.diagram.saveDiagram(); 
this.data1 = JSON.parse(this.save); 
this.data1["layout"].type = "None"; 
 
    }; 
 
    public Load() { 
      this.data1 = JSON.stringify(this.data1); 
this.diagram.loadDiagram(this.data1); 
    }; 
 
We have attached a sample for your reference. Please find the sample in below link 
 
 
Regards 
Aravind Ravi 



VR Vithu R April 13, 2020 03:28 PM UTC

Aravind Ravi,

Thank you for your reply. Exactly what I need. 

You guys are awesome in terms of the forums support.



 


AR Aravind Ravi Syncfusion Team April 14, 2020 05:32 AM UTC

Hi Vithunan,

Thanks for your update.

Regards 
Aravind Ravi 


Loader.
Up arrow icon