Skip to content

Commit c0ba221

Browse files
982382: Documentation for Allow drag within swimlane
1 parent 9ee1f3a commit c0ba221

File tree

1 file changed

+94
-13
lines changed

1 file changed

+94
-13
lines changed

blazor/diagram/swimlane/lane/interaction.md

Lines changed: 94 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ The following image shows children interaction in lane.
5050

5151
## How to restrict nodes from being dragged or repositioned outside their assigned swimlane
5252

53-
To restrict child nodes to their swimlane, set their [Constraints](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Diagram.Node.html#Syncfusion_Blazor_Diagram_Node_Constraints) to include [NodeConstraints.AllowDragWithinSwimlane](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Diagram.NodeConstraints.html#Syncfusion_Blazor_Diagram_NodeConstraints_AllowDragWithinSwimlane). By default, nodes can move freely; however, with this constraint enabled, a node can only be dragged within the bounds of its owning swimlane. Attempts to move it across lane or swimlane boundaries are prevented.
54-
55-
The following example demonstrates one node restricted to its swimlane, while another remains unrestricted for comparison.
53+
By default, nodes in a swimlane can be moved freely within and outside the swimlane boundaries. When **NodeConstraints.AllowDragWithinSwimlane** is enabled by the nodes [Constraints](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Diagram.Node.html#Syncfusion_Blazor_Diagram_Node_Constraints) property, nodes cannot be dragged outside the swimlane. If an attempt is made to move a node beyond the swimlane’s boundaries, a “not allowed” cursor appears, indicating the restriction.
54+
55+
To enforce this restriction for all child nodes within swimlanes, set the constraint during node initialization in the [NodeCreating](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Diagram.SfDiagramComponent.html#Syncfusion_Blazor_Diagram_SfDiagramComponent_NodeCreating) event. The constraint can also be enabled or disabled dynamically at runtime, for example, via a button click.
56+
57+
The following example demonstrates a node with the text "AllowDrag Within Swimlane" restricted to its swimlane boundaries:
5658

5759
```cshtml
5860
@using Syncfusion.Blazor.Diagram
@@ -115,7 +117,13 @@ The following example demonstrates one node restricted to its swimlane, while an
115117
}
116118
}
117119
},
118-
new Node(){Height = 50, Width = 50, LaneOffsetX = 250, LaneOffsetY = 30},
120+
new Node()
121+
{
122+
Height = 50,
123+
Width = 50,
124+
LaneOffsetX = 250,
125+
LaneOffsetY = 30
126+
},
119127
}
120128
},
121129
}
@@ -145,21 +153,94 @@ The following example demonstrates one node restricted to its swimlane, while an
145153
else if (obj is Node node)
146154
{
147155
node.Style = new ShapeStyle()
148-
{
149-
Fill = "#5b9bd5",
150-
StrokeColor = "#5b9bd5"
151-
};
156+
{
157+
Fill = "#5b9bd5",
158+
StrokeColor = "#5b9bd5"
159+
};
152160
}
153161
}
154162
}
155163
156164
```
157-
A complete working sample can be downloaded from [GitHub](https://github.com/SyncfusionExamples/Blazor-Diagram-Examples/tree/master/UG-Samples/Nodes/ActionsofNodes/AddNode)
158165

159-
![Allow Drag Within Swimlane](../Swimlane-images/AllowDragWithinSwimlane.gif)
166+
The following example demonstrates enabling or disabling `AllowDragWithinSwimlane` dynamically at runtime by a button click.
167+
168+
```cshtml
169+
@using Syncfusion.Blazor.Diagram
170+
171+
<button onclick="@AllowDrag">AllowDrag</button>
172+
<SfDiagramComponent Height="600px" Swimlanes="@SwimlaneCollections" NodeCreating="@OnNodeCreating" >
173+
<SnapSettings Constraints="SnapConstraints.None"></SnapSettings>
174+
</SfDiagramComponent>
175+
176+
@code
177+
{
178+
//Define diagram's swimlane collection
179+
DiagramObjectCollection<Swimlane> SwimlaneCollections = new DiagramObjectCollection<Swimlane>();
160180
161-
>**Note:**
162-
* To restrict a node to its owning swimlane, add [NodeConstraints.AllowDragWithinSwimlane](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Diagram.NodeConstraints.html#Syncfusion_Blazor_Diagram_NodeConstraints_AllowDragWithinSwimlane) to the node’s `Constraints` property.
181+
protected override void OnInitialized()
182+
{
183+
// A swimlane is created and stored in the swimlanes collection.
184+
Swimlane swimlane = new Swimlane()
185+
{
186+
Header = new SwimlaneHeader()
187+
{
188+
Annotation = new ShapeAnnotation()
189+
{
190+
Content = "SALES PROCESS FLOW CHART"
191+
},
192+
Height = 50,
193+
},
194+
OffsetX = 400,
195+
OffsetY = 200,
196+
Height = 120,
197+
Width = 450,
198+
Lanes = new DiagramObjectCollection<Lane>()
199+
{
200+
new Lane()
201+
{
202+
Height = 100,
203+
Header = new SwimlaneHeader()
204+
{
205+
Width = 30,
206+
Annotation = new ShapeAnnotation(){ Content = "Consumer" }
207+
},
208+
Children = new DiagramObjectCollection<Node>()
209+
{
210+
new Node()
211+
{
212+
Height = 50,
213+
Width = 100,
214+
LaneOffsetX = 250,
215+
LaneOffsetY = 30
216+
},
217+
}
218+
},
219+
}
220+
};
221+
// Add swimlane
222+
SwimlaneCollections.Add(swimlane);
223+
}
224+
225+
public void AllowDrag()
226+
{
227+
if (diagramComponent.SelectionSettings.Nodes.Count > 0)
228+
{
229+
if (diagramComponent.SelectionSettings.Nodes[0].Constraints.HasFlag(NodeConstraints.AllowDragWithinSwimlane))
230+
{
231+
diagramComponent.SelectionSettings.Nodes[0].Constraints &= ~NodeConstraints.AllowDragWithinSwimlane;
232+
233+
}
234+
else
235+
{
236+
diagramComponent.SelectionSettings.Nodes[0].Constraints |= NodeConstraints.AllowDragWithinSwimlane;
237+
}
238+
}
239+
}
240+
}
241+
242+
```
163243

164-
* To enforce this restriction for all child nodes within swimlanes, set the [Constraints](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Diagram.Node.html#Syncfusion_Blazor_Diagram_Node_Constraints) during node initialization in the NodeCreating event.
244+
{% previewsample "https://blazorplayground.syncfusion.com/embed/BjVeMBiRzuEmRSmS?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5" backgroundimage "[Allow Drag Within Swimlane](../Swimlane-images/AllowDragWithinSwimlane.gif)" %}
165245

246+
A complete working sample can be downloaded from [GitHub](https://github.com/SyncfusionExamples/Blazor-Diagram-Examples/tree/master/UG-Samples/Swimlanes/Lane/AllowDragWithinSwimlane/AllowDragWithinSwimlane)

0 commit comments

Comments
 (0)