Preview


390 × 400 pixels
Create this example
Create a console project, add the ChartForgeX package, and replace Program.cs with this source. Run it to write SVG, PNG and HTML with the default system fonts.
For the same typography as the gallery, download the gallery-font recipe and copy the gallery’s fonts directory beside your program.
#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 = TopologyPathDecorationRecipe.Create("compact", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(390, 400)), theme, mode,
new VisualFrame("Independent maintenance boundary", "One native path decorates the graph without adding source nodes or relationships", 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
/// <summary>An ordinary native topology with a curved maintenance boundary, separate from graph facts.</summary>
public static class TopologyPathDecorationRecipe {
/// <summary>Creates a script-free plan with two services, one relationship and an optional independent boundary.</summary>
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;
}
}
#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.Dark;
var theme = VisualTheme.Graphite();
var model = TopologyPathDecorationRecipe.Create("compact", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(390, 400)), theme, mode,
new VisualFrame("Independent maintenance boundary", "One native path decorates the graph without adding source nodes or relationships", 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
/// <summary>An ordinary native topology with a curved maintenance boundary, separate from graph facts.</summary>
public static class TopologyPathDecorationRecipe {
/// <summary>Creates a script-free plan with two services, one relationship and an optional independent boundary.</summary>
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;
}
}