每当我尝试旋转代码时,都会在开发控制台中收到以下错误。错误如下:
g++ -O3 -shared jj.cpp -o lib/jj.so
real 0m0.541s
user 0m0.483s
sys 0m0.045s
此处显示的错误代码的实时版本: https://s3.amazonaws.com/mnas/index.html
此处为实际代码:
Error: missing: 1 3d-force-graph:5:22166
TypeError: r.attributes.position is undefine
这是以下代码的分支: https://github.com/vasturiano/3d-force-graph/blob/master/example/click-to-focus/index.html
我唯一改变的是我替换了jsonUrl方法,以便可以代替地传递静态数据。
我已经尝试通过开发控制台进行调试,但似乎无法找出问题所在。
感谢您的帮助。
答案 0 :(得分:1)
您缺少“ id”属性
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<style> body { margin: 0; } </style>
<script src="//unpkg.com/3d-force-graph"></script>
<!--<script src="3d-force-graph.js"></script>-->
</head>
<body>
<div id="3d-graph"></div>
<script>
const elem = document.getElementById('3d-graph');
const Graph = ForceGraph3D()
(elem)
.graphData({"nodes":[{ "name": "Myriel","group": 1, "id" : 1},{ "name": "Napoleon","group": 1, "id": 2 }], links: [ { "source": 1, "target": 2, "value": 1 }]})
.nodeLabel('name')
.nodeAutoColorBy('group')
.onNodeHover(node => elem.style.cursor = node ? 'pointer' : null)
.onNodeClick(node => {
// Aim at node from outside it
const distance = 40;
const distRatio = 1 + distance/Math.hypot(node.x, node.y, node.z);
Graph.cameraPosition(
{ x: node.x * distRatio, y: node.y * distRatio, z: node.z * distRatio }, // new position
node, // lookAt ({ x, y, z })
3000 // ms transition duration
);
});
</script>
</body>