Example of Tooltip in ASP.NET MVC Diagram Control
Tooltip: rest the pointer on a node or a connector, or reach it with the Tab key, to see more about it. Escape hides the tooltip.
@Html.UiDiagram((UiDiagramOptions)ViewData["diagram"])
<p>
Tooltip: rest the pointer on a node or a connector, or reach it with the Tab key, to see more about it. Escape hides the tooltip.
</p>
@Html.UiDiagram((UiDiagramOptions)ViewData["diagram"])
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/Tooltip.cshtml; it draws what ViewData holds.
public ActionResult Tooltip()
{
UiDiagramConnector link = Link("toServer", "browser", "server", "HTTPS");
link.Tooltip = new UiDiagramTooltip { Content = "Requests go over HTTPS, port 443." };
ViewData["diagram"] = new UiDiagramOptions
{
Id = "tooltipDiagram",
Height = "400px",
AriaLabel = "Diagram with tooltips",
Nodes = new List<UiDiagramNode>
{
Tip(Node("browser", 130, 150, "Browser", UiDiagramShapeType.Basic, "Rectangle", 130, 60, "#e8f0fe"), "The user's web browser."),
Tip(Node("server", 400, 150, "Web server", UiDiagramShapeType.Basic, "Rectangle", 130, 60, "#e6f4ea"), "IIS, running the ASP.NET MVC site."),
Tip(Node("database", 400, 310, "Database", UiDiagramShapeType.Basic, "Cylinder", 110, 70, "#fff4e5"), "SQL Server: orders, customers and products.")
},
Connectors = new List<UiDiagramConnector> { link, Link("toData", "server", "database", "SQL") }
};
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;
}
private static UiDiagramNode Tip(UiDiagramNode node, string tip)
{
node.Tooltip = new UiDiagramTooltip { Content = tip };
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>