Skip to content

Commit

Permalink
롤백
Browse files Browse the repository at this point in the history
  • Loading branch information
dutexion committed Sep 27, 2024
1 parent e4dad59 commit 6517d3e
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions src/components/servicemap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,49 +110,35 @@ const ServiceMap: React.FC = () => {

const calculateReferences = () => {
const references: Record<string, number> = {};
const callers: Record<string, number> = {};

edges.forEach((edge) => {
references[edge.target] = (references[edge.target] || 0) + edge.calls; // 참조를 당하는 노드
callers[edge.source] = (callers[edge.source] || 0) + edge.calls; // 참조를 하는 노드
references[edge.target] = (references[edge.target] || 0) + edge.calls;
});

return { references, callers };
return references;
};

const layoutNodes = () => {
const centerX = 600;
const centerY = 400;
const maxRadius = 400; // 최대 반경 증가
const maxRadius = 300;
const minRadius = 100;
const positions: Record<string, { x: number; y: number }> = {};
const { references, callers } = calculateReferences();
const references = calculateReferences();

// Find max reference count for normalization
const maxReferences = Math.max(...Object.values(references));
const maxCallers = Math.max(...Object.values(callers));

nodes.forEach((node, index) => {
const angle = (index / nodes.length) * 2 * Math.PI;
const referenceCount = references[node.node_id] || 0;
const callerCount = callers[node.node_id] || 0;

// Normalized positions based on reference and caller counts
const normalizedX = (callerCount / maxCallers) * (maxRadius - minRadius) + minRadius; // 왼쪽
const normalizedXRight = (referenceCount / maxReferences) * (maxRadius - minRadius) + minRadius; // 오른쪽

// x 좌표는 참조를 하는 노드와 참조를 당하는 노드에 따라 조정
const x = centerX - normalizedX + normalizedXRight; // 왼쪽과 오른쪽 배치 조합

// y 좌표를 각 노드의 인덱스에 따라 조정하여 분산
const angle = (index / nodes.length) * 2 * Math.PI; // 원형 배치
const radius = minRadius + (maxRadius - minRadius) * (Math.random() * 0.5); // 랜덤하게 반경 조정
// Normalize radius based on reference count (more references = smaller radius)
const normalizedRadius = maxRadius - (referenceCount / maxReferences) * (maxRadius - minRadius);

positions[node.node_id] = {
x: x + radius * Math.cos(angle), // 분산된 x 좌표
y: centerY + radius * Math.sin(angle), // 분산된 y 좌표
x: centerX + normalizedRadius * Math.cos(angle),
y: centerY + normalizedRadius * Math.sin(angle),
};
});

return positions;
};

Expand Down

0 comments on commit 6517d3e

Please sign in to comment.