Example of Organizational Layout in ASP.NET MVC Diagram Control
Organizational Layout: the chart is made from rows (each person and the one they report to). The people under a manager who has no one under them go in a column: on both sides of the line (Alternate), to one side, or in a row. Change it, or the orientation.
@Html.UiDiagram((UiDiagramOptions)ViewData["diagram"])
<p>
Organizational Layout: the chart is made from rows (each person and the one they report to). The people under a manager who has
no one under them go in a column: on both sides of the line (Alternate), to one side, or in a row. Change it, or the orientation.
</p>
<div class="d-flex flex-wrap gap-3 align-items-center mb-2" role="group" aria-label="Layout" data-dg-target="orgDiagram">
<label class="d-flex align-items-center gap-1">Orientation
<select class="form-select form-select-sm" data-layout="orientation"><option selected>TopToBottom</option><option>BottomToTop</option><option>LeftToRight</option><option>RightToLeft</option></select>
</label>
<label class="d-flex align-items-center gap-1">Leaves
<select class="form-select form-select-sm" data-layout="leafLayout"><option selected>Alternate</option><option>Left</option><option>Right</option><option>Horizontal</option></select>
</label>
</div>
@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; }
}
var fills = { Executive: '#c5cae9', Director: '#bbdefb', Manager: '#d7ecd9', Staff: '#fff3e0' };
/** DoBinding: the colour from the role, the role in the tooltip. */
function bind(node, row) {
node.style.fill = fills[row.Role] || null;
node.tooltip = { content: row.Name + ', ' + row.Role };
}
/** The layout's controls: data-layout is the setting, the diagram is laid out again with it. */
document.addEventListener('change', function (e) {
var control = e.target && e.target.closest ? e.target.closest('[data-layout]') : null;
if (!control) { return; }
var diagram = Lumen.get(control.closest('[data-dg-target]').getAttribute('data-dg-target'));
var setting = {};
setting[control.getAttribute('data-layout')] = control.type === 'number' ? Number(control.value) : control.value;
diagram.doLayout(setting);
var l = diagram.getLayout();
status('Laid out again: ' + l.type + ', ' + l.orientation + (l.type === 'OrganizationalChart' ? ', leaves ' + l.leafLayout : '') + '.');
});
return { bind: bind };
})();
</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/OrganizationalLayout.cshtml; it draws what ViewData holds.
public ActionResult OrganizationalLayout()
{
var rows = new List<Employee>
{
new Employee { Id = "ceo", Name = "Maria Anders", Role = "Executive" },
new Employee { Id = "sales", ParentId = "ceo", Name = "Ana Trujillo", Role = "Director" },
new Employee { Id = "tech", ParentId = "ceo", Name = "Thomas Hardy", Role = "Director" },
new Employee { Id = "ops", ParentId = "ceo", Name = "Hanna Moos", Role = "Director" },
new Employee { Id = "north", ParentId = "sales", Name = "Antonio Moreno", Role = "Manager" },
new Employee { Id = "south", ParentId = "sales", Name = "Christina Berglund", Role = "Manager" },
new Employee { Id = "s1", ParentId = "north", Name = "Martin Sommer", Role = "Staff" },
new Employee { Id = "s2", ParentId = "north", Name = "Laurence Lebihan", Role = "Staff" },
new Employee { Id = "s3", ParentId = "north", Name = "Elizabeth Lincoln", Role = "Staff" },
new Employee { Id = "s4", ParentId = "south", Name = "Victoria Ashworth", Role = "Staff" },
new Employee { Id = "s5", ParentId = "south", Name = "Patricio Simpson", Role = "Staff" },
new Employee { Id = "t1", ParentId = "tech", Name = "Francisco Chang", Role = "Staff" },
new Employee { Id = "t2", ParentId = "tech", Name = "Yang Wang", Role = "Staff" },
new Employee { Id = "t3", ParentId = "tech", Name = "Pedro Afonso", Role = "Staff" },
new Employee { Id = "t4", ParentId = "tech", Name = "Aria Cruz", Role = "Staff" },
new Employee { Id = "o1", ParentId = "ops", Name = "Diego Roel", Role = "Staff" },
new Employee { Id = "o2", ParentId = "ops", Name = "Martine Rance", Role = "Staff" }
};
ViewData["diagram"] = new UiDiagramOptions
{
Id = "orgDiagram",
Height = "600px",
AriaLabel = "Organization chart",
DataSource = new UiDiagramDataSource
{
Data = rows, TextField = "Name", DoBinding = "DiagramSamples.bind",
NodeDefaults = new UiDiagramNode { Width = 140, Height = 44, Shape = new UiDiagramShape { Type = UiDiagramShapeType.Basic, Shape = "Rectangle", CornerRadius = 4 } },
ConnectorDefaults = new UiDiagramConnector { Type = UiDiagramConnectorType.Orthogonal, CornerRadius = 3 }
},
Layout = new UiDiagramLayout { Type = UiDiagramLayoutType.OrganizationalChart, HorizontalSpacing = 30, VerticalSpacing = 40, LeafLayout = UiDiagramLeafLayout.Alternate }
};
return View();
}
/// <summary>A row of the Local Data sample: an employee and the one they report to.</summary>
public class Employee
{
public string Id { get; set; }
public string ParentId { get; set; }
public string Name { get; set; }
public string Role { get; set; }
}
}
}
@* 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>