{"spec_id":"pie-basic","library":"makie","language":"julia","code":"# anyplot.ai\n# pie-basic: Basic Pie Chart\n# Library: makie 0.22.10 | Julia 1.11.9\n# Quality: 90/100 | Created: 2026-05-28\n\nusing CairoMakie\nusing Colors\nusing Printf\n\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 LABEL_FG    = colorant\"#FFFFFF\"\n\nconst IMPRINT_PALETTE = [\n    colorant\"#009E73\",\n    colorant\"#C475FD\",\n    colorant\"#4467A3\",\n    colorant\"#BD8233\",\n    colorant\"#AE3030\",\n]\n\nconst categories  = [\"Python\", \"JavaScript\", \"Java\", \"C / C++\", \"TypeScript\"]\nconst values      = [36.0, 29.5, 17.0, 11.5, 6.0]\nconst total       = sum(values)\nconst fracs       = values ./ total\nconst pct         = fracs .* 100\n\nconst explode_idx = argmax(values)\nconst explode_r   = 0.08\n\n# Cumulative fractions for angle calculations (matches pie! counterclockwise convention)\nconst cum        = cumsum(vcat(0.0, fracs))\nconst PIE_OFFSET = Float64(π / 2)\n\nconst title_str = \"Primary Programming Language · pie-basic · julia · makie · anyplot.ai\"\nconst title_fs  = round(Int, 20 * min(1.0, 66.0 / length(title_str)))\n\nfig = Figure(\n    size            = (1200, 1200),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n    figure_padding  = 40,\n)\n\nax = Axis(\n    fig[1, 1];\n    title              = title_str,\n    titlesize          = title_fs,\n    titlefont          = :bold,\n    titlegap           = 24,\n    titlecolor         = INK,\n    aspect             = DataAspect(),\n    backgroundcolor    = PAGE_BG,\n    topspinevisible    = false,\n    rightspinevisible  = false,\n    leftspinevisible   = false,\n    bottomspinevisible = false,\n    xgridvisible       = false,\n    ygridvisible       = false,\n    xticksvisible      = false,\n    yticksvisible      = false,\n    xticklabelsvisible = false,\n    yticklabelsvisible = false,\n)\n\n# High-level Makie pie! recipe — idiomatic slice rendering\np = pie!(\n    ax, fracs;\n    color       = IMPRINT_PALETTE[1:length(categories)],\n    strokecolor = PAGE_BG,\n    strokewidth = 3,\n    offset      = PIE_OFFSET,\n)\n\n# Explode the dominant slice by translating its child polygon outward\nlet θ = PIE_OFFSET + (cum[explode_idx] + fracs[explode_idx] / 2) * 2π\n    translate!(p.plots[explode_idx], Vec3f(explode_r * cos(θ), explode_r * sin(θ), 0))\nend\n\n# Percentage labels at arc midpoints; dominant slice gets bolder, larger label\nfor i in 1:length(values)\n    θ  = PIE_OFFSET + (cum[i] + fracs[i] / 2) * 2π\n    ex = i == explode_idx ? explode_r * cos(θ) : 0.0\n    ey = i == explode_idx ? explode_r * sin(θ) : 0.0\n    if i == explode_idx\n        text!(ax, ex + 0.62 * cos(θ), ey + 0.62 * sin(θ);\n              text     = @sprintf(\"%.1f%%\", pct[i]),\n              align    = (:center, :center),\n              fontsize = 17,\n              font     = :bold,\n              color    = LABEL_FG,\n        )\n    else\n        text!(ax, ex + 0.62 * cos(θ), ey + 0.62 * sin(θ);\n              text     = @sprintf(\"%.1f%%\", pct[i]),\n              align    = (:center, :center),\n              fontsize = 13,\n              color    = LABEL_FG,\n        )\n    end\nend\n\n# Explicit limits so the translated slice stays fully in view\nlimits!(ax, -1.2, 1.2, -1.2, 1.2)\n\nlegend_entries = [PolyElement(color = IMPRINT_PALETTE[i], strokecolor = :transparent) for i in 1:length(categories)]\nlegend_labels  = [@sprintf(\"%s  %.1f%%\", categories[i], pct[i]) for i in 1:length(categories)]\n\nLegend(\n    fig[1, 2],\n    legend_entries,\n    legend_labels;\n    framevisible    = false,\n    backgroundcolor = ELEVATED_BG,\n    labelcolor      = INK,\n    labelsize       = 14,\n    rowgap          = 14,\n    halign          = :left,\n    valign          = :center,\n    padding         = (16, 16, 16, 16),\n)\n\ncolsize!(fig.layout, 1, Relative(0.68))\ncolgap!(fig.layout, 1, 20)\n\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}