index.community/frontend/src/components/Graph.jsx

57 lines
1.6 KiB
React
Raw Normal View History

import * as React from 'react';
import { connect } from 'react-redux';
2018-09-03 18:15:28 +00:00
import { Sigma, SigmaEnableWebGL, Filter, ForceAtlas2 } from 'react-sigma';
2018-09-01 17:24:05 +00:00
import { selectAndLoadInstance } from '../redux/actions';
const STYLE = {
bottom: "0",
left: "0",
position: "absolute",
right: "0",
top: "50px",
}
const SETTINGS = {
defaultEdgeColor: "#5C7080",
2018-09-01 17:54:13 +00:00
defaultLabelColor: "#F5F8FA",
defaultNodeColor: "#CED9E0",
drawEdges: true,
drawLabels: true,
edgeColor: "default",
2018-09-01 17:54:13 +00:00
labelColor: "default",
2018-09-03 18:15:28 +00:00
labelThreshold: 10,
maxEdgeSize: 1,
minEdgeSize: 0.3,
}
class GraphImpl extends React.Component {
render() {
if (!this.props.graph) {
return null;
}
return (
<Sigma
graph={this.props.graph}
renderer="webgl"
settings={SETTINGS}
style={STYLE}
2018-09-01 17:24:05 +00:00
onClickNode={(e) => this.props.selectAndLoadInstance(e.data.node.label)}
onClickStage={(e) => this.props.selectAndLoadInstance(null)}
>
<Filter neighborsOf={this.props.currentInstanceName} />
2018-09-03 18:15:28 +00:00
<ForceAtlas2 iterationsPerRender={1} timeout={6000}/>
</Sigma>
)
}
}
const mapStateToProps = (state) => ({
2018-09-01 17:24:05 +00:00
currentInstanceName: state.currentInstance.currentInstanceName,
graph: state.data.graph,
})
const mapDispatchToProps = (dispatch) => ({
2018-09-01 17:24:05 +00:00
selectAndLoadInstance: (instanceName) => dispatch(selectAndLoadInstance(instanceName)),
})
export const Graph = connect(mapStateToProps, mapDispatchToProps)(GraphImpl)