# Allocation through the team hierarchy · Sunburst

Preview

![Allocation through the team hierarchy](family-sunburst-wide-light.png)

![Allocation through the team hierarchy](family-sunburst-wide-dark.png)

800 × 440 pixels

## Create this example

Create a console project, add the ChartForgeX and ChartForgeX.Interactivity.Html packages, and replace Program.cs with this source. Run it to write SVG, PNG and HTML with the default system fonts.

For the same typography as the gallery, [download the gallery-font recipe](family-sunburst-wide-light.gallery.csharp.txt) and copy the gallery’s fonts directory beside your program.

```
#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;

var mode = ThemeMode.Light;
var theme = VisualTheme.Graphite();
var model = SunburstRecipe.Create("wide", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("Allocation through the team hierarchy", "", 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

/// <summary>Creates a sunburst showing allocation through a team hierarchy.</summary>
public static class SunburstRecipe {
    /// <summary>Creates the source model for a gallery variant without choosing an export backend.</summary>
    public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("wide" or "compact" or "sparse" or "options" or "compact-options"
            or "authored-total" or "compact-authored-total"))
            throw new ArgumentOutOfRangeException(nameof(variant));

        var inclusive = variant is "authored-total" or "compact-authored-total";
        var configured = inclusive || variant is "options" or "compact-options";
        var items = new[] {
            new ChartHierarchyItem("all", "All teams", value: configured ? 140 : null, colorValue: configured ? -10 : null),
            new ChartHierarchyItem("engineering", "Engineering", "all", configured ? 80 : null, configured ? 12 : null),
            new ChartHierarchyItem("operations", "Operations", "all", colorValue: configured ? 0 : null),
            new ChartHierarchyItem("platform", "Platform", "engineering", 35, configured ? -4 : null),
            new ChartHierarchyItem("engineering-support", "Support", "engineering", 25, configured ? 5 : null),
            new ChartHierarchyItem("operations-support", "Support", "operations", 40),
            new ChartHierarchyItem("reserve", "Reserve", "operations", 0)
        };
        var allocation = ChartSeries.CreateSunburst(new ChartSeriesId("allocation-source"), "Allocated work", items);
        var chart = Chart.Create().DataLabels().AddSeries(allocation);
        if (configured) {
            var colors = VisualTheme.Graphite().Resolve(mode);
            var low = mode == ThemeMode.Dark ? ChartColor.FromRgb(153, 138, 224) : ChartColor.FromRgb(101, 78, 169);
            var high = mode == ThemeMode.Dark ? ChartColor.FromRgb(238, 157, 98) : ChartColor.FromRgb(191, 92, 34);
            chart.Sunburst(options => {
                options.CornerRadius = 6;
                options.SecondaryLabelFormatter = context => context.Item.Id == "all" ? "Allocation" : context.Item.Id == "engineering" ? "Delivery teams"
                    : context.Item.Id == "operations-support" ? "Shared service" : null;
                options.ParentValuePolicy = inclusive ? ChartHierarchyValuePolicy.AuthoredTotal : ChartHierarchyValuePolicy.LeafAggregate;
                options.ColorDimension.Name = "Change (%)";
                options.ColorScale = ChartColorScale.Diverging(low, colors.Border, high, 0).WithValueRange(-10, 15)
                    .WithLabels("Decrease", "No change", "Increase").WithNoDataColor(colors.Surface);
            });
            allocation.NodeState("engineering-support", ChartSeriesState.Warning);
            allocation.PointFillPattern(4, ChartFillPattern.DiagonalForward);
        }
        return chart;
    }
}
```

```
#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;

var mode = ThemeMode.Dark;
var theme = VisualTheme.Graphite();
var model = SunburstRecipe.Create("wide", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("Allocation through the team hierarchy", "", 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

/// <summary>Creates a sunburst showing allocation through a team hierarchy.</summary>
public static class SunburstRecipe {
    /// <summary>Creates the source model for a gallery variant without choosing an export backend.</summary>
    public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("wide" or "compact" or "sparse" or "options" or "compact-options"
            or "authored-total" or "compact-authored-total"))
            throw new ArgumentOutOfRangeException(nameof(variant));

        var inclusive = variant is "authored-total" or "compact-authored-total";
        var configured = inclusive || variant is "options" or "compact-options";
        var items = new[] {
            new ChartHierarchyItem("all", "All teams", value: configured ? 140 : null, colorValue: configured ? -10 : null),
            new ChartHierarchyItem("engineering", "Engineering", "all", configured ? 80 : null, configured ? 12 : null),
            new ChartHierarchyItem("operations", "Operations", "all", colorValue: configured ? 0 : null),
            new ChartHierarchyItem("platform", "Platform", "engineering", 35, configured ? -4 : null),
            new ChartHierarchyItem("engineering-support", "Support", "engineering", 25, configured ? 5 : null),
            new ChartHierarchyItem("operations-support", "Support", "operations", 40),
            new ChartHierarchyItem("reserve", "Reserve", "operations", 0)
        };
        var allocation = ChartSeries.CreateSunburst(new ChartSeriesId("allocation-source"), "Allocated work", items);
        var chart = Chart.Create().DataLabels().AddSeries(allocation);
        if (configured) {
            var colors = VisualTheme.Graphite().Resolve(mode);
            var low = mode == ThemeMode.Dark ? ChartColor.FromRgb(153, 138, 224) : ChartColor.FromRgb(101, 78, 169);
            var high = mode == ThemeMode.Dark ? ChartColor.FromRgb(238, 157, 98) : ChartColor.FromRgb(191, 92, 34);
            chart.Sunburst(options => {
                options.CornerRadius = 6;
                options.SecondaryLabelFormatter = context => context.Item.Id == "all" ? "Allocation" : context.Item.Id == "engineering" ? "Delivery teams"
                    : context.Item.Id == "operations-support" ? "Shared service" : null;
                options.ParentValuePolicy = inclusive ? ChartHierarchyValuePolicy.AuthoredTotal : ChartHierarchyValuePolicy.LeafAggregate;
                options.ColorDimension.Name = "Change (%)";
                options.ColorScale = ChartColorScale.Diverging(low, colors.Border, high, 0).WithValueRange(-10, 15)
                    .WithLabels("Decrease", "No change", "Increase").WithNoDataColor(colors.Surface);
            });
            allocation.NodeState("engineering-support", ChartSeriesState.Warning);
            allocation.PointFillPattern(4, ChartFillPattern.DiagonalForward);
        }
        return chart;
    }
}
```

<!-- PowerForge markdown artifact sha256:069AD494BF465D1EFAD92BD8AD8CFD12D89FD9813946AC153EA8C6CB3FC032BC -->
