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
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
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 like this
Build an Editable Monthly Budget Snapshot One-Pager in a Single HTML File
A one-page personal budget snapshot with editable income and spending figures that instantly update a donut chart, savings-rate meter and over-budget flags, and that prints cleanly.
Build a 100-Person Icon Array Demographic Infographic in One HTML File
You get a single HTML file that shows a fictional town as 100 SVG person icons, with tabs for commute, age and housing and an interactive legend that highlights each group.
Build a 12-Week Fitness Progress Tracker Infographic in a Single HTML File
Generates a one-page fitness report with bodyweight and lift line charts, personal-record badges, a streak calendar and an instant kg/lb toggle, all from built-in sample data.
Build a Before-and-After Statistics Infographic With Color-Coded Change Arrows
A single HTML infographic comparing two years across nine metrics, showing old and new values, absolute and percent change, and arrows colored by whether up is good.
Build a Classroom Grade Distribution Infographic with Histogram and Quartiles
A single HTML file that turns an inline array of class scores into a histogram with mean and median markers, a box plot, stat cards and a plain-language summary.
Build a Company Fact Sheet One-Pager with Animated Stats and a Location Map
You get a single HTML file laid out like an investor or press fact sheet, with animated stat counters, mission, leadership, milestones, an interactive SVG office map and a brand-color theme switch.