forked from Blazor-Diagrams/Blazor.Diagrams
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
122 additions
and
16 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
samples/SharedDemo/Demos/CustomSvgGroup/CustomSvgGroupModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Blazor.Diagrams.Core.Models; | ||
using Blazor.Diagrams.Models; | ||
|
||
namespace SharedDemo.Demos.CustomSvgGroup | ||
{ | ||
public class CustomSvgGroupModel : SvgGroupModel | ||
{ | ||
public CustomSvgGroupModel(NodeModel[] children, string title, byte padding = 30) : base(children, padding) | ||
{ | ||
Title = title; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
samples/SharedDemo/Demos/CustomSvgGroup/CustomSvgGroupWidget.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@{ | ||
var rectX = Group.Size.Width / 2 - 50; | ||
var textX = rectX + 50; | ||
var textY = -60 + 25.0; | ||
} | ||
|
||
<rect x="@rectX.ToInvariantString()" y="-60" width="100" height="50" fill="yellow"></rect> | ||
<text x="@textX.ToInvariantString()" y="@textY.ToInvariantString()">@Group.Title</text> | ||
|
||
<GroupNodes Group="Group" /> | ||
|
||
@foreach (var port in Group.Ports) | ||
{ | ||
<PortRenderer Port="port" Class="group-port"></PortRenderer> | ||
} | ||
|
||
|
||
@code { | ||
[Parameter] public CustomSvgGroupModel Group { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@page "/demos/custom-svg-group" | ||
@layout DemoLayout | ||
@inject LayoutData LayoutData | ||
|
||
<CascadingValue Value="_diagram"> | ||
<DiagramCanvas></DiagramCanvas> | ||
</CascadingValue> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Blazor.Diagrams; | ||
using Blazor.Diagrams.Core.Geometry; | ||
using Blazor.Diagrams.Core.Models; | ||
using Blazor.Diagrams.Models; | ||
using SharedDemo.Demos.Nodes; | ||
|
||
namespace SharedDemo.Demos.CustomSvgGroup | ||
{ | ||
partial class Demo | ||
{ | ||
private readonly Diagram _diagram = new Diagram(); | ||
|
||
protected override void OnInitialized() | ||
{ | ||
base.OnInitialized(); | ||
|
||
LayoutData.Title = "Custom SVG group"; | ||
LayoutData.Info = "Creating your own custom svg groups is very easy!"; | ||
LayoutData.DataChanged(); | ||
|
||
_diagram.RegisterModelComponent<CustomSvgGroupModel, CustomSvgGroupWidget>(); | ||
_diagram.RegisterModelComponent<SvgNodeModel, SvgNodeWidget>(); | ||
|
||
var node1 = NewNode(50, 50); | ||
var node2 = NewNode(300, 300); | ||
var node3 = NewNode(500, 100); | ||
|
||
_diagram.Nodes.Add(new[] { node1, node2, node3 }); | ||
_diagram.AddGroup(new CustomSvgGroupModel(new[] { node2, node3 }, "Group 1")); | ||
|
||
_diagram.Links.Add(new LinkModel(node1.GetPort(PortAlignment.Right), node2.GetPort(PortAlignment.Left))); | ||
_diagram.Links.Add(new LinkModel(node2.GetPort(PortAlignment.Right), node3.GetPort(PortAlignment.Left))); | ||
} | ||
|
||
private NodeModel NewNode(double x, double y) | ||
{ | ||
var node = new SvgNodeModel(new Point(x, y)); | ||
node.AddPort(PortAlignment.Bottom); | ||
node.AddPort(PortAlignment.Top); | ||
node.AddPort(PortAlignment.Left); | ||
node.AddPort(PortAlignment.Right); | ||
return node; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.