frewsxcv / frewsxcv/graphosaurus

Incorrect logic related to hover/click events

Open
#82 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
391
Forks
48
PR merge metrics
No merged PRs in 30d

Description

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]);

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.