Example of UML Activity Diagram in ASP.NET MVC Diagram Control
UML Activity Diagram: an order from its start to its end, with a decision, a fork and join of two parallel actions, a merge and a note.
@Html.UiSymbolPalette((UiSymbolPaletteOptions)ViewData["palette"])
@Html.UiDiagram((UiDiagramOptions)ViewData["diagram"])
<p>
UML Activity Diagram: an order from its start to its end, with a decision, a fork and join of two parallel actions, a merge
and a note.
</p>
<div class="row g-2">
<div class="col-lg-3">
@Html.UiSymbolPalette((UiSymbolPaletteOptions)ViewData["palette"])
</div>
<div class="col-lg-9">
@Html.UiDiagram((UiDiagramOptions)ViewData["diagram"])
</div>
</div>
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/UmlActivityDiagram.cshtml; it draws what ViewData holds.
public ActionResult UmlActivityDiagram()
{
{
ViewData["palette"] = new UiSymbolPaletteOptions
{
Id = "activityPalette", TargetId = "activityDiagram", Height = "720px", Width = "100%", AriaLabel = "UML activity shapes",
Palettes = new List<UiSymbolPalette>
{
Group("actions", "Actions and control", UiDiagramShapeType.UmlActivity, "Action:140:44", "Decision:50:50", "Merge:50:50", "Initial:30:30", "Final:32:32",
"FlowFinal:32:32", "Fork:200:8", "Join:200:8"),
Group("signals", "Signals and notes", UiDiagramShapeType.UmlActivity, "TimeEvent:30:40", "AcceptEvent:140:44", "SendSignal:140:44", "Note:150:56", "StructuredNode:200:140"),
new UiSymbolPalette
{
Id = "activityFlows", Title = "Flows",
ConnectorSymbols = new List<UiDiagramConnector> { LinkSymbol("controlFlow", Flow("x", null, null)), LinkSymbol("noteLink", Flow("x", null, null, null, UiDiagramConnectorType.Straight, "4 3", UiDiagramDecoratorShape.None)) }
}
}
};
}
{
ViewData["diagram"] = new UiDiagramOptions
{
Id = "activityDiagram",
LineRouting = true,
Height = "720px",
AriaLabel = "UML activity diagram of an order",
Nodes = new List<UiDiagramNode>
{
Shape("initial", 300, 40, UiDiagramShapeType.UmlActivity, "Initial", 30, 30),
Shape("receive", 300, 110, UiDiagramShapeType.UmlActivity, "Action", 140, 44, "Receive order"),
Shape("decide", 300, 190, UiDiagramShapeType.UmlActivity, "Decision", 50, 50),
Shape("fill", 300, 280, UiDiagramShapeType.UmlActivity, "Action", 140, 44, "Fill order"),
Shape("reject", 540, 280, UiDiagramShapeType.UmlActivity, "Action", 140, 44, "Reject order"),
Shape("fork", 300, 350, UiDiagramShapeType.UmlActivity, "Fork", 200, 8),
Shape("invoice", 200, 420, UiDiagramShapeType.UmlActivity, "SendSignal", 140, 44, "Send invoice"),
Shape("shipping", 400, 420, UiDiagramShapeType.UmlActivity, "Action", 140, 44, "Ship order"),
Shape("join", 300, 490, UiDiagramShapeType.UmlActivity, "Join", 200, 8),
Shape("merge", 300, 550, UiDiagramShapeType.UmlActivity, "Merge", 50, 50),
Shape("close", 300, 625, UiDiagramShapeType.UmlActivity, "Action", 120, 44, "Close order"),
Shape("final", 300, 690, UiDiagramShapeType.UmlActivity, "Final", 32, 32),
Shape("note", 560, 140, UiDiagramShapeType.UmlActivity, "Note", 150, 56, "Orders over $1,000 need a manager", "#fffde7")
},
Connectors = new List<UiDiagramConnector>
{
Flow("a1", "initial", "receive"), Flow("a2", "receive", "decide"), Flow("a3", "decide", "fill", "[accepted]"),
Flow("a4", "decide", "reject", "[rejected]"), Flow("a5", "fill", "fork"), Flow("a6", "fork", "invoice"), Flow("a7", "fork", "shipping"),
Flow("a8", "invoice", "join"), Flow("a9", "shipping", "join"), Flow("a10", "join", "merge"), Flow("a11", "reject", "merge"),
Flow("a12", "merge", "close"), Flow("a13", "close", "final"),
Flow("a14", "note", "decide", null, UiDiagramConnectorType.Straight, "4 3", UiDiagramDecoratorShape.None)
}
};
}
return View();
}
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;
}
private static UiDiagramNode Shape(string id, double x, double y, UiDiagramShapeType type, string shape, double width, double height, string text = null, 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;
}
/// <summary>A connector of a given look: its line's dashes, its ends' decorators (a hollow end has a transparent fill).</summary>
private static UiDiagramConnector Flow(string id, string from, string to, string label = null, UiDiagramConnectorType type = UiDiagramConnectorType.Orthogonal,
string dashes = null, UiDiagramDecoratorShape target = UiDiagramDecoratorShape.Arrow, bool hollowTarget = false,
UiDiagramDecoratorShape source = UiDiagramDecoratorShape.None, bool hollowSource = false)
{
UiDiagramConnector c = Link(id, from, to, label, type);
c.Style = new UiDiagramStyle { StrokeDashArray = dashes };
c.TargetDecorator = new UiDiagramDecorator { Shape = target, Width = 12, Height = 10, Style = new UiDiagramStyle { Fill = hollowTarget ? "transparent" : null } };
c.SourceDecorator = new UiDiagramDecorator { Shape = source, Width = 14, Height = 10, Style = new UiDiagramStyle { Fill = hollowSource ? "transparent" : null } };
return c;
}
/// <summary>A connector symbol for a palette: a sample of the line, not attached to anything.</summary>
private static UiDiagramConnector LinkSymbol(string id, UiDiagramConnector look)
{
look.Id = id;
look.SourceID = null;
look.TargetID = null;
look.SourcePoint = new UiDiagramPoint { X = 0, Y = 0 };
look.TargetPoint = new UiDiagramPoint { X = 120, Y = 60 };
look.Annotations.Clear();
return look;
}
private static UiSymbolPalette Group(string id, string title, UiDiagramShapeType type, params string[] shapes)
{
return new UiSymbolPalette
{
Id = id, Title = title,
Symbols = shapes.Select(sh =>
{
string[] parts = sh.Split(':');
double w = parts.Length > 1 ? double.Parse(parts[1], System.Globalization.CultureInfo.InvariantCulture) : 100;
double h = parts.Length > 2 ? double.Parse(parts[2], System.Globalization.CultureInfo.InvariantCulture) : 60;
return Shape(parts[0].ToLowerInvariant(), 0, 0, type, parts[0], w, h);
}).ToList()
};
}
}
}
@* 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>