#region Setup using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using ChartForgeX; 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 = ThemeMode.Light; var theme = VisualTheme.Graphite(); var model = UseCaseSourceDepthRecipe.Create("wide", mode); var context = new VisualRenderContext( new VisualLayoutOptions(new VisualSize(900, 520)), theme, mode, new VisualFrame("Native actor and use case captions", "Native stereotypes, attached approval notes and independently styled named associations", 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.Topology).ToHtmlPage()); #endregion /// Authors native actors, use cases, visible stereotypes, notes and independently styled associations. /// The separately shared Mermaid fixture proves source parsing; this Core recipe uses only native public APIs. public static class UseCaseSourceDepthRecipe { /// Creates the complete native example in wide/compact and light/dark variants. public static TopologyChart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) { if (variant is not ("wide" or "compact")) throw new ArgumentOutOfRangeException(nameof(variant)); var compact = variant == "compact"; var chart = TopologyChart.Create().Id("native-usecase-depth").Title("Publish prepared documents") .Subtitle("Actors, stereotypes, approval notes and named associations") .Theme(VisualTheme.Graphite()).ThemeMode(mode).Viewport(new TopologyViewport(compact ? 390 : 900, compact ? 620 : 520, 28)) .LayoutMode(TopologyLayoutMode.Swimlane).LayoutDirection(compact ? TopologyLayoutDirection.TopToBottom : TopologyLayoutDirection.LeftToRight); chart.DefaultRenderOptions = new TopologyRenderOptions { FitContentToViewport = true, MaxNodeLabelLines = 8, MaxNodeSubtitleLines = 8, WrapNodeLabels = true, AllowMultilineNodeLabels = true }; chart.AddAutoGroup("Service", "Publication service"); chart.AddAutoNode("Operator", "Release coordinator", width: 190, height: 110); chart.AddAutoNode("Publish", "Publish prepared documents", groupId: "Service", width: 200, height: 92); chart.AddAutoNode("Validate", "Validate request", groupId: "Service", width: 180, height: 76); foreach (var node in chart.Nodes) { node.Kind = TopologyNodeKind.Generic; node.Shape = node.Id == "Operator" ? TopologyNodeShape.Actor : TopologyNodeShape.Ellipse; node.DisplayMode = TopologyNodeDisplayMode.Card; node.PreserveDisplayModeSize = true; node.ShowStatusBadge = false; node.FitLabelToContent = node.Shape != TopologyNodeShape.Actor; node.MaximumTextWidth = 150; if (node.Shape != TopologyNodeShape.Actor) node.TextStyle = new ChartForgeX.Typography.TextStyleOverride { FontSize = 13, FontWeight = 400 }; } chart.Nodes[0].Subtitle = "«primary»"; chart.Nodes[0].TextStyle = new ChartForgeX.Typography.TextStyleOverride { FontSize = 14, FontWeight = 500 }; chart.Nodes[1].Subtitle = "«business action»"; chart.AddEdge("request", "Operator", "Publish", "requests", kind: TopologyEdgeKind.Dependency, direction: VisualLinkDirection.Forward, routing: TopologyEdgeRouting.Straight); var request = chart.Edges[0]; request.Color = ChartColor.FromHex("#2563EB"); request.LabelColor = ChartColor.FromHex("#0F766E"); request.StrokeWidth = 2.5; request.Opacity = .8; request.LineStyle = TopologyEdgeLineStyle.Solid; request.DashPattern.AddRange(new[] { 6d, 3, 2, 6, 3, 2 }); chart.AddEdge("include-validation", "Publish", "Validate", "<>", kind: TopologyEdgeKind.Dependency, direction: VisualLinkDirection.Forward, routing: TopologyEdgeRouting.Straight); chart.Edges[1].LineStyle = TopologyEdgeLineStyle.Dotted; chart.Edges[1].MinimumRankSpan = 2; chart.Annotations.Add(new TopologyAnnotation("approval", "Approval required before delivery", "Publish")); chart.Accessibility.Name = "Document publication use cases"; return chart; } }