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

Face Coloring for Cluster Visualization #21

Open
pitwegner opened this issue Oct 12, 2019 · 5 comments
Open

Face Coloring for Cluster Visualization #21

pitwegner opened this issue Oct 12, 2019 · 5 comments

Comments

@pitwegner
Copy link

pitwegner commented Oct 12, 2019

Is your feature request related to a problem? Please describe.
I want to visualize clusters by coloring the space between the nodes that belong to that cluster.

Describe the solution you'd like
I want to provide an array of node arrays that represent the different clusters, potentially but not necessarily overlapping. Then the space inbetween these nodes should be colored using distinct colors (basically color the faces between edges/links between the nodes, the convex hull).

My call would look like that:

const Graph = ForceGraph3D()(document.getElementById("3d-graph"));
Graph.resetProps();
Graph.cooldownTicks(200)
        .nodeLabel('name')
        .enableClusterVisualization(true)
        .jsonUrl('some-data.json')

with the json in the form of:

{
    "nodes": [
        {
            "id": "id1",
            "name": "name1",
            "val": 1
        },
        {
            "id": "id2",
            "name": "name2",
            "val": 10
        },
        (...)
    ],
    "links": [
        {
            "source": "id1",
            "target": "id2"
        },
        (...)
    ],
    "clusters": [
        ["id1", "id2"],
        ["id3", "id4"],
        (...)
    ]
}

Describe alternatives you've considered
Just coloring the nodes is not enough (e.g. for overlapping clusters).

@pitwegner
Copy link
Author

pitwegner commented Oct 12, 2019

I'd implement it myself, if you could give me a hint where to start :)
Or is there maybe an accessor for the graphScene and node positions that I could extend the functionality in my own application?
Doesn't look too hard in Three: https://threejs.org/docs/#examples/en/geometries/ConvexGeometry

@vasturiano
Copy link
Owner

@pitwegner thanks for reaching out. This is a good idea, but I'd recommend doing this outside of this library to not bloat the functionality.

If you're using three-forcegraph you are in control of the scene where the graph is placed, so you can add any additional elements that you wish. If using 3d-force-graph, you can access the scene object with myGraph.scene(). Here's an example where the scene gets extended.

As for the node objects, you can always access the data itself, and look for the x, y and z attributes in each of the nodes, representing their current coordinates.

This should give you enough leverage to compute the convex hull of your node clusters and render additional Three objects that represent their geometries.

Let me know if you get it to work. 👍

@pitwegner
Copy link
Author

pitwegner commented Oct 13, 2019

That's what I figured also :) Got it to work with your hint to retrieve the objects from the scene. Yet I do have an occlusion problem of the nodes now. Even though my convex hull has an opacity of only 0.1, the nodes vanish behind some faces for some angles (see attached example).
Screenshot from 2019-10-13 11-06-56 Screenshot from 2019-10-13 11-10-07

@vasturiano
Copy link
Owner

vasturiano commented Oct 13, 2019

@pitwegner very nice!
And I've seen some of those rendering issues before. Could it be that you're not rendering both sides of the material? https://threejs.org/docs/#api/en/materials/Material.side

I would like to understand why this occurs, so do let me know if you get to the bottom of it.

Also, would you consider contributing a node cluster example to 3d-force-graph?

@pitwegner
Copy link
Author

That was my first impression as well, but rendering both sides didn‘t change anything related to disappearing nodes.

Oh, surely I can open a pull request to include my example :) Then you can also have a look at the occlusion culling :D

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

2 participants