Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions frontend/src/components/treeView/hooks/useTreeViewData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,27 @@ export const useTreeViewData = ({
const getLayoutedElements = useCallback(
(nodes: CustomNode[], edges: CustomEdge[], direction = 'LR') => {
const { currentZoom } = useZoomStore.getState();
const scaleFactor = Math.max(0.5, Math.min(2.0, currentZoom));
const clampedZoom = Math.max(0.5, Math.min(2.0, currentZoom));
const BASE_NODE_WIDTH = 146;
const BASE_NODE_HEIGHT = 30;
const BASE_NODE_SEP = 60;
const BASE_RANK_SEP = 150;

const isCompressedZoom = clampedZoom <= 0.6;
const spacingScaleX = isCompressedZoom ? 3 : 1;
const spacingScaleY = isCompressedZoom ? 2 : 1;

const effectiveNodeWidth = BASE_NODE_WIDTH * clampedZoom;
const effectiveNodeHeight = BASE_NODE_HEIGHT * clampedZoom;
const nodeSep = BASE_NODE_SEP * clampedZoom * spacingScaleX;
const rankSep = BASE_RANK_SEP * clampedZoom * spacingScaleY;

const dagreGraph = new dagre.graphlib.Graph();
dagreGraph.setDefaultEdgeLabel(() => ({}));
dagreGraph.setGraph({
rankdir: direction,
nodesep: 50 * scaleFactor, // Increased from 30
ranksep: 130 * scaleFactor, // Increased from 60
nodesep: nodeSep,
ranksep: rankSep,
});

const nodeMap = new Map<string, CustomNode>();
Expand All @@ -147,8 +160,8 @@ export const useTreeViewData = ({
const cachedNode = nodeMap.get(node.id);
if (!cachedNode || !isEqual(cachedNode, node) || shouldRecalculate) {
dagreGraph.setNode(node.id, {
width: 146 * scaleFactor,
height: 30 * scaleFactor, // Match the actual node height from zoom store
width: effectiveNodeWidth,
height: effectiveNodeHeight, // Match the actual node height from zoom store
});
newNodes.push(node);
} else {
Expand All @@ -168,8 +181,8 @@ export const useTreeViewData = ({
? {
...node,
position: {
x: dagreNode.x - 73 * scaleFactor + 50 * scaleFactor,
y: dagreNode.y - 15 * scaleFactor + 50 * scaleFactor, // This is correct: 30/2 = 15
x: dagreNode.x - effectiveNodeWidth / 2 + 50,
y: dagreNode.y - effectiveNodeHeight / 2 + 50, // Keep padding consistent while using scaled height
},
}
: node;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/wds_topology/ZoomControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ export const ZoomControls = memo<ZoomControlsProps>(
animation: `${bounceIn} 0.6s ease-out`,
width: 'fit-content',
minWidth: 'fit-content',
maxWidth: 'calc(100vw - clamp(20px, 40px, 4vw))',
maxWidth: 'min(calc(100vw - clamp(20px, 40px, 4vw)), calc(100% - 16px))',
zIndex: 5,
maxHeight: 'calc(100vh - clamp(20px, 40px, 4vh))',
maxHeight: 'min(calc(100vh - clamp(20px, 40px, 4vh)), calc(100% - 16px))',
overflowY: 'auto',
overflowX: 'hidden',
overscrollBehavior: 'contain',
Expand Down
Loading