Skip to content

Commit

Permalink
docs: Nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
zHaytam committed Mar 22, 2021
1 parent 66bd785 commit bb736de
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 9 deletions.
7 changes: 7 additions & 0 deletions samples/SharedDemo/Demos/Nodes/PortlessLinks.razor
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>
46 changes: 46 additions & 0 deletions samples/SharedDemo/Demos/Nodes/PortlessLinks.razor.cs
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) { }
}
}
5 changes: 5 additions & 0 deletions samples/SharedDemo/Demos/Nodes/RoundedNodeWidget.razor
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; }
}
7 changes: 7 additions & 0 deletions samples/SharedDemo/Demos/Nodes/SvgDemo.razor
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>
41 changes: 41 additions & 0 deletions samples/SharedDemo/Demos/Nodes/SvgDemo.razor.cs
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;
}
}
}
14 changes: 14 additions & 0 deletions samples/SharedDemo/Demos/Nodes/SvgNodeWidget.razor
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; }
}
26 changes: 17 additions & 9 deletions samples/SharedDemo/Layouts/DemoLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,12 @@
<DemoMenu Href="demos/zoomtofit" Text="Zoom to fit" />
<DemoMenu Href="demos/snaptogrid" Text="Snap to Grid" />
<DemoMenu Href="demos/drag-and-drop" Text="Drag & Drop" />
<DemoMenu Text="Groups">
<li>
<a href="demos/groups" class="list-group-item list-group-item-action bg-light">Simple</a>
</li>
<li>
<a href="demos/groups-factory" class="list-group-item list-group-item-action bg-light">Factory</a>
</li>
<DemoMenu Text="Nodes">
<li>
<a href="demos/groups-dynamic" class="list-group-item list-group-item-action bg-light">Dynamic</a>
<a href="nodes/svg" class="list-group-item list-group-item-action bg-light">SVG</a>
</li>
<li>
<a href="demos/groups-custom-shortcut" class="list-group-item list-group-item-action bg-light">Custom shortcut</a>
<a href="nodes/portless-links" class="list-group-item list-group-item-action bg-light">Portless Links</a>
</li>
</DemoMenu>
<DemoMenu Text="Links">
Expand All @@ -73,6 +67,20 @@
<a href="links/path-generators" class="list-group-item list-group-item-action bg-light">Path generators</a>
</li>
</DemoMenu>
<DemoMenu Text="Groups">
<li>
<a href="demos/groups" class="list-group-item list-group-item-action bg-light">Simple</a>
</li>
<li>
<a href="demos/groups-factory" class="list-group-item list-group-item-action bg-light">Factory</a>
</li>
<li>
<a href="demos/groups-dynamic" class="list-group-item list-group-item-action bg-light">Dynamic</a>
</li>
<li>
<a href="demos/groups-custom-shortcut" class="list-group-item list-group-item-action bg-light">Custom shortcut</a>
</li>
</DemoMenu>
<DemoMenu Text="Customization">
<li>
<a href="demos/custom-node" class="list-group-item list-group-item-action bg-light">Custom node</a>
Expand Down

0 comments on commit bb736de

Please sign in to comment.