Incorrect logic related to hover/click events
frewsxcv opened this issue · 0 comments
frewsxcv commented
I got an email from someone who is using the library. They're reporting the logic related to hovering/clicking on nodes is incorrect. Here's what they wrote:
the node ids that are returned refer to the
THREE.BufferGeometry node and not the Graph Node nodes.
Hence the label will always be incorrect.
I added a BufferAttribute to the BufferGeometry to map back to the
Graph Node ids.
Frame.prototype._syncNodeDataFromGraph = function () {
var nodes = this.graph.nodes();
var positions = new THREE.BufferAttribute(
new Float32Array(nodes.length * 3), 3);
var colors = new THREE.BufferAttribute(
new Float32Array(nodes.length * 3), 3);
//id array
var ids = new THREE.BufferAttribute(
new Float32Array(nodes.length), 1);
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
var pos = node._pos;
var color = node._color;
positions.setXYZ(i, this.scale * pos.x, this.scale *
pos.y, this.scale * pos.z);
colors.setXYZ(i, color.r, color.g, color.b);
ids.setX(i, node._id);
}
this.points.addAttribute('position', positions);
this.points.addAttribute('color', colors);
this.points.addAttribute('id', ids);
this.points.computeBoundingSphere();
this._normalizePositions();
this.positionCamera();
};
and
Frame.prototype._initMouseEvents = function (elem) {
..
var intersects =
raycaster.intersectObject(self.pointCloud);
if (intersects.length) {
var nodeIndex =
intersects[0].object.geometry.attributes.id.getX(intersects[0].index);
callback(self.graph._nodes[nodeIndex]);