Skip to content

Commit

Permalink
feat: Don't show links unless they are initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
zHaytam committed Mar 15, 2021
1 parent 6ea1252 commit 855568e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/Blazor.Diagrams/Components/LinkWidget.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
var pathGenerator = Link.PathGenerator ?? Diagram.Options.Links.DefaultPathGenerator;
var route = router(Diagram, Link);
(var source, var target) = FindConnectionPoints(route);
if (source == null || target == null)
return;

var result = pathGenerator(Diagram, Link, route, source, target);
var color = Link.Selected ? (Link.SelectedColor ?? Diagram.Options.Links.DefaultSelectedColor)
: (Link.Color ?? Diagram.Options.Links.DefaultColor);
Expand Down
9 changes: 5 additions & 4 deletions src/Blazor.Diagrams/Components/LinkWidget.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Components.Web;
using Blazor.Diagrams.Core.Geometry;
using System.Collections.Generic;
using System;

namespace Blazor.Diagrams.Components
{
Expand All @@ -30,11 +31,8 @@ private void OnMouseDown(MouseEventArgs e, int index)
{
if (Link.SourcePort == null) // Portless
{
var source = Point.Zero;
var target = Point.Zero;

if (Link.SourceNode.Size == null || Link.TargetNode?.Size == null)
return (source, target);
return (null, null);

var sourceCenter = Link.SourceNode.GetBounds().Center;
var targetCenter = Link.TargetNode?.GetBounds().Center ?? Link.OnGoingPosition;
Expand All @@ -50,6 +48,9 @@ private void OnMouseDown(MouseEventArgs e, int index)
}
else
{
if (!Link.SourcePort.Initialized || Link.TargetPort?.Initialized == false)
return (null, null);

return (Link.SourcePort.MiddlePosition, Link.TargetPort?.MiddlePosition ?? Link.OnGoingPosition);
}
}
Expand Down

0 comments on commit 855568e

Please sign in to comment.