blob: 3a9692de6de01d00497e1942d6718408690be2a9 (
plain)
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
|
// JS module imports
import { useEffect, useRef, useState } from "react";
import Graph from 'vis-react';
// CSS imports
import '../css/Canvas.css';
/**
* This function renders and mantains thhe canvas.
* @param {Object} props The props for the canvas.
* @returns {import("react").HtmlHTMLAttributes} The canvas to be retured.
*/
function Visualization(props) {
const [graphState, setGraphState] = useState({
nodes: [],
edges: []
});
const getNodes = () => {
console.log(props.data)
let nodes = []
props.data.forEach(hub => {
nodes.push({
id: hub.id,
label: hub.name,
size: hub.suspicionScore * 25
});
});
return nodes;
}
const getEdges = () => {
let edges = []
props.data.forEach(hub => {
hub.followers.forEach(follower => {
edges.push({
from: hub.id,
to: follower.id
});
});
});
return edges;
}
// Hooks to update graph state
useEffect(() => setGraphState({nodes: getNodes(), edges: getEdges()}), []);
useEffect(() => setGraphState({nodes: getNodes(), edges: getEdges()}), [props.data]);
return (
<div className="Map-canvas">
<Graph
graph={graphState}>
</Graph>
</div>
);
}
export default Visualization;
|