Skip to content

Link the sidebar and treemap selections, with size sparklines in the sidebar - #23

Merged
phalladar merged 5 commits into
phalladar:mainfrom
horus-leonardo:feat/linked-sidebar
Nov 24, 2026
Merged

phalladar merged 5 commits into
phalladar:mainfrom
horus-leonardo:feat/linked-sidebar

Conversation

@horus-leonardo

Copy link
Copy Markdown
Contributor

Closes #21. Three commits: per-category totals, linked selection, sparklines.

What changes

  • Sidebar → treemap: selecting a folder outlines it in the treemap and dims everything outside it. If the folder is outside the treemap's current root, the treemap moves to the folder's parent.
  • Treemap → sidebar: clicking a rectangle expands the sidebar down to that folder and scrolls to it. A file selects its folder's row while the inspector keeps showing the file.
  • Double-click or Return on a row drills the treemap into the folder; the context menu offers Reveal in Finder, Copy Path and Show in Treemap. Collapsing a folder that hides the selection selects that folder, as in Finder.
  • Sparklines: each row shows the folder's share of its parent, split by category in the treemap's colors.

Implementation notes

  • The sidebar is a List of DisclosureGroups bound to expandedIDs in AppState. OutlineGroup can't be expanded or scrolled programmatically, which the treemap → sidebar direction needs. Native chevrons, ←/→ and outline accessibility are kept.
  • computeAggregates stores bytes per category in each folder, so the sparklines and the inspector's breakdown stop walking the subtree.
  • The selection outline is drawn on its own canvas, so changing the selection doesn't redraw the treemap.
  • Reveal in Finder and Copy Path moved into FileActions, shared by the inspector, the sidebar and the treemap menus.

Measurements

Synthetic tree of 1.37M files and 137k folders, swiftc -O:

main this PR
categoryBreakdown on the root 41 ms 0.2 µs
computeAggregates 27 ms 35 ms
memory 307 MB 332 MB (+8%)

File and allocated sizes share one array, so a node grows from 184 to 192 bytes and stays in the same malloc size class.

Behavior changes

  • Categories with zero bytes are no longer listed in the breakdown.
  • The sidebar's ideal width goes from 260 to 300 pt to fit the sparkline column.

Validation

  • swift build and swift test.
  • On macOS 27, with a local build (SDK 15) and the same build stamped as SDK 26 with vtool: revealing and scrolling to a folder 10 levels deep from a treemap click, ←/→, collapsing an ancestor of the selection, double-click/Return drill-down, and the context menu.

🤖 Generated with Claude Code

horus-leonardo and others added 3 commits November 24, 2026 12:08
computeAggregates now also sums bytes per category, so categoryBreakdown
reads stored totals instead of walking the subtree on every call. The
inspector calls it on each selection, and the sidebar sparklines will
call it once per visible row.

On a synthetic tree of 1.37M files and 137k folders (swiftc -O):
- categoryBreakdown on the root: 41 ms -> 0.2 µs per call
- computeAggregates: 27 ms -> 35 ms
- memory: +25 MB (+8%)

File and allocated sizes share one array, so a node grows from 184 to
192 bytes and stays in the same malloc size class; with two arrays it
crossed into the next one. Categories with zero bytes are no longer
listed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Selecting a folder in the sidebar outlines it in the treemap and dims
everything outside it; if the folder is outside the treemap's current
root, the treemap moves to the folder's parent. Clicking in the treemap
expands the sidebar down to the item's folder and scrolls to it. A file
selects its folder's row while the inspector keeps showing the file.

OutlineGroup can't be expanded or scrolled programmatically, so the
sidebar is now a List of DisclosureGroups bound to a set of expanded
folders in AppState. Rows keep native chevrons, arrow keys and outline
accessibility. Double-click or Return on a row drills the treemap into
the folder, and the context menu offers Reveal in Finder, Copy Path and
Show in Treemap. Collapsing a folder that hides the selection selects
that folder, as in Finder.

