Hold the selection glide during a layout switch

- Do not start the glide to a newly selected node while the layout
  switches; the switch centers on the latest selection when it finishes.
- Only skip children at the same position in the child gap, so distinct
  children in a zoomed-out tree still get room.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
jbouwhandClaude Opus 5.5 committed 2026-12-01 12:09:31 +00:00
1 parent a7388ef5ec
commit cfbc45bb2e
3 files changed
+18 -4

No files matched your search

+8 -2
View File
@@ -488,8 +488,14 @@ export class HaNetworkGraph extends LitElement {
private _moveToSelectedNode() {
this._followSelectedNode = !!this.selectedNode;
this._stopSelectAnimation();
// Without a chart yet there is no view to glide from
if (this.selectedNode && this._baseChart?.chart && !this._reducedMotion) {
// Without a chart yet there is no view to glide from. A layout switch
// moves the view to the node once its nodes moved.
if (
this.selectedNode &&
this._baseChart?.chart &&
!this._reducedMotion &&
!this._layoutSwitching
) {
this._selectAnimationFrame = requestAnimationFrame(this._animateView);
}
this._updateFollowing();
+2 -2
View File
@@ -223,8 +223,8 @@ export const selectedNodeRoam = (
TREE_MIN_CHILD_GAP,
(child.size + previous.size) / 2 + TREE_CHILD_SPACING
);
// Hidden nodes fold onto their parent
if (gap >= 0.5) {
// Hidden nodes fold onto their parent, at the same position
if (gap > 0) {
targetZoom = Math.max(targetZoom, (zoom * needed) / gap);
}
}
@@ -272,6 +272,14 @@ describe("selectedNodeRoam in a tree layout", () => {
expect(roam?.zoom).toBeCloseTo(24 / 10);
});
it("gives room to children that are less than a pixel apart", () => {
const roam = selectedNodeRoam(treeView, { x: 100, y: 300 }, [
{ x: 300, y: 300, size: 20 },
{ x: 300, y: 300.4, size: 20 },
]);
expect(roam?.zoom).toBeCloseTo(28 / 0.4);
});
it("skips children folded onto each other", () => {
const roam = selectedNodeRoam(treeView, { x: 100, y: 300 }, [
{ x: 300, y: 300, size: 20 },