Example of Shapes in ASP.NET MVC Diagram Control
This sample illustrates basic built-in shapes, such as basic shapes, flow shapes, and BPMN shapes. The Type of a node's
Shape chooses the kind, and its Shape the name.
@using System.Collections.Generic
@Html.UiDiagram(new UiDiagramOptions
{
Id = "shapesDiagram",
Height = "700px",
AriaLabel = "Basic, flow and BPMN shapes",
Nodes = (List<UiDiagramNode>)ViewData["nodes"]
})
@using System.Collections.Generic
<p>
This sample illustrates basic built-in shapes, such as basic shapes, flow shapes, and BPMN shapes. The <code>Type</code> of a node's
<code>Shape</code> chooses the kind, and its <code>Shape</code> the name.
</p>
@Html.UiDiagram(new UiDiagramOptions
{
Id = "shapesDiagram",
Height = "700px",
AriaLabel = "Basic, flow and BPMN shapes",
Nodes = (List<UiDiagramNode>)ViewData["nodes"]
})
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/Shapes.cshtml; it draws what ViewData holds.
public ActionResult Shapes()
{
var basic = new[] { "Rectangle", "Ellipse", "Triangle", "Plus", "Star", "Pentagon", "Heptagon", "Octagon", "Trapezoid", "Decagon", "RightTriangle", "Parallelogram" };
var flow = new[]
{
"Terminator", "Process", "Decision", "Document", "PreDefinedProcess", "PaperTap", "DirectData", "SequentialData", "Sort", "MultiDocument",
"Collate", "SummingJunction", "Or", "InternalStorage", "Extract", "ManualOperation", "Merge", "OffPageReference", "SequentialAccessStorage", "Data", "Card"
};
var bpmn = new[] { "StartEvent", "IntermediateEvent", "EndEvent", "Gateway", "Task", "SubProcess", "Message", "DataObject", "DataStore", "Group", "TextAnnotation" };
// "RightTriangle" is shown as "Right Triangle".
Func<string, string> words = name =>
{
string text = "";
foreach (char c in name) { text += (char.IsUpper(c) && text.Length > 0 ? " " : "") + c; }
return text;
};
var nodes = new List<UiDiagramNode>();
// A heading, then the shapes in rows of ten, 90 pixels apart, each with its name under it.
Action<string, UiDiagramShapeType, string[], double> group = (title, type, names, headingY) =>
{
nodes.Add(new UiDiagramNode
{
Id = type + "Title", OffsetX = 90, OffsetY = headingY, Width = 150, Height = 100,
Shape = new UiDiagramShape { Type = UiDiagramShapeType.Text, Content = title },
Style = new UiDiagramStyle { FontSize = 16, Bold = true },
Constraints = UiDiagramNodeConstraints.None
});
for (int i = 0; i < names.Length; i++)
{
string name = names[i];
// Most are 40 by 40; the flat flow shapes are lower.
double height = 40;
if (name == "Process" || name == "Terminator") { height = 20; }
else if (name == "Decision") { height = 35; }
else if (name == "Document" || name == "DirectData" || name == "MultiDocument" || name == "PreDefinedProcess") { height = 30; }
nodes.Add(new UiDiagramNode
{
Id = type + name, OffsetX = 60 + (i % 10) * 90, OffsetY = headingY + 50 + (i / 10) * 100, Width = 40, Height = height,
Shape = new UiDiagramShape { Type = type, Shape = name },
Annotations =
{
new UiDiagramAnnotation
{
Content = words(name), Offset = new UiDiagramPoint { X = 0.5, Y = 1 },
VerticalAlignment = UiDiagramVerticalAlignment.Top, Margin = new UiDiagramMargin { Top = 10 }
}
}
});
}
};
group("Basic Shapes", UiDiagramShapeType.Basic, basic, 50);
group("Flow Shapes", UiDiagramShapeType.Flow, flow, 300);
group("BPMN Shapes", UiDiagramShapeType.Bpmn, bpmn, 650);
ViewData["nodes"] = nodes;
return View();
}
}
}
@* 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>