#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 = ScatterRecipe.Create("sparse", mode); var context = new VisualRenderContext( new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode, new VisualFrame("Processing time by workload", "Missing observations remain visible as gaps", 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.Chart).ToHtmlPage()); #endregion /// Plots processing time against batch size for two job queues, including a sparse observation example. public static class ScatterRecipe { /// Creates the selected example without choosing a renderer or export backend. public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) { if (variant is not ("wide" or "compact" or "sparse")) throw new ArgumentOutOfRangeException(nameof(variant)); return variant == "sparse" ? Sparse() : ProcessingTime(variant == "compact" ? 14 : 28); } private static Chart ProcessingTime(int count) { // Processing time grows with batch size; priority jobs run on reserved capacity and finish faster. var standard = ChartSeries.CreateScatter(new ChartSeriesId("standard"), "Standard queue", Batches(count, 0, 9, .42)); var priority = ChartSeries.CreateScatter(new ChartSeriesId("priority"), "Priority queue", Batches(count, 3, 4, .24)); return Chart.Create().XAxis(x => x.Title("Batch size (items)")).YAxis(y => y.Title("Processing time (minutes)")) .AddSeries(standard).AddSeries(priority); } private static IEnumerable Batches(int count, int seed, double overhead, double perItem) { for (var index = 0; index < count; index++) { // Golden-ratio steps spread the batch sizes evenly without a visible pattern. var size = Math.Round(8 + (index * .618034 + seed * .29) % 1 * 112); // A deterministic wobble stands in for queue contention. var noise = Math.Sin((index + 1) * 2.3 + seed) * 4 + Math.Cos((index + 2) * 1.7 + seed) * 2.5; yield return new ChartPoint(size, Math.Round(overhead + size * perItem + noise, 1)); } } private static Chart Sparse() { var observations = new[] { 1, 3, 6 }.Select(index => new ChartPoint(index, 20 + index * 7 % 29, index == 6)); var processing = ChartSeries.CreateScatter(new ChartSeriesId("processing-time"), "Processing time", observations); return Chart.Create().XLabels("1", "2", "3", "4", "5", "6") .XAxis(x => x.Title("Workload batches")).YAxis(y => y.Title("Time (minutes)")).AddSeries(processing); } }