#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 = TreemapCaptionPoliciesRecipe.Create("caption-policies", 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), 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
/// Opts into bounded caption shrinking and whole-text-element ellipsis while retaining complete source names.
public static class TreemapCaptionPoliciesRecipe {
/// Creates the complete source model; layout and exports use the existing Treemap owner.
public static Chart Create(string variant = "caption-policies", ThemeMode mode = ThemeMode.Light) {
if (variant is not ("caption-policies" or "compact-caption-policies")) throw new ArgumentOutOfRangeException(nameof(variant));
var chart = Chart.Create().Legend(false).DataLabels().TransparentBackground(false)
.AddTreemap("Reconciliation", new[] {
new ChartHierarchyItem("all", "International reconciliation, settlement and regional ownership — complete source caption"),
new ChartHierarchyItem("processing", "Regional processing reconciliation and settlement allocation", "all", 55),
new ChartHierarchyItem("regional", "North America processing", "all", 30),
new ChartHierarchyItem("reserve", "Reserve capacity", "all", 15)
}).Treemap(options => {
options.MinimumLabelFontSize = 11;
options.LabelTrimming = ChartForgeX.Typography.TextTrimming.Ellipsis;
options.ShowValues = true;
});
chart.Series[0].DataLabelStyle(style => style.FontSize(14));
return chart.ValueFormat(ChartValueFormat.Number("0", System.Globalization.CultureInfo.InvariantCulture));
}
}