-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathVisGraph.tsx
More file actions
87 lines (74 loc) · 2.12 KB
/
VisGraph.tsx
File metadata and controls
87 lines (74 loc) · 2.12 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'use client'
import React, { useRef, useEffect } from 'react'
import HelpIcon from '../HelpIcon/HelpIcon'
import {Node, Edge, Options} from 'src/data/queries/relatedWorks'
import {DataSet, Network} from 'vis-network/standalone'
import styles from './VisGraph.module.scss'
interface VisNetworkProps {
nodes: Node[];
edges: Edge[];
options?: Options;
}
const VisNetwork: React.FC<VisNetworkProps> = ({ nodes, edges, options }) => {
const networkRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const container = networkRef.current;
if (container) {
const data = {
nodes: new DataSet<Node>(nodes),
edges: new DataSet<Edge>(edges),
};
// Network options will be overridden if provided
const networkOptions: Options = options || {
autoResize: true,
height: '100%',
width: '100%',
interaction: {
zoomView: false,
dragView: true,
dragNodes: true,
hover: true,
hoverConnectedEdges: true,
selectConnectedEdges: true,
navigationButtons: true,
},
physics: {
enabled: true,
},
};
const network = new Network(container, data, networkOptions);
return () => {
network.destroy();
};
}
}, [nodes, edges, options]);
return <div ref={networkRef} style={{ width: '100%', height: '500px' }} />;
};
type VisGraphData = {
nodes: Node[]
edges: Edge[]
}
type Props = {
titleText: string | string[]
graph: VisGraphData
options?: Options
tooltipText?: string
}
const VisGraph: React.FunctionComponent<Props> = ({ titleText, graph, options, tooltipText }) => {
return (
<div className="panel panel-transparent">
<div className="panel-body production-chart">
<div className={styles.chartTitle}>
{titleText}
{tooltipText && <HelpIcon text={tooltipText} padding={25} position='inline' color='#34495E' />}
</div>
<VisNetwork
nodes={graph.nodes}
edges={graph.edges}
options={options}
/>
</div>
</div>
)
}
export default VisGraph