CytoscapeをReactJSで使用しようとしていますが、単純なコンポーネントに何も表示されていないものがあります。CytoscapeとReactJSの統合
ここにコードがあります。私は、静的なグラフを表示しようとしているので、私はエッジとノードをハードコーディングしているので、空のオブジェクトをmapStateToPropsに戻しています。 "^ 2.7.6"、 "反応": "^ 15.2.1"、ここで
がCyctoscapeである私が使用していますCytoscapeのバージョンは私のpackage.jsonから
"cytoscape" でありますjsbin私は私のサンプルを使用しています。
任意の助けに感謝。
おかげ
import React,{Component} from 'react';
import cytoscape from 'cytoscape';
import {connect} from 'react-redux';
import { bindActionCreators } from 'redux';
class GraphContainer extends React.Component{
constructor(props){
super(props);
this.renderCytoscapeElement = this.renderCytoscapeElement.bind(this);
}
renderCytoscapeElement(){
console.log('* Cytoscape.js is rendering the graph..');
this.cy = cytoscape(
{
container: document.getElementById('cy'),
boxSelectionEnabled: false,
autounselectify: true,
style: cytoscape.stylesheet()
.selector('node')
.css({
'height': 80,
'width': 80,
'background-fit': 'cover',
'border-color': '#000',
'border-width': 3,
'border-opacity': 0.5,
'content': 'data(name)',
'text-valign': 'center',
})
.selector('edge')
.css({
'width': 6,
'target-arrow-shape': 'triangle',
'line-color': '#ffaaaa',
'target-arrow-color': '#ffaaaa',
'curve-style': 'bezier'
})
,
elements: {
nodes: [
{ data: { id: 'cat' } },
{ data: { id: 'bird' } },
{ data: { id: 'ladybug' } },
{ data: { id: 'aphid' } },
{ data: { id: 'rose' } },
{ data: { id: 'grasshopper' } },
{ data: { id: 'plant' } },
{ data: { id: 'wheat' } }
],
edges: [
{ data: { source: 'cat', target: 'bird' } },
{ data: { source: 'bird', target: 'ladybug' } },
{ data: { source: 'bird', target: 'grasshopper' } },
{ data: { source: 'grasshopper', target: 'plant' } },
{ data: { source: 'grasshopper', target: 'wheat' } },
{ data: { source: 'ladybug', target: 'aphid' } },
{ data: { source: 'aphid', target: 'rose' } }
]
},
layout: {
name: 'breadthfirst',
directed: true,
padding: 10
}
});
}
componentDidMount(){
this.renderCytoscapeElement();
}
render(){
return(
<div className="node_selected">
<div id="cy"/>
</div>
)
}
}
function mapStateToProps(state){
return {};
}
export default connect(mapStateToProps,null)(GraphContainer);
これは機能するはずです。コンソール上の何か? cytoscapeにデフォルトのエクスポートがない場合は、{cytoscape}をインポートします。 – vijayst
コンソールにエラーはありません。私はrenderCytoscapeElement()からconsole.logを見ているので、インポートに何も問題はないと思います。私がインポートしたものをあなたが私にエラーがあると示唆したものに置き換えたときGraphContainer.js?faef:24Uncaught TypeError:未定義のプロパティ 'stylesheet'を読むことができません –