#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;
// Native PNG and standalone SVG use bundled Archivo.
// Add ChartFontAssets.StyleSheet once for other text on a host page.
var mode = ThemeMode.Light;
var theme = VisualTheme.Graphite();
var model = TopologyPathDecorationRecipe.Create("wide", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(760, 420)), theme, mode,
new VisualFrame("Independent maintenance boundary", "One native path decorates the graph without adding source nodes or relationships", showLegend: null, showSurface: false), FontSpec.FromFamily(ChartFontStacks.ProductSans));
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
/// An ordinary native topology with a curved maintenance boundary, separate from graph facts.
public static class TopologyPathDecorationRecipe {
/// Creates a script-free plan with two services, one relationship and an optional independent boundary.
public static TopologyChart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
if (variant is not ("wide" or "compact" or "plain" or "compact-plain")) throw new ArgumentOutOfRangeException(nameof(variant));
var compact = variant.StartsWith("compact", StringComparison.Ordinal);
var includeBoundary = !variant.EndsWith("plain", StringComparison.Ordinal);
var chart = TopologyChart.Create().Id("maintenance-boundary").Title("Maintenance boundary")
.Viewport(new TopologyViewport(compact ? 390 : 760, 400, 28)).Theme(VisualTheme.Graphite()).ThemeMode(mode);
if (compact) chart.DefaultRenderOptions(new TopologyRenderOptions { FitContentToViewport = true });
chart.AddNode("gateway", "Gateway", 80, 130, width: 180, height: 90);
chart.AddNode("worker", "Worker", 460, 130, width: 180, height: 90);
chart.AddEdge("dispatch", "gateway", "worker", "Dispatch");
if (includeBoundary) chart.PathDecorations.Add(new TopologyPathDecoration("maintenance-zone",
"M 370 70 C 330 120 410 170 370 220 C 330 270 410 300 370 330",
stroke: mode == ThemeMode.Dark ? ChartColor.FromHex("#FBBF24") : ChartColor.FromHex("#92400E"),
strokeWidth: 3, dashPattern: new[] { 8d, 4d }));
return chart;
}
}