Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Diagram/Server/Pages/Methods/AddAsyncMethod.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@page "/AddAsyncMethod"

@using Syncfusion.Blazor.Diagram
@using Syncfusion.Blazor.Buttons

<SfButton Content="Add Port and Annotation" OnClick="@AddPortAndAnnotationAsync" />

<SfDiagramComponent @ref="_diagram" Width="900px" Height="500px" Nodes="@_nodes" Connectors="@_connectors">
</SfDiagramComponent>

@code
{
// Reference the diagram.
private SfDiagramComponent _diagram;

// Initialize the nodes and connectors collections.
private DiagramObjectCollection<Node> _nodes = new DiagramObjectCollection<Node>();
private DiagramObjectCollection<Connector> _connectors = new DiagramObjectCollection<Connector>();

protected override void OnInitialized()
{
Node node = new Node()
{
ID = "node1",
OffsetX = 300,
OffsetY = 200,
Width = 120,
Height = 60,
Style = new ShapeStyle() { Fill = "#6495ED", StrokeColor = "#6495ED" },
Shape = new BasicShape() { Type = NodeShapes.Basic, Shape = NodeBasicShapes.Rectangle },
};

_nodes.Add(node);
}

private async Task AddPortAndAnnotationAsync()
{
Node node = _diagram.Nodes[0];

await node.Ports.AddAsync(new PointPort()
{
ID = "port1",
Offset = new DiagramPoint() { X = 1, Y = 0.5 },
Visibility = PortVisibility.Visible,
Height = 10,
Width = 10,
Style = new ShapeStyle() { Fill = "#FFFFFF", StrokeColor = "#1F3A93" }
});

await node.Annotations.AddAsync(new ShapeAnnotation()
{
Content = "Node 1",
Offset = new DiagramPoint() { X = 0.5, Y = 0.5 }
});
}
}
34 changes: 34 additions & 0 deletions Diagram/Server/Pages/Methods/AddDiagramElements.razor
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,44 @@
// Type of the connector
Type = ConnectorSegmentType.Straight,
};

Swimlane swimlane = new Swimlane()
{
ID = "swimlane1",
OffsetX = 650,
OffsetY = 200,
Height = 150,
Width = 450,
Header = new SwimlaneHeader()
{
Annotation = new ShapeAnnotation() { Content = "Sales Process" },
Height = 50,
},
Lanes = new DiagramObjectCollection<Lane>()
{
new Lane()
{
ID = "lane1",
Height = 100,
Header = new SwimlaneHeader()
{
Width = 30,
Annotation = new ShapeAnnotation() { Content = "Consumer" }
},
Children = new DiagramObjectCollection<Node>()
{
new Node(){Height = 50, Width = 50, LaneOffsetX = 100, LaneOffsetY = 30},
new Node(){Height = 50, Width = 50, LaneOffsetX = 250, LaneOffsetY = 30},
}
}
}
};

DiagramObjectCollection<NodeBase> nodeCollection = new DiagramObjectCollection<NodeBase>();
nodeCollection.Add(node1);
nodeCollection.Add(node2);
nodeCollection.Add(Connector);
nodeCollection.Add(swimlane);
await _diagram.AddDiagramElementsAsync(nodeCollection);
}
}