{"spec_id":"horizon-basic","library":"makie","language":"julia","code":"# anyplot.ai\n# horizon-basic: Horizon Chart\n# Library: makie 0.21.9 | Julia 1.11.9\n# Quality: 91/100 | Created: 2026-08-20\n\nusing CairoMakie\nusing Colors\nusing Random\n\nRandom.seed!(42)\n\n# --- Theme tokens -----------------------------------------------------------\nconst THEME    = get(ENV, \"ANYPLOT_THEME\", \"light\")\nconst PAGE_BG  = THEME == \"light\" ? colorant\"#FAF8F1\" : colorant\"#1A1A17\"\nconst INK      = THEME == \"light\" ? colorant\"#1A1A17\" : colorant\"#F0EFE8\"\nconst INK_SOFT = THEME == \"light\" ? colorant\"#4A4A44\" : colorant\"#B8B7B0\"\nconst IMPRINT_PALETTE = [\n    colorant\"#009E73\", colorant\"#C475FD\", colorant\"#4467A3\", colorant\"#BD8233\",\n    colorant\"#AE3030\", colorant\"#2ABCCD\", colorant\"#954477\", colorant\"#99B314\",\n]\nconst POS_COLOR = IMPRINT_PALETTE[1]  # brand green — above-baseline deviation\nconst NEG_COLOR = IMPRINT_PALETTE[5]  # matte red — below-baseline deviation\n\n# --- Data ---------------------------------------------------------------\n# Ten server CPU-load deviations (percentage points) from a 24h rolling\n# baseline, sampled every 10 minutes — a typical horizon-chart dashboard use.\nconst N_POINTS = 145\nconst N_BANDS  = 3\n\nserver_names = [\n    \"api-gateway\", \"auth-service\", \"web-frontend\", \"payments-svc\",\n    \"search-index\", \"cache-redis\", \"db-primary\", \"db-replica\",\n    \"worker-queue\", \"load-balancer\",\n]\nn_series = length(server_names)\n\nt = collect(range(0.0, 24.0; length = N_POINTS))\n\nseries_values = Vector{Vector{Float64}}(undef, n_series)\nfor i in 1:n_series\n    walk = cumsum(randn(N_POINTS) .* 0.9)\n    trend = range(walk[1], walk[end]; length = N_POINTS)\n    series_values[i] = walk .- collect(trend)\nend\n\nband_height = maximum(maximum(abs.(v)) for v in series_values) / N_BANDS\nband_alphas = range(0.35, 1.0; length = N_BANDS)\n\n# Most notable anomaly, for an explicit storytelling callout below the chart.\npeak_series_idx = argmax([maximum(abs.(v)) for v in series_values])\npeak_series_name = server_names[peak_series_idx]\npeak_values = series_values[peak_series_idx]\npeak_idx = argmax(abs.(peak_values))\npeak_time = t[peak_idx]\npeak_value = peak_values[peak_idx]\npeak_sign = peak_value >= 0 ? \"above\" : \"below\"\n\n# --- Plot -----------------------------------------------------------------\nfig = Figure(\n    resolution      = (1600, 900),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\nLabel(\n    fig[1, 1], \"horizon-basic · julia · makie · anyplot.ai\";\n    fontsize = 22, color = INK, font = :bold, halign = :left,\n)\nLabel(\n    fig[2, 1],\n    \"CPU load deviation from 24h baseline, folded into $(N_BANDS) bands of ≈$(round(band_height, digits = 2))pp each per server — darker fill marks larger deviation\";\n    fontsize = 13, color = INK_SOFT, halign = :left,\n)\n\nLegend(\n    fig[1:2, 2],\n    [PolyElement(color = POS_COLOR), PolyElement(color = NEG_COLOR)],\n    [\"Above baseline\", \"Below baseline\"];\n    framevisible = false,\n    labelsize = 12,\n    labelcolor = INK,\n    patchsize = (14, 10),\n    patchlabelgap = 6,\n    rowgap = 2,\n    tellheight = false,\n    valign = :center,\n    halign = :left,\n)\n\nzero_line = zeros(N_POINTS)\nfor (i, name) in enumerate(server_names)\n    row = 2 + i\n    ax = Axis(\n        fig[row, 1];\n        ylabel              = name,\n        ylabelsize          = 13,\n        ylabelcolor         = INK,\n        ylabelfont          = (i == peak_series_idx ? :bold : :regular),\n        ylabelrotation      = 0,\n        backgroundcolor     = PAGE_BG,\n        xgridvisible        = false,\n        ygridvisible        = false,\n        topspinevisible     = false,\n        rightspinevisible   = false,\n        leftspinevisible    = false,\n        bottomspinevisible  = (i == n_series),\n        bottomspinecolor    = INK_SOFT,\n    )\n\n    values = series_values[i]\n    for b in 1:N_BANDS\n        folded_pos = clamp.(values .- (b - 1) * band_height, 0.0, band_height)\n        band!(ax, t, zero_line, folded_pos; color = (POS_COLOR, band_alphas[b]))\n\n        folded_neg = clamp.(.-values .- (b - 1) * band_height, 0.0, band_height)\n        band!(ax, t, zero_line, folded_neg; color = (NEG_COLOR, band_alphas[b]))\n    end\n\n    limits!(ax, (0.0, 24.0), (0.0, band_height))\n    hideydecorations!(ax; label = false)\n\n    if i == n_series\n        ax.xlabel = \"Time (hours)\"\n        ax.xlabelsize = 14\n        ax.xlabelcolor = INK\n        ax.xticklabelsize = 12\n        ax.xticklabelcolor = INK_SOFT\n        ax.xtickcolor = INK_SOFT\n    else\n        hidexdecorations!(ax)\n    end\nend\n\nrowgap!(fig.layout, 4)\ncolgap!(fig.layout, 20)\n\nLabel(\n    fig[n_series + 3, 1:2],\n    \"Notable: $(peak_series_name) shows the largest deviation of all ten servers — \" *\n    \"$(round(abs(peak_value), digits = 2))pp $(peak_sign) baseline at $(round(peak_time, digits = 1))h\";\n    fontsize = 11, color = INK_SOFT, halign = :left,\n)\n\n# --- Save -------------------------------------------------------------------\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}