Reputation: 517
I am using mxGraph in Angular web application that can swtich between different pages where the mxGraph drawings are kept.
The component that displays current drawing uses mxGraphModel and mxCodec objects as properties. Need to save mxGraphModel and mxCodec objects:
let m: mxGraphModel;
let c: mxCodec; // they are initialized inside the application
into localStorage using well known commands:
localStorage.setItem('MX_GRAPH_MODEL', m);
localStorage.setItem('MX_CODEC', c);
so that they can be retrieved upon the page refresh.
m and c variables are used as properties of the Angular component, they contain graphical information and styling and are therefore reloaded each time a page is refreshed which is what I need to avoid by saving their last version as local storage.
Now I know that the above commands will not work and also stringifying them via JSON won't work either:
localStorage.setItem('MX_GRAPH_MODEL', JSON.stringify(m));
localStorage.setItem('MX_CODEC', JSON.stringify(c));
The question: Is there mxGraph library function, a method that can convert/encode these objects to-string and vice versa, from-string (so that they can be saved using localStorage)?
If not, what would be the appropriate way to save the mxGraph objects to avoid them being changed upon page refresh. I use singleton class in Angular to keep them which is ok for swotching between the pages, however, once the refresh is called, all classes (including singleton) are constructed once again and my current graph drawing is lost.
Upvotes: 0
Views: 567
Reputation: 819
have a look at the getGraphXml() functions of the examples provided, you will have your model as a string that can be stored anywhere I guess
Upvotes: 0