Example of Grouping And Ordering in ASP.NET MVC Diagram Control
Grouping And Ordering: Left and Right are a group, selected and moved as one. Select two or more shapes (Shift or Ctrl and click, or Ctrl+A) and group them; select a group and ungroup it. The overlapping circles can be brought to the front or sent back. Keys: Ctrl+G group, Ctrl+Shift+U ungroup, Ctrl+Shift+F front, Ctrl+Shift+B back, Ctrl+] forward, Ctrl+[ backward.
@Html.UiDiagram((UiDiagramOptions)ViewData["diagram"])
<p>
Grouping And Ordering: Left and Right are a group, selected and moved as one. Select two or more shapes (Shift or Ctrl and click,
or Ctrl+A) and group them; select a group and ungroup it. The overlapping circles can be brought to the front or sent back.
Keys: Ctrl+G group, Ctrl+Shift+U ungroup, Ctrl+Shift+F front, Ctrl+Shift+B back, Ctrl+] forward, Ctrl+[ backward.
</p>
<div class="mb-2" role="toolbar" aria-label="Grouping and ordering" data-dg-target="groupingDiagram">
<button type="button" class="btn btn-sm btn-outline-primary mb-1" data-dg-command="group">Group</button>
<button type="button" class="btn btn-sm btn-outline-primary mb-1" data-dg-command="unGroup">Ungroup</button>
<button type="button" class="btn btn-sm btn-outline-primary mb-1" data-dg-command="bringToFront">Bring to front</button>
<button type="button" class="btn btn-sm btn-outline-primary mb-1" data-dg-command="sendToBack">Send to back</button>
<button type="button" class="btn btn-sm btn-outline-primary mb-1" data-dg-command="moveForward">Bring forward</button>
<button type="button" class="btn btn-sm btn-outline-primary mb-1" data-dg-command="sendBackward">Send backward</button>
</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; }
}
/** OnSelectionChange: what is selected. */
function selected(args) {
status(args.newValue.length ? 'Selected: ' + args.newValue.map(function (o) { return o.id; }).join(', ') : 'Nothing selected.');
}
/** The toolbar's buttons: data-dg-command is the diagram's method, data-dg-arg its argument. */
document.addEventListener('click', function (e) {
var button = e.target.closest ? e.target.closest('[data-dg-command]') : null;
if (!button) { return; }
var bar = button.closest('[data-dg-target]');
var diagram = bar ? Lumen.get(bar.getAttribute('data-dg-target')) : null;
if (!diagram) { return; }
var arg = button.getAttribute('data-dg-arg');
var done = diagram[button.getAttribute('data-dg-command')](arg === null ? undefined : arg);
var nothing = done === false || done === null || done === 0 || (Array.isArray(done) && !done.length);
status(button.textContent + (nothing ? ': nothing to do (select more, or something else).' : ': done.'));
});
return { selected: selected };
})();
</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/GroupingAndOrdering.cshtml; it draws what ViewData holds.
public ActionResult GroupingAndOrdering()
{
var group = new UiDiagramNode { Id = "pair", Shape = new UiDiagramShape { Type = UiDiagramShapeType.Group }, Children = new List<string> { "left", "right" } };
ViewData["diagram"] = new UiDiagramOptions
{
Id = "groupingDiagram",
Height = "460px",
AriaLabel = "Grouping and ordering",
Nodes = new List<UiDiagramNode>
{
Node("left", 120, 120, "Left", UiDiagramShapeType.Basic, "Rectangle", 110, 70, "#e8f0fe"),
Node("right", 250, 120, "Right", UiDiagramShapeType.Basic, "Rectangle", 110, 70, "#e8f0fe"),
group,
Node("red", 460, 170, "Red", UiDiagramShapeType.Basic, "Ellipse", 130, 100, "#f8d7da"),
Node("green", 520, 210, "Green", UiDiagramShapeType.Basic, "Ellipse", 130, 100, "#d4edda"),
Node("blue", 580, 250, "Blue", UiDiagramShapeType.Basic, "Ellipse", 130, 100, "#cce5ff")
},
OnSelectionChange = "DiagramSamples.selected"
};
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;
}
}
}
@* 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>