#region Setup using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using ChartForgeX.Core; using ChartForgeX.Primitives; using ChartForgeX.Rendering; using ChartForgeX.Themes; using ChartForgeX.Topology; using ChartForgeX.Typography; using ChartForgeX.VisualArtifacts; using ChartForgeX.VisualBlocks; var mode = VisualThemeMode.Dark; var theme = VisualTheme.Graphite(); var model = FindingsRecipe.Create("wide", mode); var context = new VisualRenderContext( new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode, new VisualFrame("Findings by category", "Open findings from the October assessment", showLegend: null, showSurface: false)); var prepared = model.Prepare(context); File.WriteAllText("visual.svg", prepared.ToSvg()); File.WriteAllBytes("visual.png", prepared.ToPng()); File.WriteAllText("visual.html", prepared.ToArtifact("example", VisualArtifactKind.Chart).ToHtmlPage()); #endregion /// Open assessment findings by category with explicit zero, empty, dense and semantic-color variants. public static class FindingsRecipe { private static readonly (string Name, string Long, double Count)[] Categories = { ("Patching", "Missing security updates on servers", 46), ("Identity", "Stale and over-privileged accounts", 38), ("Certificates", "Certificates expiring within 30 days", 27), ("Network", "Exposed management ports", 21), ("Backups", "Backups without a recent restore test", 17), ("Logging", "Audit logging disabled or incomplete", 12), ("Encryption", "Unencrypted data at rest", 8) }; private static readonly string[] DenseCategories = { "Patching", "Identity", "Certificates", "Network", "Backups", "Logging", "Encryption", "DNS", "Firewall", "Endpoints", "Mail flow", "Licensing", "Monitoring", "Replication", "Group Policy", "Service accounts", "Shares", "Printers", "Remote access", "Web servers", "Databases", "Hypervisors", "Storage", "Wireless" }; public static Chart Create(string variant = "wide", VisualThemeMode mode = VisualThemeMode.Light) { var dense = variant == "dense"; var count = variant == "empty" ? 0 : dense ? DenseCategories.Length : Categories.Length; // Dense findings fall off steeply, as they do in a real assessment: a few categories carry most of the work. double Count(int index) => dense ? Math.Round(60 * Math.Pow(.84, index)) + 1 : Categories[index].Count; string Name(int index) => dense ? DenseCategories[index] : variant == "wrapped-legend" ? Categories[index].Long : Categories[index].Name; var points = Enumerable.Range(0, count).Where(index => variant != "missing" || index is not (2 or 3)) .Select(index => new ChartPoint(index + 1, variant == "zero" ? 0 : Count(index))); var findings = new ChartSeries(new ChartSeriesId("findings"), "Findings", ChartSeriesKind.Donut, points); if (variant is "explicit-status" or "explicit-series") { var colors = VisualTheme.Graphite().Resolve(mode); var selected = variant == "explicit-status" ? new[] { colors.Status.Pass.Fill, colors.Status.Medium.Fill, colors.Status.Critical.Fill } : colors.Palette.Take(3).ToArray(); for (var index = 0; index < findings.Points.Count; index++) findings.WithPointColor(index, selected[index % selected.Length]); } return Chart.Create().WithXLabels(Enumerable.Range(0, count).Select(Name).ToArray()).AddSeries(findings); } }