当前位置:   article > 正文

【前端可视化】3d-force-graph 3d力导向图(知识图谱相关)配置和使用

3d-force-graph

效果图

image

文档

可以先去官网看看文档或者看看我下面的参考博客,把基本配置看懂(英语差的同学可以看下面的翻译)。3d-force-graph使用及相关设置github.com/vasturiano/3d-force-graph3d-force-graph:文档翻译

配置

  1. // 初始化 3d
  2. function threeInit() {
  3. const relationData = _.cloneDeep(props.echartsData);
  4. const data = {
  5. links: relationData.edges,
  6. nodes: relationData.nodes,
  7. };
  8. const elm: any = document.getElementById("3d-graph");
  9. const width = elm.offsetWidth;
  10. const height = elm.offsetHeight;
  11. let CSS2DRendererItem: any = new CSS2DRenderer();
  12. Graph = ForceGraph3D({
  13. extraRenderers: [CSS2DRendererItem],
  14. })(elm).graphData(data);
  15. Graph.numDimensions(3) // 维度 3 就是 3d
  16. .width(width)
  17. .height(height)
  18. .backgroundColor("#f3f5fa")
  19. .showNavInfo(false)
  20. /* 节点配置 */
  21. .nodeRelSize(8)
  22. .nodeColor((node: any) => colorMap[node.label])
  23. .nodeOpacity(1)
  24. .nodeResolution(30) // 节点分辨率
  25. .nodeLabel((node: any) => `<div class='node-label2'>${node.name}</div>`)
  26. .nodeThreeObjectExtend(true)
  27. .nodeThreeObject((node: any) => {
  28. const nodeEl = document.createElement("div");
  29. nodeEl.textContent = node.name;
  30. nodeEl.className = "node-label";
  31. nodeEl.style.color = colorMap[node.label];
  32. return new CSS2DObject(nodeEl);
  33. })
  34. .onNodeHover((node: any) => {
  35. elm.style.cursor = node ? "pointer" : null;
  36. })
  37. .onNodeClick((node: any) => {
  38. // 首页点击节点聚焦
  39. if (store.routerName === "home" && node.name !== focusNodeName) {
  40. focusNodeName = node.name;
  41. focusNode(node);
  42. }
  43. // 故障推理点击节点
  44. if (store.routerName === "fault") {
  45. tempNode = node;
  46. emit("nodesClcik", node);
  47. }
  48. })
  49. /* 边配置 */
  50. .linkLabel((link: any) => {
  51. return `<div class='link-label'>${lineTextMap[link.type]}</div>`;
  52. })
  53. .onLinkHover((node: any) => {
  54. elm.style.cursor = node ? "pointer" : null;
  55. })
  56. .linkDirectionalArrowLength(3) // 边的指向箭头长度
  57. .linkDirectionalArrowRelPos(1) // 边的标签显示(鼠标滑到边上显示)
  58. .linkColor((link: any) => "#727279")
  59. .linkOpacity(1);
  60. cameraCenter();
  61. }
  62. // 聚焦 3d 节点
  63. function focusNode(node: any) {
  64. const distance = 200;
  65. const distRatio = 1 + distance / Math.hypot(node.x, node.y, node.z);
  66. Graph.cameraPosition(
  67. {
  68. x: node.x * distRatio,
  69. y: node.y * distRatio,
  70. z: node.z * distRatio,
  71. }, // new position
  72. node, // lookAt ({ x, y, z })
  73. 2000 // ms transition duration)
  74. );
  75. }
  76. // 3d 镜头拉近
  77. function cameraCenter(x: any = -300, y: any = 30, z: any = 30) {
  78. Graph.cameraPosition({
  79. x: x,
  80. y: y,
  81. z: z,
  82. });
  83. }

参考博客

3D知识图谱可视化3d-force-graph示例学习记录在Vue中使用3d-force-graph渲染neo4j图谱

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/132726
推荐阅读
相关标签
  

闽ICP备14008679号