Bezier Segments in Blazor Diagram Component
19 Aug 20246 minutes to read
How to edit bezier segments based on bezier connector settings
The intermediate point of two adjacent bezier segments can be edited interactively based on the BezierConnectorSettings.SegmentEditOrientation property of the Connector class.
SegmentEditOrientation value | Description | Output |
---|---|---|
Bidirectional | It allows the intermediate points to be dragged in either vertical or horizontal directions. | |
Freeform | It allows the intermediate points to be dragged in any direction. |
The following code illustrates how to interact with Bezier efficiently by using the BezierConnectorSettings.Smoothness and BezierConnectorSettings.SegmentEditOrientation properties of the Connector class.
@using Syncfusion.Blazor.Diagram
<SfDiagramComponent Width="1000px" Height="500px" Nodes="@nodes" Connectors="@connectors"></SfDiagramComponent>
@code {
//Define the diagram's connector collection.
DiagramObjectCollection<Connector> connectors = new DiagramObjectCollection<Connector>();
//Define the diagram's node collection.
DiagramObjectCollection<Node> nodes = new DiagramObjectCollection<Node>();
protected override void OnInitialized()
{
nodes.Add(
new Node()
{
ID = "node1",
OffsetX = 300,
OffsetY = 100,
Width = 100,
Height = 100,
Ports = new DiagramObjectCollection<PointPort>()
{
new PointPort()
{
ID="Port1",
Visibility = PortVisibility.Visible,
Offset = new DiagramPoint() { X = 1, Y = 0.5 },
},
}
});
nodes.Add(new Node()
{
ID = "node2",
OffsetX = 300,
OffsetY = 350,
Width = 100,
Height = 100,
Ports = new DiagramObjectCollection<PointPort>()
{
new PointPort()
{
ID="Port1",
Visibility = PortVisibility.Visible,
Offset = new DiagramPoint() { X = 0, Y = 0.5 },
},
}
});
Connector connector1 = new Connector()
{
ID = "connector1",
SourceID = "node1",
TargetID = "node2",
SourcePortID = "Port1",
TargetPortID = "Port1",
Type = ConnectorSegmentType.Bezier,
BezierConnectorSettings = new BezierConnectorSettings()
{
//Define the smoothness for a bezier connector.
Smoothness = BezierSmoothness.SymmetricAngle,
//Define the orientation of the segment editing controls.
SegmentEditOrientation = BezierSegmentEditOrientation.FreeForm
},
Constraints = ConnectorConstraints.Default | ConnectorConstraints.DragSegmentThumb
};
connectors.Add(connector1);
}
}
You can download a complete working sample from GitHub.