@@ -21,40 +21,71 @@ This component takes three vis.js configuration objects as properties:
21
21
# Usage
22
22
23
23
``` 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" }
33
40
],
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 }
39
46
]
40
- };
47
+ };
41
48
42
- const options = {
49
+ const options = {
43
50
layout: {
44
- hierarchical: true
51
+ hierarchical: true
45
52
},
46
53
edges: {
47
- color: " #000000"
48
- }
49
- };
54
+ color: " #000000"
55
+ },
56
+ height: " 500px"
57
+ };
50
58
51
- const events = {
59
+ const events = {
52
60
select : function (event ) {
53
- var { nodes, edges } = event ;
61
+ var { nodes, edges } = event ;
54
62
}
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
+ );
55
74
}
56
75
57
- React .render (< Graph graph= {graph} options= {options} events= {events} / > , document .body );
76
+ const rootElement = document .getElementById (" root" );
77
+ ReactDOM .render (< App / > , rootElement);
78
+
58
79
```
59
80
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
60
91
You can also check out the demo in the [ ` example ` ] ( https://github.com/crubier/react-graph-vis/tree/master/example ) folder.
0 commit comments