From 00da4bc55021a4e487a868d8b9b7b3bcfa4b3b8f Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sun, 23 Jun 2019 05:48:46 +0000 Subject: [PATCH] Remove soft nodes from the graph --- architype.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/architype.js b/architype.js index 1b5c3b1..12c0161 100644 --- a/architype.js +++ b/architype.js @@ -27,6 +27,7 @@ class Architype { onEdit(e) { this.graph_ = this.buildGraph(); + console.log(this.graph_); this.updateTargets(); } @@ -67,6 +68,7 @@ class Architype { groups: [], }; this.buildGraphInt(graph, this.editor_.getEntries()); + this.trimSoftNodes(graph); return graph; } @@ -109,6 +111,16 @@ class Architype { this.buildGraphInt(graph, [link.getFrom(), link.getTo()]); // TODO: record link information on source node } + + trimSoftNodes(graph) { + for (let entries of graph.targetsByLabel.values()) { + for (let i = entries.length - 1; i >= 0 && entries.length > 1; --i) { + if (entries[i] instanceof Node && entries[i].isSoft()) { + entries.splice(i, 1); + } + } + } + } } class ListenUtils { @@ -491,6 +503,17 @@ class Node extends EditorEntryBase { return this.input_.value; } + isSoft() { + // Nested nodes are presumed to be references to other nodes if they exist + let iter = this.elem_.parentElement; + for (let iter = this.elem_.parentElement; iter; iter = iter.parentElement) { + if (iter.xArchObj) { + return true; + } + } + return false; + } + onInput() { this.input_.setAttribute('data-arch-value', this.input_.value); }