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
7 changed files
with
137 additions
and
9 deletions.
There are no files selected for viewing
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 "/nodes/portless-links" | ||
@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,46 @@ | ||
using Blazor.Diagrams.Core.Models; | ||
using Blazor.Diagrams.Core; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Blazor.Diagrams.Core.Geometry; | ||
|
||
namespace SharedDemo.Demos.Nodes | ||
{ | ||
public partial class PortlessLinks | ||
{ | ||
private Diagram _diagram = new Diagram(); | ||
|
||
protected override void OnInitialized() | ||
{ | ||
base.OnInitialized(); | ||
|
||
LayoutData.Title = "Portless Links"; | ||
LayoutData.Info = "Starting from 2.0, you can create links between nodes directly! " + | ||
"All you need to specify is the shape of your nodes in order to calculate the connection points."; | ||
LayoutData.DataChanged(); | ||
|
||
InitializeDiagram(); | ||
} | ||
|
||
private void InitializeDiagram() | ||
{ | ||
_diagram.RegisterModelComponent<RoundedNode, RoundedNodeWidget>(); | ||
|
||
var node1 = new NodeModel(new Point(80, 80), shape: Shapes.Rectangle); | ||
var node2 = new RoundedNode(new Point(280, 150), shape: Shapes.Circle); | ||
_diagram.Nodes.Add(node1); | ||
_diagram.Nodes.Add(node2); | ||
_diagram.Links.Add(new LinkModel(node1, node2) | ||
{ | ||
SourceMarker = LinkMarker.Arrow, | ||
TargetMarker = LinkMarker.Arrow | ||
}); | ||
} | ||
} | ||
|
||
class RoundedNode : NodeModel | ||
{ | ||
public RoundedNode(Point position = null, ShapeDefiner shape = null) : base(position, RenderLayer.HTML, shape) { } | ||
} | ||
} |
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,5 @@ | ||
<div style="border-radius: 50%; width: 100px; height: 100px; background: blue;"></div> | ||
|
||
@code { | ||
[Parameter] public NodeModel Node { 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 "/nodes/svg" | ||
@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,41 @@ | ||
using Blazor.Diagrams.Core; | ||
using Blazor.Diagrams.Core.Geometry; | ||
using Blazor.Diagrams.Core.Models; | ||
|
||
namespace SharedDemo.Demos.Nodes | ||
{ | ||
public partial class SvgDemo | ||
{ | ||
private Diagram _diagram = new Diagram(); | ||
|
||
protected override void OnInitialized() | ||
{ | ||
base.OnInitialized(); | ||
|
||
LayoutData.Title = "SVG Nodes"; | ||
LayoutData.Info = "You can also have SVG nodes! All you need to do is to set the Layer to RenderLayer.SVG."; | ||
LayoutData.DataChanged(); | ||
|
||
InitializeDiagram(); | ||
} | ||
|
||
private void InitializeDiagram() | ||
{ | ||
_diagram.Options.DefaultNodeComponent = typeof(SvgNodeWidget); | ||
|
||
var node1 = NewNode(80, 80); | ||
var node2 = NewNode(280, 150); | ||
_diagram.Nodes.Add(node1); | ||
_diagram.Nodes.Add(node2); | ||
_diagram.Links.Add(new LinkModel(node1.GetPort(PortAlignment.Right), node2.GetPort(PortAlignment.Left))); | ||
} | ||
|
||
private NodeModel NewNode(double x, double y) | ||
{ | ||
var node = new NodeModel(new Point(x, y), RenderLayer.SVG); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<path d="M 0 -50 L 50 -50 L 50 -10 A 1 1 0 0 0 50 10 L 50 50 L 0 50 L 0 10 A 1 1 0 0 0 0 -10 Z" | ||
fill="black"></path> | ||
|
||
<PortRenderer Port="Node.GetPort(PortAlignment.Left)"> | ||
<circle cx="0" cy="0" r="8"></circle> | ||
</PortRenderer> | ||
|
||
<PortRenderer Port="Node.GetPort(PortAlignment.Right)"> | ||
<circle cx="50" cy="0" r="8"></circle> | ||
</PortRenderer> | ||
|
||
@code { | ||
[Parameter] public NodeModel Node { 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