#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 = DumbbellEndpointRecipe.Create("endpoint-markers", mode); var context = new VisualRenderContext( new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode, new VisualFrame("Service capacity before and after", "Independent endpoint shapes, sizes and colors preserve source order", 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 service capacity with independent Start and End glyphs on either physical orientation. public static class DumbbellEndpointRecipe { /// Creates source-ordered pairs; marker presentation never sorts or replaces the two endpoint values. public static Chart Create(string variant = "endpoint-markers", VisualThemeMode mode = VisualThemeMode.Light) { if (variant is not ("horizontal" or "compact-horizontal" or "endpoint-markers" or "compact-endpoint-markers")) throw new ArgumentOutOfRangeException(nameof(variant)); var colors = VisualTheme.Graphite().Resolve(mode); var capacity = ChartSeries.CreateDumbbell(new ChartSeriesId("capacity"), "Start / End capacity", new[] { new ChartDumbbell(1, 32, 44), new ChartDumbbell(2, 58, 38), new ChartDumbbell(3, 51, 72), new ChartDumbbell(4, 43, 67), new ChartDumbbell(5, 81, 58) }).WithObservationIds(new[] { "standard", "express", "premium", "bulk", "return" }.Select(id => new ChartObservationId(id))) .ConfigureDumbbell(options => { options.StartMarker.Shape = ChartMarkerShape.Circle; options.StartMarker.Radius = 4; options.StartMarker.Fill = colors.Palette[1]; options.EndMarker.Shape = ChartMarkerShape.Diamond; options.EndMarker.Radius = 8; options.EndMarker.Fill = colors.Palette[0]; options.EndMarker.Stroke = colors.Surface; options.EndMarker.StrokeWidth = 1; }); var chart = Chart.Create().WithXLabels("Standard", "Express", "Premium", "Bulk", "Return") .WithLegend(true).WithDataLabels(false).AddSeries(capacity) .WithValueFormat(ChartValueFormat.Number("0", CultureInfo.InvariantCulture)); if (variant.EndsWith("horizontal", StringComparison.Ordinal)) { chart.Options.DumbbellOrientation = ChartOrientation.Horizontal; chart.WithXAxis("Capacity").WithYAxis("Service"); } else chart.WithXAxis("Service").WithYAxis("Capacity"); return chart; } }