#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 = SlopeStagesRecipe.Create("compact-stages", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
new VisualFrame("Capacity change across teams", "", 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
/// Compares complete stage observations without inventing values for unrecorded stages.
public static class SlopeStagesRecipe {
/// Creates ordered stage lines, including one explicit disconnected interval, on either physical orientation.
public static Chart Create(string variant = "stages", ThemeMode mode = ThemeMode.Light) {
if (variant is not ("stages" or "compact-stages" or "horizontal-stages" or "compact-horizontal-stages"))
throw new ArgumentOutOfRangeException(nameof(variant));
var chart = Chart.Create().Theme(VisualTheme.Graphite()).ThemeMode(mode).XLabels("Received", "Prepared", "Reviewed", "Accepted")
.Legend(true).DataLabels(false)
.AddSlope("Standard", new[] { new ChartPoint(1, 28), new ChartPoint(2, 43), new ChartPoint(3, 38), new ChartPoint(4, 64) })
.AddSlope("Express", new[] { new ChartPoint(1, 52), new ChartPoint(2, 49), new ChartPoint(3, 58, true), new ChartPoint(4, 71) })
.ValueFormat(ChartValueFormat.Number("0", CultureInfo.InvariantCulture));
var ids = new[] { "received", "prepared", "reviewed", "accepted" }.Select(id => new ChartObservationId(id)).ToArray();
foreach (var series in chart.Series) series.ObservationIds(ids);
if (variant.EndsWith("horizontal-stages", StringComparison.Ordinal)) {
chart.Options.SlopeOrientation = ChartOrientation.Horizontal;
chart.XAxis(x => x.Title("Recorded capacity")).YAxis(y => y.Title("Delivery stage"));
} else chart.XAxis(x => x.Title("Delivery stage")).YAxis(y => y.Title("Recorded capacity"));
return chart;
}
}