Example of Overview in ASP.NET MVC Diagram Control
Overview: the small view shows the whole diagram, the part in view outlined. Drag the outline, or click elsewhere in the overview, to move the view there; with the focus on the overview the arrow keys move the view (Shift: more) and Home goes back to the start.
@Html.UiDiagram((UiDiagramOptions)ViewData["diagram"])
@Html.UiDiagramOverview((UiDiagramOverviewOptions)ViewData["overview"])
<p>
Overview: the small view shows the whole diagram, the part in view outlined. Drag the outline, or click elsewhere in the overview, to
move the view there; with the focus on the overview the arrow keys move the view (Shift: more) and Home goes back to the start.
</p>
<div class="row g-2">
<div class="col-lg-9">
@Html.UiDiagram((UiDiagramOptions)ViewData["diagram"])
</div>
<div class="col-lg-3">
@Html.UiDiagramOverview((UiDiagramOverviewOptions)ViewData["overview"])
</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/Overview.cshtml; it draws what ViewData holds.
public ActionResult Overview()
{
{
UiDiagramOptions o = Spread("overviewDiagram", 10, 8, 220, 160);
o.AriaLabel = "A large diagram, with an overview";
o.Height = "440px";
ViewData["diagram"] = o;
}
{
ViewData["overview"] = new UiDiagramOverviewOptions { Id = "overview", SourceId = "overviewDiagram", Width = "100%", Height = "180px", AriaLabel = "Overview of the diagram" };
}
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;
}
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;
}
/// <summary>A flow of n steps across and down, for the samples that need room (zoom, scrolling, overview).</summary>
private static UiDiagramOptions Spread(string id, int across, int down, double gapX, double gapY)
{
var nodes = new List<UiDiagramNode>();
var links = new List<UiDiagramConnector>();
string[] fills = { "#e8f0fe", "#e6f4ea", "#fff4e5", "#f3e5f5" };
for (int r = 0; r < down; r++)
{
for (int c = 0; c < across; c++)
{
int i = r * across + c;
string nid = "step" + (i + 1);
nodes.Add(Node(nid, 100 + c * gapX, 80 + r * gapY, "Step " + (i + 1), UiDiagramShapeType.Flow, i % 5 == 4 ? "Decision" : "Process",
120, i % 5 == 4 ? 70 : 54, fills[r % fills.Length]));
if (c > 0) { links.Add(Link("l" + i, "step" + i, nid)); }
else if (r > 0) { links.Add(Link("l" + i, "step" + ((r - 1) * across + 1), nid)); }
}
}
return new UiDiagramOptions { Id = id, Height = "480px", Nodes = nodes, Connectors = links };
}
}
}
@* 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>