#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 = PieSliceRadiusRecipe.Create("variable-radius", mode); var context = new VisualRenderContext( new VisualLayoutOptions(new VisualSize(900, 480)), theme, mode, new VisualFrame("Service shares with authored radii", "Values determine angles; explicit fractions determine band thickness", 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 /// Authored Pie radii remain independent of each value's angular share. public static class PieSliceRadiusRecipe { /// Creates service shares with explicit source identities and normalized band-relative radii. public static Chart Create(string variant = "variable-radius", VisualThemeMode mode = VisualThemeMode.Light) { if (variant is not ("variable-radius" or "compact-variable-radius")) throw new ArgumentOutOfRangeException(nameof(variant)); var services = new ChartSeries(new ChartSeriesId("services"), "Services", ChartSeriesKind.Pie, new[] { new ChartPoint(1, 80), new ChartPoint(2, 60), new ChartPoint(3, 20) }) .WithObservationIds(new[] { new ChartObservationId("subscriptions"), new ChartObservationId("consulting"), new ChartObservationId("support") }) .WithPointSliceRadiusRatio(0, .35).WithPointSliceRadiusRatio(1, .7).WithPointSliceRadiusRatio(2, 1); services.DataLabelPlacement = ChartDataLabelPlacement.Outside; return Chart.Create().WithXLabels("Subscriptions", "Consulting", "Support").WithDataLabels() .WithPieSliceLabelContent(ChartPieSliceLabelContent.LabelAndPercent).WithDonutCenterLabel(false) .AddSeries(services); } }