Cytoscape布局预先设置为crashAll,并在展开节点组上更改布局

问题描述

我正在将cytoscape js与cytoscape和cytoscape undoRedo进行反应,然后cytoscape展开崩溃。在第一个渲染中,我想按预设进行布局(我具有所有节点的位置)。它工作正常,但是当我执行api.collapseAll()时,看起来节点没有这些位置。即使分组的节点与父节点的位置相同。在扩展上,我想使用cose bilkent布局。有办法吗?

import React,{ useRef,useEffect,useState } from 'react';
import Cytoscape from 'cytoscape';
import CytoscapeComponent from 'react-cytoscapejs';
import COSEBilkent from 'cytoscape-cose-bilkent';
import undoRedo from 'cytoscape-undo-redo';
import expandCollapse from 'cytoscape-expand-collapse';

const Test = ({}) => {
  const [cy,setCy] = useState(null);

  useEffect(() => {
    if (cy) {

      const api = cy.expandCollapse({
        layoutBy: {
          name: 'cose-bilkent',// name: 'preset',I want to have this layout on first render
          animate: 'end',randomize: false,fit: false
        },fisheye: true
      });
      cy.undoRedo();
      api.collapseAll();
    }
  },[cy]);
return (
    <CytoscapeComponent
      stylesheet={styles}
      cy={cy => {
        setCy(cy);
      }}
      elements={elements}
      style={{ width: '1200px',height: '1200px'}}
    />
  );
}

解决方法

是的,有可能。我是通过在crashAll方法中设置layoutBy来实现的;)