f5 / unovis

Modular data visualization framework for React, Angular, Svelte, Vue, and vanilla TypeScript or JavaScript
https://unovis.dev
Apache License 2.0
2.23k stars 43 forks source link

Force graph doesn't have force physics after rendering #393

Closed mossy426 closed 3 months ago

mossy426 commented 4 months ago

This might be a misunderstanding, but we have properties for "force" in the layout settings like so:

type GraphForceLayoutSettings = {
  /** Preferred Link Distance. Default: `60` */
  linkDistance?: number;
  /** Link Strength [0:1]. Default: `0.45` */
  linkStrength?: number;
  /** Charge Force (<0 repulsion, >0 attraction). Default: `-500` */
  charge?: number;
  /** X-centring force. Default: `0.15` */
  forceXStrength?: number;
  /** Y-centring force. Default: `0.25` */
  forceYStrength?: number;
}

And we also have the "fixNodePositionAfterSimulation" property within that as well.

It doesn't seem to matter if you set fixNodePositionAfterSimulation to true or false. Even in the gallery you guys have, the nodes are always fixed. It seems the only force for a force graph is upon initialization of the graph, otherwise everything is pinned and not acted on by forces.

In our Microbetrace application, you can change the charge, force strength, etc. of the network at any time. Is this not possible in Unovis?/Are all nodes pinned after instantiation regardless of whatever layout you choose?

Might be more of a discussion than an issue, but please let me know :)

rokotyan commented 4 months ago

@mossy426 Can you please tell which version of Unovis do you use?

We had a bug in the code that has been fixed in one of the latest betas but didn't make it to the main release yet.

mossy426 commented 4 months ago

All good! I'm using the 1.4.1 build. Should I switch to another?

rokotyan commented 4 months ago

@mossy426 It turned out that 1.4.1 doesn't contain the fix that was published in 1.4.1-alpha.8. We'll be releasing 1.4.2 soon. In the meantime, can you please check if it work on 1.4.1-alpha.8 for you?

mossy426 commented 4 months ago

@rokotyan I updated the environment on stackblitz for a quick test to use 1.4.1-alpha.8 for both packages and it appears to still not work, even with fixNodePositionAfterSimulation set to false. https://stackblitz.com/edit/angular-zyybxk?file=src%2Fforce-graph%2Fforce-graph.component.ts

rokotyan commented 4 months ago

Thanks @mossy426! I think I know what was causing this. I've just published new package versions 1.4.2-alpha.2 to test. They should fix the problem

mossy426 commented 4 months ago

Great! Thanks, please let me know when I can try it out

rokotyan commented 4 months ago

@mossy426 Strange, NPM shows it's there. Let's wait a bit and I'll try to release another version if it still doesn't work.

image SCR-20240604-pium
mossy426 commented 4 months ago

Interesting, yes it might take a bit I guess? I'm getting an unable to resolve package error when trying that. I'll check back later.

mossy426 commented 4 months ago

@rokotyan Ok I was able to download both packages for 1.4.2-alpha.2. It still seems like the nodes are all fixed on load. Stackblitz for reference in case I'm missing something:

https://stackblitz.com/edit/angular-zyybxk?file=src%2Fforce-graph%2Fforce-graph.component.ts

rokotyan commented 4 months ago

@mossy426 Thanks, investigating

rokotyan commented 4 months ago

@mossy426 I've tried your example on my end with different fixNodePositionAfterSimulation values and here is what I see

fixNodePositionAfterSimulation: true

https://github.com/f5/unovis/assets/755708/1d7459bc-34c3-4c7a-bd09-7796bf8540a4

fixNodePositionAfterSimulation: false

https://github.com/f5/unovis/assets/755708/906430eb-8fc0-440a-98a4-9259e97c0d6b

Can you please tell us a bit more about what behavior you're expecting?

mossy426 commented 4 months ago

@rokotyan Oh wow ok I'm sorry I should have clarified better. I mean with the force graphs in d3 we are using, the forces are always active. Here the forces are only active on load and then all the nodes become fixed, or unaffected by forces and stay in place now matter how you move other nodes around.

For instance, in the force graph I'm talking about, if we were to take a node and move it around the network, you would see the surrounding nodes kind of move out of the way and readjust due to the forces the nodes give off.

Here the nodes are fixed in that no forces affect them after launch. If they weren't fixed, I could then adjust the forces like link strength, center force, etc. in a variety of ways that would animate and help shape the network to what the user is looking for much more easily.

Does that make sense?

rokotyan commented 4 months ago

@mossy426 Ah, I get it now, thanks for the clarification!

We intentionally disabled animated force layout because:

  1. With the level of detail our nodes have, real-time updates can be slow, especially on old hardware;
  2. While the force simulation animation looks nice, we couldn't find the actual use case for it.

In your specific case, if you adjust the forces, you should still be able to see the updated layout on the graph. However, the animation won't look as organic as the force layout generally does because the node positions are simply interpolated between the two states. Or are you experiencing issues with this too?

mossy426 commented 4 months ago

Got it, thanks! We should be good. I'll let you know if we need anything.