retejs / rete

JavaScript framework for visual programming
https://retejs.org
MIT License
10.17k stars 653 forks source link

Feature Request: Save and restore the current area/zoom level #441

Closed martin31821 closed 4 years ago

martin31821 commented 4 years ago

I'm building a flow editor within an angular app, using rete and the vue render plugin. I'd like to store the current position and zoom level of the rete canvas within localstorage and restore it.

How can I achieve this?

Hatead1 commented 4 years ago

editor.view.area.zoom(zoom_data); // see rete/src/view/area.ts

martin31821 commented 4 years ago

got it solved by using:

// save
localStorage.setItem('GRAPH_EDITOR_VIEW', JSON.stringify(this.editor.view.area.transform));

// restore
try {
  const viewString = localStorage.getItem('GRAPH_EDITOR_VIEW');
  if (viewString) {
    const view = JSON.parse(viewString);
    this.editor.view.area.transform = view;
    this.editor.view.area.update();
  }
} catch (err) {
  localStorage.removeItem('GRAPH_EDITOR_VIEW');
}