#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.Light;
var theme = VisualTheme.Graphite();
var model = LollipopHorizontalRecipe.Create("horizontal", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
new VisualFrame("Orders at each delivery stage", "Delivery stages share a horizontal order-count axis", 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 delivery-stage orders on a physical horizontal value axis.
public static class LollipopHorizontalRecipe {
/// Creates the horizontal example through the canonical lollipop and physical-axis owners.
public static Chart Create(string variant = "horizontal", VisualThemeMode mode = VisualThemeMode.Light) {
if (variant is not ("horizontal" or "compact-horizontal")) throw new ArgumentOutOfRangeException(nameof(variant));
var points = Enumerable.Range(1, 6).Select(index => new ChartPoint(index, 20 + index * 7 % 29));
var orders = new ChartSeries(new ChartSeriesId("orders"), "Orders", ChartSeriesKind.Lollipop, points)
.WithObservationIds(new[] { "received", "packed", "shipped", "transit", "delivered", "reviewed" }.Select(id => new ChartObservationId(id)));
var chart = Chart.Create().WithXLabels("Received", "Packed", "Shipped", "In transit", "Delivered", "Reviewed")
.WithXAxis("Orders").WithYAxis("Delivery stage").WithLegend(false).AddSeries(orders)
.WithValueFormat(ChartValueFormat.Number("0", CultureInfo.InvariantCulture));
chart.Options.LollipopOrientation = ChartOrientation.Horizontal;
return chart;
}
}