Build a Budget Allocation Treemap Infographic in a Single HTML File

You get one HTML file that draws a squarified treemap of a city budget, hides labels on small blocks, and shows a details panel when you tap or click any block.

The prompt

Prompt
Act as a senior data-visualization developer who writes clean, dependency-free JavaScript.

Build a budget infographic called "Where Your Dollar Goes" for the fictional town of Alder Falls, showing its $48.6M annual budget as a treemap. Use 12 realistic line items (police, fire and rescue, roads, water and sewer, parks, library, transit, housing, debt service, administration, waste collection, arts and events) grouped into four color-coded groups: Public Safety, Infrastructure, Community, Operations.

Rules:
1. Write your own squarified treemap algorithm in plain JavaScript. No libraries, canvas optional. Each block is a focusable button whose area matches its share of the total.
2. Labels must hide gracefully: show name plus amount on large blocks, name only on medium blocks, and no text on tiny blocks. Every block keeps a full aria-label and tooltip.
3. Clicking, tapping or pressing Enter on a block fills a details panel with amount, percent of budget, cost per resident (population 41,200), a progress bar and a one-sentence plain-language note. Escape clears the selection.
4. Add a legend whose group buttons highlight one group and dim the others, with group totals shown.
5. Recompute the layout on window resize. The treemap sits beside the panel on wide screens and stacks above it under 760px.
6. Use four muted colors with white text at readable contrast, a clear type scale, and disable transitions for prefers-reduced-motion.

Output format: one complete HTML file in a single code block, then 3 short ideas to extend it.

Example output

One HTML file. Save it and open it in any browser.Open full screen

Example: Where Your Dollar Goes, the Alder Falls 2025 budget treemap.

The page shows twelve spending blocks sized by their share of a $48.6M budget, colored by four groups. Big blocks show the name and amount, smaller ones show just the name, and tiny ones show no text. Click or tap a block, or Tab to it and press Enter, to see its amount, share, cost per resident and a short explanation. Use the legend to highlight a group. Press Esc to clear. Resize the window to watch the layout rebuild.

Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Spelling out the squarified algorithm and label thresholds avoids long, thin slivers and overlapping text on small blocks.
  • Making each block a real button gives you keyboard, touch and screen-reader support without extra code.
  • Fixed sample data with a population figure lets the model compute per-resident costs, so the panel feels real right away.

Paste the prompt into ChatGPT, Claude or Gemini. Save the returned code as budget.html and open it in any browser, or view it in the chat's preview or canvas panel.

Common edits

  • Swap in your own budget lines, amounts and groups, such as a household, startup or school budget, and change the title and population.
  • Add a second level so tapping a group zooms into its sub-items, or add a toggle that compares this year with last year.

Prompt details

By
Prompts-GPT editors
Published

Did this prompt work?

Keep exploring

More in Infographics