[javascript] Cytoscape.js에서 그래프의 레이아웃을 고정하여 영구적으로 유지하는 방법은 무엇인가요?

다음은 예제 코드입니다:

// Cytoscape 객체 생성
var cy = cytoscape({
  container: document.getElementById('cy'),
  
  // 그래프 요소 정의
  elements: {
    nodes: [
      { data: { id: 'node1' } },
      { data: { id: 'node2' } },
      { data: { id: 'node3' } }
    ],
    edges: [
      { data: { source: 'node1', target: 'node2' } },
      { data: { source: 'node2', target: 'node3' } }
    ]
  },
  
  // 그래프 레이아웃 설정
  layout: {
    name: 'preset',
    positions: {
      'node1': { x: 100, y: 100 },
      'node2': { x: 200, y: 200 },
      'node3': { x: 300, y: 300 }
    }
  },
  
  // 스타일 지정
  style: [
    {
      selector: 'node',
      style: {
        'background-color': 'red',
        'label': 'data(id)'
      }
    },
    {
      selector: 'edge',
      style: {
        'width': 3,
        'line-color': 'blue',
        'target-arrow-shape': 'triangle',
        'target-arrow-color': 'blue'
      }
    }
  ]
});

위의 코드에서는 preset 레이아웃을 사용하여 노드의 좌표를 고정하고 있습니다. name 속성에 preset을 지정하고, 각 노드의 좌표를 positions 속성에 설정합니다. 이렇게 하면 그래프의 레이아웃이 고정되어 영구적으로 유지됩니다.

자세한 내용은 Cytoscape.js 문서를 참조하세요.