Skip to content

Trace tree paths and colour by tree distance in the inspector - #39

Merged
afloresep merged 1 commit into
masterfrom
tree-path-explorer
Aug 22, 2026
Merged

Trace tree paths and colour by tree distance in the inspector#39
afloresep merged 1 commit into
masterfrom
tree-path-explorer

Conversation

@afloresep

Copy link
Copy Markdown
Owner

Follows #37. The tree layout is what TMAP is pitched on, but the operations that make a tree worth having were reachable only from Python (model.path, distances_from). The interactive HTML — the thing people actually share — could not do them.

This adds two of them to the inspector.

Path. Pin two points and the map highlights the tree path between them. The inspector lists every node along the way with its step number and running tree distance.

Colour by distance. One click colours the whole map by tree distance from the selected point.

UI

The Neighbors and Path chips replace the old "Show neighborhood" toggle. The chip picks what the list below it contains, so no new panel or toolbar button is added — the section head goes from one button to two chips. Path is disabled with a tooltip until a second point is pinned, so it is discoverable before it is usable.

Distance colouring is a text link that registers a synthetic column and hands it to the existing Color by menu, so the legend, colormap and selector work unmodified.

Cost

Both features are one breadth-first walk over the adjacency index #37 already builds. Nothing new is written to the exported HTML — the file grows by 20 KB (6 KB gzipped) regardless of dataset size.

Walk cost, measured on the shipped code:

tree full walk path distance column repeat walk
200k real MST 4.0 ms 3.8 ms 3.9 ms 0 ms
1M 12.2 ms 11.9 ms 13.3 ms 0 ms
5M 60.8 ms 60.3 ms 63.6 ms 0 ms

Scratch buffers are allocated once and reused: 12 bytes per point (12 MB at 1M, against a ~478 MB baseline heap for a map that size).

End to end in the browser, click to handler complete:

action 10k 200k 1M
Neighbors 8 ms 5 ms 2 ms
Path 68 ms (44 nodes) 111 ms (180 steps) 287 ms (1,637 steps)
Distance colouring 19 ms 35 ms 42 ms

Path lists start at 20 rows behind a "Show all" button. Rendering a 216-node path in full was the slowest thing the inspector did — 277 ms at 200k points versus 111 ms capped — and long paths are common.

Checked on real maps

examples/pet_breed_audit.py, unmodified: 3,669 Oxford-IIIT Pets images, 37 breeds, 90.0% probe accuracy. Tracing from a Japanese Chin to a Siamese gives a 43-step path:

Japanese Chin ×5 → Saint Bernard → Chihuahua ×6 → Sphynx ×8
  → Egyptian Mau ×4 → Russian Blue ×6 → British Shorthair ×3
  → Ragdoll / Maine Coon ×8 → Birman ×2 → Siamese

The dog-to-cat crossing runs Chihuahua → Sphynx, which is the bridge described in the README. That map has no SMILES, only add_images, so it also exercises the image fallback in the path rows.

Also checked on 10k and 200k ChEMBL molecules and a synthetic 1M-point tree.

Notes

  • A Subtree mode was built and then removed: lasso selection already covers isolating a region, and it was the only mode that needed a size guard (selecting a 1M-point branch stalled for 1.6 s inside scatterplot.select). test_subtree_isolation_is_not_offered keeps it out.
  • Fixes a pre-existing light-theme contrast problem on the "Show all" button, which used a dark-theme blue on white.
  • 458 passed, 33 skipped. Four new tests cover the chips, the traversal primitives, the synthetic distance column, and the row cap.

Pinning two points now traces the tree path between them: the map
highlights the connecting edges and the inspector lists every node along
the way with its step number and running tree distance. A second control
colours the whole map by tree distance from the selected point.

These were only reachable from Python (model.path, distances_from) even
though the tree layout is what the tool is pitched on.

Both are one breadth-first walk over the adjacency index the neighbourhood
explorer already builds, so nothing new is written to the exported HTML;
the file grows by 20 KB regardless of dataset size. A walk costs 4 ms on a
200k-point map and 12 ms at 1M, and repeating it from the same anchor is
free. Scratch buffers cost 12 bytes per point.

- The Neighbors and Path chips replace the "Show neighborhood" toggle.
  The chip picks what the list below it contains, so no panel or toolbar
  button is added. Path is disabled until a second point is pinned.
- Distance colouring registers a synthetic column and hands it to the
  existing Color by menu, so the legend, colormap and selector work
  unmodified.
- Path lists start at 20 rows behind a "Show all" button. Rendering a
  216-node path in full was the slowest thing the inspector did (277 ms
  at 200k points, versus 111 ms capped).
@afloresep
afloresep merged commit da86caa into master Aug 22, 2026
6 checks 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.

1 participant