Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect logic related to hover/click events #82

Open
frewsxcv opened this issue Jun 11, 2017 · 0 comments
Open

Incorrect logic related to hover/click events #82

frewsxcv opened this issue Jun 11, 2017 · 0 comments

Comments

@frewsxcv
Copy link
Owner

frewsxcv commented Jun 11, 2017

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]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant