Reactjs 在“展开节点”组上使用collapseAll预设Cytoscape布局并更改布局

Reactjs 在“展开节点”组上使用collapseAll预设Cytoscape布局并更改布局,reactjs,cytoscape.js,Reactjs,Cytoscape.js,我正在使用cytoscape js,其中包含react cytoscape和cytoscape undoRedo以及cytoscape expand-collapse。在第一次渲染时,我希望按预设布局(我有所有节点的位置)。它工作得很好,但当我执行api.collapseAll()时,节点似乎没有这些位置。即使分组节点的位置与父节点相同。在展开中,我想使用cose bilkent布局。有办法吗 import React, { useRef, useEffect, useState } from

我正在使用cytoscape js,其中包含react cytoscape和cytoscape undoRedo以及cytoscape expand-collapse。在第一次渲染时,我希望按预设布局(我有所有节点的位置)。它工作得很好,但当我执行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'}}
    />
  );
}
import React,{useRef,useffect,useState}来自'React';
从“细胞景观”导入细胞景观;
从“react cytoscapejs”导入CytoscapeComponent;
从“cytoscape cose bilkent”进口COSEBilkent;
从“cytoscape撤消重做”导入撤消重做;
从“cytoscape expand collapse”导入expandCollapse;
常量测试=({})=>{
const[cy,setCy]=useState(null);
useffect(()=>{
if(cy){
常数api=cy.expandCollapse({
排班人:{
名称:“cose bilkent”,
//名称:“预设”,我希望在第一次渲染时使用此布局
设置动画:“结束”,
随机化:错误,
拟合:假
},
鱼眼:没错
});
cy.undoRedo();
api.collapseAll();
}
},[cy]);
返回(
{
赛西(赛西);
}}
元素={elements}
样式={{宽度:'1200px',高度:'1200px'}}
/>
);
}

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