{"spec_id":"audiogram-clinical","library":"makie","language":"julia","code":"# anyplot.ai\n# audiogram-clinical: Clinical Audiogram\n# Library: makie 0.22.10 | Julia 1.11.9\n# Quality: 89/100 | Created: 2026-06-15\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 ELEVATED_BG = THEME == \"light\" ? colorant\"#FFFDF6\" : colorant\"#242420\"\nconst INK         = THEME == \"light\" ? colorant\"#1A1A17\" : colorant\"#F0EFE8\"\nconst INK_SOFT    = THEME == \"light\" ? colorant\"#4A4A44\" : colorant\"#B8B7B0\"\nconst INK_MUTED   = THEME == \"light\" ? colorant\"#6B6A63\" : colorant\"#A8A79F\"\n\n# Audiogram follows standard audiological color conventions (semantic exception):\n# right ear → red (Imprint position 5), left ear → blue (Imprint position 3)\nconst RIGHT_EAR_COLOR = colorant\"#AE3030\"\nconst LEFT_EAR_COLOR  = colorant\"#4467A3\"\n\n# Pure-tone audiometry data — noise-induced high-frequency sensorineural notch\nconst FREQUENCIES     = Float64[125, 250, 500, 1000, 2000, 4000, 8000]\nconst THRESHOLD_RIGHT = Float64[10,  10,  15,  20,   35,   65,   50]\nconst THRESHOLD_LEFT  = Float64[15,  15,  20,  25,   40,   70,   55]\n\n# Severity band fill alpha — dark mode reduced to prevent over-saturation\nband_alpha = THEME == \"light\" ? 0.12f0 : 0.14f0\n\n# Severity bands: (y_low, y_high, label, fill_color)\n# Colors derived from exact Imprint palette members:\n#   IP1 #009E73 (pos 1 — green), IP4 #BD8233 (pos 4 — ochre), IP5 #AE3030 (pos 5 — red)\nbands = [\n    (-10.0,  25.0, \"Normal\",      RGBAf(0.000f0, 0.620f0, 0.451f0, band_alpha)),\n    ( 25.0,  40.0, \"Mild\",        RGBAf(0.741f0, 0.510f0, 0.200f0, band_alpha)),\n    ( 40.0,  55.0, \"Moderate\",    RGBAf(0.741f0, 0.510f0, 0.200f0, band_alpha * 1.4f0)),\n    ( 55.0,  70.0, \"Mod. Severe\", RGBAf(0.682f0, 0.188f0, 0.188f0, band_alpha)),\n    ( 70.0,  90.0, \"Severe\",      RGBAf(0.682f0, 0.188f0, 0.188f0, band_alpha * 1.5f0)),\n    ( 90.0, 120.0, \"Profound\",    RGBAf(0.682f0, 0.188f0, 0.188f0, band_alpha * 2.0f0)),\n]\n\n# Figure — square canvas (audiograms are conventionally square)\nfig = Figure(\n    resolution      = (1200, 1200),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\nax = Axis(\n    fig[1, 1];\n    title             = \"audiogram-clinical · julia · makie · anyplot.ai\",\n    titlesize         = 20,\n    titlecolor        = INK,\n    xlabel            = \"Frequency (Hz)\",\n    ylabel            = \"Hearing Level (dB HL)\",\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    xscale            = log10,\n    yreversed         = true,\n    xticks            = ([125, 250, 500, 1000, 2000, 4000, 8000],\n                         [\"125\", \"250\", \"500\", \"1k\", \"2k\", \"4k\", \"8k\"]),\n    yticks            = collect(-10:10:120),\n    limits            = (90, 10000, -10, 120),\n    xgridcolor        = RGBAf(INK.r, INK.g, INK.b, 0.15f0),\n    ygridcolor        = RGBAf(INK.r, INK.g, INK.b, 0.15f0),\n    xminorgridvisible = false,\n    yminorgridvisible = false,\n)\n\n# Severity bands drawn below data; labels centered in each band at 1 kHz\nfor (y1, y2, label, band_color) in bands\n    hspan!(ax, y1, y2; color = band_color)\n    text!(ax, 1000.0, (y1 + y2) / 2;\n          text     = label,\n          color    = INK_MUTED,\n          fontsize = 12,\n          align    = (:center, :center))\nend\n\n# Focal-point emphasis on clinically significant 4 kHz sensorineural notch\ntext!(ax, 4700.0, 56.0;\n      text     = \"4 kHz notch\",\n      color    = INK_SOFT,\n      fontsize = 10,\n      align    = (:left, :center))\n\n# Connecting lines (drawn first so markers sit on top)\nlines!(ax, FREQUENCIES, THRESHOLD_RIGHT;\n       color     = RIGHT_EAR_COLOR,\n       linewidth = 2.5)\nlines!(ax, FREQUENCIES, THRESHOLD_LEFT;\n       color     = LEFT_EAR_COLOR,\n       linewidth = 2.5,\n       linestyle = :dash)\n\n# Markers — right ear: filled circle (O), left ear: × cross (X)\nscatter!(ax, FREQUENCIES, THRESHOLD_RIGHT;\n         color       = RIGHT_EAR_COLOR,\n         marker      = :circle,\n         markersize  = 16,\n         strokewidth = 1.5,\n         strokecolor = PAGE_BG)\nscatter!(ax, FREQUENCIES, THRESHOLD_LEFT;\n         color      = LEFT_EAR_COLOR,\n         marker     = :xcross,\n         markersize = 18,\n         strokewidth = 0)\n\n# Inset legend\nleg_entries = [\n    [MarkerElement(marker = :circle, color = RIGHT_EAR_COLOR, markersize = 14,\n                   strokewidth = 1.5, strokecolor = PAGE_BG),\n     LineElement(color = RIGHT_EAR_COLOR, linewidth = 2.5)],\n    [MarkerElement(marker = :xcross, color = LEFT_EAR_COLOR, markersize = 14),\n     LineElement(color = LEFT_EAR_COLOR, linewidth = 2.5, linestyle = :dash)],\n]\nleg_labels = [\"Right Ear (O)\", \"Left Ear (X)\"]\n\nLegend(fig[1, 1], leg_entries, leg_labels;\n       tellwidth       = false,\n       tellheight      = false,\n       halign          = :right,\n       valign          = :bottom,\n       margin          = (20, 20, 20, 20),\n       framevisible    = true,\n       framecolor      = INK_SOFT,\n       backgroundcolor = ELEVATED_BG,\n       labelcolor      = INK,\n       fontsize        = 12,\n       patchsize       = (22, 12),\n)\n\n# Save\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}