Example of Venn Diagram in ASP.NET MVC Diagram Control
Venn Diagram: three skills and what lies where they overlap. The circles are partly see-through, so their overlaps show; each can be moved and resized.
@Html.UiDiagram((UiDiagramOptions)ViewData["diagram"])
<p>
Venn Diagram: three skills and what lies where they overlap. The circles are partly see-through, so their overlaps show; each can be
moved and resized.
</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/VennDiagram.cshtml; it draws what ViewData holds.
public ActionResult VennDiagram()
{
System.Func<string, double, double, string, string, UiDiagramNode> circle = (id, x, y, text, fill) =>
{
UiDiagramNode n = Node(id, x, y, null, UiDiagramShapeType.Basic, "Ellipse", 280, 280, fill);
n.Style.Opacity = 0.55;
n.Style.StrokeColor = "#455a64";
n.Annotations.Add(new UiDiagramAnnotation { Content = text, Offset = new UiDiagramPoint { X = 0.5, Y = y < 250 ? 0.22 : 0.8 }, Style = new UiDiagramStyle { Bold = true, FontSize = 15 } });
return n;
};
System.Func<string, double, double, string, UiDiagramNode> label = (id, x, y, text) => new UiDiagramNode
{
Id = id, OffsetX = x, OffsetY = y, Width = 110, Height = 40, Shape = new UiDiagramShape { Type = UiDiagramShapeType.Text, Content = text },
Style = new UiDiagramStyle { FontSize = 13 }
};
ViewData["diagram"] = new UiDiagramOptions
{
Id = "vennDiagram",
Height = "560px",
AriaLabel = "Venn diagram of a data scientist's skills",
Nodes = new List<UiDiagramNode>
{
circle("maths", 330, 200, "Maths and statistics", "#90caf9"),
circle("code", 500, 200, "Programming", "#a5d6a7"),
circle("domain", 415, 345, "Business knowledge", "#ffcc80"),
label("ml", 415, 165, "Machine learning"),
label("research", 335, 320, "Research"),
label("software", 500, 320, "Software for the business"),
label("science", 415, 260, "Data science")
}
};
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>