Skip to content

Commit 7b047b2

Browse files
committed
change graph to fit example
1 parent a1f9e94 commit 7b047b2

File tree

3 files changed

+45
-59
lines changed

3 files changed

+45
-59
lines changed

app/containers/Inspect.jsx

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect } from 'react';
22
import * as d3 from 'd3'; // Import D3 libraries here
33
import ForceGraph3D from '3d-force-graph'; // Import 3d-force-graph library here
44
import dat from 'dat.gui'; // Import dat.gui library here
5-
// import fs from 'fs';
5+
import '../stylesheets/Inspect.scss';
66

77
const Inspect = () => {
88
useEffect(() => {
@@ -34,40 +34,6 @@ const Inspect = () => {
3434
// Decrease repel intensity
3535
graph.d3Force('charge').strength(-15);
3636

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-
// });
7137

7238
fetch('http://localhost:1111/api/data')
7339
.then(r => r.text())
@@ -97,18 +63,44 @@ const Inspect = () => {
9763
}
9864
});
9965

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+
10086
graph(document.getElementById('graph'))
10187
.graphData({ nodes, links })
10288
.onNodeDragEnd(node => {
10389
node.fx = node.x;
10490
node.fy = node.y;
10591
node.fz = node.z;
106-
});
92+
})
93+
94+
10795
});
10896
}, []);
10997

11098

111-
return <div id="graph" />;
99+
return <div id="Infrastructure">
100+
<h2>Infrastructure</h2>
101+
<div id="graph" />;
102+
</div>
103+
// <div id="graph" />;
112104
};
113105

114106
export default Inspect;

app/stylesheets/Inspect.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
h2 {
2+
display: flex;
3+
justify-content: center;
4+
align-items: center;
5+
}

chronos_npm_package/server/data.csv

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
size,path
2-
,d3
3-
,d3/d3-array
4-
,d3/d3-array/threshold
5-
,d3/d3-axis
6-
,d3/d3-brush
7-
,d3/d3-chord
8-
,d3/d3-collection
9-
,d3/d3-color
10-
,d3/d3-dispatch
11-
,d3/d3-drag
12-
,d3/d3-dsv
13-
,d3/d3-ease
14-
,d3/d3-force
15-
,d3/d3-format
16-
,d3/d3-geo
17-
,d3/d3-geo/clip
18-
,d3/d3-geo/path
19-
,d3/d3-geo/projection
20-
,d3/d3-hierarchy
21-
,d3/d3-hierarchy/hierarchy
22-
,d3/d3-hierarchy/pack
23-
,d3/d3-hierarchy/treemap
2+
,default
3+
,default/service-backend
4+
,default/service-backend/pod
5+
,default/service-frontend
6+
,default/service-frontend/pod
7+
,default/service-grafana
8+
,default/service-grafana/pod
9+
,default/service-kubernetes
10+
,default/service-kubernetes/pod
11+
,default/service-prometheus
12+
,default/service-prometheus/pod

0 commit comments

Comments
 (0)