-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
64 lines (57 loc) · 1.3 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import "babel-polyfill";
import React, { Component } from "react";
import { connect } from "react-redux";
import { Graph, DefaultLink, DefaultNode } from "@vx/network";
import { getNodes, getLinks, initialize, tick } from "redux-force";
class App extends Component {
componentDidMount() {
this.props.initialize();
}
componentWillUpdate() {
window.requestAnimationFrame(this.props.tick);
}
get x() {
return -this.props.width / 2;
}
get y() {
return -this.props.height / 2;
}
get viewBox() {
return `${this.x} ${this.y} ${this.props.width} ${this.props.height}`;
}
render() {
return (
<div>
<svg width={this.props.width} height={this.props.height} viewBox={this.viewBox}>
<rect
x={this.x}
y={this.y}
width={this.props.width}
height={this.props.height}
rx={14}
fill="#272b4d"
/>
<Graph
graph={this.props.dataSample}
linkComponent={DefaultLink}
nodeComponent={DefaultNode}
/>
</svg>
</div>
);
}
}
export default connect(
state => ({
dataSample: {
nodes: getNodes(state),
links: getLinks(state),
},
width: 800,
height: 600,
}),
{
initialize,
tick,
}
)(App);