diff --git a/src/Neuroglia.Blazor.Dagre/Models/ClusterViewModel.cs b/src/Neuroglia.Blazor.Dagre/Models/ClusterViewModel.cs index 1c02f385..d41247dd 100644 --- a/src/Neuroglia.Blazor.Dagre/Models/ClusterViewModel.cs +++ b/src/Neuroglia.Blazor.Dagre/Models/ClusterViewModel.cs @@ -66,6 +66,7 @@ public ClusterViewModel( child.Changed += OnChildChanged; if (child is IClusterViewModel cluster) { + cluster.ChildAdded += this.OnChildAdded; this._allClusters.Add(cluster.Id, cluster); this.Flatten(cluster); } @@ -106,6 +107,7 @@ public virtual void AddChild(INodeViewModel node) this.ChildAdded?.Invoke(this, node); if (node is IClusterViewModel cluster) { + cluster.ChildAdded += this.OnChildAdded; this._allClusters.Add(cluster.Id, cluster); this.Flatten(cluster); return; @@ -114,6 +116,22 @@ public virtual void AddChild(INodeViewModel node) this.OnChange(); } + /// + public virtual void OnChildAdded(object? sender, INodeViewModel child) + { + if (child is IClusterViewModel cluster) + { + this._allClusters.Add(cluster.Id, cluster); + this.Flatten(cluster); + } + else if (child is INodeViewModel node) + { + this._allNodes.Add(node.Id, node); + } + this.OnChange(); + this.ChildAdded?.Invoke(this, child); + } + /// /// Adds nested nodes/clusters to allNodes/Clusters /// diff --git a/src/Neuroglia.Blazor.Dagre/Models/GraphViewModel.cs b/src/Neuroglia.Blazor.Dagre/Models/GraphViewModel.cs index 1cf1d98e..7d819302 100644 --- a/src/Neuroglia.Blazor.Dagre/Models/GraphViewModel.cs +++ b/src/Neuroglia.Blazor.Dagre/Models/GraphViewModel.cs @@ -429,7 +429,6 @@ public virtual async Task OnWheelAsync(ElementReference sender, WheelEventArgs e if (this.Wheel != null) await this.Wheel.Invoke(new(e, sender, element)); } - /// public virtual void OnChildAdded(object? sender, INodeViewModel child) { if (child is IClusterViewModel cluster)