# How work is allocated across teams · Treemap

Preview

![How work is allocated across teams](family-treemap-wide-light.png)

![How work is allocated across teams](family-treemap-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-treemap-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 = TreemapRecipe.Create("wide", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("How work is allocated across teams", "", 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 treemap showing work allocation and independent numeric color values.</summary>
public static class TreemapRecipe {
    /// <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"))
            throw new ArgumentOutOfRangeException(nameof(variant));

        var items = variant == "sparse" ? new[] {
            new ChartHierarchyItem("independent", "Independent team", value: 100, colorValue: 7),
            new ChartHierarchyItem("reserve", "Reserve", value: 0)
        } : new[] {
            new ChartHierarchyItem("north", "North"),
            new ChartHierarchyItem("north-services", "Services", parentId: "north"),
            new ChartHierarchyItem("north-support", "Support", parentId: "north-services", value: 18, colorValue: -4),
            new ChartHierarchyItem("north-research", "Research", parentId: "north-services", value: 12, colorValue: 11),
            new ChartHierarchyItem("north-platform", "Platform", parentId: "north", value: 18, colorValue: 3),
            new ChartHierarchyItem("south", "South"),
            new ChartHierarchyItem("south-services", "Services", parentId: "south"),
            new ChartHierarchyItem("south-support", "Support", parentId: "south-services", value: 22, colorValue: 8),
            new ChartHierarchyItem("south-field", "Field", parentId: "south-services", value: 15, colorValue: 1),
            new ChartHierarchyItem("south-operations", "Operations", parentId: "south", value: 15, colorValue: -6),
            new ChartHierarchyItem("research", "Independent research", value: 8, colorValue: 14)
        };
        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);
        var scale = variant == "options" ? ChartColorScale.Discrete(new[] {
            new ChartColorBand(0, low, "Decline"), new ChartColorBand(10, colors.Border, "Steady"), new ChartColorBand(null, high, "Growth")
        }) : ChartColorScale.Diverging(low, colors.Border, high, 0).WithValueRange(-10, 15).WithLabels("Decrease", "No change", "Increase");
        var allocation = ChartSeries.CreateTreemap(new ChartSeriesId("allocation-source"), "Allocated work", items);
        var chart = Chart.Create().DataLabels(true).AddSeries(allocation).Treemap(options => {
            options.GroupPadding = variant == "options" ? 8 : 6;
            options.Gap = 3;
            options.ShowGroupLabels = true;
            options.ColorDimension.Name = "Change (%)";
            // Only the sparse model has an item without a measured change, so only it needs a no-data colour.
            options.ColorScale = variant == "sparse" ? scale.WithNoDataColor(colors.Surface) : scale;
        });
        if (variant == "options") allocation.NodeState("south-support", ChartSeriesState.Warning);
        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 = TreemapRecipe.Create("wide", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("How work is allocated across teams", "", 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 treemap showing work allocation and independent numeric color values.</summary>
public static class TreemapRecipe {
    /// <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"))
            throw new ArgumentOutOfRangeException(nameof(variant));

        var items = variant == "sparse" ? new[] {
            new ChartHierarchyItem("independent", "Independent team", value: 100, colorValue: 7),
            new ChartHierarchyItem("reserve", "Reserve", value: 0)
        } : new[] {
            new ChartHierarchyItem("north", "North"),
            new ChartHierarchyItem("north-services", "Services", parentId: "north"),
            new ChartHierarchyItem("north-support", "Support", parentId: "north-services", value: 18, colorValue: -4),
            new ChartHierarchyItem("north-research", "Research", parentId: "north-services", value: 12, colorValue: 11),
            new ChartHierarchyItem("north-platform", "Platform", parentId: "north", value: 18, colorValue: 3),
            new ChartHierarchyItem("south", "South"),
            new ChartHierarchyItem("south-services", "Services", parentId: "south"),
            new ChartHierarchyItem("south-support", "Support", parentId: "south-services", value: 22, colorValue: 8),
            new ChartHierarchyItem("south-field", "Field", parentId: "south-services", value: 15, colorValue: 1),
            new ChartHierarchyItem("south-operations", "Operations", parentId: "south", value: 15, colorValue: -6),
            new ChartHierarchyItem("research", "Independent research", value: 8, colorValue: 14)
        };
        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);
        var scale = variant == "options" ? ChartColorScale.Discrete(new[] {
            new ChartColorBand(0, low, "Decline"), new ChartColorBand(10, colors.Border, "Steady"), new ChartColorBand(null, high, "Growth")
        }) : ChartColorScale.Diverging(low, colors.Border, high, 0).WithValueRange(-10, 15).WithLabels("Decrease", "No change", "Increase");
        var allocation = ChartSeries.CreateTreemap(new ChartSeriesId("allocation-source"), "Allocated work", items);
        var chart = Chart.Create().DataLabels(true).AddSeries(allocation).Treemap(options => {
            options.GroupPadding = variant == "options" ? 8 : 6;
            options.Gap = 3;
            options.ShowGroupLabels = true;
            options.ColorDimension.Name = "Change (%)";
            // Only the sparse model has an item without a measured change, so only it needs a no-data colour.
            options.ColorScale = variant == "sparse" ? scale.WithNoDataColor(colors.Surface) : scale;
        });
        if (variant == "options") allocation.NodeState("south-support", ChartSeriesState.Warning);
        return chart;
    }

}
```

<!-- PowerForge markdown artifact sha256:D081326A4E5C271471D023ACA65066767D97598C293A6C15CC3FF68F97E01D50 -->
