Skip to content

Commit

Permalink
feat: Added guid/string constructors as Ids for Connections to allow …
Browse files Browse the repository at this point in the history
…for more fluid creation
  • Loading branch information
Snappey committed Jan 2, 2024
1 parent 4086f4a commit 7887ac8
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions D2/Connection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using System;
using System.Text;
using D2.Enums;
using D2.Extensions;
using D2.Interfaces;
Expand All @@ -8,17 +9,28 @@ namespace D2
{
public class Connection : IRenderable
{
private Shape _from { get; }
private Shape _to { get; }
private string _from { get; }
private string _to { get; }
private string? _label { get; }

private ConnectionType _type { get; }
private ArrowheadOptions? _fromArrowhead { get; }
private ArrowheadOptions? _toArrowhead { get; }

public Connection(Shape from, Shape to) : this(from, to, string.Empty) { }
public Connection(Shape from,
Shape to,
public Connection(Guid from, Guid to) : this(from.ToString(), to.ToString(), string.Empty, null) { }
public Connection(Shape from, Shape to) : this(from.Key, to.Key, string.Empty, null) { }
public Connection(string from, string to) : this(from, to, string.Empty, null) { }
public Connection(Guid from, Guid to, string label) : this(from.ToString(), to.ToString(), label, null) { }
public Connection(Shape from, Shape to, string label) : this(from.Key, to.Key, label, null) { }
public Connection(string from, string to, string label, ArrowheadOptions? fromArrowhead = null, ArrowheadOptions? toArrowhead = null) : this(from, to, label, ConnectionType.From, fromArrowhead, toArrowhead) { }
public Connection(Guid from, Guid to, string label, ConnectionType type) : this(from.ToString(), to.ToString(), label, type) { }
public Connection(Shape from, Shape to, string label, ConnectionType type) : this(from.Key, to.Key, label, type) { }
public Connection(string from, string to, string label, ConnectionType type) : this(from, to, label, type, null, null) { }
public Connection(string from, string to, string label, ConnectionType type, ArrowheadOptions? fromArrowhead) : this(from, to, label, type, fromArrowhead, null) { }
public Connection(Shape from, Shape to, string label, ConnectionType type = ConnectionType.From, ArrowheadOptions? fromArrowhead = null, ArrowheadOptions? toArrowhead = null) : this(from.Key, to.Key, label, type, fromArrowhead, toArrowhead) { }
public Connection(Guid from, Guid to, string label, ConnectionType type = ConnectionType.From, ArrowheadOptions? fromArrowhead = null, ArrowheadOptions? toArrowhead = null) : this(from.ToString(), to.ToString(), label, type, fromArrowhead, toArrowhead) { }
public Connection(string from,
string to,
string label,
ConnectionType type = ConnectionType.From,
ArrowheadOptions? fromArrowhead = null,
Expand All @@ -34,7 +46,7 @@ public Connection(Shape from,

public override string ToString()
{
var sb = new StringBuilder($"{_from.Key} {_type.CatalogName()} {_to.Key}");
var sb = new StringBuilder($"{_from} {_type.CatalogName()} {_to}");

var hasProperties = _fromArrowhead != null || _toArrowhead != null;
var hasLabel = !string.IsNullOrEmpty(_label);
Expand Down

0 comments on commit 7887ac8

Please sign in to comment.