Example of Swimlane in ASP.NET MVC Diagram Control
Swimlane: an order's fulfilment in three lanes (who does each step) and two phases (when). Drag a step into another lane and it belongs to that lane; drag the swimlane by its header and its steps go with it. The status says which lane a moved step is in.
@Html.UiDiagram((UiDiagramOptions)ViewData["diagram"])
<p>
Swimlane: an order's fulfilment in three lanes (who does each step) and two phases (when). Drag a step into another lane and it
belongs to that lane; drag the swimlane by its header and its steps go with it. The status says which lane a moved step is in.
</p>
@Html.UiDiagram((UiDiagramOptions)ViewData["diagram"])
<p class="small text-muted mt-2" id="diagramStatus" role="status" aria-live="polite"></p>
<script>
window.DiagramSamples = (function () {
'use strict';
function status(text) {
var el = document.getElementById('diagramStatus');
if (el) { el.textContent = text; }
}
function nameOf(o) { return o.annotations && o.annotations.length && o.annotations[0].content ? o.annotations[0].content : o.id; }
/** OnPositionChange: where a moved node is, once the move is finished (it may have joined or left a lane or a container). */
function moved(args) {
if (args.state !== 'Completed') { return; }
var diagram = Lumen.get(document.querySelector('.ui-diagram').id);
window.setTimeout(function () {
var p = diagram.getParent(args.source.id);
status(nameOf(args.source) + (p ? ' is in ' + (p.lane ? 'the ' + p.lane + ' lane' : nameOf(p.node)) : ' is not in a lane or a container') + '.');
}, 0);
}
return { moved: moved };
})();
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class DiagramController : Controller
{
// The page is Views/Diagram/Swimlane.cshtml; it draws what ViewData holds.
public ActionResult Swimlane()
{
var lane = new UiDiagramNode
{
Id = "fulfilment", OffsetX = 335, OffsetY = 227, Width = 630, Height = 414,
Shape = new UiDiagramShape
{
Type = UiDiagramShapeType.SwimLane, HeaderHeight = 30,
Phases = new List<UiDiagramPhase>
{
new UiDiagramPhase { Id = "ordering", Header = "Ordering", Size = 300 },
new UiDiagramPhase { Id = "delivery", Header = "Delivery", Size = 300 }
},
Lanes = new List<UiDiagramLane>
{
new UiDiagramLane { Id = "customer", Header = "Customer", Size = 120, Children = new List<string> { "placeOrder", "receiveGoods" } },
new UiDiagramLane { Id = "sales", Header = "Sales", Size = 120, Children = new List<string> { "confirmOrder", "sendInvoice" } },
new UiDiagramLane { Id = "warehouse", Header = "Warehouse", Size = 120, Children = new List<string> { "pickItems" } }
}
},
Style = new UiDiagramStyle { Fill = "#f5f9ff" }
};
lane.Annotations.Add(new UiDiagramAnnotation { Content = "Order fulfilment", Style = new UiDiagramStyle { Bold = true } });
ViewData["diagram"] = new UiDiagramOptions
{
Id = "swimlaneDiagram",
Height = "500px",
AriaLabel = "Order fulfilment swimlane",
Nodes = new List<UiDiagramNode>
{
lane,
Node("placeOrder", 200, 134, "Place order", UiDiagramShapeType.Flow, "Terminator"),
Node("receiveGoods", 500, 134, "Receive goods", UiDiagramShapeType.Flow, "Terminator"),
Node("confirmOrder", 200, 254, "Confirm order"),
Node("sendInvoice", 500, 254, "Send invoice", UiDiagramShapeType.Flow, "Document"),
Node("pickItems", 500, 374, "Pick and pack")
},
Connectors = new List<UiDiagramConnector>
{
Link("c1", "placeOrder", "confirmOrder"),
Link("c2", "confirmOrder", "pickItems"),
Link("c3", "pickItems", "receiveGoods"),
Link("c4", "confirmOrder", "sendInvoice")
},
OnPositionChange = "DiagramSamples.moved"
};
return View();
}
private static UiDiagramNode Node(string id, double x, double y, string text, UiDiagramShapeType type = UiDiagramShapeType.Flow, string shape = "Process",
double width = 120, double height = 54, string fill = null)
{
var node = new UiDiagramNode
{
Id = id, OffsetX = x, OffsetY = y, Width = width, Height = height,
Shape = new UiDiagramShape { Type = type, Shape = shape },
Style = new UiDiagramStyle { Fill = fill }
};
if (text != null) { node.Annotations.Add(new UiDiagramAnnotation { Content = text }); }
return node;
}
private static UiDiagramConnector Link(string id, string from, string to, string label = null,
UiDiagramConnectorType type = UiDiagramConnectorType.Orthogonal)
{
var c = new UiDiagramConnector { Id = id, SourceID = from, TargetID = to, Type = type };
if (label != null) { c.Annotations.Add(new UiDiagramAnnotation { Content = label, Offset = new UiDiagramPoint { X = 0.5, Y = 0 } }); }
return c;
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>