memgraph / orb

Graph visualization library
Apache License 2.0
350 stars 17 forks source link

Fix the Typescript usage of the view settings #16

Open tonilastre opened 2 years ago

tonilastre commented 2 years ago

Issue: Typescript interface is not correctly applied to view (DefaultView, MapView) settings

Details can be read on Stackoverflow: How to setup typescript generics in class constructors and functions

The problem is that main orb object handles different views through orb.setView where each view can have different settings so orb.view.setSettings is not able to apply correct Typescript interface (at least with the current latest TS version).

The solution could be to create a new instance on view changes, e.g.

const orb = new Orb({ generalSettings });

const view = orb.createView((context) => new DefaultView(container1, { viewSettings }));

// Use view from now on
view.render(() => {
  view.recenter();
});

const newView = orb.createView((context) => new MapView(container2, { viewSettings }));