Skip to content

Commit

Permalink
fix: markers wrong position
Browse files Browse the repository at this point in the history
  • Loading branch information
zHaytam committed Mar 22, 2021
1 parent 5d19b76 commit dc8f9c6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Blazor.Diagrams.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CEEAE4C2-CE68-4FC3-9E0F-D4781B91F7F4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blazor.Diagrams.Core.Tests", "tests\Blazor.Diagrams.Core.Tests\Blazor.Diagrams.Core.Tests.csproj", "{36B4DCCD-45AB-4338-9224-DDAF386A23A3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Diagrams.Core.Tests", "tests\Blazor.Diagrams.Core.Tests\Blazor.Diagrams.Core.Tests.csproj", "{36B4DCCD-45AB-4338-9224-DDAF386A23A3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
9 changes: 1 addition & 8 deletions src/Blazor.Diagrams.Core/Routers/Routers.Orthogonal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,10 @@ public static Point[] Orthogonal(Diagram _, BaseLinkModel link)
var origin = ExtrudeCp(originA, shapeMargin, sideA);
var destination = ExtrudeCp(originB, shapeMargin, sideB);

var start = originA;
var end = originB;

var path = ShortestPath(graph, origin, destination);
if (path.Length > 0)
{
var result = new List<Point>();
result.Add(start);
result.AddRange(SimplifyPath(path));
result.Add(end);
return result.ToArray();
return SimplifyPath(path);
}
else
{
Expand Down
31 changes: 30 additions & 1 deletion src/Blazor.Diagrams/Components/LinkWidget.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,36 @@ private LinkVertexModel CreateVertex(double clientX, double clientY, int index)
if (!Link.SourcePort.Initialized || Link.TargetPort?.Initialized == false)
return (null, null);

return (Link.SourcePort.MiddlePosition, Link.TargetPort?.MiddlePosition ?? Link.OnGoingPosition);
var source = GetPortPositionBasedOnAlignment(Link.SourcePort, Link.SourceMarker);
var target = GetPortPositionBasedOnAlignment(Link.TargetPort, Link.TargetMarker);
return (source, target ?? Link.OnGoingPosition);
}
}

private Point GetPortPositionBasedOnAlignment(PortModel port, LinkMarker marker)
{
if (marker == null)
return port.MiddlePosition;

var pt = port.Position;
switch (port.Alignment)
{
case PortAlignment.Top:
return new Point(pt.X + port.Size.Width / 2, pt.Y);
case PortAlignment.TopRight:
return new Point(pt.X + port.Size.Width, pt.Y);
case PortAlignment.Right:
return new Point(pt.X + port.Size.Width, pt.Y + port.Size.Height / 2);
case PortAlignment.BottomRight:
return new Point(pt.X + port.Size.Width, pt.Y + port.Size.Height);
case PortAlignment.Bottom:
return new Point(pt.X + port.Size.Width / 2, pt.Y + port.Size.Height);
case PortAlignment.BottomLeft:
return new Point(pt.X, pt.Y + port.Size.Height);
case PortAlignment.Left:
return new Point(pt.X, pt.Y + port.Size.Height / 2);
default:
return pt;
}
}

Expand Down

0 comments on commit dc8f9c6

Please sign in to comment.