@@ -2,7 +2,7 @@ import React, { useEffect } from 'react';
2
2
import * as d3 from 'd3' ; // Import D3 libraries here
3
3
import ForceGraph3D from '3d-force-graph' ; // Import 3d-force-graph library here
4
4
import dat from 'dat.gui' ; // Import dat.gui library here
5
- // import fs from 'fs ';
5
+ import '../stylesheets/Inspect.scss ';
6
6
7
7
const Inspect = ( ) => {
8
8
useEffect ( ( ) => {
@@ -34,40 +34,6 @@ const Inspect = () => {
34
34
// Decrease repel intensity
35
35
graph . d3Force ( 'charge' ) . strength ( - 15 ) ;
36
36
37
- // fs.readFile('./d3-dependencies.csv', 'utf8', function (err, data) {
38
- // if (err) {
39
- // return console.log(err);
40
- // } else {
41
- // console.log(data);
42
- // const nodes = [], links = [];
43
- // data.forEach(({ size, path }) => {
44
- // const levels = path.split('/'),
45
- // level = levels.length - 1,
46
- // module = level > 0 ? levels[1] : null,
47
- // leaf = levels.pop(),
48
- // parent = levels.join('/');
49
-
50
- // const node = {
51
- // path,
52
- // leaf,
53
- // module,
54
- // size: +size || 20,
55
- // level
56
- // };
57
-
58
- // nodes.push(node);
59
-
60
- // if (parent) {
61
- // links.push({ source: parent, target: path, targetNode: node });
62
- // }
63
- // });
64
-
65
-
66
-
67
- // graph(document.getElementById('graph'))
68
- // .graphData({ nodes, links });
69
- // }
70
- // });
71
37
72
38
fetch ( 'http://localhost:1111/api/data' )
73
39
. then ( r => r . text ( ) )
@@ -97,18 +63,44 @@ const Inspect = () => {
97
63
}
98
64
} ) ;
99
65
66
+ const elem = document . getElementById ( 'graph' ) ;
67
+ const Graph = ForceGraph3D ( )
68
+ ( elem )
69
+ . onNodeClick ( node => {
70
+ // Aim at node from outside it
71
+ const distance = 40 ;
72
+ const distRatio = 1 + distance / Math . hypot ( node . x , node . y , node . z ) ;
73
+
74
+ const newPos = node . x || node . y || node . z
75
+ ? { x : node . x * distRatio , y : node . y * distRatio , z : node . z * distRatio }
76
+ : { x : 0 , y : 0 , z : distance } ; // special case if node is in (0,0,0)
77
+
78
+ Graph . cameraPosition (
79
+ newPos , // new position
80
+ node , // lookAt ({ x, y, z })
81
+ 3000 // ms transition duration
82
+ ) ;
83
+ } ) ;
84
+
85
+
100
86
graph ( document . getElementById ( 'graph' ) )
101
87
. graphData ( { nodes, links } )
102
88
. onNodeDragEnd ( node => {
103
89
node . fx = node . x ;
104
90
node . fy = node . y ;
105
91
node . fz = node . z ;
106
- } ) ;
92
+ } )
93
+
94
+
107
95
} ) ;
108
96
} , [ ] ) ;
109
97
110
98
111
- return < div id = "graph" /> ;
99
+ return < div id = "Infrastructure" >
100
+ < h2 > Infrastructure</ h2 >
101
+ < div id = "graph" /> ;
102
+ </ div >
103
+ // <div id="graph" />;
112
104
} ;
113
105
114
106
export default Inspect ;
0 commit comments