index.html 906 B

123456789101112131415161718192021222324252627282930313233343536
  1. <head>
  2. <style> body { margin: 30px; } </style>
  3. <script src="//unpkg.com/element-resize-detector/dist/element-resize-detector.min.js"></script>
  4. <script src="//unpkg.com/3d-force-graph"></script>
  5. <!-- <script src="../../dist/3d-force-graph.js"></script>-->
  6. </head>
  7. <body>
  8. <div id="3d-graph"></div>
  9. <script>
  10. // Random tree
  11. const N = 300;
  12. const gData = {
  13. nodes: [...Array(N).keys()].map(i => ({ id: i })),
  14. links: [...Array(N).keys()]
  15. .filter(id => id)
  16. .map(id => ({
  17. source: id,
  18. target: Math.round(Math.random() * (id-1))
  19. }))
  20. };
  21. const Graph = ForceGraph3D()
  22. (document.getElementById('3d-graph'))
  23. .height(window.innerHeight - 60)
  24. .graphData(gData);
  25. elementResizeDetectorMaker().listenTo(
  26. document.getElementById('3d-graph'),
  27. el => Graph.width(el.offsetWidth)
  28. );
  29. </script>
  30. </body>