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; // Optional exact gallery typography; copy the gallery's fonts directory beside this program. FontRegistry.Register("CFX Proof Carlito", "fonts/Carlito-Regular.ttf", 400); FontRegistry.Register("CFX Proof Carlito", "fonts/Carlito-Bold.ttf", 700); var mode = VisualThemeMode.Light; var theme = VisualTheme.Graphite(); var model = SankeyRecipe.Create("wide", mode); var context = new VisualRenderContext( new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode, new VisualFrame("Requests across processing stages", "Explore the data, then download the chart", showLegend: null, showSurface: false), FontSpec.FromFamily("CFX Proof Carlito")); 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()); /// Weighted requests flow through automatic and manual processing. public static class SankeyRecipe { public static Chart Create(string variant = "wide", VisualThemeMode mode = VisualThemeMode.Light) { var requests = ChartSeries.CreateSankey(new ChartSeriesId("requests"), "Requests", new[] { new ChartNode("received", "Received"), new ChartNode("automatic", "Automatic"), new ChartNode("manual", "Manual"), new ChartNode("completed", "Completed"), new ChartNode("review", "Review") }, new[] { new ChartFlowLink("received-automatic", "received", "automatic", 72), new ChartFlowLink("received-manual", "received", "manual", 28), new ChartFlowLink("automatic-completed", "automatic", "completed", 65), new ChartFlowLink("automatic-review", "automatic", "review", 7), new ChartFlowLink("manual-completed", "manual", "completed", 20), new ChartFlowLink("manual-review", "manual", "review", 8) }); if (variant == "sparse") requests.ReplaceFlowData(new[] { new ChartNode("received", "Received"), new ChartNode("completed", "Completed"), new ChartNode("review", "Review") }, new[] { new ChartFlowLink("received-completed", "received", "completed", 85), new ChartFlowLink("received-review", "received", "review", 15) }); return Chart.Create().AddSeries(requests).WithValueFormat(ChartValueFormat.Number("0.##", CultureInfo.InvariantCulture)); } }