The selection outline moved from the base canvas to its own overlay, so
changing the selection doesn't redraw the treemap. Reveal in Finder and
Copy Path moved into FileActions, now shared by three menus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each row gets a small bar: its length is the folder's share of its
parent, split by file category in the treemap's colors, so you can see
where the space goes without opening every folder. It reads the
per-category totals stored by computeAggregates.

The sparkline and a fixed-width size column take about 50 pt, so the
sidebar's ideal width goes from 260 to 300 pt, and the folder name keeps
layout priority so deep rows don't truncate it to nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@phalladar phalladar left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @horus-leonardo, this is a great addition! Linking the sidebar and treemap makes the app much easier to navigate, and the per-category totals are a nice win for the inspector. I built it locally, ran the tests, and tried the linked selection in the app; it works well.

Two small things I'd like changed before merging, both performance:

  1. FileCategory.index runs a linear search over allCases for every file in computeAggregates. allCases likely allocates a fresh array on each call, which probably accounts for most of the 27 → 35 ms slowdown. A switch, or a lookup cached in a static let, should get most of that back.

  2. revealInTree writes to expandedIDs on every selection, even when the ancestors are already expanded. Any mutation of an @Observable property notifies its observers, so every treemap click redraws every visible DisclosureGroup row. That gets noticeable on large expanded trees. Checking contains before insert, or building the new set and assigning it only when it differs, would avoid it.

Non-blocking, just thoughts:

  • Once a folder is selected, the dimming stays until the selection changes. It might be worth letting Esc or a click on empty space clear it.
  • When a file is selected, clicking its folder's row does nothing and the inspector keeps showing the file. I see that's deliberate, but some users may expect to see the folder.

Happy to approve once the two fixes are in. Thanks again!

horus-leonardo and others added 2 commits November 24, 2026 12:40
Any write to an @observable property notifies its observers, so
inserting ids that were already present made every treemap click
redraw every visible sidebar row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Esc selects the folder the treemap shows, which removes the dimming
around a selected folder.

Clicking the sidebar row of a selected file's folder now selects the
folder. The selection setter ignored the row's own id to keep the file
selected, but the List only writes the selection on a click, so the
guard only blocked that case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@horus-leonardo

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Pushed two commits:

  • d82255c revealInTree checks contains before inserting, so a click that doesn't expand anything no longer notifies observers.
  • b2bcefc Esc selects the folder the treemap shows, clearing the dimming. Clicking the row of a selected file's folder now selects the folder: the guard in the selection setter only ever blocked that click, since the List writes the selection only when a row is clicked.

On FileCategory.index, I measured before changing it (synthetic tree, 1.37M files / 137k folders, swiftc -O, best of 5):

Variant computeAggregates
main ~27 ms
this PR (allCases.firstIndex) ~35 ms
switch ~35 ms
allCases cached in a static let ~36 ms
allocating the per-folder array, no summing ~32 ms

The lookup costs about nothing; the compiler doesn't allocate allCases for a simple enum. Of the extra 8 ms, about 5 come from allocating one 20-slot array per folder and about 3 from the sums, which is the cost of storing the totals. So I left it as is, but happy to use a switch if you prefer it for readability.

Tested on macOS 27 with SDK 15 and SDK 26 builds.

@phalladar phalladar left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @horus-leonardo, the updates look great, and thanks for measuring the FileCategory.index change. You're right that the lookup costs nothing, so leaving it as is makes sense.

I tested the new build in the app, and everything passed:

  • Clicking a file deep in the treemap expands and scrolls the sidebar to its folder, and the inspector keeps showing the file.
  • Clicking a selected file's folder row selects the folder, with the outline and dimming.
  • Esc clears the dimming.
  • Esc still cancels a scan in progress.

Merging now. Thanks again for the contribution, it's a really nice improvement to the app!

@phalladar
phalladar merged commit 9aad387 into phalladar:main Nov 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Link the sidebar and the treemap selection, with size sparklines in the sidebar

2 participants