Skip to content

Commit

Permalink
Support expanding all layers through initial ui state.
Browse files Browse the repository at this point in the history
Set deepestExpandedGroupNodeIds to ['___all___']

PiperOrigin-RevId: 669105037
  • Loading branch information
Google AI Edge authored and copybara-github committed Aug 30, 2024
1 parent 21874a7 commit db7065e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/ui/src/components/visualizer/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export function getDeepestExpandedGroupNodeIds(
root: GroupNode | undefined,
modelGraph: ModelGraph,
deepestExpandedGroupNodeIds: string[],
ignoreExpandedState = false,
) {
let nsChildrenIds: string[] = [];
if (root == null) {
Expand All @@ -183,17 +184,25 @@ export function getDeepestExpandedGroupNodeIds(
if (!childNode) {
continue;
}
if (isGroupNode(childNode) && childNode.expanded) {
const isDeepest = (childNode.nsChildrenIds || [])
.filter((id) => isGroupNode(modelGraph.nodesById[id]))
.every((id) => !(modelGraph.nodesById[id] as GroupNode).expanded);
if (
isGroupNode(childNode) &&
(ignoreExpandedState || (!ignoreExpandedState && childNode.expanded))
) {
const nsChildrenIds = childNode.nsChildrenIds || [];
const isDeepest = ignoreExpandedState
? nsChildrenIds.filter((id) => isGroupNode(modelGraph.nodesById[id]))
.length === 0
: nsChildrenIds
.filter((id) => isGroupNode(modelGraph.nodesById[id]))
.every((id) => !(modelGraph.nodesById[id] as GroupNode).expanded);
if (isDeepest) {
deepestExpandedGroupNodeIds.push(childNode.id);
}
getDeepestExpandedGroupNodeIds(
childNode,
modelGraph,
deepestExpandedGroupNodeIds,
ignoreExpandedState,
);
}
}
Expand Down
19 changes: 18 additions & 1 deletion src/ui/src/components/visualizer/webgl_renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {
} from './common/types';
import {
genUid,
getDeepestExpandedGroupNodeIds,
getHighQualityPixelRatio,
getNodeStyleValue,
hasNonEmptyQueries,
Expand Down Expand Up @@ -766,9 +767,25 @@ export class WebglRenderer implements OnInit, OnDestroy {
if (!paneState) {
initGraphFn();
} else {
// Expand all layers if paneState.deepestExpandedGroupNodeIds has only
// one elemenet '___all___'.
let deepestExpandedGroupNodeIds = paneState.deepestExpandedGroupNodeIds;
if (
deepestExpandedGroupNodeIds.length === 1 &&
deepestExpandedGroupNodeIds[0] === '___all___'
) {
const groupNodeIds: string[] = [];
getDeepestExpandedGroupNodeIds(
undefined,
this.curModelGraph,
groupNodeIds,
true,
);
deepestExpandedGroupNodeIds = groupNodeIds;
}
this.sendRelayoutGraphRequest(
paneState.selectedNodeId,
paneState.deepestExpandedGroupNodeIds,
deepestExpandedGroupNodeIds,
true,
);
// This is needed for loading old perma-link.
Expand Down

0 comments on commit db7065e

Please sign in to comment.