简体   繁体   English

React 中的 CytoscapeJS:运行布局

[英]CytoscapeJS in React: run the layout

I have cytoscape in react using plotly's cytoscape for react, here .我有 cytoscape 使用 plotly 的 cytoscape 进行反应, here

I have performed the following steps:我执行了以下步骤:

// import and register the layouts
import Cytoscape from 'cytoscape';  
import COSEBilkent from 'cytoscape-cose-bilkent'; 

Cytoscape.use(COSEBilkent);  

And I am rendering my graph inside the component (elements are properly formed):我在组件内渲染我的图形(元素正确形成):

render() {
...
let elements = ...
const layout = {name:'cose-bilkent'}; 
...
<Cytoscape
elements={elements} 
style={{width:'1635px',height:'1114px'}} 
layout={layout}
/>

And yet the nodes retain their default positions upon rendering.然而,节点在渲染时保留其默认位置。 I have not yet had much time to work with react.我还没有太多时间来处理 react。 Is there a simple step that I am missing in order to get this graph to render with a layout?是否有一个简单的步骤是我遗漏的,以便使用布局呈现该图形?

You need to import another library.您需要导入另一个库。 Such that:这样:

// import and register the layouts
import Cytoscape from "cytoscape";
import CytoscapeComponent from "react-cytoscapejs";
import COSEBilkent from "cytoscape-cose-bilkent";

Cytoscape.use(COSEBilkent);

And then call the React component:然后调用 React 组件:

<CytoscapeComponent /> instead of <Cytoscape /> as you have done.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM