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 = CalendarHeatmapColorScaleRecipe.Create("compact-color-scale", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
new VisualFrame("Daily activity across four months", "Every observed value shares one scale; missing days stay distinct", 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());
/// Colors dated activity from quiet to busy on a fixed numeric scale.
public static class CalendarHeatmapColorScaleRecipe {
/// Creates a Monday-first calendar with an explicit activity range and missing-data color.
public static Chart Create(string variant = "color-scale", VisualThemeMode mode = VisualThemeMode.Light) {
if (variant is not ("color-scale" or "compact-color-scale")) throw new ArgumentOutOfRangeException(nameof(variant));
var colors = VisualTheme.Graphite().Resolve(mode);
return Chart.Create().ConfigureCalendar(options => options.FirstDayOfWeek = DayOfWeek.Monday)
.AddCalendarHeatmap("Daily observations", Enumerable.Range(0, 120)
.Where(index => index % 7 != 0 && index % 9 != 0)
.Select(index => new ChartCalendarHeatmapItem(new DateTime(2026, 1, 1).AddDays(index), index * 7 % 13)),
id: new ChartSeriesId("daily-observations"))
.WithHeatmapColorScale(ChartColorScale.Sequential(colors.SequentialRamp).WithValueRange(0, 12)
.WithLabels("Quiet", null, "Busy").WithNoDataColor(colors.Border))
.WithValueFormat(ChartValueFormat.Number("0.##", CultureInfo.InvariantCulture));
}
}