Skip to content

Commit

Permalink
feat: Allow empty groups
Browse files Browse the repository at this point in the history
  • Loading branch information
zHaytam committed Feb 27, 2021
1 parent 9781661 commit b870b25
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Blazor.Diagrams.Core/Diagram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ public GroupModel Group(params NodeModel[] children)
/// <param name="group">A group instance.</param>
public void AddGroup(GroupModel group)
{
if (group.Children.Length < 2)
throw new ArgumentException("Number of nodes must be >= 2");

var layers = group.Children.Select(n => n.Layer).Distinct();
if (layers.Count() > 1)
throw new InvalidOperationException("Cannot group nodes with different layers");
if (group.Children.Length > 0)
{
var layers = group.Children.Select(n => n.Layer).Distinct();
if (layers.Count() > 1)
throw new InvalidOperationException("Cannot group nodes with different layers");

if (layers.First() == RenderLayer.SVG)
throw new InvalidOperationException("SVG groups aren't implemented yet");
if (layers.First() == RenderLayer.SVG)
throw new InvalidOperationException("SVG groups aren't implemented yet");
}

foreach (var child in group.Children)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Blazor.Diagrams.Core/Extensions/DiagramExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
using Blazor.Diagrams.Core.Models;
using Blazor.Diagrams.Core.Models.Core;
using System.Collections.Generic;
using System.Linq;

namespace Blazor.Diagrams.Core.Extensions
{
public static class DiagramExtensions
{
public static Rectangle GetBounds(this IEnumerable<NodeModel> nodes)
{
if (!nodes.Any())
return Rectangle.Zero;

var minX = double.MaxValue;
var maxX = double.MinValue;
var minY = double.MaxValue;
Expand Down
2 changes: 2 additions & 0 deletions src/Blazor.Diagrams.Core/Models/Core/Rectangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace Blazor.Diagrams.Core.Models.Core
{
public class Rectangle
{
public static Rectangle Zero { get; } = new Rectangle(0, 0, 0, 0);

public double Width { get; set; }
public double Height { get; set; }
public double Top { get; set; }
Expand Down

0 comments on commit b870b25

Please sign in to comment.