Example of Scrolling in ASP.NET MVC Diagram Control
Scrolling: the diagram is larger than its view. Scroll with the scroll bars, the wheel or the keyboard; drag a node near the edge and the view scrolls with it. With the Infinity limit there is a view's room around the diagram on every side.
@Html.UiDiagram((UiDiagramOptions)ViewData["diagram"])
<p>
Scrolling: the diagram is larger than its view. Scroll with the scroll bars, the wheel or the keyboard; drag a node near the edge and
the view scrolls with it. With the Infinity limit there is a view's room around the diagram on every side.
</p>
<div class="d-flex flex-wrap gap-3 align-items-center mb-2">
<label class="d-flex align-items-center gap-1">Scroll limit
<select class="form-select form-select-sm" id="scrollLimit"><option selected>Diagram</option><option>Infinity</option></select>
</label>
<label class="d-flex align-items-center gap-1">Padding
<input class="form-control form-control-sm" type="number" id="padding" value="40" min="0" max="400" step="20" style="width:6em">
</label>
<div class="form-check"><input class="form-check-input" type="checkbox" id="autoScroll" checked><label class="form-check-label" for="autoScroll">Scroll while dragging near the edge</label></div>
<button type="button" class="btn btn-sm btn-outline-primary" data-view="last">Show the last step</button>
<button type="button" class="btn btn-sm btn-outline-primary" data-view="first">Centre the first step</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; }
}
function diagram() { return Lumen.get('scrollDiagram'); }
/** OnScrollChange: where the view is. */
function scrolled(args) {
status('The view starts at ' + Math.round(args.newValue.horizontalOffset) + ', ' + Math.round(args.newValue.verticalOffset) + '.');
}
document.addEventListener('change', function (e) {
var t = e.target;
if (!t || ['scrollLimit', 'padding', 'autoScroll'].indexOf(t.id) < 0) { return; }
var s = diagram().setScrollSettings({
scrollLimit: document.getElementById('scrollLimit').value,
padding: Number(document.getElementById('padding').value) || 0,
canAutoScroll: document.getElementById('autoScroll').checked
});
status('Scroll limit ' + s.scrollLimit + ', padding ' + s.padding + ', auto scroll ' + (s.canAutoScroll ? 'on' : 'off') + '.');
});
document.addEventListener('click', function (e) {
var b = e.target.closest ? e.target.closest('[data-view]') : null;
if (!b) { return; }
if (b.getAttribute('data-view') === 'last') { diagram().bringIntoView('step48'); } else { diagram().bringToCenter('step1'); }
});
return { scrolled: scrolled };
})();
</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/Scrolling.cshtml; it draws what ViewData holds.
public ActionResult Scrolling()
{
UiDiagramOptions o = Spread("scrollDiagram", 8, 6, 220, 170);
o.AriaLabel = "A large diagram to scroll";
o.Height = "420px";
// Syncfusion's default is no auto scroll (Phase 5b); this sample shows it.
o.ScrollSettings = new UiDiagramScrollSettings { Padding = 40, ScrollLimit = UiDiagramScrollLimit.Diagram, CanAutoScroll = true };
o.OnScrollChange = "DiagramSamples.scrolled";
ViewData["diagram"] = o;
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>