Example of Nodes in ASP.NET MVC Diagram Control
This sample visualizes the different stages of a software development life cycle using a circular flow diagram. Customizing the appearance of the nodes is illustrated in this example: click a style in the property panel to change how the nodes look. The Lock check box stops the nodes from being moved, resized, rotated or deleted (they can still be selected).
Properties
Appearance
Behaviour
@using System.Collections.Generic
@Html.UiDiagram(new UiDiagramOptions
{
Id = "nodesDiagram",
Height = "700px",
AriaLabel = "Software development life cycle",
Nodes = (List<UiDiagramNode>)ViewData["nodes"],
Connectors = (List<UiDiagramConnector>)ViewData["connectors"]
})
@Html.UiCheckBox("lock", false, new UiCheckBoxOptions { Id = "lock", Label = "Lock", OnChange = "DiagramSamples.lockChanged" })
@using System.Collections.Generic
<p>
This sample visualizes the different stages of a software development life cycle using a circular flow diagram. Customizing the
appearance of the nodes is illustrated in this example: click a style in the property panel to change how the nodes look. The Lock
check box stops the nodes from being moved, resized, rotated or deleted (they can still be selected).
</p>
<div style="display:flex; gap:12px; align-items:flex-start">
<div style="flex:1; min-width:0">
@Html.UiDiagram(new UiDiagramOptions
{
Id = "nodesDiagram",
Height = "700px",
AriaLabel = "Software development life cycle",
Nodes = (List<UiDiagramNode>)ViewData["nodes"],
Connectors = (List<UiDiagramConnector>)ViewData["connectors"]
})
</div>
<div style="width:300px; border:1px solid var(--ui-border, #d5d5d5); border-radius:4px; padding:12px">
<div style="font-weight:600; margin-bottom:10px">Properties</div>
<div style="font-size:13px; font-weight:500; margin-bottom:6px">Appearance</div>
<div id="nodeStyles" style="display:flex; gap:6px; margin-bottom:14px">
<button type="button" data-node-style="plain" aria-pressed="true" title="No outline" aria-label="No outline" style="width:70px; height:70px; background:#fff; border:2px solid #d5d5d5; border-radius:4px">
<span style="display:block; width:44px; height:44px; margin:auto; border-radius:50%; background:#37909A"></span>
</button>
<button type="button" data-node-style="outline" aria-pressed="false" title="Outline" aria-label="Outline" style="width:70px; height:70px; background:#fff; border:2px solid #d5d5d5; border-radius:4px">
<span style="display:block; width:44px; height:44px; margin:auto; border-radius:50%; background:#37909A; border:2px solid #024249; box-sizing:border-box"></span>
</button>
<button type="button" data-node-style="dashed" aria-pressed="false" title="Dashed outline" aria-label="Dashed outline" style="width:70px; height:70px; background:#fff; border:2px solid #d5d5d5; border-radius:4px">
<span style="display:block; width:44px; height:44px; margin:auto; border-radius:50%; background:#37909A; border:2px dashed #024249; box-sizing:border-box"></span>
</button>
</div>
<div style="font-size:13px; font-weight:500; margin-bottom:6px">Behaviour</div>
@Html.UiCheckBox("lock", false, new UiCheckBoxOptions { Id = "lock", Label = "Lock", OnChange = "DiagramSamples.lockChanged" })
</div>
</div>
<script>
window.DiagramSamples = (function () {
'use strict';
function diagram() { return Lumen.get('nodesDiagram'); }
// The appearance buttons: the outline of every node (its width, and its dashes).
var STYLES = { plain: [0, null], outline: [2, null], dashed: [2, '5 5'] };
document.addEventListener('click', function (e) {
var b = e.target.closest ? e.target.closest('[data-node-style]') : null;
if (!b) { return; }
var s = STYLES[b.getAttribute('data-node-style')];
var d = diagram();
d.nodes.forEach(function (node) {
node.style.fill = '#37909A';
node.style.strokeColor = '#024249';
node.style.strokeWidth = s[0];
node.style.strokeDashArray = s[1];
});
d.dataBind();
Array.prototype.forEach.call(document.querySelectorAll('[data-node-style]'), function (other) {
other.setAttribute('aria-pressed', other === b ? 'true' : 'false');
other.style.borderColor = other === b ? '#006CE6' : '#d5d5d5';
});
});
/** The Lock check box: a locked node or connector can be selected, and nothing else. */
function lockChanged(checked) {
var d = diagram();
var constraints = checked ? 'Select' : 'Default';
d.nodes.forEach(function (node) { node.constraints = constraints; });
d.connectors.forEach(function (connector) { connector.constraints = constraints; });
d.dataBind();
}
return { lockChanged: lockChanged };
})();
</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/Nodes.cshtml; it draws what ViewData holds.
public ActionResult Nodes()
{
// A teal circle with white text: its X and Y are its centre, in pixels.
Func<string, double, double, string, UiDiagramNode> circle = (id, x, y, text) => new UiDiagramNode
{
Id = id, OffsetX = x, OffsetY = y, Width = 100, Height = 100,
Shape = new UiDiagramShape { Type = UiDiagramShapeType.Basic, Shape = "Ellipse" },
Style = new UiDiagramStyle { Fill = "#37909A", StrokeColor = "#024249" },
Annotations = { new UiDiagramAnnotation { Content = text, Style = new UiDiagramStyle { Color = "#ffffff" } } }
};
var nodes = new List<UiDiagramNode>
{
circle("sdlc", 270, 250, "SDLC"),
circle("analysis", 270, 110, "Analysis"),
circle("design", 405, 205, "Design"),
circle("implement", 352, 370, "Implement"),
circle("deploy", 184, 370, "Deploy"),
circle("support", 130, 205, "Support")
};
// Each stage points to the next one, round the ring (the first node, SDLC, is the middle).
var connectors = new List<UiDiagramConnector>();
for (int i = 1; i < nodes.Count; i++)
{
connectors.Add(new UiDiagramConnector
{
Id = "link" + i,
SourceID = nodes[i].Id,
TargetID = nodes[(i % 5) + 1].Id,
Style = new UiDiagramStyle { StrokeColor = "#024249", StrokeWidth = 2 },
TargetDecorator = new UiDiagramDecorator { Style = new UiDiagramStyle { Fill = "#024249", StrokeColor = "#024249" } }
});
}
ViewData["nodes"] = nodes;
ViewData["connectors"] = connectors;
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>