Skip to content

Commit

Permalink
frontend Map: Move graph constants in a separate file
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Dubenko <[email protected]>
  • Loading branch information
sniok committed Dec 10, 2024
1 parent 6086750 commit da2a758
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions frontend/src/components/resourceMap/GraphRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import React from 'react';
import { useTranslation } from 'react-i18next';
import { Loader } from '../common';
import { KubeRelationEdge } from './edges/KubeRelationEdge';
import { maxZoom, minZoom } from './graphConstants';
import { GraphControls } from './GraphControls';
import { GroupNodeComponent } from './nodes/GroupNode';
import { KubeGroupNodeComponent } from './nodes/KubeGroupNode';
Expand Down Expand Up @@ -81,8 +82,8 @@ export function GraphRenderer({
onBackgroundClick?.();
}
}}
minZoom={0.1}
maxZoom={2.0}
minZoom={minZoom}
maxZoom={maxZoom}
connectionMode={ConnectionMode.Loose}
>
<Background variant={BackgroundVariant.Dots} style={{ color: theme.palette.divider }} />
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/components/resourceMap/GraphView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
} from './graph/graphGrouping';
import { applyGraphLayout } from './graph/graphLayout';
import { GraphNode, GraphSource, GroupNode, isGroup, KubeObjectNode } from './graph/graphModel';
import { viewportPaddingPx } from './graphConstants';
import { GraphControlButton } from './GraphControls';
import { GraphRenderer } from './GraphRenderer';
import { NodeHighlight, useNodeHighlight } from './NodeHighlight';
Expand Down Expand Up @@ -162,16 +163,14 @@ function GraphViewContent({
(nodes: Node[]) => {
const bounds = getNodesBounds(nodes);

const defaultViewportPaddingPx = 50;

const topLeftOrigin = { x: defaultViewportPaddingPx, y: defaultViewportPaddingPx };
const topLeftOrigin = { x: viewportPaddingPx, y: viewportPaddingPx };
const centerOrigin = {
x: reactFlowWidth / 2 - bounds.width / 2,
y: reactFlowHeight / 2 - bounds.height / 2,
};

const xFits = bounds.width + defaultViewportPaddingPx * 2 <= reactFlowWidth;
const yFits = bounds.height + defaultViewportPaddingPx * 2 <= reactFlowHeight;
const xFits = bounds.width + viewportPaddingPx * 2 <= reactFlowWidth;
const yFits = bounds.height + viewportPaddingPx * 2 <= reactFlowHeight;

const defaultZoomViewport = {
x: xFits ? centerOrigin.x : topLeftOrigin.x,
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/resourceMap/graphConstants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const minZoom = 0.1;
export const maxZoom = 2.0;
export const viewportPaddingPx = 50;

0 comments on commit da2a758

Please sign in to comment.