Skip to content

Commit 86a7e08

Browse files
committedMay 9, 2019
Merge branch 'master' into visjs-network-community
2 parents 2aa7b23 + 20dde9d commit 86a7e08

File tree

1 file changed

+54
-23
lines changed

1 file changed

+54
-23
lines changed
 

‎README.md

+54-23
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,71 @@ This component takes three vis.js configuration objects as properties:
2121
# Usage
2222

2323
```javascript
24-
import Graph from 'react-graph-vis';
25-
26-
const graph = {
27-
nodes: [
28-
{id: 1, label: 'Node 1'},
29-
{id: 2, label: 'Node 2'},
30-
{id: 3, label: 'Node 3'},
31-
{id: 4, label: 'Node 4'},
32-
{id: 5, label: 'Node 5'}
24+
import React from "react";
25+
import ReactDOM from "react-dom";
26+
import Graph from "react-graph-vis";
27+
28+
import "./styles.css";
29+
// need to import the vis network css in order to show tooltip
30+
import "./network.css";
31+
32+
function App() {
33+
const graph = {
34+
nodes: [
35+
{ id: 1, label: "Node 1", title: "node 1 tootip text" },
36+
{ id: 2, label: "Node 2", title: "node 2 tootip text" },
37+
{ id: 3, label: "Node 3", title: "node 3 tootip text" },
38+
{ id: 4, label: "Node 4", title: "node 4 tootip text" },
39+
{ id: 5, label: "Node 5", title: "node 5 tootip text" }
3340
],
34-
edges: [
35-
{from: 1, to: 2},
36-
{from: 1, to: 3},
37-
{from: 2, to: 4},
38-
{from: 2, to: 5}
41+
edges: [
42+
{ from: 1, to: 2 },
43+
{ from: 1, to: 3 },
44+
{ from: 2, to: 4 },
45+
{ from: 2, to: 5 }
3946
]
40-
};
47+
};
4148

42-
const options = {
49+
const options = {
4350
layout: {
44-
hierarchical: true
51+
hierarchical: true
4552
},
4653
edges: {
47-
color: "#000000"
48-
}
49-
};
54+
color: "#000000"
55+
},
56+
height: "500px"
57+
};
5058

51-
const events = {
59+
const events = {
5260
select: function(event) {
53-
var { nodes, edges } = event;
61+
var { nodes, edges } = event;
5462
}
63+
};
64+
return (
65+
<Graph
66+
graph={graph}
67+
options={options}
68+
events={events}
69+
getNetwork={network => {
70+
// if you want access to vis.js network api you can set the state in a parent component using this property
71+
}}
72+
/>
73+
);
5574
}
5675

57-
React.render(<Graph graph={graph} options={options} events={events} />, document.body);
76+
const rootElement = document.getElementById("root");
77+
ReactDOM.render(<App />, rootElement);
78+
5879
```
5980

81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
6091
You can also check out the demo in the [`example`](https://github.com/crubier/react-graph-vis/tree/master/example) folder.

0 commit comments

Comments
 (0)
Please sign in to comment.