shadcn.io is not affiliated with official shadcn/ui
Treemap Stats Block for React
A treemap of eight folders for a cloud-storage tool, each box as big as its share of the disk, at weights from 100% to 9%, with every folder's size and share in a list under the map.
Installation
Overview
A treemap for React with Base UI. A start-aligned header names the biggest folder, "Photos fill 35% of your 1.2 TB", and under it one hairline frame with a + on each corner holds a treemap of eight folders and a list of all eight. Each folder is a box whose area is its share of the disk: the list is halved, the map is cut along its longer side in the same ratio, and each half is cut again, so the biggest folders get the biggest boxes. The boxes are solid mixes of your theme's text colour, from full strength down to 9%, with a two-pixel gap between them, and carry their name and size when they have room: all but the two smallest on a wide screen, the five biggest on the square map a phone draws. The list under the map gives every folder's size and share (the shares add to exactly 100). The layout is computed once from the folder sizes, so the map, the list and the headline agree. It's absolutely positioned boxes with no chart library. For storage, budget, traffic and any breakdown where size should look like size.
FAQ
How do I change the folders?
Edit FOLDERS at the top of the file: each is a name and its size in gigabytes, biggest first. The shares, the layout, the labels and the headline are computed from them. The tones in TONES are listed by rank, so with a different number of folders add or remove tones to match.
How is the treemap laid out?
By repeated halving. The folders are split into two groups of about the same total, the box is cut along its longer side in the ratio of the groups, and each half is cut again until one folder is left in each box. That keeps the order of the list (the biggest folder at the start), never produces a sliver, and needs no library. It runs once when the module loads and writes each box as a position and size in percent, so there is no layout code in the browser.
Why does the map change shape on a phone?
A 16 by 7 map would be 343 pixels wide and 150 tall on a phone, too small for any label. The block computes a second layout for a square and shows that one below sm, with the five biggest boxes labelled; the other three are in the list. Only one of the two is shown at a time, and both are hidden from assistive technology because the list says the same in words.
Can a screen reader read the chart?
Yes, through the list under it: a description list with each folder's name, its size and its share, in the order of the map. The boxes themselves are decorative. Text on the three darkest boxes is the page's background colour and text on the lighter ones is the foreground colour, so every label is readable in light and dark themes.
Does it work in right-to-left languages?
The map sits in a left-to-right box, so the biggest folder is always at the start of the line and the layout never mirrors; the header, the list and the shares follow the page direction, and the sizes and percents are wrapped in bdi elements so they never reorder.
Related
- Pro
Waffle Chart Stats
Parts of a wholeA ten by ten grid of a hundred squares for a polling tool, one square per percent of the votes, filled column by column from the foot in four tones, with a list of the answers that lifts its squares when you point at it.
- Pro
Stacked Percentage Bar Stats
Parts of a wholeOne thick bar of a consultancy's week split into four segments at four weights with labels inside the wide ones, and a band of four legend cells under it; pointing at or focusing a cell brackets its segment.
- Pro
Donut Breakdown Stats
Parts of a wholeA budgeting app's month of spending as a framed donut with its total rolling up in the middle, beside a legend of five buckets with amount and share, the shares adding up to exactly 100%.
- Pro
Horizontal Bar Chart Card Stats
Bar and columnNine ranked survey answers where each row is its own bar: a quiet fill from the start behind the label, the share and the count at the end, and the leading row a little stronger.
- Pro
Pareto Chart Stats
Bar and columnA defect Pareto: seven bars sorted largest first, a cumulative line on a second axis, an 80% line and a bracket over the vital few, with a list of every cause's count, share and running share.
- Pro
Lollipop Chart Stats
Bar and columnA week of steps as seven thin stems topped by dots, the count above each, a goal hairline and a ring around the peak, in a split with the week's total, the daily average and the days at goal.