{"spec_id":"span-basic","library":"makie","language":"julia","code":"# anyplot.ai\n# span-basic: Basic Span Plot (Highlighted Region)\n# Library: makie 0.21.9 | Julia 1.11.9\n# Quality: 91/100 | Created: 2026-07-25\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 ANYPLOT_AMBER = colorant\"#DDCC77\"  # warning / caution — outside the categorical pool\nconst ANYPLOT_MUTED = THEME == \"light\" ? colorant\"#6B6A63\" : colorant\"#A8A79F\"\nconst ANYPLOT_ALERT = colorant\"#AE3030\"  # bad / breach — semantic-red anchor\n\n# --- Data ---------------------------------------------------------------\n# Daily API response latency (ms) over a 90-day monitoring window, with two\n# operational events overlaid: an incident-driven spike and a planned\n# maintenance bump.\ndays = 1:90\nlatency = fill(120.0, 90) .+ randn(90) .* 8.0\n\nincident_days = 35:41\nlatency[incident_days] .+= 55.0 .+ randn(length(incident_days)) .* 5.0\n\nmaintenance_days = 65:70\nlatency[maintenance_days] .+= 18.0 .+ randn(length(maintenance_days)) .* 3.0\n\nsla_threshold = 160.0  # ms — response times above this breach the SLA\n\n# --- Plot -----------------------------------------------------------------\nfig = Figure(\n    size            = (1600, 900),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\nax = Axis(\n    fig[1, 1];\n    title              = \"span-basic · julia · makie · anyplot.ai\",\n    titlesize          = 20,\n    titlecolor         = INK,\n    xlabel             = \"Day of Monitoring Window\",\n    ylabel             = \"API Response Latency (ms)\",\n    xlabelsize         = 14,\n    ylabelsize         = 14,\n    xlabelcolor        = INK,\n    ylabelcolor        = INK,\n    xticklabelsize     = 12,\n    yticklabelsize     = 12,\n    xticklabelcolor    = INK_SOFT,\n    yticklabelcolor    = INK_SOFT,\n    xtickcolor         = INK_SOFT,\n    ytickcolor         = INK_SOFT,\n    backgroundcolor    = PAGE_BG,\n    topspinevisible    = false,\n    rightspinevisible  = false,\n    leftspinecolor     = INK_SOFT,\n    bottomspinecolor   = INK_SOFT,\n    xgridvisible       = false,\n    ygridcolor         = RGBAf(INK.r, INK.g, INK.b, 0.15),\n)\n\nvspan!(ax, 34.5, 41.5; color = (ANYPLOT_AMBER, 0.25), label = \"Incident: Database Failover\")\nvspan!(ax, 64.5, 70.5; color = (ANYPLOT_MUTED, 0.2), label = \"Scheduled Maintenance\")\nhspan!(ax, sla_threshold, 200; color = (ANYPLOT_ALERT, 0.09), label = \"SLA Threshold (>160ms)\")\n\n# Thin edge strokes give each span a crisper boundary against the grid,\n# without adding duplicate legend entries.\nvlines!(ax, [34.5, 41.5]; color = ANYPLOT_AMBER, linewidth = 1.5, linestyle = :dash)\nvlines!(ax, [64.5, 70.5]; color = ANYPLOT_MUTED, linewidth = 1.5, linestyle = :dash)\nhlines!(ax, [sla_threshold]; color = ANYPLOT_ALERT, linewidth = 1.5, linestyle = :dash)\n\nlines!(ax, days, latency; color = IMPRINT_PALETTE[1], linewidth = 3, label = \"Response Latency\")\n\n# Fix y-limits to the data's natural range; the SLA hspan's upper bound (200)\n# is intentionally past the visible area so the \"breach zone\" reads as\n# extending to the top of the chart, without dragging the autolimits along.\nylims!(ax, 95, 195)\n\naxislegend(\n    ax;\n    position        = :lt,\n    framevisible    = false,\n    backgroundcolor = :transparent,\n    labelcolor      = INK_SOFT,\n)\n\n# --- Save -------------------------------------------------------------------\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}