ngx-relationship-visualiser 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -476,6 +476,9 @@ class DexieService extends Dexie {
476
476
  async deleteGraphData(dataId) {
477
477
  await this.graphData.delete(dataId);
478
478
  }
479
+ async findGraphData(dataId) {
480
+ return this.graphData.get(dataId);
481
+ }
479
482
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: DexieService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
480
483
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: DexieService, providedIn: 'root' });
481
484
  }
@@ -952,21 +955,15 @@ class VisualiserGraphService {
952
955
  }
953
956
  const parentWidth = parentElement.clientWidth;
954
957
  const parentHeight = parentElement.clientHeight;
955
- // Check to see if nodes are in Dexie
956
- const oldData = await this.dexieService.getGraphData('nodes');
957
- const oldNodes = oldData ? oldData.nodes : [];
958
- if (Array.isArray(oldNodes)) {
958
+ // Nodes from the previous render, if any. On first load in a fresh browser
959
+ // there is no 'nodes' record yet, so this must not throw.
960
+ const oldData = await this.dexieService.findGraphData('nodes');
961
+ if (oldData && Array.isArray(oldData.nodes)) {
959
962
  // Compare and set property for new nodes
960
- this.nodes = this.compareAndMarkNodesNew(nodes, oldNodes);
961
- // Remove old nodes from Dexie
962
- await this.dexieService.deleteGraphData('nodes');
963
- // Add new nodes to Dexie
964
- await this.dexieService.saveGraphData({ dataId: 'nodes', nodes: data.nodes, links: data.links });
965
- }
966
- else {
967
- // Add first set of nodes to Dexie
968
- await this.dexieService.saveGraphData({ dataId: 'nodes', nodes: data.nodes, links: data.links });
963
+ this.nodes = this.compareAndMarkNodesNew(this.nodes, oldData.nodes);
969
964
  }
965
+ // Store this render's nodes for next time (put() overwrites any existing record)
966
+ await this.dexieService.saveGraphData({ dataId: 'nodes', nodes: data.nodes, links: data.links });
970
967
  // If nodes don't have a fx/fy coordinate we generate a random one - dagre nodes without links and new nodes added to canvas have null coordinates by design
971
968
  this.nodes = this.randomiseNodePositions(this.nodes, parentWidth, parentHeight);
972
969
  // Getting parents lineStyle and adding it to child objects