Example of WorkFlow Diagram in ASP.NET MVC Diagram Control
WorkFlow Diagram: a support ticket's workflow from left to right. Each step says who does it and where it is: done (green), in progress (yellow) or waiting (grey).
@Html.UiDiagram((UiDiagramOptions)ViewData["diagram"])
<p>
WorkFlow Diagram: a support ticket's workflow from left to right. Each step says who does it and where it is: done (green), in
progress (yellow) or waiting (grey).
</p>
@Html.UiDiagram((UiDiagramOptions)ViewData["diagram"])
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/WorkflowDiagram.cshtml; it draws what ViewData holds.
public ActionResult WorkflowDiagram()
{
System.Func<string, string, string, string, string, string, UiDiagramNode> step = (id, title, who, state, kind, fill) =>
{
UiDiagramNode n = Node(id, 0, 0, title, UiDiagramShapeType.Flow, kind, kind == "Decision" ? 200 : 160, kind == "Decision" ? 100 : 70, fill);
n.Annotations[0].Offset = new UiDiagramPoint { X = 0.5, Y = 0.3 };
n.Annotations[0].Style = new UiDiagramStyle { Bold = true };
n.Annotations.Add(new UiDiagramAnnotation { Content = who + " - " + state, Offset = new UiDiagramPoint { X = 0.5, Y = 0.7 }, Style = new UiDiagramStyle { FontSize = 11 } });
return n;
};
ViewData["diagram"] = new UiDiagramOptions
{
Id = "workflowDiagram",
Height = "820px",
AriaLabel = "Support ticket workflow",
Nodes = new List<UiDiagramNode>
{
step("opened", "Ticket opened", "Customer", "done", "Terminator", "#c8e6c9"),
step("triage", "Triage", "Help desk", "done", "Process", "#c8e6c9"),
step("known", "Known problem?", "Help desk", "done", "Decision", "#c8e6c9"),
step("answer", "Send the answer", "Help desk", "waiting", "Document", "#eeeeee"),
step("investigate", "Investigate", "Engineer", "in progress", "Process", "#fff59d"),
step("fix", "Fix and test", "Engineer", "waiting", "Process", "#eeeeee"),
step("confirm", "Customer confirms", "Customer", "waiting", "ManualInput", "#eeeeee"),
step("closedTicket", "Ticket closed", "Help desk", "waiting", "Terminator", "#eeeeee")
},
Connectors = new List<UiDiagramConnector>
{
Link("w1", "opened", "triage", null, UiDiagramConnectorType.Bezier), Link("w2", "triage", "known", null, UiDiagramConnectorType.Bezier),
Link("w3", "known", "answer", "Yes", UiDiagramConnectorType.Bezier), Link("w4", "known", "investigate", "No", UiDiagramConnectorType.Bezier),
Link("w5", "investigate", "fix", null, UiDiagramConnectorType.Bezier), Link("w6", "fix", "confirm", null, UiDiagramConnectorType.Bezier),
Link("w7", "answer", "confirm", null, UiDiagramConnectorType.Bezier), Link("w8", "confirm", "closedTicket", null, UiDiagramConnectorType.Bezier)
},
Layout = new UiDiagramLayout { Type = UiDiagramLayoutType.ComplexHierarchicalTree, HorizontalSpacing = 60, VerticalSpacing = 40 }
};
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>